Browse Source

Some code optimisations.

j8
yanas 8 years ago
parent
commit
2b492883ca
1 changed files with 14 additions and 16 deletions
  1. 14
    16
      modules/keyboardshortcut/keyboardshortcut.js

+ 14
- 16
modules/keyboardshortcut/keyboardshortcut.js View File

82
         $('body').popover({ selector: '[data-toggle=popover]',
82
         $('body').popover({ selector: '[data-toggle=popover]',
83
             trigger: 'click hover',
83
             trigger: 'click hover',
84
             content: function() {
84
             content: function() {
85
-                var shortcutAttr = this.getAttribute("shortcut");
86
-
87
-                var shortcutString = (shortcutAttr)
88
-                                        ? self._getShortcutTooltip(shortcutAttr)
89
-                                        : "";
90
-                return this.getAttribute("content") + shortcutString;
85
+                return this.getAttribute("content")
86
+                    + self._getShortcutTooltip(this.getAttribute("shortcut"));
91
             }
87
             }
92
         });
88
         });
93
     },
89
     },
130
     },
126
     },
131
 
127
 
132
     /**
128
     /**
129
+     * Returns the tooltip string for the given shortcut attribute.
133
      *
130
      *
134
-     * @param id indicates the popover associated with the shortcut
135
-     * @returns {string} the keyboard shortcut used for the id given
131
+     * @param shortcutAttr indicates the popover associated with the shortcut
132
+     * @returns {string} the tooltip string to add to the given shortcut popover
133
+     * or an empty string if the shortcutAttr is null, an empty string or not
134
+     * found in the shortcut mapping
136
      */
135
      */
137
-    _getShortcutTooltip: function (id) {
138
-        if (!id || id.length <= 0)
139
-            return "";
140
-
141
-        for (var key in _shortcuts) {
142
-            if (_shortcuts.hasOwnProperty(key)) {
143
-                if (_shortcuts[key].shortcutAttr
144
-                    && _shortcuts[key].shortcutAttr === id) {
136
+    _getShortcutTooltip: function (shortcutAttr) {
137
+        if (typeof shortcutAttr === "string" && shortcutAttr.length > 0) {
138
+            for (var key in _shortcuts) {
139
+                if (_shortcuts.hasOwnProperty(key)
140
+                    && _shortcuts[key].shortcutAttr
141
+                    && _shortcuts[key].shortcutAttr === shortcutAttr) {
145
                     return " (" + _shortcuts[key].character + ")";
142
                     return " (" + _shortcuts[key].character + ")";
146
                 }
143
                 }
147
             }
144
             }
148
         }
145
         }
146
+
149
         return "";
147
         return "";
150
     },
148
     },
151
     /**
149
     /**

Loading…
Cancel
Save