hot key directive: fix issue when setting numbers as hotkeys + if a hotkey only consist of one key, disable keyboard shortcut in input's.

This commit is contained in:
Mads Rasmussen
2015-07-15 12:25:02 +02:00
parent d7aed9069d
commit c3a30cccfb

View File

@@ -6,23 +6,30 @@ angular.module("umbraco.directives")
.directive('hotkey', function ($window, keyboardService, $log) {
return function (scope, el, attrs) {
//support data binding
var keyCombo = scope.$eval(attrs["hotkey"]);
var options = {};
var keyCombo = attrs.hotkey;
if (!keyCombo) {
keyCombo = attrs["hotkey"];
//support data binding
keyCombo = scope.$eval(attrs["hotkey"]);
}
keyboardService.bind(keyCombo, function() {
var element = $(el);
// disable shortcuts in input fields if keycombo is 1 character
if(keyCombo.length === 1) {
options = {
inputDisabled: true
};
}
keyboardService.bind(keyCombo, function(){
var element = $(el);
if(element.is("a,div,button,input[type='button'],input[type='submit'],input[type='checkbox']") && !element.is(':disabled') ){
element.click();
}else{
element.focus();
}
});
}, options);
el.on('$destroy', function(){
keyboardService.unbind(keyCombo);