From 7858c157c1080c129dfb70e9443e25c19eb20189 Mon Sep 17 00:00:00 2001 From: yanas Date: Mon, 29 Aug 2016 23:56:20 -0500 Subject: [PATCH 1/2] Fix shortcut appearing in tooltip of wrong buttons --- modules/keyboardshortcut/keyboardshortcut.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/keyboardshortcut/keyboardshortcut.js b/modules/keyboardshortcut/keyboardshortcut.js index 9c1258cad..8e8015725 100644 --- a/modules/keyboardshortcut/keyboardshortcut.js +++ b/modules/keyboardshortcut/keyboardshortcut.js @@ -82,8 +82,12 @@ var KeyboardShortcut = { $('body').popover({ selector: '[data-toggle=popover]', trigger: 'click hover', content: function() { - return this.getAttribute("content") + - self._getShortcut(this.getAttribute("shortcut")); + var shortcutAttr = this.getAttribute("shortcut"); + + var shortcutString = (shortcutAttr) + ? self._getShortcutTooltip(shortcutAttr) + : ""; + return this.getAttribute("content") + shortcutString; } }); }, @@ -130,10 +134,14 @@ var KeyboardShortcut = { * @param id indicates the popover associated with the shortcut * @returns {string} the keyboard shortcut used for the id given */ - _getShortcut: function (id) { + _getShortcutTooltip: function (id) { + if (!id || id.length <= 0) + return ""; + for (var key in _shortcuts) { if (_shortcuts.hasOwnProperty(key)) { - if (_shortcuts[key].shortcutAttr === id) { + if (_shortcuts[key].shortcutAttr + && _shortcuts[key].shortcutAttr === id) { return " (" + _shortcuts[key].character + ")"; } } From 2b492883ca86e2e77e76e7076eae16a498935b12 Mon Sep 17 00:00:00 2001 From: yanas Date: Tue, 30 Aug 2016 14:14:52 -0500 Subject: [PATCH 2/2] Some code optimisations. --- modules/keyboardshortcut/keyboardshortcut.js | 30 +++++++++----------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/modules/keyboardshortcut/keyboardshortcut.js b/modules/keyboardshortcut/keyboardshortcut.js index 8e8015725..7a54b7321 100644 --- a/modules/keyboardshortcut/keyboardshortcut.js +++ b/modules/keyboardshortcut/keyboardshortcut.js @@ -82,12 +82,8 @@ var KeyboardShortcut = { $('body').popover({ selector: '[data-toggle=popover]', trigger: 'click hover', content: function() { - var shortcutAttr = this.getAttribute("shortcut"); - - var shortcutString = (shortcutAttr) - ? self._getShortcutTooltip(shortcutAttr) - : ""; - return this.getAttribute("content") + shortcutString; + return this.getAttribute("content") + + self._getShortcutTooltip(this.getAttribute("shortcut")); } }); }, @@ -130,22 +126,24 @@ var KeyboardShortcut = { }, /** + * Returns the tooltip string for the given shortcut attribute. * - * @param id indicates the popover associated with the shortcut - * @returns {string} the keyboard shortcut used for the id given + * @param shortcutAttr indicates the popover associated with the shortcut + * @returns {string} the tooltip string to add to the given shortcut popover + * or an empty string if the shortcutAttr is null, an empty string or not + * found in the shortcut mapping */ - _getShortcutTooltip: function (id) { - if (!id || id.length <= 0) - return ""; - - for (var key in _shortcuts) { - if (_shortcuts.hasOwnProperty(key)) { - if (_shortcuts[key].shortcutAttr - && _shortcuts[key].shortcutAttr === id) { + _getShortcutTooltip: function (shortcutAttr) { + if (typeof shortcutAttr === "string" && shortcutAttr.length > 0) { + for (var key in _shortcuts) { + if (_shortcuts.hasOwnProperty(key) + && _shortcuts[key].shortcutAttr + && _shortcuts[key].shortcutAttr === shortcutAttr) { return " (" + _shortcuts[key].character + ")"; } } } + return ""; }, /**