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

Unified Diff: third_party/polymer/v1_0/components-chromium/paper-toast/paper-toast-extracted.js

Issue 2898303004: [MD Bookmarks] Add toasts. (Closed)
Patch Set: Created 3 years, 7 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: third_party/polymer/v1_0/components-chromium/paper-toast/paper-toast-extracted.js
diff --git a/third_party/polymer/v1_0/components-chromium/paper-toast/paper-toast-extracted.js b/third_party/polymer/v1_0/components-chromium/paper-toast/paper-toast-extracted.js
new file mode 100644
index 0000000000000000000000000000000000000000..b24b58ae4d1cfc64627fde2c61d414007ec083c0
--- /dev/null
+++ b/third_party/polymer/v1_0/components-chromium/paper-toast/paper-toast-extracted.js
@@ -0,0 +1,210 @@
+(function() {
+ 'use strict';
+
+ // Keeps track of the toast currently opened.
+ var currentToast = null;
+
+ Polymer({
+ is: 'paper-toast',
+
+ behaviors: [
+ Polymer.IronOverlayBehavior
tsergeant 2017/05/26 05:19:24 Adding a dependency on IronOverlayBehavior is a bi
Dan Beam 2017/05/30 23:25:31 +1, why do we need this?
dpapad 2017/05/30 23:33:39 Would it be too hard to roll our own toast now? In
calamity 2017/05/31 08:10:42 Rolled.
+ ],
+
+ properties: {
+ /**
+ * The element to fit `this` into.
+ * Overridden from `Polymer.IronFitBehavior`.
+ */
+ fitInto: {
+ type: Object,
+ value: window,
+ observer: '_onFitIntoChanged'
+ },
+
+ /**
+ * The orientation against which to align the dropdown content
+ * horizontally relative to `positionTarget`.
+ * Overridden from `Polymer.IronFitBehavior`.
+ */
+ horizontalAlign: {
+ type: String,
+ value: 'left'
+ },
+
+ /**
+ * The orientation against which to align the dropdown content
+ * vertically relative to `positionTarget`.
+ * Overridden from `Polymer.IronFitBehavior`.
+ */
+ verticalAlign: {
+ type: String,
+ value: 'bottom'
+ },
+
+ /**
+ * The duration in milliseconds to show the toast.
+ * Set to `0`, a negative number, or `Infinity`, to disable the
+ * toast auto-closing.
+ */
+ duration: {
+ type: Number,
+ value: 3000
+ },
+
+ /**
+ * The text to display in the toast.
+ */
+ text: {
+ type: String,
+ value: ''
+ },
+
+ /**
+ * Overridden from `IronOverlayBehavior`.
+ * Set to false to enable closing of the toast by clicking outside it.
+ */
+ noCancelOnOutsideClick: {
+ type: Boolean,
+ value: true
+ },
+
+ /**
+ * Overridden from `IronOverlayBehavior`.
+ * Set to true to disable auto-focusing the toast or child nodes with
+ * the `autofocus` attribute` when the overlay is opened.
+ */
+ noAutoFocus: {
+ type: Boolean,
+ value: true
+ }
+ },
+
+ listeners: {
+ 'transitionend': '__onTransitionEnd'
+ },
+
+ /**
+ * Read-only. Deprecated. Use `opened` from `IronOverlayBehavior`.
+ * @property visible
+ * @deprecated
+ */
+ get visible() {
+ Polymer.Base._warn('`visible` is deprecated, use `opened` instead');
+ return this.opened;
+ },
+
+ /**
+ * Read-only. Can auto-close if duration is a positive finite number.
+ * @property _canAutoClose
+ */
+ get _canAutoClose() {
+ return this.duration > 0 && this.duration !== Infinity;
+ },
+
+ created: function() {
+ this._autoClose = null;
+ Polymer.IronA11yAnnouncer.requestAvailability();
+ },
+
+ /**
+ * Show the toast. Without arguments, this is the same as `open()` from `IronOverlayBehavior`.
+ * @param {(Object|string)=} properties Properties to be set before opening the toast.
+ * e.g. `toast.show('hello')` or `toast.show({text: 'hello', duration: 3000})`
+ */
+ show: function(properties) {
+ if (typeof properties == 'string') {
+ properties = { text: properties };
+ }
+ for (var property in properties) {
+ if (property.indexOf('_') === 0) {
+ Polymer.Base._warn('The property "' + property + '" is private and was not set.');
+ } else if (property in this) {
+ this[property] = properties[property];
+ } else {
+ Polymer.Base._warn('The property "' + property + '" is not valid.');
+ }
+ }
+ this.open();
+ },
+
+ /**
+ * Hide the toast. Same as `close()` from `IronOverlayBehavior`.
+ */
+ hide: function() {
+ this.close();
+ },
+
+ /**
+ * Called on transitions of the toast, indicating a finished animation
+ * @private
+ */
+ __onTransitionEnd: function(e) {
+ // there are different transitions that are happening when opening and
+ // closing the toast. The last one so far is for `opacity`.
+ // This marks the end of the transition, so we check for this to determine if this
+ // is the correct event.
+ if (e && e.target === this && e.propertyName === 'opacity') {
+ if (this.opened) {
+ this._finishRenderOpened();
+ } else {
+ this._finishRenderClosed();
+ }
+ }
+ },
+
+ /**
+ * Overridden from `IronOverlayBehavior`.
+ * Called when the value of `opened` changes.
+ */
+ _openedChanged: function() {
+ if (this._autoClose !== null) {
+ this.cancelAsync(this._autoClose);
+ this._autoClose = null;
+ }
+ if (this.opened) {
+ if (currentToast && currentToast !== this) {
+ currentToast.close();
+ }
+ currentToast = this;
+ this.fire('iron-announce', {
+ text: this.text
+ });
+ if (this._canAutoClose) {
+ this._autoClose = this.async(this.close, this.duration);
+ }
+ } else if (currentToast === this) {
+ currentToast = null;
+ }
+ Polymer.IronOverlayBehaviorImpl._openedChanged.apply(this, arguments);
+ },
+
+ /**
+ * Overridden from `IronOverlayBehavior`.
+ */
+ _renderOpened: function() {
+ this.classList.add('paper-toast-open');
+ },
+
+ /**
+ * Overridden from `IronOverlayBehavior`.
+ */
+ _renderClosed: function() {
+ this.classList.remove('paper-toast-open');
+ },
+
+ /**
+ * @private
+ */
+ _onFitIntoChanged: function(fitInto) {
+ this.positionTarget = fitInto;
+ }
+
+ /**
+ * Fired when `paper-toast` is opened.
+ *
+ * @event 'iron-announce'
+ * @param {{text: string}} detail Contains text that will be announced.
+ */
+ });
+ })();

Powered by Google App Engine
This is Rietveld 408576698