OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 /** | |
6 * Toggle Button. | |
7 * | |
8 * activated or deactivated events are dispatched when the state of the button | |
9 * is toggled. | |
10 * | |
11 * You can change ripple color by the following CSS selector. | |
12 * | |
13 * gallery-toggle-button#my-button::shadow .ripple { | |
14 * background-color: black; | |
15 * } | |
16 */ | |
17 var GalleryToggleButton = Polymer({ | |
18 is: 'gallery-toggle-button', | |
19 | |
20 properties: { | |
21 'activated': { | |
22 type: Boolean, | |
23 value: false, | |
24 observer: 'onActivatedChanged_' | |
fukino
2015/06/10 08:28:52
nit: 'activatedChanged' or 'activatedChanged_' loo
yawano
2015/06/10 08:55:19
Done.
| |
25 }, | |
26 }, | |
27 | |
28 /** | |
29 * Called when button is tapped or clicked. | |
30 * @private | |
31 */ | |
32 onTapped_: function() { | |
fukino
2015/06/10 08:28:53
I'm not sure if TAP is the trigger for this animat
yawano
2015/06/11 03:21:31
The active state here means "pressed", e.g. showin
| |
33 this.activated = !this.activated; | |
34 }, | |
35 | |
36 /** | |
37 * Called when value of activated property is changed. | |
38 * @param {boolean} newValue New value. | |
39 * @param {boolean} oldValue Old value. | |
40 * @private | |
41 */ | |
42 onActivatedChanged_: function(newValue, oldValue) { | |
43 if (newValue === oldValue) | |
44 return; | |
45 | |
46 if (newValue) { | |
47 this.fire('activated'); | |
48 this.performActivateAnimation_(); | |
49 } else { | |
50 this.fire('deactivated'); | |
51 this.performDeactivateAnimation_(); | |
52 } | |
53 }, | |
54 | |
55 /** | |
56 * Perform activate animation. | |
57 * @private | |
58 */ | |
59 performActivateAnimation_: function() { | |
60 this.$.ripple.animate([ | |
61 {opacity: 0, offset: 0, easing: 'linear'}, | |
62 {opacity: 0.2, offset: 1} | |
63 ], 50); | |
64 this.$.ripple.animate([ | |
65 { | |
66 width: '38.5%', | |
67 height: '38.5%', | |
68 offset: 0, | |
69 easing: 'cubic-bezier(0, 0, 0.330066603741, 0.931189591041)' | |
70 }, | |
71 { | |
72 width: '97.4%', | |
73 height: '97.4%', | |
74 offset: 0.5, | |
75 easing: 'cubic-bezier(0.435623148352, 0.141946042876, 0.2, 1.0)' | |
76 }, | |
77 { | |
78 width: '60.3%', | |
79 height: '60.3%', | |
80 offset: 1 | |
81 } | |
82 ], 500); | |
83 this.$.ripple.animate([ | |
84 { | |
85 'border-radius': '48.7%', | |
86 offset: 0, | |
87 easing: 'linear' | |
88 }, | |
89 { | |
90 'border-radius': '48.7%', | |
91 offset: 0.333, | |
92 easing: 'cubic-bezier(0.109613342381, 0.32112094549, 0.2, 1.0)' | |
93 }, | |
94 { | |
95 'border-radius': '2.56%', | |
96 offset: 1 | |
97 } | |
98 ], 750); | |
99 | |
100 this.$.ripple.classList.add('activated'); | |
101 }, | |
102 | |
103 /** | |
104 * Perform deactivate animation. | |
105 * @private | |
106 */ | |
107 performDeactivateAnimation_: function() { | |
108 this.$.ripple.animate([ | |
109 {opacity: 0.2, offset: 0, easing: 'linear'}, | |
110 {opacity: 0, offset: 1} | |
111 ], 150); | |
112 this.$.ripple.animate([ | |
113 { | |
114 width: '60.3%', | |
115 height: '60.3%', | |
116 offset: 0, | |
117 easing: 'cubic-bezier(0, 0, 0.6, 1)' | |
118 }, | |
119 { | |
120 width: '100%', | |
121 height: '100%', | |
122 offset: 1 | |
123 } | |
124 ], 150); | |
125 this.$.ripple.animate([ | |
126 { | |
127 'border-radius': '2.56%', | |
fukino
2015/06/10 08:28:52
nit: These single quotation marks looks unnecessar
yawano
2015/06/10 08:55:19
If we remove single quotes, it becomes syntax erro
| |
128 offset: 0, | |
129 easing: 'cubic-bezier(0, 0, 0.2, 1)' | |
130 }, | |
131 { | |
132 'border-radius': '50%', | |
fukino
2015/06/10 08:28:53
ditto
| |
133 offset: 1 | |
134 } | |
135 ], 150); | |
136 | |
137 this.$.ripple.classList.remove('activated'); | |
138 } | |
139 }); | |
OLD | NEW |