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 this.$.toast.open = true; | |
tsergeant
2017/06/05 03:33:54
This looks like it was leftover from a rebase
calamity
2017/06/06 05:36:02
Yeah, oops, the last CL has been wreaking havoc on
| |
65 var content = this.$.content; | |
66 content.textContent = ''; | |
67 pieces.forEach(function(p) { | |
68 if (p.value.length == 0) | |
69 return; | |
70 | |
71 var span = document.createElement('span'); | |
72 span.textContent = p.value; | |
73 if (p.collapsible) | |
74 span.classList.add('collapsible'); | |
75 | |
76 content.appendChild(span); | |
77 }); | |
78 | |
79 this.showInternal_(showUndo); | |
80 }, | |
81 | |
82 /** | |
83 * @param {boolean} showUndo Whether the undo button should be shown. | |
84 * @private | |
85 */ | |
86 showInternal_: function(showUndo) { | |
54 this.open_ = true; | 87 this.open_ = true; |
55 // TODO(calamity): Support collapsing of long bookmark names in label. | |
56 this.$.content.textContent = label; | |
57 this.showUndo_ = showUndo; | 88 this.showUndo_ = showUndo; |
58 | 89 |
59 if (!this.duration) | 90 if (!this.duration) |
60 return; | 91 return; |
61 | 92 |
62 if (this.hideTimeout_ != null) { | 93 if (this.hideTimeout_ != null) { |
63 this.clearTimeout_(this.hideTimeout_); | 94 this.clearTimeout_(this.hideTimeout_); |
64 this.hideTimeout_ = null; | 95 this.hideTimeout_ = null; |
65 } | 96 } |
66 | 97 |
(...skipping 19 matching lines...) Expand all Loading... | |
86 | 117 |
87 /** @return {!bookmarks.ToastManager} */ | 118 /** @return {!bookmarks.ToastManager} */ |
88 ToastManager.getInstance = function() { | 119 ToastManager.getInstance = function() { |
89 return assert(ToastManager.instance_); | 120 return assert(ToastManager.instance_); |
90 }; | 121 }; |
91 | 122 |
92 return { | 123 return { |
93 ToastManager: ToastManager, | 124 ToastManager: ToastManager, |
94 }; | 125 }; |
95 }); | 126 }); |
OLD | NEW |