| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 * Initializes the content of the Snackbar with the given |options| | 64 * Initializes the content of the Snackbar with the given |options| |
| 65 * including the message, action link text, and click action of the link. | 65 * including the message, action link text, and click action of the link. |
| 66 * @param {!SnackbarOptions} options | 66 * @param {!SnackbarOptions} options |
| 67 */ | 67 */ |
| 68 initialize: function(options) { | 68 initialize: function(options) { |
| 69 this.messageDiv_.textContent = options.message; | 69 this.messageDiv_.textContent = options.message; |
| 70 this.classList.add(options.type); | 70 this.classList.add(options.type); |
| 71 this.actionLink_.textContent = options.actionText || 'Dismiss'; | 71 this.actionLink_.textContent = options.actionText || 'Dismiss'; |
| 72 | 72 |
| 73 this.actionLink_.addEventListener('click', function() { | 73 this.actionLink_.addEventListener('click', function() { |
| 74 if (options.action) options.action(); | 74 if (options.action) |
| 75 options.action(); |
| 75 this.dismiss(); | 76 this.dismiss(); |
| 76 }.bind(this)); | 77 }.bind(this)); |
| 77 }, | 78 }, |
| 78 | 79 |
| 79 /** | 80 /** |
| 80 * Shows the Snackbar. | 81 * Shows the Snackbar. |
| 81 */ | 82 */ |
| 82 show: function() { | 83 show: function() { |
| 83 this.classList.add('open'); | 84 this.classList.add('open'); |
| 84 if (Snackbar.hasContentFocus_) this.startTimeout_(); | 85 if (Snackbar.hasContentFocus_) |
| 85 else this.stopTimeout_(); | 86 this.startTimeout_(); |
| 87 else |
| 88 this.stopTimeout_(); |
| 86 | 89 |
| 87 document.addEventListener('contentfocus', this.boundStartTimeout_); | 90 document.addEventListener('contentfocus', this.boundStartTimeout_); |
| 88 document.addEventListener('contentblur', this.boundStopTimeout_); | 91 document.addEventListener('contentblur', this.boundStopTimeout_); |
| 89 }, | 92 }, |
| 90 | 93 |
| 91 /** | 94 /** |
| 92 * Dismisses the Snackbar. Once the Snackbar is completely hidden, the | 95 * Dismisses the Snackbar. Once the Snackbar is completely hidden, the |
| 93 * 'dismissed' event is fired. | 96 * 'dismissed' event is fired. |
| 94 */ | 97 */ |
| 95 dismiss: function() { | 98 dismiss: function() { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 newSnackbar.show(); | 209 newSnackbar.show(); |
| 207 }, 10); | 210 }, 10); |
| 208 }; | 211 }; |
| 209 | 212 |
| 210 /** | 213 /** |
| 211 * Dismisses the Snackbar currently showing. | 214 * Dismisses the Snackbar currently showing. |
| 212 * @param {boolean} clearQueue If true, clears the Snackbar queue before | 215 * @param {boolean} clearQueue If true, clears the Snackbar queue before |
| 213 * dismissing. | 216 * dismissing. |
| 214 */ | 217 */ |
| 215 Snackbar.dismiss = function(clearQueue) { | 218 Snackbar.dismiss = function(clearQueue) { |
| 216 if (clearQueue) Snackbar.queue_ = []; | 219 if (clearQueue) |
| 217 if (Snackbar.current_) Snackbar.current_.dismiss(); | 220 Snackbar.queue_ = []; |
| 221 if (Snackbar.current_) |
| 222 Snackbar.current_.dismiss(); |
| 218 }; | 223 }; |
| 219 | 224 |
| 220 | 225 |
| 221 | 226 |
| 222 return { | 227 return { |
| 223 Snackbar: Snackbar, | 228 Snackbar: Snackbar, |
| 224 SnackbarType: SnackbarType, | 229 SnackbarType: SnackbarType, |
| 225 }; | 230 }; |
| 226 }); | 231 }); |
| OLD | NEW |