merge from dev
This commit is contained in:
parent
9e1a2cf66a
commit
189942e289
298 changed files with 53049 additions and 5413 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "iron-a11y-keys-behavior",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"description": "A behavior that enables keybindings for greater a11y.",
|
||||
"keywords": [
|
||||
"web-components",
|
||||
|
@ -31,11 +31,11 @@
|
|||
},
|
||||
"ignore": [],
|
||||
"homepage": "https://github.com/polymerelements/iron-a11y-keys-behavior",
|
||||
"_release": "1.1.0",
|
||||
"_release": "1.1.1",
|
||||
"_resolution": {
|
||||
"type": "version",
|
||||
"tag": "v1.1.0",
|
||||
"commit": "cd8c972278c0d916bef57209d7dce5b81e67687c"
|
||||
"tag": "v1.1.1",
|
||||
"commit": "12af7cb19b2c6b3887e37a5ea1501ffe676d1e8a"
|
||||
},
|
||||
"_source": "git://github.com/polymerelements/iron-a11y-keys-behavior.git",
|
||||
"_target": "^1.0.0",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "iron-a11y-keys-behavior",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"description": "A behavior that enables keybindings for greater a11y.",
|
||||
"keywords": [
|
||||
"web-components",
|
||||
|
|
|
@ -86,7 +86,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
keyBindings: {
|
||||
'* pageup pagedown left right down up home end space enter @ ~ " $ ? ! \\ + : # backspace': '_updatePressed',
|
||||
'a': '_updatePressed',
|
||||
'shift+a alt+a': '_updatePressed'
|
||||
'shift+a alt+a': '_updatePressed',
|
||||
'shift+tab shift+space': '_updatePressed'
|
||||
},
|
||||
|
||||
_updatePressed: function(event) {
|
||||
|
|
|
@ -65,6 +65,15 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
'meta': 'metaKey'
|
||||
};
|
||||
|
||||
/**
|
||||
* KeyboardEvent.key is mostly represented by printable character made by
|
||||
* 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.
|
||||
*/
|
||||
var KEY_CHAR = /[a-z0-9*]/;
|
||||
|
||||
/**
|
||||
* Matches a keyIdentifier string.
|
||||
*/
|
||||
|
@ -81,14 +90,22 @@ 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 === ' ' || SPACE_KEY.test(lKey)) {
|
||||
validKey = 'space';
|
||||
} else if (lKey.length == 1) {
|
||||
validKey = lKey;
|
||||
if (!noSpecialChars || KEY_CHAR.test(lKey)) {
|
||||
validKey = lKey;
|
||||
}
|
||||
} else if (ARROW_KEY.test(lKey)) {
|
||||
validKey = lKey.replace('arrow', '');
|
||||
} else if (lKey == 'multiply') {
|
||||
|
@ -139,17 +156,29 @@ 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, event, eventKey) {
|
||||
return eventKey === keyCombo.key &&
|
||||
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 &&
|
||||
|
@ -286,9 +315,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
|
||||
keyboardEventMatchesKeys: function(event, eventString) {
|
||||
var keyCombos = parseEventString(eventString);
|
||||
var eventKey = normalizedKeyForEvent(event);
|
||||
for (var i = 0; i < keyCombos.length; ++i) {
|
||||
if (keyComboMatchesEvent(keyCombos[i], event, eventKey)) {
|
||||
if (keyComboMatchesEvent(keyCombos[i], event)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -388,11 +416,10 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
return;
|
||||
}
|
||||
|
||||
var eventKey = normalizedKeyForEvent(event);
|
||||
for (var i = 0; i < keyBindings.length; i++) {
|
||||
var keyCombo = keyBindings[i][0];
|
||||
var handlerName = keyBindings[i][1];
|
||||
if (keyComboMatchesEvent(keyCombo, event, eventKey)) {
|
||||
if (keyComboMatchesEvent(keyCombo, event)) {
|
||||
this._triggerKeyHandler(keyCombo, handlerName, event);
|
||||
// exit the loop if eventDefault was prevented
|
||||
if (event.defaultPrevented) {
|
||||
|
|
|
@ -97,7 +97,8 @@ suite('Polymer.IronA11yKeysBehavior', function() {
|
|||
],
|
||||
|
||||
keyBindings: {
|
||||
'space': '_keyHandler'
|
||||
'space': '_keyHandler',
|
||||
'@': '_keyHandler'
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -179,6 +180,13 @@ suite('Polymer.IronA11yKeysBehavior', function() {
|
|||
expect(keys.keyCount).to.be.equal(1);
|
||||
});
|
||||
|
||||
test('handles special character @', function() {
|
||||
var event = new CustomEvent('keydown');
|
||||
event.key = '@';
|
||||
keys.dispatchEvent(event);
|
||||
expect(keys.keyCount).to.be.equal(1);
|
||||
});
|
||||
|
||||
test('do not trigger the handler for non-specified keys', function() {
|
||||
MockInteractions.pressEnter(keys);
|
||||
|
||||
|
@ -284,6 +292,19 @@ suite('Polymer.IronA11yKeysBehavior', function() {
|
|||
expect(keys.keyCount).to.be.equal(1);
|
||||
});
|
||||
|
||||
test('check if KeyBoardEvent.key is alpha-numberic', function() {
|
||||
var event = new CustomEvent('keydown');
|
||||
|
||||
event.ctrlKey = true;
|
||||
event.shiftKey = true;
|
||||
event.key = 'å';
|
||||
event.keyCode = event.code = 65;
|
||||
|
||||
keys.dispatchEvent(event);
|
||||
|
||||
expect(keys.keyCount).to.be.equal(1);
|
||||
});
|
||||
|
||||
test('trigger also bindings without modifiers', function() {
|
||||
var event = new CustomEvent('keydown');
|
||||
// Combo `shift+enter`.
|
||||
|
@ -305,6 +326,7 @@ suite('Polymer.IronA11yKeysBehavior', function() {
|
|||
expect(shiftEnterSpy.called).to.be.true;
|
||||
expect(enterSpy.calledAfter(shiftEnterSpy)).to.be.true;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
suite('alternative event keys', function() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue