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 // This file exists to share common overlay behaviors. | 5 // This file exists to share common overlay behaviors. |
6 | 6 |
7 cr.define('cr.ui.overlay', function() { | 7 cr.define('cr.ui.overlay', function() { |
8 | 8 |
9 /** | 9 /** |
10 * Gets the top, visible overlay. It makes the assumption that if multiple | 10 * Gets the top, visible overlay. It makes the assumption that if multiple |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 cr.dispatchSimpleEvent(overlay, 'cancelOverlay'); | 44 cr.dispatchSimpleEvent(overlay, 'cancelOverlay'); |
45 } | 45 } |
46 }); | 46 }); |
47 } | 47 } |
48 | 48 |
49 /** | 49 /** |
50 * Adds behavioral hooks for the given overlay. | 50 * Adds behavioral hooks for the given overlay. |
51 * @param {HTMLElement} overlay The .overlay. | 51 * @param {HTMLElement} overlay The .overlay. |
52 */ | 52 */ |
53 function setupOverlay(overlay) { | 53 function setupOverlay(overlay) { |
54 /* Remove the 'shake' animation any time the overlay is hidden or shown. | 54 /* Close the overlay on clicking any of the pages' close buttons. */ |
James Hawkins
2012/03/12 20:26:01
nit: Use c++ style comment, //.
flackr
2012/03/12 20:32:13
Done.
| |
55 var closeButtons = overlay.querySelectorAll('.page .close-button'); | |
56 for (var i = 0; i < closeButtons.length; i++) { | |
57 closeButtons[i].addEventListener('click', function(e) { | |
58 cr.dispatchSimpleEvent(overlay, 'cancelOverlay'); | |
59 }); | |
60 } | |
61 | |
62 /* Remove the 'pulse' animation any time the overlay is hidden or shown. | |
55 */ | 63 */ |
56 overlay.__defineSetter__('hidden', function(value) { | 64 overlay.__defineSetter__('hidden', function(value) { |
57 this.classList.remove('shake'); | 65 this.classList.remove('pulse'); |
58 if (value) | 66 if (value) |
59 this.setAttribute('hidden', true); | 67 this.setAttribute('hidden', true); |
60 else | 68 else |
61 this.removeAttribute('hidden'); | 69 this.removeAttribute('hidden'); |
62 }); | 70 }); |
63 overlay.__defineGetter__('hidden', function() { | 71 overlay.__defineGetter__('hidden', function() { |
64 return this.hasAttribute('hidden'); | 72 return this.hasAttribute('hidden'); |
65 }); | 73 }); |
66 | 74 |
67 /* Shake when the user clicks away. */ | 75 /* Shake when the user clicks away. */ |
68 overlay.addEventListener('click', function(e) { | 76 overlay.addEventListener('click', function(e) { |
69 // Only shake if the overlay was the target of the click. | 77 // Only pulse if the overlay was the target of the click. |
70 if (this != e.target) | 78 if (this != e.target) |
71 return; | 79 return; |
72 | 80 |
73 // This may be null while the overlay is closing. | 81 // This may be null while the overlay is closing. |
74 var overlayPage = this.querySelector('.page:not([hidden])'); | 82 var overlayPage = this.querySelector('.page:not([hidden])'); |
75 if (overlayPage) | 83 if (overlayPage) |
76 overlayPage.classList.add('shake'); | 84 overlayPage.classList.add('pulse'); |
77 }); | 85 }); |
78 overlay.addEventListener('webkitAnimationEnd', function(e) { | 86 overlay.addEventListener('webkitAnimationEnd', function(e) { |
79 e.target.classList.remove('shake'); | 87 e.target.classList.remove('pulse'); |
80 }); | 88 }); |
81 } | 89 } |
82 | 90 |
83 return { | 91 return { |
84 globalInitialization: globalInitialization, | 92 globalInitialization: globalInitialization, |
85 setupOverlay: setupOverlay, | 93 setupOverlay: setupOverlay, |
86 } | 94 } |
87 }); | 95 }); |
88 | 96 |
89 document.addEventListener('DOMContentLoaded', | 97 document.addEventListener('DOMContentLoaded', |
90 cr.ui.overlay.globalInitialization); | 98 cr.ui.overlay.globalInitialization); |
OLD | NEW |