assets/javascripts/material/components/util.js in material-sass-4.0.0.beta2 vs assets/javascripts/material/components/util.js in material-sass-4.0.0.beta3

- old
+ new

@@ -1,43 +1,34 @@ /* * 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 escapeId(selector) { + selector = typeof $.escapeSelector === 'function' ? $.escapeSelector(selector).substr(1) : selector.replace(/(:|\.|\[|\]|,|=|@)/g, '\\$1'); + return selector; + } 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 event.handleObj.handler.apply(this, arguments); // eslint-disable-line prefer-rest-params } - return undefined; + + return undefined; // eslint-disable-line no-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(); } @@ -49,85 +40,84 @@ 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; + return { + end: 'transitionend' + }; } var Util = { TRANSITION_END: 'mdTransitionEnd', - getSelectorFromElement: function getSelectorFromElement(element) { var selector = element.getAttribute('data-target'); - if (!selector) { + if (!selector || selector === '#') { selector = element.getAttribute('href') || ''; - selector = /^#[a-z]/i.test(selector) ? selector : null; } - return selector; + if (selector.charAt(0) === '#') { + selector = escapeId(selector); + } + + try { + var $selector = $(document).find(selector); + return $selector.length > 0 ? selector : null; + } catch (err) { + return null; + } }, 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) { - new Function('md', 'return md')(element.offsetHeight); + 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 (configTypes.hasOwnProperty(property)) { + if (Object.prototype.hasOwnProperty.call(configTypes, property)) { var expectedTypes = configTypes[property]; var value = config[property]; - var valueType = value && isElement(value) ? 'element' : toType(value); + 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 + '".')); + throw new Error(componentName.toUpperCase() + ": " + ("Option \"" + property + "\" provided type \"" + valueType + "\" ") + ("but expected type \"" + expectedTypes + "\".")); } } } } }; - setTransitionEndSupport(); - return Util; -}(jQuery); +}($); +//# sourceMappingURL=util.js.map \ No newline at end of file