Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Unified Diff: chrome/browser/resources/md_bookmarks/toast_manager.js

Issue 2898303004: [MD Bookmarks] Add toasts. (Closed)
Patch Set: fix nits Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..dabd588565432ee81d5591809c244f1465691801
--- /dev/null
+++ b/chrome/browser/resources/md_bookmarks/toast_manager.js
@@ -0,0 +1,95 @@
+// 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: {
+ duration: {
+ type: Number,
+ value: 0,
+ },
+
+ /** @private */
+ open_: {
+ type: Boolean,
+ reflectToAttribute: true,
+ },
+
+ /** @private */
+ showUndo_: Boolean,
+ },
+
+ /** @private {function(number)} */
+ clearTimeout_: window.clearTimeout.bind(window),
+
+ /** @private {function((Function|null|string), number)} */
+ setTimeout_: window.setTimeout.bind(window),
+
+ /** @private {number|null} */
+ hideTimeout_: null,
+
+ /** @override */
+ attached: function() {
+ assert(ToastManager.instance_ == null);
+ ToastManager.instance_ = this;
+ },
+
+ /** @override */
+ 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) {
+ this.open_ = true;
+ // TODO(calamity): Support collapsing of long bookmark names in label.
+ this.$.content.textContent = label;
+ this.showUndo_ = showUndo;
+
+ if (!this.duration)
+ return;
+
+ if (this.hideTimeout_ != null) {
+ this.clearTimeout_(this.hideTimeout_);
+ this.hideTimeout_ = null;
+ }
+
+ this.hideTimeout_ = this.setTimeout_(function() {
+ this.open_ = false;
+ this.hideTimeout_ = null;
+ }.bind(this), this.duration);
+ },
+
+ hide: function() {
+ this.open_ = false;
+ },
+
+ /** @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,
+ };
+});
« no previous file with comments | « chrome/browser/resources/md_bookmarks/toast_manager.html ('k') | chrome/browser/resources/md_bookmarks/toolbar.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698