| 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,
|
| + };
|
| +});
|
|
|