OLD | NEW |
| (Empty) |
1 | |
2 | |
3 (function() { | |
4 | |
5 'use strict'; | |
6 | |
7 function classNames(obj) { | |
8 var classNames = []; | |
9 for (var key in obj) { | |
10 if (obj.hasOwnProperty(key) && obj[key]) { | |
11 classNames.push(key); | |
12 } | |
13 } | |
14 | |
15 return classNames.join(' '); | |
16 } | |
17 | |
18 Polymer({ | |
19 | |
20 is: 'paper-toolbar', | |
21 | |
22 hostAttributes: { | |
23 'role': 'toolbar' | |
24 }, | |
25 | |
26 properties: { | |
27 | |
28 /** | |
29 * Controls how the items are aligned horizontally when they are placed | |
30 * at the bottom. | |
31 * Options are `start`, `center`, `end`, `justified` and `around`. | |
32 * | |
33 * @attribute bottomJustify | |
34 * @type string | |
35 * @default '' | |
36 */ | |
37 bottomJustify: { | |
38 type: String, | |
39 value: '' | |
40 }, | |
41 | |
42 /** | |
43 * Controls how the items are aligned horizontally. | |
44 * Options are `start`, `center`, `end`, `justified` and `around`. | |
45 * | |
46 * @attribute justify | |
47 * @type string | |
48 * @default '' | |
49 */ | |
50 justify: { | |
51 type: String, | |
52 value: '' | |
53 }, | |
54 | |
55 /** | |
56 * Controls how the items are aligned horizontally when they are placed | |
57 * in the middle. | |
58 * Options are `start`, `center`, `end`, `justified` and `around`. | |
59 * | |
60 * @attribute middleJustify | |
61 * @type string | |
62 * @default '' | |
63 */ | |
64 middleJustify: { | |
65 type: String, | |
66 value: '' | |
67 } | |
68 | |
69 }, | |
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 | |
115 _computeBarClassName: function(barJustify) { | |
116 var classObj = { | |
117 center: true, | |
118 horizontal: true, | |
119 layout: true, | |
120 'toolbar-tools': true | |
121 }; | |
122 | |
123 // If a blank string or any falsy value is given, no other class name is | |
124 // added. | |
125 if (barJustify) { | |
126 var justifyClassName = (barJustify === 'justified') ? | |
127 barJustify : | |
128 barJustify + '-justified'; | |
129 | |
130 classObj[justifyClassName] = true; | |
131 } | |
132 | |
133 return classNames(classObj); | |
134 } | |
135 | |
136 }); | |
137 | |
138 }()); | |
139 | |
OLD | NEW |