OLD | NEW |
1 | 1 |
2 | 2 |
3 (function() { | 3 (function() { |
4 | 4 |
5 'use strict'; | 5 'use strict'; |
6 | 6 |
7 function classNames(obj) { | 7 function classNames(obj) { |
8 var classNames = []; | 8 var classNames = []; |
9 for (var key in obj) { | 9 for (var key in obj) { |
10 if (obj.hasOwnProperty(key) && obj[key]) { | 10 if (obj.hasOwnProperty(key) && obj[key]) { |
11 classNames.push(key); | 11 classNames.push(key); |
12 } | 12 } |
13 } | 13 } |
14 | 14 |
15 return classNames.join(' '); | 15 return classNames.join(' '); |
16 } | 16 } |
17 | 17 |
18 Polymer({ | 18 Polymer({ |
19 | 19 |
20 is: 'paper-toolbar', | 20 is: 'paper-toolbar', |
21 | 21 |
22 enableCustomStyleProperties: true, | 22 hostAttributes: { |
| 23 'role': 'toolbar' |
| 24 }, |
23 | 25 |
24 properties: { | 26 properties: { |
25 | 27 |
26 /** | 28 /** |
27 * Controls how the items are aligned horizontally when they are placed | 29 * Controls how the items are aligned horizontally when they are placed |
28 * at the bottom. | 30 * at the bottom. |
29 * Options are `start`, `center`, `end`, `justified` and `around`. | 31 * Options are `start`, `center`, `end`, `justified` and `around`. |
30 * | 32 * |
31 * @attribute bottomJustify | 33 * @attribute bottomJustify |
32 * @type string | 34 * @type string |
(...skipping 26 matching lines...) Expand all Loading... |
59 * @type string | 61 * @type string |
60 * @default '' | 62 * @default '' |
61 */ | 63 */ |
62 middleJustify: { | 64 middleJustify: { |
63 type: String, | 65 type: String, |
64 value: '' | 66 value: '' |
65 } | 67 } |
66 | 68 |
67 }, | 69 }, |
68 | 70 |
| 71 attached: function() { |
| 72 this._observer = this._observe(this); |
| 73 this._updateAriaLabelledBy(); |
| 74 }, |
| 75 |
| 76 detached: function() { |
| 77 if (this._observer) { |
| 78 this._observer.disconnect(); |
| 79 } |
| 80 }, |
| 81 |
| 82 _observe: function(node) { |
| 83 var observer = new MutationObserver(function() { |
| 84 this._updateAriaLabelledBy(); |
| 85 }.bind(this)); |
| 86 observer.observe(node, { |
| 87 childList: true, |
| 88 subtree: true |
| 89 }); |
| 90 return observer; |
| 91 }, |
| 92 |
| 93 _updateAriaLabelledBy: function() { |
| 94 var labelledBy = []; |
| 95 var contents = Polymer.dom(this.root).querySelectorAll('content'); |
| 96 for (var content, index = 0; content = contents[index]; index++) { |
| 97 var nodes = Polymer.dom(content).getDistributedNodes(); |
| 98 for (var node, jndex = 0; node = nodes[jndex]; jndex++) { |
| 99 if (node.hasAttribute && node.hasAttribute('title')) { |
| 100 if (node.id) { |
| 101 labelledBy.push(node.id); |
| 102 } else { |
| 103 var id = 'paper-toolbar-label-' + Math.floor(Math.random() * 100
00); |
| 104 node.id = id; |
| 105 labelledBy.push(id); |
| 106 } |
| 107 } |
| 108 } |
| 109 } |
| 110 if (labelledBy.length > 0) { |
| 111 this.setAttribute('aria-labelledby', labelledBy.join(' ')); |
| 112 } |
| 113 }, |
| 114 |
69 _computeBarClassName: function(barJustify) { | 115 _computeBarClassName: function(barJustify) { |
70 var classObj = { | 116 var classObj = { |
71 center: true, | 117 center: true, |
72 horizontal: true, | 118 horizontal: true, |
73 layout: true, | 119 layout: true, |
74 'toolbar-tools': true | 120 'toolbar-tools': true |
75 }; | 121 }; |
76 | 122 |
77 // If a blank string or any falsy value is given, no other class name is | 123 // If a blank string or any falsy value is given, no other class name is |
78 // added. | 124 // added. |
79 if (barJustify) { | 125 if (barJustify) { |
80 var justifyClassName = (barJustify === 'justified') ? | 126 var justifyClassName = (barJustify === 'justified') ? |
81 barJustify : | 127 barJustify : |
82 barJustify + '-justified'; | 128 barJustify + '-justified'; |
83 | 129 |
84 classObj[justifyClassName] = true; | 130 classObj[justifyClassName] = true; |
85 } | 131 } |
86 | 132 |
87 return classNames(classObj); | 133 return classNames(classObj); |
88 } | 134 } |
89 | 135 |
90 }); | 136 }); |
91 | 137 |
92 }()); | 138 }()); |
93 | 139 |
OLD | NEW |