| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 function addAnimation(code) { | 8 function addAnimation(code) { |
| 9 var name = 'anim' + animationCounter; | 9 var name = 'anim' + animationCounter; |
| 10 animationCounter++; | 10 animationCounter++; |
| 11 var rules = document.createTextNode( | 11 var rules = document.createTextNode( |
| 12 '@-webkit-keyframes ' + name + ' {' + code + '}'); | 12 '@-webkit-keyframes ' + name + ' {' + code + '}'); |
| 13 var el = document.createElement('style'); | 13 var el = document.createElement('style'); |
| 14 el.type = 'text/css'; | 14 el.type = 'text/css'; |
| 15 el.appendChild(rules); | 15 el.appendChild(rules); |
| 16 document.body.appendChild(el); | 16 document.body.appendChild(el); |
| 17 | 17 |
| 18 return name; | 18 return name; |
| 19 } | 19 } |
| 20 | 20 |
| 21 function showInvalidHint(el) { | 21 function fadeInElement(el) { |
| 22 if (el.classList.contains('visible')) | 22 if (el.classList.contains('visible')) |
| 23 return; | 23 return; |
| 24 el.classList.remove('closing'); | 24 el.classList.remove('closing'); |
| 25 el.style.height = 'auto'; | 25 el.style.height = 'auto'; |
| 26 var height = el.offsetHeight; | 26 var height = el.offsetHeight; |
| 27 el.style.height = height + 'px'; | 27 el.style.height = height + 'px'; |
| 28 var animName = addAnimation( | 28 var animName = addAnimation( |
| 29 '0% { opacity: 0; height: 0; } ' + | 29 '0% { opacity: 0; height: 0; } ' + |
| 30 '80% { height: ' + (height + 4) + 'px; }' + | 30 '80% { height: ' + (height + 4) + 'px; }' + |
| 31 '100% { opacity: 1; height: ' + height + 'px; }'); | 31 '100% { opacity: 1; height: ' + height + 'px; }'); |
| 32 el.style.webkitAnimationName = animName; | 32 el.style.webkitAnimationName = animName; |
| 33 el.classList.add('visible'); | 33 el.classList.add('visible'); |
| 34 el.addEventListener('webkitAnimationEnd', function() { |
| 35 el.style.height = ''; |
| 36 el.style.webkitAnimationName = ''; |
| 37 }, false ); |
| 34 } | 38 } |
| 35 | 39 |
| 36 function hideInvalidHint(el) { | 40 function fadeOutElement(el) { |
| 37 if (!el.classList.contains('visible')) | 41 if (!el.classList.contains('visible')) |
| 38 return; | 42 return; |
| 39 el.style.webkitAnimationName = ''; | 43 el.style.webkitAnimationName = ''; |
| 40 el.classList.add('closing'); | 44 el.classList.add('closing'); |
| 41 el.classList.remove('visible'); | 45 el.classList.remove('visible'); |
| 42 } | 46 } |
| OLD | NEW |