Deselect food, egg, and potion when hitting the escape key

This commit is contained in:
TheHollidayInn
2015-07-21 21:52:29 -05:00
parent 11f56d491c
commit 107e27a2c6
3 changed files with 44 additions and 1 deletions

View File

@@ -89,4 +89,27 @@ describe('Inventory Controller', function() {
expect(user.balance).to.eql(3.25);
expect(user.items.eggs).to.eql({Cactus: 1, Wolf: 1})
}));
describe('Deselecting Items', function() {
it('deselects a food', function(){
scope.chooseFood('Meat');
scope.deselectItem();
expect(scope.selectedFood).to.eql(null);
});
it('deselects a potion', function(){
scope.choosePotion('Base');
scope.deselectItem();
expect(scope.selectedPotion).to.eql(null);
});
it('deselects a egg', function(){
scope.chooseEgg('Cactus');
scope.deselectItem();
expect(scope.selectedEgg).to.eql(null);
});
});
});

View File

@@ -211,5 +211,25 @@ habitrpg.controller("InventoryCtrl",
break;
}
};
$scope.$on("habit:keyup", function (e, keyEvent) {
if (keyEvent.keyCode == "27") {
$scope.deselectItem();
}
});
//$scope.listen(keyEvent)
$scope.deselectItem = function() {
if ($scope.selectedFood) {
$scope.selectedFood = null;
}
if ($scope.selectedPotion) {
$scope.selectedPotion = null
}
if ($scope.selectedEgg) {
$scope.selectedEgg = null;
}
}
}
]);

View File

@@ -1,6 +1,6 @@
doctype html
//html(ng-app="habitrpg", ng-controller="RootCtrl", ng-class='{"applying-action":applyingAction}', ui-keypress="{27:'castCancel()'}")
html(ng-app="habitrpg", ng-controller="RootCtrl", ng-class='{"applying-action":applyingAction}', ui-keyup="{27:'castCancel()'}")
html(ng-app="habitrpg", ng-controller="RootCtrl", ng-class='{"applying-action":applyingAction}', ui-keyup="{27:'castCancel()'}", ng-keydown="$broadcast('habit:keyup', $event)")
head
title=env.t('titleIndex')
// ?v=1 needed to force refresh