@material/snackbar
Advanced tools
Comparing version 0.2.2 to 0.3.0
@@ -51,5 +51,2 @@ /*! | ||
/******/ | ||
/******/ // identity function for calling harmony imports with the correct context | ||
/******/ __webpack_require__.i = function(value) { return value; }; | ||
/******/ | ||
/******/ // define getter function for harmony exports | ||
@@ -82,3 +79,3 @@ /******/ __webpack_require__.d = function(exports, name, getter) { | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 91); | ||
/******/ return __webpack_require__(__webpack_require__.s = 77); | ||
/******/ }) | ||
@@ -119,3 +116,2 @@ /************************************************************************/ | ||
/** @return enum{cssClasses} */ | ||
@@ -160,3 +156,3 @@ get: function get() { | ||
/** | ||
* @param {!A} adapter | ||
* @param {A=} adapter | ||
*/ | ||
@@ -171,3 +167,3 @@ | ||
/** @private {!A} */ | ||
/** @protected {!A} */ | ||
this.adapter_ = adapter; | ||
@@ -199,33 +195,3 @@ } | ||
"use strict"; | ||
Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__foundation__ = __webpack_require__(0); | ||
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "MDCFoundation", function() { return __WEBPACK_IMPORTED_MODULE_0__foundation__["a"]; }); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__component__ = __webpack_require__(2); | ||
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "MDCComponent", function() { return __WEBPACK_IMPORTED_MODULE_1__component__["a"]; }); | ||
/** | ||
* Copyright 2016 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/***/ }), | ||
/***/ 2: | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__foundation__ = __webpack_require__(0); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
@@ -261,3 +227,2 @@ | ||
/** | ||
@@ -277,3 +242,3 @@ * @param {!Element} root | ||
* @param {!Element} root | ||
* @param {!F} foundation | ||
* @param {F=} foundation | ||
* @param {...?} args | ||
@@ -299,3 +264,3 @@ */ | ||
// this.root_ is defined and can be used within the foundation class. | ||
/** @private {!F} */ | ||
/** @protected {!F} */ | ||
this.foundation_ = foundation === undefined ? this.getDefaultFoundation() : foundation; | ||
@@ -402,3 +367,3 @@ this.foundation_.init(); | ||
/***/ 32: | ||
/***/ 2: | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
@@ -408,6 +373,46 @@ | ||
Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__foundation__ = __webpack_require__(0); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__component__ = __webpack_require__(1); | ||
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "MDCFoundation", function() { return __WEBPACK_IMPORTED_MODULE_0__foundation__["a"]; }); | ||
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "MDCComponent", function() { return __WEBPACK_IMPORTED_MODULE_1__component__["a"]; }); | ||
/** | ||
* Copyright 2016 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/***/ }), | ||
/***/ 77: | ||
/***/ (function(module, exports, __webpack_require__) { | ||
module.exports = __webpack_require__(78); | ||
/***/ }), | ||
/***/ 78: | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MDCSnackbar", function() { return MDCSnackbar; }); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__material_base__ = __webpack_require__(1); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__foundation__ = __webpack_require__(63); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__material_animation__ = __webpack_require__(7); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__material_base__ = __webpack_require__(2); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__foundation__ = __webpack_require__(79); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__material_animation__ = __webpack_require__(8); | ||
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "MDCSnackbarFoundation", function() { return __WEBPACK_IMPORTED_MODULE_1__foundation__["a"]; }); | ||
@@ -500,2 +505,26 @@ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
}, | ||
setFocus: function setFocus() { | ||
return getActionButton().focus(); | ||
}, | ||
visibilityIsHidden: function visibilityIsHidden() { | ||
return document.hidden; | ||
}, | ||
registerCapturedBlurHandler: function registerCapturedBlurHandler(handler) { | ||
return getActionButton().addEventListener('blur', handler, true); | ||
}, | ||
deregisterCapturedBlurHandler: function deregisterCapturedBlurHandler(handler) { | ||
return getActionButton().removeEventListener('blur', handler, true); | ||
}, | ||
registerVisibilityChangeHandler: function registerVisibilityChangeHandler(handler) { | ||
return document.addEventListener('visibilitychange', handler); | ||
}, | ||
deregisterVisibilityChangeHandler: function deregisterVisibilityChangeHandler(handler) { | ||
return document.removeEventListener('visibilitychange', handler); | ||
}, | ||
registerCapturedInteractionHandler: function registerCapturedInteractionHandler(evt, handler) { | ||
return document.body.addEventListener(evt, handler, true); | ||
}, | ||
deregisterCapturedInteractionHandler: function deregisterCapturedInteractionHandler(evt, handler) { | ||
return document.body.removeEventListener(evt, handler, true); | ||
}, | ||
registerActionClickHandler: function registerActionClickHandler(handler) { | ||
@@ -508,6 +537,6 @@ return getActionButton().addEventListener('click', handler); | ||
registerTransitionEndHandler: function registerTransitionEndHandler(handler) { | ||
return _this2.root_.addEventListener(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2__material_animation__["getCorrectEventName"])(window, 'transitionend'), handler); | ||
return _this2.root_.addEventListener(__WEBPACK_IMPORTED_MODULE_2__material_animation__["getCorrectEventName"](window, 'transitionend'), handler); | ||
}, | ||
deregisterTransitionEndHandler: function deregisterTransitionEndHandler(handler) { | ||
return _this2.root_.removeEventListener(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2__material_animation__["getCorrectEventName"])(window, 'transitionend'), handler); | ||
return _this2.root_.removeEventListener(__WEBPACK_IMPORTED_MODULE_2__material_animation__["getCorrectEventName"](window, 'transitionend'), handler); | ||
} | ||
@@ -536,52 +565,8 @@ }); | ||
/***/ 62: | ||
/***/ 79: | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return cssClasses; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return strings; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "c", function() { return numbers; }); | ||
/** | ||
* Copyright 2016 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
var cssClasses = { | ||
ROOT: 'mdc-snackbar', | ||
TEXT: 'mdc-snackbar__text', | ||
ACTION_WRAPPER: 'mdc-snackbar__action-wrapper', | ||
ACTION_BUTTON: 'mdc-snackbar__action-button', | ||
ACTIVE: 'mdc-snackbar--active', | ||
MULTILINE: 'mdc-snackbar--multiline', | ||
ACTION_ON_BOTTOM: 'mdc-snackbar--action-on-bottom' | ||
}; | ||
var strings = { | ||
TEXT_SELECTOR: '.mdc-snackbar__text', | ||
ACTION_WRAPPER_SELECTOR: '.mdc-snackbar__action-wrapper', | ||
ACTION_BUTTON_SELECTOR: '.mdc-snackbar__action-button' | ||
}; | ||
var numbers = { | ||
MESSAGE_TIMEOUT: 2750 | ||
}; | ||
/***/ }), | ||
/***/ 63: | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__material_base__ = __webpack_require__(1); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__constants__ = __webpack_require__(62); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__material_base__ = __webpack_require__(2); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__constants__ = __webpack_require__(80); | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
@@ -632,3 +617,3 @@ | ||
get: function get() { | ||
return __WEBPACK_IMPORTED_MODULE_1__constants__["b" /* strings */]; | ||
return __WEBPACK_IMPORTED_MODULE_1__constants__["c" /* strings */]; | ||
} | ||
@@ -643,6 +628,17 @@ }, { | ||
unsetAriaHidden: function unsetAriaHidden() {}, | ||
setMessageText: function setMessageText() /* message: string */{}, | ||
setActionText: function setActionText() /* actionText: string */{}, | ||
setActionAriaHidden: function setActionAriaHidden() {}, | ||
unsetActionAriaHidden: function unsetActionAriaHidden() {}, | ||
setActionText: function setActionText() /* actionText: string */{}, | ||
setMessageText: function setMessageText() /* message: string */{}, | ||
setFocus: function setFocus() {}, | ||
visibilityIsHidden: function visibilityIsHidden() { | ||
return (/* boolean */false | ||
); | ||
}, | ||
registerCapturedBlurHandler: function registerCapturedBlurHandler() /* handler: EventListener */{}, | ||
deregisterCapturedBlurHandler: function deregisterCapturedBlurHandler() /* handler: EventListener */{}, | ||
registerVisibilityChangeHandler: function registerVisibilityChangeHandler() /* handler: EventListener */{}, | ||
deregisterVisibilityChangeHandler: function deregisterVisibilityChangeHandler() /* handler: EventListener */{}, | ||
registerCapturedInteractionHandler: function registerCapturedInteractionHandler() /* evtType: string, handler: EventListener */{}, | ||
deregisterCapturedInteractionHandler: function deregisterCapturedInteractionHandler() /* evtType: string, handler: EventListener */{}, | ||
registerActionClickHandler: function registerActionClickHandler() /* handler: EventListener */{}, | ||
@@ -662,7 +658,36 @@ deregisterActionClickHandler: function deregisterActionClickHandler() /* handler: EventListener */{}, | ||
_this.active_ = false; | ||
_this.actionWasClicked_ = false; | ||
_this.dismissOnAction_ = true; | ||
_this.firstFocus_ = true; | ||
_this.pointerDownRecognized_ = false; | ||
_this.snackbarHasFocus_ = false; | ||
_this.snackbarData_ = null; | ||
_this.queue_ = []; | ||
_this.actionClickHandler_ = function () { | ||
return _this.invokeAction_(); | ||
_this.actionWasClicked_ = true; | ||
_this.invokeAction_(); | ||
}; | ||
_this.visibilitychangeHandler_ = function () { | ||
clearTimeout(_this.timeoutId_); | ||
_this.snackbarHasFocus_ = true; | ||
if (!_this.adapter_.visibilityIsHidden()) { | ||
setTimeout(_this.cleanup_.bind(_this), _this.snackbarData_.timeout || __WEBPACK_IMPORTED_MODULE_1__constants__["b" /* numbers */].MESSAGE_TIMEOUT); | ||
} | ||
}; | ||
_this.interactionHandler_ = function (evt) { | ||
if (evt.type == 'touchstart' || evt.type == 'mousedown') { | ||
_this.pointerDownRecognized_ = true; | ||
} | ||
_this.handlePossibleTabKeyboardFocus_(evt); | ||
if (evt.type == 'focus') { | ||
_this.pointerDownRecognized_ = false; | ||
} | ||
}; | ||
_this.blurHandler_ = function () { | ||
clearTimeout(_this.timeoutId_); | ||
_this.snackbarHasFocus_ = false; | ||
_this.timeoutId_ = setTimeout(_this.cleanup_.bind(_this), _this.snackbarData_.timeout || __WEBPACK_IMPORTED_MODULE_1__constants__["b" /* numbers */].MESSAGE_TIMEOUT); | ||
}; | ||
return _this; | ||
@@ -681,3 +706,10 @@ } | ||
value: function destroy() { | ||
var _this2 = this; | ||
this.adapter_.deregisterActionClickHandler(this.actionClickHandler_); | ||
this.adapter_.deregisterCapturedBlurHandler(this.blurHandler_); | ||
this.adapter_.deregisterVisibilityChangeHandler(this.visibilitychangeHandler_); | ||
['touchstart', 'mousedown', 'focus'].forEach(function (evtType) { | ||
_this2.adapter_.deregisterCapturedInteractionHandler(evtType, _this2.interactionHandler_); | ||
}); | ||
} | ||
@@ -697,15 +729,24 @@ }, { | ||
value: function show(data) { | ||
if (!data) { | ||
var _this3 = this; | ||
clearTimeout(this.timeoutId_); | ||
this.snackbarData_ = data; | ||
this.firstFocus_ = true; | ||
this.adapter_.registerVisibilityChangeHandler(this.visibilitychangeHandler_); | ||
this.adapter_.registerCapturedBlurHandler(this.blurHandler_); | ||
['touchstart', 'mousedown', 'focus'].forEach(function (evtType) { | ||
_this3.adapter_.registerCapturedInteractionHandler(evtType, _this3.interactionHandler_); | ||
}); | ||
if (!this.snackbarData_) { | ||
throw new Error('Please provide a data object with at least a message to display.'); | ||
} | ||
if (!data.message) { | ||
if (!this.snackbarData_.message) { | ||
throw new Error('Please provide a message to be displayed.'); | ||
} | ||
if (data.actionHandler && !data.actionText) { | ||
if (this.snackbarData_.actionHandler && !this.snackbarData_.actionText) { | ||
throw new Error('Please provide action text with the handler.'); | ||
} | ||
if (this.active) { | ||
this.queue_.push(data); | ||
return; | ||
this.queue_.push(this.snackbarData_); | ||
} | ||
@@ -716,10 +757,9 @@ | ||
ACTION_ON_BOTTOM = __WEBPACK_IMPORTED_MODULE_1__constants__["a" /* cssClasses */].ACTION_ON_BOTTOM; | ||
var MESSAGE_TIMEOUT = __WEBPACK_IMPORTED_MODULE_1__constants__["c" /* numbers */].MESSAGE_TIMEOUT; | ||
this.adapter_.setMessageText(data.message); | ||
this.adapter_.setMessageText(this.snackbarData_.message); | ||
if (data.multiline) { | ||
if (this.snackbarData_.multiline) { | ||
this.adapter_.addClass(MULTILINE); | ||
if (data.actionOnBottom) { | ||
if (this.snackbarData_.actionOnBottom) { | ||
this.adapter_.addClass(ACTION_ON_BOTTOM); | ||
@@ -729,5 +769,5 @@ } | ||
if (data.actionHandler) { | ||
this.adapter_.setActionText(data.actionText); | ||
this.actionHandler_ = data.actionHandler; | ||
if (this.snackbarData_.actionHandler) { | ||
this.adapter_.setActionText(this.snackbarData_.actionText); | ||
this.actionHandler_ = this.snackbarData_.actionHandler; | ||
this.setActionHidden_(false); | ||
@@ -744,5 +784,23 @@ } else { | ||
this.timeoutId_ = setTimeout(this.cleanup_.bind(this), data.timeout || MESSAGE_TIMEOUT); | ||
this.timeoutId_ = setTimeout(this.cleanup_.bind(this), this.snackbarData_.timeout || __WEBPACK_IMPORTED_MODULE_1__constants__["b" /* numbers */].MESSAGE_TIMEOUT); | ||
} | ||
}, { | ||
key: 'handlePossibleTabKeyboardFocus_', | ||
value: function handlePossibleTabKeyboardFocus_() { | ||
var hijackFocus = this.firstFocus_ && !this.pointerDownRecognized_; | ||
if (hijackFocus) { | ||
this.setFocusOnAction_(); | ||
} | ||
this.firstFocus_ = false; | ||
} | ||
}, { | ||
key: 'setFocusOnAction_', | ||
value: function setFocusOnAction_() { | ||
this.adapter_.setFocus(); | ||
this.snackbarHasFocus_ = true; | ||
this.firstFocus_ = false; | ||
} | ||
}, { | ||
key: 'invokeAction_', | ||
@@ -758,3 +816,2 @@ value: function invokeAction_() { | ||
if (this.dismissOnAction_) { | ||
clearTimeout(this.timeoutId_); | ||
this.cleanup_(); | ||
@@ -767,24 +824,28 @@ } | ||
value: function cleanup_() { | ||
var _this2 = this; | ||
var _this4 = this; | ||
var ACTIVE = __WEBPACK_IMPORTED_MODULE_1__constants__["a" /* cssClasses */].ACTIVE, | ||
MULTILINE = __WEBPACK_IMPORTED_MODULE_1__constants__["a" /* cssClasses */].MULTILINE, | ||
ACTION_ON_BOTTOM = __WEBPACK_IMPORTED_MODULE_1__constants__["a" /* cssClasses */].ACTION_ON_BOTTOM; | ||
var allowDismissal = !this.snackbarHasFocus_ || this.actionWasClicked_; | ||
if (allowDismissal) { | ||
var ACTIVE = __WEBPACK_IMPORTED_MODULE_1__constants__["a" /* cssClasses */].ACTIVE, | ||
MULTILINE = __WEBPACK_IMPORTED_MODULE_1__constants__["a" /* cssClasses */].MULTILINE, | ||
ACTION_ON_BOTTOM = __WEBPACK_IMPORTED_MODULE_1__constants__["a" /* cssClasses */].ACTION_ON_BOTTOM; | ||
this.adapter_.removeClass(ACTIVE); | ||
var handler = function handler() { | ||
_this2.adapter_.deregisterTransitionEndHandler(handler); | ||
_this2.adapter_.removeClass(MULTILINE); | ||
_this2.adapter_.removeClass(ACTION_ON_BOTTOM); | ||
_this2.setActionHidden_(true); | ||
_this2.adapter_.setMessageText(null); | ||
_this2.adapter_.setActionText(null); | ||
_this2.adapter_.setAriaHidden(); | ||
_this2.active_ = false; | ||
_this2.showNext_(); | ||
}; | ||
this.adapter_.removeClass(ACTIVE); | ||
this.adapter_.registerTransitionEndHandler(handler); | ||
var handler = function handler() { | ||
clearTimeout(_this4.timeoutId_); | ||
_this4.adapter_.deregisterTransitionEndHandler(handler); | ||
_this4.adapter_.removeClass(MULTILINE); | ||
_this4.adapter_.removeClass(ACTION_ON_BOTTOM); | ||
_this4.setActionHidden_(true); | ||
_this4.adapter_.setAriaHidden(); | ||
_this4.active_ = false; | ||
_this4.snackbarHasFocus_ = false; | ||
_this4.showNext_(); | ||
}; | ||
this.adapter_.registerTransitionEndHandler(handler); | ||
} | ||
} | ||
@@ -797,3 +858,2 @@ }, { | ||
} | ||
this.show(this.queue_.shift()); | ||
@@ -819,3 +879,3 @@ } | ||
/***/ 7: | ||
/***/ 8: | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
@@ -968,8 +1028,44 @@ | ||
/***/ 91: | ||
/***/ (function(module, exports, __webpack_require__) { | ||
/***/ 80: | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
module.exports = __webpack_require__(32); | ||
"use strict"; | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return cssClasses; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "c", function() { return strings; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return numbers; }); | ||
/** | ||
* Copyright 2016 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
var cssClasses = { | ||
ROOT: 'mdc-snackbar', | ||
TEXT: 'mdc-snackbar__text', | ||
ACTION_WRAPPER: 'mdc-snackbar__action-wrapper', | ||
ACTION_BUTTON: 'mdc-snackbar__action-button', | ||
ACTIVE: 'mdc-snackbar--active', | ||
MULTILINE: 'mdc-snackbar--multiline', | ||
ACTION_ON_BOTTOM: 'mdc-snackbar--action-on-bottom' | ||
}; | ||
var strings = { | ||
TEXT_SELECTOR: '.mdc-snackbar__text', | ||
ACTION_WRAPPER_SELECTOR: '.mdc-snackbar__action-wrapper', | ||
ACTION_BUTTON_SELECTOR: '.mdc-snackbar__action-button' | ||
}; | ||
var numbers = { | ||
MESSAGE_TIMEOUT: 2750 | ||
}; | ||
/***/ }) | ||
@@ -976,0 +1072,0 @@ |
@@ -6,2 +6,2 @@ /*! | ||
*/ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.snackbar=e():(t.mdc=t.mdc||{},t.mdc.snackbar=e())}(this,function(){return function(t){function e(i){if(n[i])return n[i].exports;var r=n[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,e),r.l=!0,r.exports}var n={};return e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,i){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:i})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="/assets/",e(e.s=91)}({0:function(t,e,n){"use strict";function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var r=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),o=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};i(this,t),this.adapter_=e}return r(t,null,[{key:"cssClasses",get:function(){return{}}},{key:"strings",get:function(){return{}}},{key:"numbers",get:function(){return{}}},{key:"defaultAdapter",get:function(){return{}}}]),r(t,[{key:"init",value:function(){}},{key:"destroy",value:function(){}}]),t}();e.a=o},1:function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=n(0);n.d(e,"MDCFoundation",function(){return i.a});var r=n(2);n.d(e,"MDCComponent",function(){return r.a})},2:function(t,e,n){"use strict";function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var r=n(0),o=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),a=function(){function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;i(this,t),this.root_=e;for(var r=arguments.length,o=Array(r>2?r-2:0),a=2;a<r;a++)o[a-2]=arguments[a];this.initialize.apply(this,o),this.foundation_=void 0===n?this.getDefaultFoundation():n,this.foundation_.init(),this.initialSyncWithDOM()}return o(t,null,[{key:"attachTo",value:function(e){return new t(e,new r.a)}}]),o(t,[{key:"initialize",value:function(){}},{key:"getDefaultFoundation",value:function(){throw new Error("Subclasses must override getDefaultFoundation to return a properly configured foundation class")}},{key:"initialSyncWithDOM",value:function(){}},{key:"destroy",value:function(){this.foundation_.destroy()}},{key:"listen",value:function(t,e){this.root_.addEventListener(t,e)}},{key:"unlisten",value:function(t,e){this.root_.removeEventListener(t,e)}},{key:"emit",value:function(t,e){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=void 0;"function"==typeof CustomEvent?i=new CustomEvent(t,{detail:e,bubbles:n}):(i=document.createEvent("CustomEvent"),i.initCustomEvent(t,n,!1,e)),this.root_.dispatchEvent(i)}}]),t}();e.a=a},32:function(t,e,n){"use strict";function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function o(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(e,"__esModule",{value:!0}),n.d(e,"MDCSnackbar",function(){return f});var a=n(1),s=n(63),u=n(7);n.d(e,"MDCSnackbarFoundation",function(){return s.a});var c=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),f=function(t){function e(){return i(this,e),r(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return o(e,t),c(e,[{key:"show",value:function(t){this.foundation_.show(t)}},{key:"getDefaultFoundation",value:function(){var t=this,e=s.a.strings,i=e.TEXT_SELECTOR,r=e.ACTION_BUTTON_SELECTOR,o=function(){return t.root_.querySelector(i)},a=function(){return t.root_.querySelector(r)};return new s.a({addClass:function(e){return t.root_.classList.add(e)},removeClass:function(e){return t.root_.classList.remove(e)},setAriaHidden:function(){return t.root_.setAttribute("aria-hidden","true")},unsetAriaHidden:function(){return t.root_.removeAttribute("aria-hidden")},setActionAriaHidden:function(){return a().setAttribute("aria-hidden","true")},unsetActionAriaHidden:function(){return a().removeAttribute("aria-hidden")},setActionText:function(t){a().textContent=t},setMessageText:function(t){o().textContent=t},registerActionClickHandler:function(t){return a().addEventListener("click",t)},deregisterActionClickHandler:function(t){return a().removeEventListener("click",t)},registerTransitionEndHandler:function(e){return t.root_.addEventListener(n.i(u.getCorrectEventName)(window,"transitionend"),e)},deregisterTransitionEndHandler:function(e){return t.root_.removeEventListener(n.i(u.getCorrectEventName)(window,"transitionend"),e)}})}},{key:"dismissesOnAction",get:function(){return this.foundation_.dismissesOnAction()},set:function(t){this.foundation_.setDismissOnAction(t)}}],[{key:"attachTo",value:function(t){return new e(t)}}]),e}(a.MDCComponent)},62:function(t,e,n){"use strict";n.d(e,"a",function(){return i}),n.d(e,"b",function(){return r}),n.d(e,"c",function(){return o});var i={ROOT:"mdc-snackbar",TEXT:"mdc-snackbar__text",ACTION_WRAPPER:"mdc-snackbar__action-wrapper",ACTION_BUTTON:"mdc-snackbar__action-button",ACTIVE:"mdc-snackbar--active",MULTILINE:"mdc-snackbar--multiline",ACTION_ON_BOTTOM:"mdc-snackbar--action-on-bottom"},r={TEXT_SELECTOR:".mdc-snackbar__text",ACTION_WRAPPER_SELECTOR:".mdc-snackbar__action-wrapper",ACTION_BUTTON_SELECTOR:".mdc-snackbar__action-button"},o={MESSAGE_TIMEOUT:2750}},63:function(t,e,n){"use strict";function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function o(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var a=n(1),s=n(62),u=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},c=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),f=function(t){function e(t){i(this,e);var n=r(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,u(e.defaultAdapter,t)));return n.active_=!1,n.dismissOnAction_=!0,n.queue_=[],n.actionClickHandler_=function(){return n.invokeAction_()},n}return o(e,t),c(e,[{key:"active",get:function(){return this.active_}}],[{key:"cssClasses",get:function(){return s.a}},{key:"strings",get:function(){return s.b}},{key:"defaultAdapter",get:function(){return{addClass:function(){},removeClass:function(){},setAriaHidden:function(){},unsetAriaHidden:function(){},setMessageText:function(){},setActionText:function(){},setActionAriaHidden:function(){},unsetActionAriaHidden:function(){},registerActionClickHandler:function(){},deregisterActionClickHandler:function(){},registerTransitionEndHandler:function(){},deregisterTransitionEndHandler:function(){}}}}]),c(e,[{key:"init",value:function(){this.adapter_.registerActionClickHandler(this.actionClickHandler_),this.adapter_.setAriaHidden(),this.adapter_.setActionAriaHidden()}},{key:"destroy",value:function(){this.adapter_.deregisterActionClickHandler(this.actionClickHandler_)}},{key:"dismissesOnAction",value:function(){return this.dismissOnAction_}},{key:"setDismissOnAction",value:function(t){this.dismissOnAction_=!!t}},{key:"show",value:function(t){if(!t)throw new Error("Please provide a data object with at least a message to display.");if(!t.message)throw new Error("Please provide a message to be displayed.");if(t.actionHandler&&!t.actionText)throw new Error("Please provide action text with the handler.");if(this.active)return void this.queue_.push(t);var e=s.a.ACTIVE,n=s.a.MULTILINE,i=s.a.ACTION_ON_BOTTOM,r=s.c.MESSAGE_TIMEOUT;this.adapter_.setMessageText(t.message),t.multiline&&(this.adapter_.addClass(n),t.actionOnBottom&&this.adapter_.addClass(i)),t.actionHandler?(this.adapter_.setActionText(t.actionText),this.actionHandler_=t.actionHandler,this.setActionHidden_(!1)):(this.setActionHidden_(!0),this.actionHandler_=null,this.adapter_.setActionText(null)),this.active_=!0,this.adapter_.addClass(e),this.adapter_.unsetAriaHidden(),this.timeoutId_=setTimeout(this.cleanup_.bind(this),t.timeout||r)}},{key:"invokeAction_",value:function(){try{if(!this.actionHandler_)return;this.actionHandler_()}finally{this.dismissOnAction_&&(clearTimeout(this.timeoutId_),this.cleanup_())}}},{key:"cleanup_",value:function(){var t=this,e=s.a.ACTIVE,n=s.a.MULTILINE,i=s.a.ACTION_ON_BOTTOM;this.adapter_.removeClass(e);var r=function e(){t.adapter_.deregisterTransitionEndHandler(e),t.adapter_.removeClass(n),t.adapter_.removeClass(i),t.setActionHidden_(!0),t.adapter_.setMessageText(null),t.adapter_.setActionText(null),t.adapter_.setAriaHidden(),t.active_=!1,t.showNext_()};this.adapter_.registerTransitionEndHandler(r)}},{key:"showNext_",value:function(){this.queue_.length&&this.show(this.queue_.shift())}},{key:"setActionHidden_",value:function(t){t?this.adapter_.setActionAriaHidden():this.adapter_.unsetActionAriaHidden()}}]),e}(a.MDCFoundation);e.a=f},7:function(t,e,n){"use strict";function i(t){return void 0!==t.document&&"function"==typeof t.document.createElement}function r(t){return t in c||t in f}function o(t,e,n){return e[t].styleProperty in n.style?e[t].noPrefix:e[t].webkitPrefix}function a(t,e){if(!i(t)||!r(e))return e;var n=e in c?c:f,a=t.document.createElement("div");return n===c?o(e,n,a):n[e].noPrefix in a.style?n[e].noPrefix:n[e].webkitPrefix}function s(t,e){return a(t,e)}function u(t,e){return a(t,e)}Object.defineProperty(e,"__esModule",{value:!0}),n.d(e,"transformStyleProperties",function(){return d}),e.getCorrectEventName=s,e.getCorrectPropertyName=u;var c={animationstart:{noPrefix:"animationstart",webkitPrefix:"webkitAnimationStart",styleProperty:"animation"},animationend:{noPrefix:"animationend",webkitPrefix:"webkitAnimationEnd",styleProperty:"animation"},animationiteration:{noPrefix:"animationiteration",webkitPrefix:"webkitAnimationIteration",styleProperty:"animation"},transitionend:{noPrefix:"transitionend",webkitPrefix:"webkitTransitionEnd",styleProperty:"transition"}},f={animation:{noPrefix:"animation",webkitPrefix:"-webkit-animation"},transform:{noPrefix:"transform",webkitPrefix:"-webkit-transform"},transition:{noPrefix:"transition",webkitPrefix:"-webkit-transition"}},d=["transform","WebkitTransform","MozTransform","OTransform","MSTransform"]},91:function(t,e,n){t.exports=n(32)}})}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.snackbar=e():(t.mdc=t.mdc||{},t.mdc.snackbar=e())}(this,function(){return function(t){function e(i){if(n[i])return n[i].exports;var r=n[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,e),r.l=!0,r.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,i){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:i})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="/assets/",e(e.s=77)}({0:function(t,e,n){"use strict";function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var r=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),a=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};i(this,t),this.adapter_=e}return r(t,null,[{key:"cssClasses",get:function(){return{}}},{key:"strings",get:function(){return{}}},{key:"numbers",get:function(){return{}}},{key:"defaultAdapter",get:function(){return{}}}]),r(t,[{key:"init",value:function(){}},{key:"destroy",value:function(){}}]),t}();e.a=a},1:function(t,e,n){"use strict";function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var r=n(0),a=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),o=function(){function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;i(this,t),this.root_=e;for(var r=arguments.length,a=Array(r>2?r-2:0),o=2;o<r;o++)a[o-2]=arguments[o];this.initialize.apply(this,a),this.foundation_=void 0===n?this.getDefaultFoundation():n,this.foundation_.init(),this.initialSyncWithDOM()}return a(t,null,[{key:"attachTo",value:function(e){return new t(e,new r.a)}}]),a(t,[{key:"initialize",value:function(){}},{key:"getDefaultFoundation",value:function(){throw new Error("Subclasses must override getDefaultFoundation to return a properly configured foundation class")}},{key:"initialSyncWithDOM",value:function(){}},{key:"destroy",value:function(){this.foundation_.destroy()}},{key:"listen",value:function(t,e){this.root_.addEventListener(t,e)}},{key:"unlisten",value:function(t,e){this.root_.removeEventListener(t,e)}},{key:"emit",value:function(t,e){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=void 0;"function"==typeof CustomEvent?i=new CustomEvent(t,{detail:e,bubbles:n}):(i=document.createEvent("CustomEvent"),i.initCustomEvent(t,n,!1,e)),this.root_.dispatchEvent(i)}}]),t}();e.a=o},2:function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=n(0),r=n(1);n.d(e,"MDCFoundation",function(){return i.a}),n.d(e,"MDCComponent",function(){return r.a})},77:function(t,e,n){t.exports=n(78)},78:function(t,e,n){"use strict";function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function a(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(e,"__esModule",{value:!0}),n.d(e,"MDCSnackbar",function(){return d});var o=n(2),s=n(79),u=n(8);n.d(e,"MDCSnackbarFoundation",function(){return s.a});var c=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),d=function(t){function e(){return i(this,e),r(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),c(e,[{key:"show",value:function(t){this.foundation_.show(t)}},{key:"getDefaultFoundation",value:function(){var t=this,e=s.a.strings,n=e.TEXT_SELECTOR,i=e.ACTION_BUTTON_SELECTOR,r=function(){return t.root_.querySelector(n)},a=function(){return t.root_.querySelector(i)};return new s.a({addClass:function(e){return t.root_.classList.add(e)},removeClass:function(e){return t.root_.classList.remove(e)},setAriaHidden:function(){return t.root_.setAttribute("aria-hidden","true")},unsetAriaHidden:function(){return t.root_.removeAttribute("aria-hidden")},setActionAriaHidden:function(){return a().setAttribute("aria-hidden","true")},unsetActionAriaHidden:function(){return a().removeAttribute("aria-hidden")},setActionText:function(t){a().textContent=t},setMessageText:function(t){r().textContent=t},setFocus:function(){return a().focus()},visibilityIsHidden:function(){return document.hidden},registerCapturedBlurHandler:function(t){return a().addEventListener("blur",t,!0)},deregisterCapturedBlurHandler:function(t){return a().removeEventListener("blur",t,!0)},registerVisibilityChangeHandler:function(t){return document.addEventListener("visibilitychange",t)},deregisterVisibilityChangeHandler:function(t){return document.removeEventListener("visibilitychange",t)},registerCapturedInteractionHandler:function(t,e){return document.body.addEventListener(t,e,!0)},deregisterCapturedInteractionHandler:function(t,e){return document.body.removeEventListener(t,e,!0)},registerActionClickHandler:function(t){return a().addEventListener("click",t)},deregisterActionClickHandler:function(t){return a().removeEventListener("click",t)},registerTransitionEndHandler:function(e){return t.root_.addEventListener(u.getCorrectEventName(window,"transitionend"),e)},deregisterTransitionEndHandler:function(e){return t.root_.removeEventListener(u.getCorrectEventName(window,"transitionend"),e)}})}},{key:"dismissesOnAction",get:function(){return this.foundation_.dismissesOnAction()},set:function(t){this.foundation_.setDismissOnAction(t)}}],[{key:"attachTo",value:function(t){return new e(t)}}]),e}(o.MDCComponent)},79:function(t,e,n){"use strict";function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function a(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var o=n(2),s=n(80),u=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},c=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),d=function(t){function e(t){i(this,e);var n=r(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,u(e.defaultAdapter,t)));return n.active_=!1,n.actionWasClicked_=!1,n.dismissOnAction_=!0,n.firstFocus_=!0,n.pointerDownRecognized_=!1,n.snackbarHasFocus_=!1,n.snackbarData_=null,n.queue_=[],n.actionClickHandler_=function(){n.actionWasClicked_=!0,n.invokeAction_()},n.visibilitychangeHandler_=function(){clearTimeout(n.timeoutId_),n.snackbarHasFocus_=!0,n.adapter_.visibilityIsHidden()||setTimeout(n.cleanup_.bind(n),n.snackbarData_.timeout||s.b.MESSAGE_TIMEOUT)},n.interactionHandler_=function(t){"touchstart"!=t.type&&"mousedown"!=t.type||(n.pointerDownRecognized_=!0),n.handlePossibleTabKeyboardFocus_(t),"focus"==t.type&&(n.pointerDownRecognized_=!1)},n.blurHandler_=function(){clearTimeout(n.timeoutId_),n.snackbarHasFocus_=!1,n.timeoutId_=setTimeout(n.cleanup_.bind(n),n.snackbarData_.timeout||s.b.MESSAGE_TIMEOUT)},n}return a(e,t),c(e,[{key:"active",get:function(){return this.active_}}],[{key:"cssClasses",get:function(){return s.a}},{key:"strings",get:function(){return s.c}},{key:"defaultAdapter",get:function(){return{addClass:function(){},removeClass:function(){},setAriaHidden:function(){},unsetAriaHidden:function(){},setActionAriaHidden:function(){},unsetActionAriaHidden:function(){},setActionText:function(){},setMessageText:function(){},setFocus:function(){},visibilityIsHidden:function(){return!1},registerCapturedBlurHandler:function(){},deregisterCapturedBlurHandler:function(){},registerVisibilityChangeHandler:function(){},deregisterVisibilityChangeHandler:function(){},registerCapturedInteractionHandler:function(){},deregisterCapturedInteractionHandler:function(){},registerActionClickHandler:function(){},deregisterActionClickHandler:function(){},registerTransitionEndHandler:function(){},deregisterTransitionEndHandler:function(){}}}}]),c(e,[{key:"init",value:function(){this.adapter_.registerActionClickHandler(this.actionClickHandler_),this.adapter_.setAriaHidden(),this.adapter_.setActionAriaHidden()}},{key:"destroy",value:function(){var t=this;this.adapter_.deregisterActionClickHandler(this.actionClickHandler_),this.adapter_.deregisterCapturedBlurHandler(this.blurHandler_),this.adapter_.deregisterVisibilityChangeHandler(this.visibilitychangeHandler_),["touchstart","mousedown","focus"].forEach(function(e){t.adapter_.deregisterCapturedInteractionHandler(e,t.interactionHandler_)})}},{key:"dismissesOnAction",value:function(){return this.dismissOnAction_}},{key:"setDismissOnAction",value:function(t){this.dismissOnAction_=!!t}},{key:"show",value:function(t){var e=this;if(clearTimeout(this.timeoutId_),this.snackbarData_=t,this.firstFocus_=!0,this.adapter_.registerVisibilityChangeHandler(this.visibilitychangeHandler_),this.adapter_.registerCapturedBlurHandler(this.blurHandler_),["touchstart","mousedown","focus"].forEach(function(t){e.adapter_.registerCapturedInteractionHandler(t,e.interactionHandler_)}),!this.snackbarData_)throw new Error("Please provide a data object with at least a message to display.");if(!this.snackbarData_.message)throw new Error("Please provide a message to be displayed.");if(this.snackbarData_.actionHandler&&!this.snackbarData_.actionText)throw new Error("Please provide action text with the handler.");this.active&&this.queue_.push(this.snackbarData_);var n=s.a.ACTIVE,i=s.a.MULTILINE,r=s.a.ACTION_ON_BOTTOM;this.adapter_.setMessageText(this.snackbarData_.message),this.snackbarData_.multiline&&(this.adapter_.addClass(i),this.snackbarData_.actionOnBottom&&this.adapter_.addClass(r)),this.snackbarData_.actionHandler?(this.adapter_.setActionText(this.snackbarData_.actionText),this.actionHandler_=this.snackbarData_.actionHandler,this.setActionHidden_(!1)):(this.setActionHidden_(!0),this.actionHandler_=null,this.adapter_.setActionText(null)),this.active_=!0,this.adapter_.addClass(n),this.adapter_.unsetAriaHidden(),this.timeoutId_=setTimeout(this.cleanup_.bind(this),this.snackbarData_.timeout||s.b.MESSAGE_TIMEOUT)}},{key:"handlePossibleTabKeyboardFocus_",value:function(){this.firstFocus_&&!this.pointerDownRecognized_&&this.setFocusOnAction_(),this.firstFocus_=!1}},{key:"setFocusOnAction_",value:function(){this.adapter_.setFocus(),this.snackbarHasFocus_=!0,this.firstFocus_=!1}},{key:"invokeAction_",value:function(){try{if(!this.actionHandler_)return;this.actionHandler_()}finally{this.dismissOnAction_&&this.cleanup_()}}},{key:"cleanup_",value:function(){var t=this;if(!this.snackbarHasFocus_||this.actionWasClicked_){var e=s.a.ACTIVE,n=s.a.MULTILINE,i=s.a.ACTION_ON_BOTTOM;this.adapter_.removeClass(e);var r=function e(){clearTimeout(t.timeoutId_),t.adapter_.deregisterTransitionEndHandler(e),t.adapter_.removeClass(n),t.adapter_.removeClass(i),t.setActionHidden_(!0),t.adapter_.setAriaHidden(),t.active_=!1,t.snackbarHasFocus_=!1,t.showNext_()};this.adapter_.registerTransitionEndHandler(r)}}},{key:"showNext_",value:function(){this.queue_.length&&this.show(this.queue_.shift())}},{key:"setActionHidden_",value:function(t){t?this.adapter_.setActionAriaHidden():this.adapter_.unsetActionAriaHidden()}}]),e}(o.MDCFoundation);e.a=d},8:function(t,e,n){"use strict";function i(t){return void 0!==t.document&&"function"==typeof t.document.createElement}function r(t){return t in c||t in d}function a(t,e,n){return e[t].styleProperty in n.style?e[t].noPrefix:e[t].webkitPrefix}function o(t,e){if(!i(t)||!r(e))return e;var n=e in c?c:d,o=t.document.createElement("div");return n===c?a(e,n,o):n[e].noPrefix in o.style?n[e].noPrefix:n[e].webkitPrefix}function s(t,e){return o(t,e)}function u(t,e){return o(t,e)}Object.defineProperty(e,"__esModule",{value:!0}),n.d(e,"transformStyleProperties",function(){return l}),e.getCorrectEventName=s,e.getCorrectPropertyName=u;var c={animationstart:{noPrefix:"animationstart",webkitPrefix:"webkitAnimationStart",styleProperty:"animation"},animationend:{noPrefix:"animationend",webkitPrefix:"webkitAnimationEnd",styleProperty:"animation"},animationiteration:{noPrefix:"animationiteration",webkitPrefix:"webkitAnimationIteration",styleProperty:"animation"},transitionend:{noPrefix:"transitionend",webkitPrefix:"webkitTransitionEnd",styleProperty:"transition"}},d={animation:{noPrefix:"animation",webkitPrefix:"-webkit-animation"},transform:{noPrefix:"transform",webkitPrefix:"-webkit-transform"},transition:{noPrefix:"transition",webkitPrefix:"-webkit-transition"}},l=["transform","WebkitTransform","MozTransform","OTransform","MSTransform"]},80:function(t,e,n){"use strict";n.d(e,"a",function(){return i}),n.d(e,"c",function(){return r}),n.d(e,"b",function(){return a});var i={ROOT:"mdc-snackbar",TEXT:"mdc-snackbar__text",ACTION_WRAPPER:"mdc-snackbar__action-wrapper",ACTION_BUTTON:"mdc-snackbar__action-button",ACTIVE:"mdc-snackbar--active",MULTILINE:"mdc-snackbar--multiline",ACTION_ON_BOTTOM:"mdc-snackbar--action-on-bottom"},r={TEXT_SELECTOR:".mdc-snackbar__text",ACTION_WRAPPER_SELECTOR:".mdc-snackbar__action-wrapper",ACTION_BUTTON_SELECTOR:".mdc-snackbar__action-button"},a={MESSAGE_TIMEOUT:2750}}})}); |
@@ -35,6 +35,14 @@ /** | ||
unsetAriaHidden: () => {}, | ||
setMessageText: (/* message: string */) => {}, | ||
setActionText: (/* actionText: string */) => {}, | ||
setActionAriaHidden: () => {}, | ||
unsetActionAriaHidden: () => {}, | ||
setActionText: (/* actionText: string */) => {}, | ||
setMessageText: (/* message: string */) => {}, | ||
setFocus: () => {}, | ||
visibilityIsHidden: () => /* boolean */ false, | ||
registerCapturedBlurHandler: (/* handler: EventListener */) => {}, | ||
deregisterCapturedBlurHandler: (/* handler: EventListener */) => {}, | ||
registerVisibilityChangeHandler: (/* handler: EventListener */) => {}, | ||
deregisterVisibilityChangeHandler: (/* handler: EventListener */) => {}, | ||
registerCapturedInteractionHandler: (/* evtType: string, handler: EventListener */) => {}, | ||
deregisterCapturedInteractionHandler: (/* evtType: string, handler: EventListener */) => {}, | ||
registerActionClickHandler: (/* handler: EventListener */) => {}, | ||
@@ -55,5 +63,36 @@ deregisterActionClickHandler: (/* handler: EventListener */) => {}, | ||
this.active_ = false; | ||
this.actionWasClicked_ = false; | ||
this.dismissOnAction_ = true; | ||
this.firstFocus_ = true; | ||
this.pointerDownRecognized_ = false; | ||
this.snackbarHasFocus_ = false; | ||
this.snackbarData_ = null; | ||
this.queue_ = []; | ||
this.actionClickHandler_ = () => this.invokeAction_(); | ||
this.actionClickHandler_ = () => { | ||
this.actionWasClicked_ = true; | ||
this.invokeAction_(); | ||
}; | ||
this.visibilitychangeHandler_ = () => { | ||
clearTimeout(this.timeoutId_); | ||
this.snackbarHasFocus_ = true; | ||
if (!this.adapter_.visibilityIsHidden()) { | ||
setTimeout(this.cleanup_.bind(this), this.snackbarData_.timeout || numbers.MESSAGE_TIMEOUT); | ||
} | ||
}; | ||
this.interactionHandler_ = (evt) => { | ||
if (evt.type == 'touchstart' || evt.type == 'mousedown') { | ||
this.pointerDownRecognized_ = true; | ||
} | ||
this.handlePossibleTabKeyboardFocus_(evt); | ||
if (evt.type == 'focus') { | ||
this.pointerDownRecognized_ = false; | ||
} | ||
}; | ||
this.blurHandler_ = () => { | ||
clearTimeout(this.timeoutId_); | ||
this.snackbarHasFocus_ = false; | ||
this.timeoutId_ = setTimeout(this.cleanup_.bind(this), this.snackbarData_.timeout || numbers.MESSAGE_TIMEOUT); | ||
}; | ||
} | ||
@@ -69,2 +108,7 @@ | ||
this.adapter_.deregisterActionClickHandler(this.actionClickHandler_); | ||
this.adapter_.deregisterCapturedBlurHandler(this.blurHandler_); | ||
this.adapter_.deregisterVisibilityChangeHandler(this.visibilitychangeHandler_); | ||
['touchstart', 'mousedown', 'focus'].forEach((evtType) => { | ||
this.adapter_.deregisterCapturedInteractionHandler(evtType, this.interactionHandler_); | ||
}); | ||
} | ||
@@ -81,26 +125,32 @@ | ||
show(data) { | ||
if (!data) { | ||
clearTimeout(this.timeoutId_); | ||
this.snackbarData_ = data; | ||
this.firstFocus_ = true; | ||
this.adapter_.registerVisibilityChangeHandler(this.visibilitychangeHandler_); | ||
this.adapter_.registerCapturedBlurHandler(this.blurHandler_); | ||
['touchstart', 'mousedown', 'focus'].forEach((evtType) => { | ||
this.adapter_.registerCapturedInteractionHandler(evtType, this.interactionHandler_); | ||
}); | ||
if (!this.snackbarData_) { | ||
throw new Error( | ||
'Please provide a data object with at least a message to display.'); | ||
} | ||
if (!data.message) { | ||
if (!this.snackbarData_.message) { | ||
throw new Error('Please provide a message to be displayed.'); | ||
} | ||
if (data.actionHandler && !data.actionText) { | ||
if (this.snackbarData_.actionHandler && !this.snackbarData_.actionText) { | ||
throw new Error('Please provide action text with the handler.'); | ||
} | ||
if (this.active) { | ||
this.queue_.push(data); | ||
return; | ||
this.queue_.push(this.snackbarData_); | ||
} | ||
const {ACTIVE, MULTILINE, ACTION_ON_BOTTOM} = cssClasses; | ||
const {MESSAGE_TIMEOUT} = numbers; | ||
this.adapter_.setMessageText(data.message); | ||
this.adapter_.setMessageText(this.snackbarData_.message); | ||
if (data.multiline) { | ||
if (this.snackbarData_.multiline) { | ||
this.adapter_.addClass(MULTILINE); | ||
if (data.actionOnBottom) { | ||
if (this.snackbarData_.actionOnBottom) { | ||
this.adapter_.addClass(ACTION_ON_BOTTOM); | ||
@@ -110,5 +160,5 @@ } | ||
if (data.actionHandler) { | ||
this.adapter_.setActionText(data.actionText); | ||
this.actionHandler_ = data.actionHandler; | ||
if (this.snackbarData_.actionHandler) { | ||
this.adapter_.setActionText(this.snackbarData_.actionText); | ||
this.actionHandler_ = this.snackbarData_.actionHandler; | ||
this.setActionHidden_(false); | ||
@@ -125,5 +175,22 @@ } else { | ||
this.timeoutId_ = setTimeout(this.cleanup_.bind(this), data.timeout || MESSAGE_TIMEOUT); | ||
this.timeoutId_ = setTimeout(this.cleanup_.bind(this), this.snackbarData_.timeout || numbers.MESSAGE_TIMEOUT); | ||
} | ||
handlePossibleTabKeyboardFocus_() { | ||
const hijackFocus = | ||
this.firstFocus_ && !this.pointerDownRecognized_; | ||
if (hijackFocus) { | ||
this.setFocusOnAction_(); | ||
} | ||
this.firstFocus_ = false; | ||
} | ||
setFocusOnAction_() { | ||
this.adapter_.setFocus(); | ||
this.snackbarHasFocus_ = true; | ||
this.firstFocus_ = false; | ||
} | ||
invokeAction_() { | ||
@@ -138,3 +205,2 @@ try { | ||
if (this.dismissOnAction_) { | ||
clearTimeout(this.timeoutId_); | ||
this.cleanup_(); | ||
@@ -146,19 +212,23 @@ } | ||
cleanup_() { | ||
const {ACTIVE, MULTILINE, ACTION_ON_BOTTOM} = cssClasses; | ||
const allowDismissal = !this.snackbarHasFocus_ || this.actionWasClicked_; | ||
this.adapter_.removeClass(ACTIVE); | ||
if (allowDismissal) { | ||
const {ACTIVE, MULTILINE, ACTION_ON_BOTTOM} = cssClasses; | ||
const handler = () => { | ||
this.adapter_.deregisterTransitionEndHandler(handler); | ||
this.adapter_.removeClass(MULTILINE); | ||
this.adapter_.removeClass(ACTION_ON_BOTTOM); | ||
this.setActionHidden_(true); | ||
this.adapter_.setMessageText(null); | ||
this.adapter_.setActionText(null); | ||
this.adapter_.setAriaHidden(); | ||
this.active_ = false; | ||
this.showNext_(); | ||
}; | ||
this.adapter_.removeClass(ACTIVE); | ||
this.adapter_.registerTransitionEndHandler(handler); | ||
const handler = () => { | ||
clearTimeout(this.timeoutId_); | ||
this.adapter_.deregisterTransitionEndHandler(handler); | ||
this.adapter_.removeClass(MULTILINE); | ||
this.adapter_.removeClass(ACTION_ON_BOTTOM); | ||
this.setActionHidden_(true); | ||
this.adapter_.setAriaHidden(); | ||
this.active_ = false; | ||
this.snackbarHasFocus_ = false; | ||
this.showNext_(); | ||
}; | ||
this.adapter_.registerTransitionEndHandler(handler); | ||
} | ||
} | ||
@@ -170,3 +240,2 @@ | ||
} | ||
this.show(this.queue_.shift()); | ||
@@ -173,0 +242,0 @@ } |
10
index.js
@@ -50,2 +50,12 @@ /** | ||
setMessageText: (text) => { getText().textContent = text; }, | ||
setFocus: () => getActionButton().focus(), | ||
visibilityIsHidden: () => document.hidden, | ||
registerCapturedBlurHandler: (handler) => getActionButton().addEventListener('blur', handler, true), | ||
deregisterCapturedBlurHandler: (handler) => getActionButton().removeEventListener('blur', handler, true), | ||
registerVisibilityChangeHandler: (handler) => document.addEventListener('visibilitychange', handler), | ||
deregisterVisibilityChangeHandler: (handler) => document.removeEventListener('visibilitychange', handler), | ||
registerCapturedInteractionHandler: (evt, handler) => | ||
document.body.addEventListener(evt, handler, true), | ||
deregisterCapturedInteractionHandler: (evt, handler) => | ||
document.body.removeEventListener(evt, handler, true), | ||
registerActionClickHandler: (handler) => getActionButton().addEventListener('click', handler), | ||
@@ -52,0 +62,0 @@ deregisterActionClickHandler: (handler) => getActionButton().removeEventListener('click', handler), |
{ | ||
"name": "@material/snackbar", | ||
"description": "The Material Components for the web snackbar component", | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"license": "Apache-2.0", | ||
@@ -18,4 +18,4 @@ "keywords": [ | ||
"@material/animation": "^0.2.3", | ||
"@material/base": "^0.2.1", | ||
"@material/button": "^0.3.8", | ||
"@material/base": "^0.2.2", | ||
"@material/button": "^0.3.9", | ||
"@material/rtl": "^0.1.6", | ||
@@ -22,0 +22,0 @@ "@material/theme": "^0.1.5", |
@@ -21,3 +21,3 @@ <!--docs: | ||
[Material Design snackbars & toasts requirements](https://material.io/guidelines/components/snackbars-toasts.html#snackbars-toasts-specs). | ||
It requires JavaScript the trigger the display and hide of the snackbar. | ||
It requires JavaScript to show and hide itself. | ||
@@ -57,2 +57,19 @@ ## Design & API Documentation | ||
### Start Aligned Snackbars (tablet and desktop only) | ||
MDC Snackbar can be start aligned (including in RTL contexts). To create a start-aligned | ||
snackbar, add the `mdc-snackbar--align-start` modifier class to the root element. | ||
```html | ||
<div class="mdc-snackbar mdc-snackbar--align-start" | ||
aria-live="assertive" | ||
aria-atomic="true" | ||
aria-hidden="true"> | ||
<div class="mdc-snackbar__text"></div> | ||
<div class="mdc-snackbar__action-wrapper"> | ||
<button type="button" class="mdc-button mdc-snackbar__action-button"></button> | ||
</div> | ||
</div> | ||
``` | ||
### Using the JS Component | ||
@@ -130,2 +147,34 @@ | ||
### Responding to a Snackbar Action | ||
To respond to a snackbar action, assign a function to the optional `actionHandler` property in the object that gets passed to the `show` method. If you choose to set this property, you *must _also_* set the `actionText` property. | ||
```html | ||
<div class="mdc-snackbar" | ||
aria-live="assertive" | ||
aria-atomic="true" | ||
aria-hidden="true"> | ||
<div class="mdc-snackbar__text"></div> | ||
<div class="mdc-snackbar__action-wrapper"> | ||
<button type="button" class="mdc-button mdc-snackbar__action-button"></button> | ||
</div> | ||
</div> | ||
``` | ||
```js | ||
import {MDCSnackbar} from 'mdc-snackbar'; | ||
const snackbar = new MDCSnackbar(document.querySelector('.mdc-snackbar')); | ||
const dataObj = { | ||
message: messageInput.value, | ||
actionText: 'Undo', | ||
actionHandler: function () { | ||
console.log('my cool function'); | ||
} | ||
}; | ||
snackbar.show(dataObj); | ||
``` | ||
### Keep snackbar when the action button is pressed | ||
@@ -155,6 +204,14 @@ | ||
| `unsetAriaHidden() => void` | Removes the `aria-hidden` attribute from the root element. | | ||
| `setMessageText(message: string) => void` | Set the text content of the message element. | | ||
| `setActionText(actionText: string) => void` | Set the text content of the action element. | | ||
| `setActionAriaHidden() => void` | Sets `aria-hidden="true"` on the action element. | | ||
| `unsetActionAriaHidden() => void` | Removes the `aria-hidden` attribute from the action element. | | ||
| `setActionText(actionText: string) => void` | Set the text content of the action element. | | ||
| `setMessageText(message: string) => void` | Set the text content of the message element. | | ||
| `setFocus() => void` | Sets focus on the action button. | | ||
| `visibilityIsHidden() => boolean` | Returns document.hidden property. | | ||
| `registerBlurHandler(handler: EventListener) => void` | Registers an event handler to be called when a `blur` event is triggered on the action button | | ||
| `deregisterBlurHandler(handler: EventListener) => void` | Deregisters a `blur` event handler from the actionButton | | ||
| `registerVisibilityChangeHandler(handler: EventListener) => void` | Registers an event handler to be called when a 'visibilitychange' event occurs | | ||
| `deregisterVisibilityChangeHandler(handler: EventListener) => void` | Deregisters an event handler to be called when a 'visibilitychange' event occurs | | ||
| `registerCapturedInteractionHandler(evtType: string, handler: EventListener) => void` | Registers an event handler to be called when the given event type is triggered on the `body` | | ||
| `deregisterCapturedInteractionHandler(evtType: string, handler: EventListener) => void` | Deregisters an event handler from the `body` | | ||
| `registerActionClickHandler(handler: EventListener) => void` | Registers an event handler to be called when a `click` event is triggered on the action element. | | ||
@@ -161,0 +218,0 @@ | `deregisterActionClickHandler(handler: EventListener) => void` | Deregisters an event handler from a `click` event on the action element. This will only be called with handlers that have previously been passed to `registerActionClickHandler` calls. | |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
98286
1611
228
1
Updated@material/base@^0.2.2
Updated@material/button@^0.3.9