Refactor to allow usage of getKeyboardEvent in behavior
This change consists of some minor refactoring of keyboard-shortcut-behavior.html to allow for its use in elements that have the behavior. Also fixes some incorrect bower paths that resulted in flaky and/or failing tests. Bug: Issue 5109, Issue 6217 Change-Id: I3a73036b2e34372fe1bf4de836e11bb88b1d0e5f
This commit is contained in:
@@ -20,24 +20,24 @@ limitations under the License.
|
||||
(function(window) {
|
||||
'use strict';
|
||||
|
||||
// Must be declared outside behavior implementation to be accessed inside
|
||||
// behavior functions.
|
||||
const getKeyboardEvent = function(e) {
|
||||
return Polymer.dom(e.detail ? e.detail.keyboardEvent : e);
|
||||
e = Polymer.dom(e.detail ? e.detail.keyboardEvent : e);
|
||||
// When e is a keyboardEvent, e.event is not null.
|
||||
if (e.event) { e = e.event; }
|
||||
return e;
|
||||
};
|
||||
|
||||
/** @polymerBehavior KeyboardShortcutBehaviorImpl */
|
||||
const KeyboardShortcutBehaviorImpl = {
|
||||
modifierPressed(e) {
|
||||
e = getKeyboardEvent(e);
|
||||
// When e is a keyboardEvent, e.event is not null.
|
||||
if (e.event) { e = e.event; }
|
||||
return e.altKey || e.ctrlKey || e.metaKey || e.shiftKey;
|
||||
},
|
||||
|
||||
isModifierPressed(e, modifier) {
|
||||
e = getKeyboardEvent(e);
|
||||
// When e is a keyboardEvent, e.event is not null.
|
||||
if (e.event) { e = e.event; }
|
||||
return e[modifier];
|
||||
return getKeyboardEvent(e)[modifier];
|
||||
},
|
||||
|
||||
shouldSuppressKeyboardShortcut(e) {
|
||||
@@ -50,6 +50,11 @@ limitations under the License.
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
// Alias for getKeyboardEvent.
|
||||
getKeyboardEvent(e) {
|
||||
return getKeyboardEvent(e);
|
||||
},
|
||||
};
|
||||
|
||||
window.Gerrit = window.Gerrit || {};
|
||||
|
||||
Reference in New Issue
Block a user