From c3a30cccfbe2044d79ea5ca9f68aefeba4be56e8 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Wed, 15 Jul 2015 12:25:02 +0200 Subject: [PATCH] hot key directive: fix issue when setting numbers as hotkeys + if a hotkey only consist of one key, disable keyboard shortcut in input's. --- .../directives/util/hotkey.directive.js | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/util/hotkey.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/util/hotkey.directive.js index 9ffc3eddb8..475d4cac4b 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/util/hotkey.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/util/hotkey.directive.js @@ -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);