From 8d511e0ce591f5d388ac2f3533908e563993aa9f Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Sat, 21 Sep 2019 13:16:20 +1000 Subject: [PATCH] Fixes broken hotkey implementation - Refs #4489 --- modules/system/assets/ui/js/input.hotkey.js | 17 +++++++++++------ modules/system/assets/ui/storm-min.js | 18 +++++++----------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/modules/system/assets/ui/js/input.hotkey.js b/modules/system/assets/ui/js/input.hotkey.js index 0fcb8e811..53f47e0bc 100644 --- a/modules/system/assets/ui/js/input.hotkey.js +++ b/modules/system/assets/ui/js/input.hotkey.js @@ -14,8 +14,9 @@ BaseProto = Base.prototype var HotKey = function (element, options) { - if (!options.hotkey) + if (!options.hotkey) { throw new Error('No hotkey has been defined.'); + } this.$el = $(element) this.$target = $(options.hotkeyTarget) @@ -34,8 +35,9 @@ HotKey.prototype.constructor = HotKey HotKey.prototype.dispose = function() { - if (this.$el === null) + if (this.$el === null) { return + } this.unregisterHandlers() @@ -94,8 +96,9 @@ condition.specific = this.keyMap[keys[keys.length-1]] - if (typeof (condition.specific) == 'undefined') + if (typeof (condition.specific) == 'undefined') { condition.specific = keys[keys.length-1].toUpperCase().charCodeAt() + } return condition } @@ -149,7 +152,7 @@ for (var i = 0, len = this.keyConditions.length; i < len; i++) { var condition = this.keyConditions[i] - if (ev.key === condition.specific + if (ev.which === condition.specific && ev.originalEvent.shiftKey === condition.shift && ev.originalEvent.ctrlKey === condition.ctrl && ev.originalEvent.metaKey === condition.cmd @@ -163,11 +166,13 @@ HotKey.prototype.onKeyDown = function(ev) { if (this.testConditions(ev)) { - if (this.options.hotkeyVisible && !this.$el.is(':visible')) + if (this.options.hotkeyVisible && !this.$el.is(':visible')) { return + } - if (this.options.callback) + if (this.options.callback) { return this.options.callback(this.$el, ev.currentTarget, ev) + } } } diff --git a/modules/system/assets/ui/storm-min.js b/modules/system/assets/ui/storm-min.js index e7dbf92aa..9a19caa4d 100644 --- a/modules/system/assets/ui/storm-min.js +++ b/modules/system/assets/ui/storm-min.js @@ -4128,8 +4128,8 @@ $.fn.changeMonitor.Constructor=ChangeMonitor $.fn.changeMonitor.noConflict=function(){$.fn.changeMonitor=old return this} $(document).render(function(){$('[data-change-monitor]').changeMonitor()})}(window.jQuery);+function($){"use strict";var Base=$.oc.foundation.base,BaseProto=Base.prototype -var HotKey=function(element,options){if(!options.hotkey) -throw new Error('No hotkey has been defined.');this.$el=$(element) +var HotKey=function(element,options){if(!options.hotkey){throw new Error('No hotkey has been defined.');} +this.$el=$(element) this.$target=$(options.hotkeyTarget) this.options=options||{} this.keyConditions=[] @@ -4139,8 +4139,7 @@ Base.call(this) this.init()} HotKey.prototype=Object.create(BaseProto) HotKey.prototype.constructor=HotKey -HotKey.prototype.dispose=function(){if(this.$el===null) -return +HotKey.prototype.dispose=function(){if(this.$el===null){return} this.unregisterHandlers() this.$el.removeData('oc.hotkey') this.$target=null @@ -4167,18 +4166,15 @@ break case'alt':case'option':condition.alt=true break}} condition.specific=this.keyMap[keys[keys.length-1]] -if(typeof(condition.specific)=='undefined') -condition.specific=keys[keys.length-1].toUpperCase().charCodeAt() +if(typeof(condition.specific)=='undefined'){condition.specific=keys[keys.length-1].toUpperCase().charCodeAt()} return condition} HotKey.prototype.initKeyMap=function(){this.keyMap={'esc':27,'tab':9,'space':32,'return':13,'enter':13,'backspace':8,'scroll':145,'capslock':20,'numlock':144,'pause':19,'break':19,'insert':45,'home':36,'delete':46,'suppr':46,'end':35,'pageup':33,'pagedown':34,'left':37,'up':38,'right':39,'down':40,'f1':112,'f2':113,'f3':114,'f4':115,'f5':116,'f6':117,'f7':118,'f8':119,'f9':120,'f10':121,'f11':122,'f12':123}} HotKey.prototype.trim=function(str){return str.replace(/^\s+/,"").replace(/\s+$/,"")} HotKey.prototype.testConditions=function(ev){for(var i=0,len=this.keyConditions.length;i