Index: chrome/browser/resources/md_bookmarks/toast_manager.js |
diff --git a/chrome/browser/resources/md_bookmarks/toast_manager.js b/chrome/browser/resources/md_bookmarks/toast_manager.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b70dc1fdbd461a7d4d1d88613c6588e68afa3eea |
--- /dev/null |
+++ b/chrome/browser/resources/md_bookmarks/toast_manager.js |
@@ -0,0 +1,65 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+/** |
+ * @fileoverview Element which shows toasts. |
+ */ |
+cr.define('bookmarks', function() { |
+ |
+ var ToastManager = Polymer({ |
+ is: 'bookmarks-toast-manager', |
+ |
+ properties: { |
+ /** @private */ |
+ showUndo_: Boolean, |
+ }, |
+ |
+ attached: function() { |
+ assert(ToastManager.instance_ == null); |
+ ToastManager.instance_ = this; |
+ }, |
+ |
+ detached: function() { |
+ ToastManager.instance_ = null; |
+ }, |
+ |
+ /** |
+ * @param {string} label The label to display inside the toast. |
+ * @param {boolean} showUndo Whether the undo button should be shown. |
+ */ |
+ show: function(label, showUndo) { |
+ var toast = this.$.toast.get(); |
+ // TODO(calamity): Support collapsing of long bookmark names in label. |
+ this.$$('#content').textContent = label; |
+ // We need to hide before showing to ensure that the width of the toast is |
+ // recalculated. |
+ toast.hide(); |
+ toast.show(); |
+ |
+ this.showUndo_ = showUndo; |
+ }, |
+ |
+ hide: function() { |
+ this.$.toast.get().hide(); |
+ }, |
+ |
+ /** @private */ |
+ onUndoTap_: function() { |
+ // Will hide the toast. |
+ this.fire('command-undo'); |
+ }, |
+ }); |
+ |
+ /** @private {bookmarks.ToastManager} */ |
+ ToastManager.instance_ = null; |
+ |
+ /** @return {!bookmarks.ToastManager} */ |
+ ToastManager.getInstance = function() { |
+ return assert(ToastManager.instance_); |
+ }; |
+ |
+ return { |
+ ToastManager: ToastManager, |
+ }; |
+}); |