OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * @fileoverview Element which shows toasts. |
| 7 */ |
| 8 cr.define('bookmarks', function() { |
| 9 |
| 10 var ToastManager = Polymer({ |
| 11 is: 'bookmarks-toast-manager', |
| 12 |
| 13 properties: { |
| 14 /** @private */ |
| 15 showUndo_: Boolean, |
| 16 }, |
| 17 |
| 18 attached: function() { |
| 19 assert(ToastManager.instance_ == null); |
| 20 ToastManager.instance_ = this; |
| 21 }, |
| 22 |
| 23 detached: function() { |
| 24 ToastManager.instance_ = null; |
| 25 }, |
| 26 |
| 27 /** |
| 28 * @param {string} label The label to display inside the toast. |
| 29 * @param {boolean} showUndo Whether the undo button should be shown. |
| 30 */ |
| 31 show: function(label, showUndo) { |
| 32 var toast = this.$.toast.get(); |
| 33 // TODO(calamity): Support collapsing of long bookmark names in label. |
| 34 this.$$('#content').textContent = label; |
| 35 // We need to hide before showing to ensure that the width of the toast is |
| 36 // recalculated. |
| 37 toast.hide(); |
| 38 toast.show(); |
| 39 |
| 40 this.showUndo_ = showUndo; |
| 41 }, |
| 42 |
| 43 hide: function() { |
| 44 this.$.toast.get().hide(); |
| 45 }, |
| 46 |
| 47 /** @private */ |
| 48 onUndoTap_: function() { |
| 49 // Will hide the toast. |
| 50 this.fire('command-undo'); |
| 51 }, |
| 52 }); |
| 53 |
| 54 /** @private {bookmarks.ToastManager} */ |
| 55 ToastManager.instance_ = null; |
| 56 |
| 57 /** @return {!bookmarks.ToastManager} */ |
| 58 ToastManager.getInstance = function() { |
| 59 return assert(ToastManager.instance_); |
| 60 }; |
| 61 |
| 62 return { |
| 63 ToastManager: ToastManager, |
| 64 }; |
| 65 }); |
OLD | NEW |