| Index: polymer_1.2.3/bower_components/iron-a11y-keys-behavior/iron-a11y-keys-behavior.html
|
| diff --git a/polymer_1.0.4/bower_components/iron-a11y-keys-behavior/iron-a11y-keys-behavior.html b/polymer_1.2.3/bower_components/iron-a11y-keys-behavior/iron-a11y-keys-behavior.html
|
| similarity index 71%
|
| copy from polymer_1.0.4/bower_components/iron-a11y-keys-behavior/iron-a11y-keys-behavior.html
|
| copy to polymer_1.2.3/bower_components/iron-a11y-keys-behavior/iron-a11y-keys-behavior.html
|
| index 47b7ee635d1ee651c170f397354da385532fbff5..50331d915102f652fe5b36696a86f5da5aa1e3be 100644
|
| --- a/polymer_1.0.4/bower_components/iron-a11y-keys-behavior/iron-a11y-keys-behavior.html
|
| +++ b/polymer_1.2.3/bower_components/iron-a11y-keys-behavior/iron-a11y-keys-behavior.html
|
| @@ -21,46 +21,10 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
| * Values taken from: http://www.w3.org/TR/2007/WD-DOM-Level-3-Events-20071221/keyset.html#KeySet-Set
|
| */
|
| var KEY_IDENTIFIER = {
|
| + 'U+0008': 'backspace',
|
| 'U+0009': 'tab',
|
| 'U+001B': 'esc',
|
| 'U+0020': 'space',
|
| - 'U+002A': '*',
|
| - 'U+0030': '0',
|
| - 'U+0031': '1',
|
| - 'U+0032': '2',
|
| - 'U+0033': '3',
|
| - 'U+0034': '4',
|
| - 'U+0035': '5',
|
| - 'U+0036': '6',
|
| - 'U+0037': '7',
|
| - 'U+0038': '8',
|
| - 'U+0039': '9',
|
| - 'U+0041': 'a',
|
| - 'U+0042': 'b',
|
| - 'U+0043': 'c',
|
| - 'U+0044': 'd',
|
| - 'U+0045': 'e',
|
| - 'U+0046': 'f',
|
| - 'U+0047': 'g',
|
| - 'U+0048': 'h',
|
| - 'U+0049': 'i',
|
| - 'U+004A': 'j',
|
| - 'U+004B': 'k',
|
| - 'U+004C': 'l',
|
| - 'U+004D': 'm',
|
| - 'U+004E': 'n',
|
| - 'U+004F': 'o',
|
| - 'U+0050': 'p',
|
| - 'U+0051': 'q',
|
| - 'U+0052': 'r',
|
| - 'U+0053': 's',
|
| - 'U+0054': 't',
|
| - 'U+0055': 'u',
|
| - 'U+0056': 'v',
|
| - 'U+0057': 'w',
|
| - 'U+0058': 'x',
|
| - 'U+0059': 'y',
|
| - 'U+005A': 'z',
|
| 'U+007F': 'del'
|
| };
|
|
|
| @@ -72,6 +36,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
| * Values from: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent.keyCode#Value_of_keyCode
|
| */
|
| var KEY_CODE = {
|
| + 8: 'backspace',
|
| 9: 'tab',
|
| 13: 'enter',
|
| 27: 'esc',
|
| @@ -94,10 +59,10 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
| * in a KeyboardEvent instance.
|
| */
|
| var MODIFIER_KEYS = {
|
| - shift: 'shiftKey',
|
| - ctrl: 'ctrlKey',
|
| - alt: 'altKey',
|
| - meta: 'metaKey'
|
| + 'shift': 'shiftKey',
|
| + 'ctrl': 'ctrlKey',
|
| + 'alt': 'altKey',
|
| + 'meta': 'metaKey'
|
| };
|
|
|
| /**
|
| @@ -105,8 +70,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
| * the keyboard, with unprintable keys labeled nicely.
|
| *
|
| * However, on OS X, Alt+char can make a Unicode character that follows an
|
| - * Apple-specific mapping. In this case, we
|
| - * fall back to .keyCode.
|
| + * Apple-specific mapping. In this case, we fall back to .keyCode.
|
| */
|
| var KEY_CHAR = /[a-z0-9*]/;
|
|
|
| @@ -126,18 +90,24 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
| */
|
| var SPACE_KEY = /^space(bar)?/;
|
|
|
| - function transformKey(key) {
|
| + /**
|
| + * Transforms the key.
|
| + * @param {string} key The KeyBoardEvent.key
|
| + * @param {Boolean} [noSpecialChars] Limits the transformation to
|
| + * alpha-numeric characters.
|
| + */
|
| + function transformKey(key, noSpecialChars) {
|
| var validKey = '';
|
| if (key) {
|
| var lKey = key.toLowerCase();
|
| - if (lKey.length == 1) {
|
| - if (KEY_CHAR.test(lKey)) {
|
| + if (lKey === ' ' || SPACE_KEY.test(lKey)) {
|
| + validKey = 'space';
|
| + } else if (lKey.length == 1) {
|
| + if (!noSpecialChars || KEY_CHAR.test(lKey)) {
|
| validKey = lKey;
|
| }
|
| } else if (ARROW_KEY.test(lKey)) {
|
| validKey = lKey.replace('arrow', '');
|
| - } else if (SPACE_KEY.test(lKey)) {
|
| - validKey = 'space';
|
| } else if (lKey == 'multiply') {
|
| // numpad '*' can map to Multiply on IE/Windows
|
| validKey = '*';
|
| @@ -151,8 +121,11 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
| function transformKeyIdentifier(keyIdent) {
|
| var validKey = '';
|
| if (keyIdent) {
|
| - if (IDENT_CHAR.test(keyIdent)) {
|
| + if (keyIdent in KEY_IDENTIFIER) {
|
| validKey = KEY_IDENTIFIER[keyIdent];
|
| + } else if (IDENT_CHAR.test(keyIdent)) {
|
| + keyIdent = parseInt(keyIdent.replace('U+', '0x'), 16);
|
| + validKey = String.fromCharCode(keyIdent).toLowerCase();
|
| } else {
|
| validKey = keyIdent.toLowerCase();
|
| }
|
| @@ -183,24 +156,45 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
| return validKey;
|
| }
|
|
|
| - function normalizedKeyForEvent(keyEvent) {
|
| - // fall back from .key, to .keyIdentifier, to .keyCode, and then to
|
| - // .detail.key to support artificial keyboard events
|
| - return transformKey(keyEvent.key) ||
|
| + /**
|
| + * Calculates the normalized key for a KeyboardEvent.
|
| + * @param {KeyboardEvent} keyEvent
|
| + * @param {Boolean} [noSpecialChars] Set to true to limit keyEvent.key
|
| + * transformation to alpha-numeric chars. This is useful with key
|
| + * combinations like shift + 2, which on FF for MacOS produces
|
| + * keyEvent.key = @
|
| + * To get 2 returned, set noSpecialChars = true
|
| + * To get @ returned, set noSpecialChars = false
|
| + */
|
| + function normalizedKeyForEvent(keyEvent, noSpecialChars) {
|
| + // Fall back from .key, to .keyIdentifier, to .keyCode, and then to
|
| + // .detail.key to support artificial keyboard events.
|
| + return transformKey(keyEvent.key, noSpecialChars) ||
|
| transformKeyIdentifier(keyEvent.keyIdentifier) ||
|
| transformKeyCode(keyEvent.keyCode) ||
|
| - transformKey(keyEvent.detail.key) || '';
|
| + transformKey(keyEvent.detail.key, noSpecialChars) || '';
|
| }
|
|
|
| - function keyComboMatchesEvent(keyCombo, keyEvent) {
|
| - return normalizedKeyForEvent(keyEvent) === keyCombo.key &&
|
| - !!keyEvent.shiftKey === !!keyCombo.shiftKey &&
|
| - !!keyEvent.ctrlKey === !!keyCombo.ctrlKey &&
|
| - !!keyEvent.altKey === !!keyCombo.altKey &&
|
| - !!keyEvent.metaKey === !!keyCombo.metaKey;
|
| + function keyComboMatchesEvent(keyCombo, event) {
|
| + // For combos with modifiers we support only alpha-numeric keys
|
| + var keyEvent = normalizedKeyForEvent(event, keyCombo.hasModifiers);
|
| + return keyEvent === keyCombo.key &&
|
| + (!keyCombo.hasModifiers || (
|
| + !!event.shiftKey === !!keyCombo.shiftKey &&
|
| + !!event.ctrlKey === !!keyCombo.ctrlKey &&
|
| + !!event.altKey === !!keyCombo.altKey &&
|
| + !!event.metaKey === !!keyCombo.metaKey)
|
| + );
|
| }
|
|
|
| function parseKeyComboString(keyComboString) {
|
| + if (keyComboString.length === 1) {
|
| + return {
|
| + combo: keyComboString,
|
| + key: keyComboString,
|
| + event: 'keydown'
|
| + };
|
| + }
|
| return keyComboString.split('+').reduce(function(parsedKeyCombo, keyComboPart) {
|
| var eventParts = keyComboPart.split(':');
|
| var keyName = eventParts[0];
|
| @@ -208,6 +202,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|
|
| if (keyName in MODIFIER_KEYS) {
|
| parsedKeyCombo[MODIFIER_KEYS[keyName]] = true;
|
| + parsedKeyCombo.hasModifiers = true;
|
| } else {
|
| parsedKeyCombo.key = keyName;
|
| parsedKeyCombo.event = event || 'keydown';
|
| @@ -220,12 +215,11 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
| }
|
|
|
| function parseEventString(eventString) {
|
| - return eventString.split(' ').map(function(keyComboString) {
|
| + return eventString.trim().split(' ').map(function(keyComboString) {
|
| return parseKeyComboString(keyComboString);
|
| });
|
| }
|
|
|
| -
|
| /**
|
| * `Polymer.IronA11yKeysBehavior` provides a normalized interface for processing
|
| * keyboard commands that pertain to [WAI-ARIA best practices](http://www.w3.org/TR/wai-aria-practices/#kbd_general_binding).
|
| @@ -241,7 +235,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
| * `keys` property is pressed.
|
| *
|
| * @demo demo/index.html
|
| - * @polymerBehavior IronA11yKeysBehavior
|
| + * @polymerBehavior
|
| */
|
| Polymer.IronA11yKeysBehavior = {
|
| properties: {
|
| @@ -255,6 +249,15 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
| }
|
| },
|
|
|
| + /**
|
| + * If true, this property will cause the implementing element to
|
| + * automatically stop propagation on any handled KeyboardEvents.
|
| + */
|
| + stopKeyboardEventPropagation: {
|
| + type: Boolean,
|
| + value: false
|
| + },
|
| +
|
| _boundKeyHandlers: {
|
| type: Array,
|
| value: function() {
|
| @@ -312,14 +315,11 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|
|
| keyboardEventMatchesKeys: function(event, eventString) {
|
| var keyCombos = parseEventString(eventString);
|
| - var index;
|
| -
|
| - for (index = 0; index < keyCombos.length; ++index) {
|
| - if (keyComboMatchesEvent(keyCombos[index], event)) {
|
| + for (var i = 0; i < keyCombos.length; ++i) {
|
| + if (keyComboMatchesEvent(keyCombos[i], event)) {
|
| return true;
|
| }
|
| }
|
| -
|
| return false;
|
| },
|
|
|
| @@ -347,6 +347,15 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
| for (var eventString in this._imperativeKeyBindings) {
|
| this._addKeyBinding(eventString, this._imperativeKeyBindings[eventString]);
|
| }
|
| +
|
| + // Give precedence to combos with modifiers to be checked first.
|
| + for (var eventName in this._keyBindings) {
|
| + this._keyBindings[eventName].sort(function (kb1, kb2) {
|
| + var b1 = kb1[0].hasModifiers;
|
| + var b2 = kb2[0].hasModifiers;
|
| + return (b1 === b2) ? 0 : b1 ? -1 : 1;
|
| + })
|
| + }
|
| },
|
|
|
| _addKeyBinding: function(eventString, handlerName) {
|
| @@ -398,23 +407,39 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
| },
|
|
|
| _onKeyBindingEvent: function(keyBindings, event) {
|
| - keyBindings.forEach(function(keyBinding) {
|
| - var keyCombo = keyBinding[0];
|
| - var handlerName = keyBinding[1];
|
| + if (this.stopKeyboardEventPropagation) {
|
| + event.stopPropagation();
|
| + }
|
| +
|
| + // if event has been already prevented, don't do anything
|
| + if (event.defaultPrevented) {
|
| + return;
|
| + }
|
|
|
| - if (!event.defaultPrevented && keyComboMatchesEvent(keyCombo, event)) {
|
| + for (var i = 0; i < keyBindings.length; i++) {
|
| + var keyCombo = keyBindings[i][0];
|
| + var handlerName = keyBindings[i][1];
|
| + if (keyComboMatchesEvent(keyCombo, event)) {
|
| this._triggerKeyHandler(keyCombo, handlerName, event);
|
| + // exit the loop if eventDefault was prevented
|
| + if (event.defaultPrevented) {
|
| + return;
|
| + }
|
| }
|
| - }, this);
|
| + }
|
| },
|
|
|
| _triggerKeyHandler: function(keyCombo, handlerName, keyboardEvent) {
|
| var detail = Object.create(keyCombo);
|
| detail.keyboardEvent = keyboardEvent;
|
| -
|
| - this[handlerName].call(this, new CustomEvent(keyCombo.event, {
|
| - detail: detail
|
| - }));
|
| + var event = new CustomEvent(keyCombo.event, {
|
| + detail: detail,
|
| + cancelable: true
|
| + });
|
| + this[handlerName].call(this, event);
|
| + if (event.defaultPrevented) {
|
| + keyboardEvent.preventDefault();
|
| + }
|
| }
|
| };
|
| })();
|
|
|