mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-18 09:52:20 +00:00
refactor: Use stateChange hook for releasing keybinding
This commit is contained in:
parent
7536ba7aa2
commit
8c81e02a87
3 changed files with 19 additions and 12 deletions
|
|
@ -264,10 +264,18 @@ habitrpg.controller("InventoryCtrl",
|
|||
}
|
||||
};
|
||||
|
||||
$scope.$on("habit:keydown", function (e, keyEvent) {
|
||||
if (keyEvent.keyCode == "27") {
|
||||
var listenForEscape = function (event) {
|
||||
if (event.keyCode === 27) {
|
||||
$scope.deselectItem();
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('keydown', listenForEscape);
|
||||
|
||||
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams, options){
|
||||
if (toState.name.indexOf('options.inventory') < 0) {
|
||||
document.removeEventListener('keydown', listenForEscape);
|
||||
}
|
||||
});
|
||||
|
||||
$scope.deselectItem = function() {
|
||||
|
|
|
|||
|
|
@ -308,16 +308,15 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
|
|||
}
|
||||
}
|
||||
|
||||
$scope.hoverIn = function () {
|
||||
document.addEventListener('keydown', isCtrlPressed);
|
||||
document.addEventListener('keyup', isCtrlLetGo);
|
||||
}
|
||||
document.addEventListener('keydown', isCtrlPressed);
|
||||
document.addEventListener('keyup', isCtrlLetGo);
|
||||
|
||||
$scope.hoverOut = function () {
|
||||
$scope.ctrlPressed = false;
|
||||
document.removeEventListener('keydown', isCtrlPressed);
|
||||
document.removeEventListener('keyup', isCtrlLetGo);
|
||||
}
|
||||
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams, options){
|
||||
if (toState.name.indexOf('tasks') < 0) {
|
||||
document.removeEventListener('keydown', isCtrlPressed);
|
||||
document.removeEventListener('keyup', isCtrlLetGo);
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
------------------------
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
script(id='partials/main.html', type="text/ng-template")
|
||||
include ./filters
|
||||
div(ng-controller='TasksCtrl', ng-mouseenter="hoverIn()", ng-mouseleave="hoverOut()")
|
||||
div(ng-controller='TasksCtrl')
|
||||
habitrpg-tasks(main='true', obj='user')
|
||||
|
|
|
|||
Loading…
Reference in a new issue