OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 /** | 5 /** |
6 * Javascript for Snackbar controls, served from chrome://bluetooth-internals/. | 6 * Javascript for Snackbar controls, served from chrome://bluetooth-internals/. |
7 */ | 7 */ |
8 | 8 |
9 cr.define('snackbar', function() { | 9 cr.define('snackbar', function() { |
10 /** @typedef {{ | 10 /** @typedef {{ |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 * Initializes the content of the Snackbar with the given |options| | 65 * Initializes the content of the Snackbar with the given |options| |
66 * including the message, action link text, and click action of the link. | 66 * including the message, action link text, and click action of the link. |
67 * @param {!SnackbarOptions} options | 67 * @param {!SnackbarOptions} options |
68 */ | 68 */ |
69 initialize: function(options) { | 69 initialize: function(options) { |
70 this.messageDiv_.textContent = options.message; | 70 this.messageDiv_.textContent = options.message; |
71 this.classList.add(options.type); | 71 this.classList.add(options.type); |
72 this.actionLink_.textContent = options.actionText || 'Dismiss'; | 72 this.actionLink_.textContent = options.actionText || 'Dismiss'; |
73 | 73 |
74 this.actionLink_.addEventListener('click', function() { | 74 this.actionLink_.addEventListener('click', function() { |
75 if (options.action) options.action(); | 75 if (options.action) |
| 76 options.action(); |
76 this.dismiss(); | 77 this.dismiss(); |
77 }.bind(this)); | 78 }.bind(this)); |
78 }, | 79 }, |
79 | 80 |
80 /** | 81 /** |
81 * Shows the Snackbar and dispatches the 'showed' event. | 82 * Shows the Snackbar and dispatches the 'showed' event. |
82 */ | 83 */ |
83 show: function() { | 84 show: function() { |
84 this.classList.add('open'); | 85 this.classList.add('open'); |
85 if (Snackbar.hasContentFocus_) this.startTimeout_(); | 86 if (Snackbar.hasContentFocus_) |
86 else this.stopTimeout_(); | 87 this.startTimeout_(); |
| 88 else |
| 89 this.stopTimeout_(); |
87 | 90 |
88 document.addEventListener('contentfocus', this.boundStartTimeout_); | 91 document.addEventListener('contentfocus', this.boundStartTimeout_); |
89 document.addEventListener('contentblur', this.boundStopTimeout_); | 92 document.addEventListener('contentblur', this.boundStopTimeout_); |
90 this.dispatchEvent(new CustomEvent('showed')); | 93 this.dispatchEvent(new CustomEvent('showed')); |
91 }, | 94 }, |
92 | 95 |
93 /** | 96 /** |
94 * Dismisses the Snackbar. Once the Snackbar is completely hidden, the | 97 * Dismisses the Snackbar. Once the Snackbar is completely hidden, the |
95 * 'dismissed' event is fired and the returned Promise is resolved. If the | 98 * 'dismissed' event is fired and the returned Promise is resolved. If the |
96 * snackbar is already hidden, a resolved Promise is returned. | 99 * snackbar is already hidden, a resolved Promise is returned. |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 newSnackbar.show(); | 220 newSnackbar.show(); |
218 }, 10); | 221 }, 10); |
219 }; | 222 }; |
220 | 223 |
221 /** | 224 /** |
222 * Dismisses the Snackbar currently showing. | 225 * Dismisses the Snackbar currently showing. |
223 * @param {boolean} clearQueue If true, clears the Snackbar queue before | 226 * @param {boolean} clearQueue If true, clears the Snackbar queue before |
224 * dismissing. | 227 * dismissing. |
225 */ | 228 */ |
226 Snackbar.dismiss = function(clearQueue) { | 229 Snackbar.dismiss = function(clearQueue) { |
227 if (clearQueue) Snackbar.queue_ = []; | 230 if (clearQueue) |
228 if (Snackbar.current_) return Snackbar.current_.dismiss(); | 231 Snackbar.queue_ = []; |
| 232 if (Snackbar.current_) |
| 233 return Snackbar.current_.dismiss(); |
229 return Promise.resolve(); | 234 return Promise.resolve(); |
230 }; | 235 }; |
231 | 236 |
232 | 237 |
233 | 238 |
234 return { | 239 return { |
235 Snackbar: Snackbar, | 240 Snackbar: Snackbar, |
236 SnackbarType: SnackbarType, | 241 SnackbarType: SnackbarType, |
237 }; | 242 }; |
238 }); | 243 }); |
OLD | NEW |