-
Notifications
You must be signed in to change notification settings - Fork 2
/
w3c-disclosure.html
52 lines (51 loc) · 1.51 KB
/
w3c-disclosure.html
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
<link rel="import" href="components/polymer/polymer.html">
<polymer-element name="w3c-disclosure" extends="button" attributes="controlfor expanded" on-click="{{buttonClick}}">
<template>
<style type="text/css">
:host #icon:before {
content:"►"; font-size: 1em;
}
:host #icon.expanded:before {
content:"▼"; font-size: 1em;
}
</style>
<span id="icon" aria-hidden="true" class="expanded"></span>
<content></content>
</template>
<script>
Polymer('w3c-disclosure', {
ready: function() {
this.setAttribute('type', 'button');
if (this.expanded === null) this.expanded = false;
else this.expanded = true;
if (this.controlfor) {
this.setAttribute('aria-controls', this.controlfor);
this.target = document.querySelector('#' + this.controlfor);
if (!this.target) {
console.log("Target not found '" + this.controlfor + "'");
}
} else {
console.log("controlfor attribute not set");
}
},
buttonClick: function(event, detail, sender) {
this.expanded = !this.expanded;
},
expandedChanged: function(oldValue, newValue) {
if (this.target) {
this.setAttribute('aria-expanded', newValue);
//this.target.hidden = !newValue;
if (newValue) {
this.$.icon.classList.add('expanded');
this.target.style.display='block';
} else {
this.$.icon.classList.remove('expanded');
this.target.style.display='none';
}
} else {
console.log("Target not found");
}
},
});
</script>
</polymer-element>