blob: b0bbc23349689919f34f9ddf7416ea4c2435a758 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
<!--
-- Copyright 2013 The Chromium Authors. All rights reserved.
-- Use of this source code is governed by a BSD-style license that can be
-- found in the LICENSE file.
-->
<polymer-element name="kb-key-sequence"
attributes="keys hintTexts keyCodes invert">
<template>
<style>
:host {
display: none;
}
</style>
</template>
<script>
(function() {
var metadata = null;
function getKeyCodeAndModifiers(keyCodeIndex) {
if (!metadata)
metadata = document.createElement('kb-key-codes');
return metadata.GetKeyCodeAndModifiers(keyCodeIndex);
}
Polymer('kb-key-sequence', {
/**
* Generates the DOM structure to replace (expand) this kb-key-sequence.
*/
generateDom: function() {
var replacement = document.createDocumentFragment();
var newKeys = this.getAttribute('keys');
var newHintTexts = this.getAttribute('hintTexts');
var keyCodes = this.getAttribute('hintCodes') || newKeys;
var invert = this.getAttribute('invert');
if (newKeys) {
if (newHintTexts && newKeys.length != newHintTexts.length) {
console.error('keys and hintTexts do not match');
return;
}
if (keyCodes && newKeys.length != keyCodes.length) {
console.error('keys and keyCodes do not match');
return;
}
for (var i = 0; i < newKeys.length; i++) {
var key = document.createElement('kb-key');
key.innerText = newKeys[i];
key.accents = newKeys[i];
if (newHintTexts)
key.hintText = newHintTexts[i];
var keyCodeIndex = keyCodes[i];
if (invert) {
key.invert = true;
key.char = newKeys[i];
keyCodeIndex = key.hintText;
}
var state = getKeyCodeAndModifiers(keyCodeIndex);
if (state) {
key.keyCode = state.keyCode;
key.keyName = state.keyName;
key.shiftModifier = state.shiftModifier;
}
replacement.appendChild(key);
}
}
return replacement;
}
});
})();
</script>
</polymer-element>
|