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 Ripple. | |
7 * | |
8 * You can change ripple color by the following CSS selector. | |
9 * | |
10 * files-toggle-ripple#my-button::shadow .ripple { | |
11 * background-color: black; | |
12 * } | |
13 * | |
14 * Ripple size of the activated state is same with the size of this element. | |
15 */ | |
16 var FilesToggleRipple = Polymer({ | |
17 is: 'files-toggle-ripple', | |
18 | |
19 properties: { | |
20 'activated': { | |
21 type: Boolean, | |
22 value: false, | |
23 observer: 'activatedChanged_' | |
24 }, | |
25 }, | |
26 | |
27 /** | |
28 * Called when value of activated property is changed. | |
29 * @param {boolean} newValue New value. | |
30 * @param {boolean} oldValue Old value. | |
31 * @private | |
32 */ | |
33 activatedChanged_: function(newValue, oldValue) { | |
34 if (newValue === oldValue) | |
35 return; | |
36 | |
37 if (newValue) | |
38 this.performActivateAnimation_(); | |
39 else | |
40 this.performDeactivateAnimation_(); | |
41 }, | |
42 | |
43 /** | |
44 * Perform activate animation. | |
45 * @private | |
46 */ | |
47 performActivateAnimation_: function() { | |
48 this.$.ripple.animate([ | |
49 {opacity: 0, offset: 0, easing: 'linear'}, | |
50 {opacity: 0.2, offset: 1} | |
51 ], 50); | |
52 this.$.ripple.animate([ | |
53 { | |
fukino
2015/06/16 07:34:16
nit: Indent level should be 2 after [.
yawano
2015/06/16 07:38:57
Done.
| |
54 width: '31.9%', | |
55 height: '31.9%', | |
56 offset: 0, | |
57 easing: 'cubic-bezier(0, 0, 0.330066603741, 0.931189591041)' | |
58 }, | |
59 { | |
60 width: '80.9%', | |
61 height: '80.9%', | |
62 offset: 0.5, | |
63 easing: 'cubic-bezier(0.435623148352, 0.141946042876, 0.2, 1.0)' | |
64 }, | |
65 { | |
66 width: '50%', | |
67 height: '50%', | |
68 offset: 1 | |
69 } | |
70 ], 500); | |
71 this.$.ripple.animate([ | |
72 { | |
73 'border-radius': '50%', | |
74 offset: 0, | |
75 easing: 'linear' | |
76 }, | |
77 { | |
78 'border-radius': '50%', | |
79 offset: 0.333, | |
80 easing: 'cubic-bezier(0.109613342381, 0.32112094549, 0.2, 1.0)' | |
81 }, | |
82 { | |
83 'border-radius': '2px', | |
84 offset: 1 | |
85 } | |
86 ], 750); | |
87 | |
88 this.$.ripple.classList.add('activated'); | |
89 }, | |
90 | |
91 /** | |
92 * Perform deactivate animation. | |
93 * @private | |
94 */ | |
95 performDeactivateAnimation_: function() { | |
96 this.$.ripple.animate([ | |
97 {opacity: 0.2, offset: 0, easing: 'linear'}, | |
98 {opacity: 0, offset: 1} | |
99 ], 150); | |
100 this.$.ripple.animate([ | |
101 { | |
102 width: '50%', | |
103 height: '50%', | |
104 offset: 0, | |
105 easing: 'cubic-bezier(0, 0, 0.6, 1)' | |
106 }, | |
107 { | |
108 width: '83.0%', | |
109 height: '83.0%', | |
110 offset: 1 | |
111 } | |
112 ], 150); | |
113 this.$.ripple.animate([ | |
114 { | |
115 'border-radius': '2px', | |
116 offset: 0, | |
117 easing: 'cubic-bezier(0, 0, 0.2, 1)' | |
118 }, | |
119 { | |
120 'border-radius': '50%', | |
121 offset: 1 | |
122 } | |
123 ], 150); | |
124 | |
125 this.$.ripple.classList.remove('activated'); | |
126 } | |
127 }); | |
OLD | NEW |