Files
gerrit/polygerrit-ui/app/behaviors/keyboard-shortcut-behavior.html
Logan Hanks c11e5a7a49 Declare behaviors with @polymerBehavior
This makes polymer lint happy.

Change-Id: If7808d901635bfa9b0757ab9bf57257808cf1ce0
2016-06-15 14:27:30 -07:00

69 lines
2.1 KiB
HTML

<!--
Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<link rel="import" href="../bower_components/polymer/polymer.html">
<script>
(function(window) {
'use strict';
/** @polymerBehavior Gerrit.KeyboardShortcutBehavior */
var KeyboardShortcutBehavior = {
enabled: true,
properties: {
keyEventTarget: {
type: Object,
value: function() { return this; },
},
_boundKeyHandler: {
type: Function,
readonly: true,
value: function() { return this._handleKey.bind(this); },
},
},
attached: function() {
this.keyEventTarget.addEventListener('keydown', this._boundKeyHandler);
},
detached: function() {
this.keyEventTarget.removeEventListener('keydown', this._boundKeyHandler);
},
shouldSupressKeyboardShortcut: function(e) {
if (!KeyboardShortcutBehavior.enabled) { return true; }
var getModifierState = e.getModifierState ?
e.getModifierState.bind(e) :
function() { return false; };
var target = e.detail ? e.detail.keyboardEvent : e.target;
return getModifierState('Control') ||
getModifierState('Alt') ||
getModifierState('Meta') ||
getModifierState('Fn') ||
target.tagName == 'INPUT' ||
target.tagName == 'TEXTAREA' ||
target.tagName == 'SELECT' ||
target.tagName == 'BUTTON' ||
target.tagName == 'A' ||
target.tagName == 'GR-BUTTON';
},
};
window.Gerrit = window.Gerrit || {};
window.Gerrit.KeyboardShortcutBehavior = KeyboardShortcutBehavior;
})(window);
</script>