Mechanical rename of base::debug -> base::trace_event [final pass]
[chromium-blink-merge.git] / third_party / polymer / components-chromium / core-label / core-label-extracted.js
blobbec4fe7552a6052568127c11bd321c59b0309778
2     (function() {
4       var ID = 0;
5       function generate(node) {
6         if (!node.id) {
7           node.id = 'core-label-' + ID++;
8         }
9         return node.id;
10       }
12       Polymer('core-label', {
13         /**
14          * A query selector string for a "target" element not nested in the `<core-label>`
15          *
16          * @attribute for
17          * @type string
18          * @default ''
19          */
20         publish: {
21           'for': {reflect: true, value: ''}
22         },
23         eventDelegates: {
24           'tap': 'tapHandler'
25         },
26         created: function() {
27           generate(this);
28           this._forElement = null;
29         },
30         ready: function() {
31           if (!this.for) {
32             this._forElement = this.querySelector('[for]');
33             this._tie();
34           }
35         },
36         tapHandler: function(ev) {
37           if (!this._forElement) {
38             return;
39           }
40           if (ev.target === this._forElement) {
41             return;
42           }
43           this._forElement.focus();
44           this._forElement.click();
45           this.fire('tap', null, this._forElement);
46         },
47         _tie: function() {
48           if (this._forElement) {
49             this._forElement.setAttribute('aria-labelledby', this.id);
50           }
51         },
52         _findScope: function() {
53           var n = this.parentNode;
54           while(n && n.parentNode) {
55             n = n.parentNode;
56           }
57           return n;
58         },
59         forChanged: function(oldFor, newFor) {
60           if (this._forElement) {
61             this._forElement.removeAttribute('aria-labelledby');
62           }
63           var scope = this._findScope();
64           if (!scope) {
65             return;
66           }
67           this._forElement = scope.querySelector(newFor);
68           if (this._forElement) {
69             this._tie();
70           }
71         }
72       });
73     })();
74