Add Snackbar hide method

This commit is contained in:
João Fernandes 2017-01-21 17:15:56 -02:00 committed by Jonathan Garbee
parent fd21836fd4
commit 03120bb944

View File

@ -38,6 +38,7 @@
this.actionHandler_ = undefined;
this.message_ = undefined;
this.actionText_ = undefined;
this.timeoutID_ = undefined;
this.queuedNotifications_ = [];
this.setActionHidden_(true);
};
@ -86,7 +87,7 @@
this.textElement_.textContent = this.message_;
this.element_.classList.add(this.cssClasses_.ACTIVE);
this.element_.setAttribute('aria-hidden', 'false');
setTimeout(this.cleanup_.bind(this), this.timeout_);
this.timeoutID_ = setTimeout(this.cleanup_.bind(this), this.timeout_);
};
@ -127,7 +128,21 @@
}
};
MaterialSnackbar.prototype['showSnackbar'] = MaterialSnackbar.prototype.showSnackbar;
/**
* Hide the snackbar.
*
* @public
*/
MaterialSnackbar.prototype.hideSnackbar = function() {
if (!this.active) {
return;
}
if (typeof this.timeoutID_ === 'number') {
clearTimeout(this.timeoutID_);
this.cleanup_();
}
};
MaterialSnackbar.prototype['hideSnackbar'] = MaterialSnackbar.prototype.hideSnackbar;
/**
* Check if the queue has items within it.
* If it does, display the next entry.
@ -158,6 +173,7 @@
this.actionHandler_ = undefined;
this.message_ = undefined;
this.actionText_ = undefined;
this.timeoutID_ = undefined;
this.active = false;
this.checkQueue_();
}.bind(this), /** @type {number} */ (this.Constant_.ANIMATION_LENGTH));