OLD | NEW |
| (Empty) |
1 | |
2 (function() { | |
3 | |
4 var PaperToast = Polymer({ | |
5 is: 'paper-toast', | |
6 | |
7 properties: { | |
8 /** | |
9 * The duration in milliseconds to show the toast. | |
10 */ | |
11 duration: { | |
12 type: Number, | |
13 value: 3000 | |
14 }, | |
15 | |
16 /** | |
17 * The text to display in the toast. | |
18 */ | |
19 text: { | |
20 type: String, | |
21 value: "" | |
22 }, | |
23 | |
24 /** | |
25 * True if the toast is currently visible. | |
26 */ | |
27 visible: { | |
28 type: Boolean, | |
29 readOnly: true, | |
30 value: false, | |
31 observer: '_visibleChanged' | |
32 } | |
33 }, | |
34 | |
35 created: function() { | |
36 Polymer.IronA11yAnnouncer.requestAvailability(); | |
37 }, | |
38 | |
39 ready: function() { | |
40 this.async(function() { | |
41 this.hide(); | |
42 }); | |
43 }, | |
44 | |
45 /** | |
46 * Show the toast. | |
47 * @method show | |
48 */ | |
49 show: function() { | |
50 if (PaperToast.currentToast) { | |
51 PaperToast.currentToast.hide(); | |
52 } | |
53 PaperToast.currentToast = this; | |
54 this.removeAttribute('aria-hidden'); | |
55 this._setVisible(true); | |
56 this.fire('iron-announce', { | |
57 text: this.text | |
58 }); | |
59 this.debounce('hide', this.hide, this.duration); | |
60 }, | |
61 | |
62 /** | |
63 * Hide the toast | |
64 */ | |
65 hide: function() { | |
66 this.setAttribute('aria-hidden', 'true'); | |
67 this._setVisible(false); | |
68 }, | |
69 | |
70 /** | |
71 * Toggle the opened state of the toast. | |
72 * @method toggle | |
73 */ | |
74 toggle: function() { | |
75 if (!this.visible) { | |
76 this.show(); | |
77 } else { | |
78 this.hide(); | |
79 } | |
80 }, | |
81 | |
82 _visibleChanged: function(visible) { | |
83 this.toggleClass('paper-toast-open', visible); | |
84 } | |
85 }); | |
86 | |
87 PaperToast.currentToast = null; | |
88 | |
89 })(); | |
OLD | NEW |