mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
refactor: Use stateChange hook for releasing keybinding
This commit is contained in:
@@ -264,10 +264,18 @@ habitrpg.controller("InventoryCtrl",
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.$on("habit:keydown", function (e, keyEvent) {
|
var listenForEscape = function (event) {
|
||||||
if (keyEvent.keyCode == "27") {
|
if (event.keyCode === 27) {
|
||||||
$scope.deselectItem();
|
$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() {
|
$scope.deselectItem = function() {
|
||||||
|
|||||||
@@ -308,16 +308,15 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.hoverIn = function () {
|
document.addEventListener('keydown', isCtrlPressed);
|
||||||
document.addEventListener('keydown', isCtrlPressed);
|
document.addEventListener('keyup', isCtrlLetGo);
|
||||||
document.addEventListener('keyup', isCtrlLetGo);
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.hoverOut = function () {
|
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams, options){
|
||||||
$scope.ctrlPressed = false;
|
if (toState.name.indexOf('tasks') < 0) {
|
||||||
document.removeEventListener('keydown', isCtrlPressed);
|
document.removeEventListener('keydown', isCtrlPressed);
|
||||||
document.removeEventListener('keyup', isCtrlLetGo);
|
document.removeEventListener('keyup', isCtrlLetGo);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
------------------------
|
------------------------
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
script(id='partials/main.html', type="text/ng-template")
|
script(id='partials/main.html', type="text/ng-template")
|
||||||
include ./filters
|
include ./filters
|
||||||
div(ng-controller='TasksCtrl', ng-mouseenter="hoverIn()", ng-mouseleave="hoverOut()")
|
div(ng-controller='TasksCtrl')
|
||||||
habitrpg-tasks(main='true', obj='user')
|
habitrpg-tasks(main='true', obj='user')
|
||||||
|
|||||||
Reference in New Issue
Block a user