/* * global util js * based on bootstrap's (v4.0.0-beta) util.js */ var Util = function ($) { var MAX_UID = 1000000; var transition = false; var TransitionEndEvent = { WebkitTransition: 'webkitTransitionEnd', MozTransition: 'transitionend', OTransition: 'oTransitionEnd otransitionend', transition: 'transitionend' }; function getSpecialTransitionEndEvent() { return { bindType: transition.end, delegateType: transition.end, handle: function handle(event) { if ($(event.target).is(this)) { // eslint-disable-next-line prefer-rest-params return event.handleObj.handler.apply(this, arguments); } return undefined; } }; } function isElement(obj) { return (obj[0] || obj).nodeType; } function setTransitionEndSupport() { transition = transitionEndTest(); $.fn.emulateTransitionEnd = transitionEndEmulator; if (Util.supportsTransitionEnd()) { $.event.special[Util.TRANSITION_END] = getSpecialTransitionEndEvent(); } } function toType(obj) { return {}.toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase(); } function transitionEndEmulator(duration) { var _this = this; var called = false; $(this).one(Util.TRANSITION_END, function () { called = true; }); setTimeout(function () { if (!called) { Util.triggerTransitionEnd(_this); } }, duration); return this; } function transitionEndTest() { if (window.QUnit) { return false; } var el = document.createElement('material'); for (var name in TransitionEndEvent) { if (el.style[name] !== undefined) { return { end: TransitionEndEvent[name] }; } } return false; } var Util = { TRANSITION_END: 'mdTransitionEnd', getSelectorFromElement: function getSelectorFromElement(element) { var selector = element.getAttribute('data-target'); if (!selector) { selector = element.getAttribute('href') || ''; selector = /^#[a-z]/i.test(selector) ? selector : null; } return selector; }, getUID: function getUID(prefix) { do { // eslint-disable-next-line no-bitwise prefix += ~~(Math.random() * MAX_UID); } while (document.getElementById(prefix)); return prefix; }, reflow: function reflow(element) { new Function('md', 'return md')(element.offsetHeight); }, supportsTransitionEnd: function supportsTransitionEnd() { return Boolean(transition); }, triggerTransitionEnd: function triggerTransitionEnd(element) { $(element).trigger(transition.end); }, typeCheckConfig: function typeCheckConfig(componentName, config, configTypes) { for (var property in configTypes) { if (configTypes.hasOwnProperty(property)) { var expectedTypes = configTypes[property]; var value = config[property]; var valueType = value && isElement(value) ? 'element' : toType(value); if (!new RegExp(expectedTypes).test(valueType)) { throw new Error(componentName.toUpperCase() + ': ' + ('Option "' + property + '" provided type "' + valueType + '" ') + ('but expected type "' + expectedTypes + '".')); } } } } }; setTransitionEndSupport(); return Util; }(jQuery);