/* * Global util js * Based on Bootstrap's (v4.1.0) `util.js` */ var Util = function ($) { var MAX_UID = 1000000; var MILLISECONDS_MULTIPLIER = 1000; var transition = false; function getSpecialTransitionEndEvent() { return { bindType: transition.end, delegateType: transition.end, handle: function handle(event) { if ($(event.target).is(this)) { return event.handleObj.handler.apply(this, arguments); // eslint-disable-line prefer-rest-params } return undefined; // eslint-disable-line no-undefined } }; } 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-z]+)/i)[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 (typeof window !== 'undefined' && window.QUnit) { return false; } return { end: 'transitionend' }; } var Util = { TRANSITION_END: 'mdTransitionEnd', getSelectorFromElement: function getSelectorFromElement(element) { var selector = element.getAttribute('data-target'); if (!selector || selector === '#') { selector = element.getAttribute('href') || ''; } try { var $selector = $(document).find(selector); return $selector.length > 0 ? selector : null; } catch (err) { return null; } }, getTransitionDurationFromElement: function getTransitionDurationFromElement(element) { if (!element) { return 0; } var transitionDuration = $(element).css('transition-duration'); if (!transitionDuration) { return 0; } transitionDuration = transitionDuration.split(',')[0]; return parseFloat(transitionDuration) * MILLISECONDS_MULTIPLIER; }, getUID: function getUID(prefix) { do { // eslint-disable-next-line no-bitwise prefix += ~~(Math.random() * MAX_UID); } while (document.getElementById(prefix)); return prefix; }, isElement: function isElement(obj) { return (obj[0] || obj).nodeType; }, reflow: function reflow(element) { return 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 (Object.prototype.hasOwnProperty.call(configTypes, property)) { var expectedTypes = configTypes[property]; var value = config[property]; var valueType = value && Util.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; }($);