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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
(function() {
'use strict';
function classNames(obj) {
var classNames = [];
for (var key in obj) {
if (obj.hasOwnProperty(key) && obj[key]) {
classNames.push(key);
}
}
return classNames.join(' ');
}
Polymer({
is: 'paper-toolbar',
hostAttributes: {
'role': 'toolbar'
},
properties: {
/**
* Controls how the items are aligned horizontally when they are placed
* at the bottom.
* Options are `start`, `center`, `end`, `justified` and `around`.
*
* @attribute bottomJustify
* @type string
* @default ''
*/
bottomJustify: {
type: String,
value: ''
},
/**
* Controls how the items are aligned horizontally.
* Options are `start`, `center`, `end`, `justified` and `around`.
*
* @attribute justify
* @type string
* @default ''
*/
justify: {
type: String,
value: ''
},
/**
* Controls how the items are aligned horizontally when they are placed
* in the middle.
* Options are `start`, `center`, `end`, `justified` and `around`.
*
* @attribute middleJustify
* @type string
* @default ''
*/
middleJustify: {
type: String,
value: ''
}
},
attached: function() {
this._observer = this._observe(this);
this._updateAriaLabelledBy();
},
detached: function() {
if (this._observer) {
this._observer.disconnect();
}
},
_observe: function(node) {
var observer = new MutationObserver(function() {
this._updateAriaLabelledBy();
}.bind(this));
observer.observe(node, {
childList: true,
subtree: true
});
return observer;
},
_updateAriaLabelledBy: function() {
var labelledBy = [];
var contents = Polymer.dom(this.root).querySelectorAll('content');
for (var content, index = 0; content = contents[index]; index++) {
var nodes = Polymer.dom(content).getDistributedNodes();
for (var node, jndex = 0; node = nodes[jndex]; jndex++) {
if (node.classList && node.classList.contains('title')) {
if (node.id) {
labelledBy.push(node.id);
} else {
var id = 'paper-toolbar-label-' + Math.floor(Math.random() * 10000);
node.id = id;
labelledBy.push(id);
}
}
}
}
if (labelledBy.length > 0) {
this.setAttribute('aria-labelledby', labelledBy.join(' '));
}
},
_computeBarClassName: function(barJustify) {
var classObj = {
'center': true,
'horizontal': true,
'layout': true,
'toolbar-tools': true
};
// If a blank string or any falsy value is given, no other class name is
// added.
if (barJustify) {
var justifyClassName = (barJustify === 'justified') ?
barJustify :
barJustify + '-justified';
classObj[justifyClassName] = true;
}
return classNames(classObj);
}
});
}());
|