OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 * @fileoverview Element which shows toasts. | 6 * @fileoverview Element which shows toasts. |
7 */ | 7 */ |
8 cr.define('bookmarks', function() { | 8 cr.define('bookmarks', function() { |
9 | 9 |
10 var ToastManager = Polymer({ | 10 var ToastManager = Polymer({ |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 /** @override */ | 44 /** @override */ |
45 detached: function() { | 45 detached: function() { |
46 ToastManager.instance_ = null; | 46 ToastManager.instance_ = null; |
47 }, | 47 }, |
48 | 48 |
49 /** | 49 /** |
50 * @param {string} label The label to display inside the toast. | 50 * @param {string} label The label to display inside the toast. |
51 * @param {boolean} showUndo Whether the undo button should be shown. | 51 * @param {boolean} showUndo Whether the undo button should be shown. |
52 */ | 52 */ |
53 show: function(label, showUndo) { | 53 show: function(label, showUndo) { |
| 54 this.$.content.textContent = label; |
| 55 this.showInternal_(showUndo); |
| 56 }, |
| 57 |
| 58 /** |
| 59 * Shows the toast, making certain text fragments collapsible. |
| 60 * @param {!Array<!{value: string, collapsible: boolean}>} pieces |
| 61 * @param {boolean} showUndo Whether the undo button should be shown. |
| 62 */ |
| 63 showForStringPieces: function(pieces, showUndo) { |
| 64 var content = this.$.content; |
| 65 content.textContent = ''; |
| 66 pieces.forEach(function(p) { |
| 67 if (p.value.length == 0) |
| 68 return; |
| 69 |
| 70 var span = document.createElement('span'); |
| 71 span.textContent = p.value; |
| 72 if (p.collapsible) |
| 73 span.classList.add('collapsible'); |
| 74 |
| 75 content.appendChild(span); |
| 76 }); |
| 77 |
| 78 this.showInternal_(showUndo); |
| 79 }, |
| 80 |
| 81 /** |
| 82 * @param {boolean} showUndo Whether the undo button should be shown. |
| 83 * @private |
| 84 */ |
| 85 showInternal_: function(showUndo) { |
54 this.open_ = true; | 86 this.open_ = true; |
55 // TODO(calamity): Support collapsing of long bookmark names in label. | |
56 this.$.content.textContent = label; | |
57 this.showUndo_ = showUndo; | 87 this.showUndo_ = showUndo; |
58 | 88 |
59 if (!this.duration) | 89 if (!this.duration) |
60 return; | 90 return; |
61 | 91 |
62 if (this.hideTimeout_ != null) { | 92 if (this.hideTimeout_ != null) { |
63 this.clearTimeout_(this.hideTimeout_); | 93 this.clearTimeout_(this.hideTimeout_); |
64 this.hideTimeout_ = null; | 94 this.hideTimeout_ = null; |
65 } | 95 } |
66 | 96 |
(...skipping 19 matching lines...) Expand all Loading... |
86 | 116 |
87 /** @return {!bookmarks.ToastManager} */ | 117 /** @return {!bookmarks.ToastManager} */ |
88 ToastManager.getInstance = function() { | 118 ToastManager.getInstance = function() { |
89 return assert(ToastManager.instance_); | 119 return assert(ToastManager.instance_); |
90 }; | 120 }; |
91 | 121 |
92 return { | 122 return { |
93 ToastManager: ToastManager, | 123 ToastManager: ToastManager, |
94 }; | 124 }; |
95 }); | 125 }); |
OLD | NEW |