OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Counter used to give webkit animations unique names. | 5 // Counter used to give webkit animations unique names. |
6 var animationCounter = 0; | 6 var animationCounter = 0; |
7 | 7 |
8 var animationEventTracker_ = new EventTracker(); | 8 var animationEventTracker_ = new EventTracker(); |
9 | 9 |
10 function addAnimation(code) { | 10 function addAnimation(code) { |
(...skipping 19 matching lines...) Expand all Loading... |
30 function getFadeInAnimationCode(targetHeight) { | 30 function getFadeInAnimationCode(targetHeight) { |
31 return '0% { opacity: 0; height: 0; } ' + | 31 return '0% { opacity: 0; height: 0; } ' + |
32 '80% { opacity: 0.5; height: ' + (targetHeight + 4) + 'px; }' + | 32 '80% { opacity: 0.5; height: ' + (targetHeight + 4) + 'px; }' + |
33 '100% { opacity: 1; height: ' + targetHeight + 'px; }'; | 33 '100% { opacity: 1; height: ' + targetHeight + 'px; }'; |
34 } | 34 } |
35 | 35 |
36 /** | 36 /** |
37 * Fades in an element. Used for both printing options and error messages | 37 * Fades in an element. Used for both printing options and error messages |
38 * appearing underneath the textfields. | 38 * appearing underneath the textfields. |
39 * @param {HTMLElement} el The element to be faded in. | 39 * @param {HTMLElement} el The element to be faded in. |
| 40 * @param {boolean=} opt_justShow Whether {@code el} should be shown with no |
| 41 * animation. |
40 */ | 42 */ |
41 function fadeInElement(el) { | 43 function fadeInElement(el, opt_justShow) { |
42 if (el.classList.contains('visible')) | 44 if (el.classList.contains('visible')) |
43 return; | 45 return; |
44 el.classList.remove('closing'); | 46 el.classList.remove('closing'); |
45 el.hidden = false; | 47 el.hidden = false; |
46 el.setAttribute('aria-hidden', 'false'); | 48 el.setAttribute('aria-hidden', 'false'); |
47 el.style.height = 'auto'; | 49 el.style.height = 'auto'; |
48 var height = el.offsetHeight; | 50 var height = el.offsetHeight; |
49 el.style.height = height + 'px'; | 51 el.style.height = height + 'px'; |
50 var animName = addAnimation(getFadeInAnimationCode(height)); | 52 if (opt_justShow) { |
51 animationEventTracker_.add( | 53 el.style.opacity = 1; |
52 el, 'webkitAnimationEnd', onFadeInAnimationEnd.bind(el), false); | 54 } else { |
53 el.style.webkitAnimationName = animName; | 55 var animName = addAnimation(getFadeInAnimationCode(height)); |
| 56 animationEventTracker_.add( |
| 57 el, 'webkitAnimationEnd', onFadeInAnimationEnd.bind(el), false); |
| 58 el.style.webkitAnimationName = animName; |
| 59 } |
54 el.classList.add('visible'); | 60 el.classList.add('visible'); |
55 } | 61 } |
56 | 62 |
57 /** | 63 /** |
58 * Fades out an element. Used for both printing options and error messages | 64 * Fades out an element. Used for both printing options and error messages |
59 * appearing underneath the textfields. | 65 * appearing underneath the textfields. |
60 * @param {HTMLElement} el The element to be faded out. | 66 * @param {HTMLElement} el The element to be faded out. |
61 */ | 67 */ |
62 function fadeOutElement(el) { | 68 function fadeOutElement(el) { |
63 if (!el.classList.contains('visible')) | 69 if (!el.classList.contains('visible')) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 if (animEl) | 112 if (animEl) |
107 animEl.parentNode.removeChild(animEl); | 113 animEl.parentNode.removeChild(animEl); |
108 element.style.webkitAnimationName = ''; | 114 element.style.webkitAnimationName = ''; |
109 animationEventTracker_.remove(element, 'webkitAnimationEnd'); | 115 animationEventTracker_.remove(element, 'webkitAnimationEnd'); |
110 } | 116 } |
111 } | 117 } |
112 | 118 |
113 /** | 119 /** |
114 * Fades in a printing option existing under |el|. | 120 * Fades in a printing option existing under |el|. |
115 * @param {HTMLElement} el The element to hide. | 121 * @param {HTMLElement} el The element to hide. |
| 122 * @param {boolean=} opt_justShow Whether {@code el} should be hidden with no |
| 123 * animation. |
116 */ | 124 */ |
117 function fadeInOption(el) { | 125 function fadeInOption(el, opt_justShow) { |
118 if (el.classList.contains('visible')) | 126 if (el.classList.contains('visible')) |
119 return; | 127 return; |
120 // To make the option visible during the first fade in. | 128 // To make the option visible during the first fade in. |
121 el.hidden = false; | 129 el.hidden = false; |
122 | 130 |
123 wrapContentsInDiv(el.querySelector('h1'), ['invisible']); | 131 var leftColumn = el.querySelector('.left-column'); |
| 132 wrapContentsInDiv(leftColumn, ['invisible']); |
124 var rightColumn = el.querySelector('.right-column'); | 133 var rightColumn = el.querySelector('.right-column'); |
125 wrapContentsInDiv(rightColumn, ['invisible']); | 134 wrapContentsInDiv(rightColumn, ['invisible']); |
126 | 135 |
127 var toAnimate = el.querySelectorAll('.collapsible'); | 136 var toAnimate = el.querySelectorAll('.collapsible'); |
128 for (var i = 0; i < toAnimate.length; i++) | 137 for (var i = 0; i < toAnimate.length; i++) |
129 fadeInElement(toAnimate[i]); | 138 fadeInElement(toAnimate[i], opt_justShow); |
130 el.classList.add('visible'); | 139 el.classList.add('visible'); |
131 } | 140 } |
132 | 141 |
133 /** | 142 /** |
134 * Fades out a printing option existing under |el|. | 143 * Fades out a printing option existing under |el|. |
135 * @param {HTMLElement} el The element to hide. | 144 * @param {HTMLElement} el The element to hide. |
136 * @param {boolean=} opt_justHide Whether {@code el} should be hidden with no | 145 * @param {boolean=} opt_justHide Whether {@code el} should be hidden with no |
137 * animation. | 146 * animation. |
138 */ | 147 */ |
139 function fadeOutOption(el, opt_justHide) { | 148 function fadeOutOption(el, opt_justHide) { |
140 if (!el.classList.contains('visible')) | 149 if (!el.classList.contains('visible')) |
141 return; | 150 return; |
142 | 151 |
143 wrapContentsInDiv(el.querySelector('h1'), ['visible']); | 152 var leftColumn = el.querySelector('.left-column'); |
| 153 wrapContentsInDiv(leftColumn, ['visible']); |
144 var rightColumn = el.querySelector('.right-column'); | 154 var rightColumn = el.querySelector('.right-column'); |
145 wrapContentsInDiv(rightColumn, ['visible']); | 155 wrapContentsInDiv(rightColumn, ['visible']); |
146 | 156 |
147 var toAnimate = el.querySelectorAll('.collapsible'); | 157 var toAnimate = el.querySelectorAll('.collapsible'); |
148 for (var i = 0; i < toAnimate.length; i++) { | 158 for (var i = 0; i < toAnimate.length; i++) { |
149 if (opt_justHide) { | 159 if (opt_justHide) { |
150 toAnimate[i].hidden = true; | 160 toAnimate[i].hidden = true; |
151 toAnimate[i].classList.add('closing'); | 161 toAnimate[i].classList.add('closing'); |
152 toAnimate[i].classList.remove('visible'); | 162 toAnimate[i].classList.remove('visible'); |
153 } else { | 163 } else { |
(...skipping 17 matching lines...) Expand all Loading... |
171 while (el.childNodes.length > 0) | 181 while (el.childNodes.length > 0) |
172 div.appendChild(el.firstChild); | 182 div.appendChild(el.firstChild); |
173 el.appendChild(div); | 183 el.appendChild(div); |
174 } | 184 } |
175 | 185 |
176 div.className = ''; | 186 div.className = ''; |
177 div.classList.add('collapsible'); | 187 div.classList.add('collapsible'); |
178 for (var i = 0; i < classes.length; i++) | 188 for (var i = 0; i < classes.length; i++) |
179 div.classList.add(classes[i]); | 189 div.classList.add(classes[i]); |
180 } | 190 } |
OLD | NEW |