refactor: Use stateChange hook for releasing keybinding

This commit is contained in:
Blade Barringer
2016-06-03 21:33:15 -05:00
parent 7536ba7aa2
commit 8c81e02a87
3 changed files with 19 additions and 12 deletions

View File

@@ -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() {