UNPKG

@odopod/odo-helpers

Version:
3 lines (2 loc) 12.7 kB
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@odopod/odo-device")):"function"==typeof define&&define.amd?define(["exports","@odopod/odo-device"],n):n(t.OdoHelpers={},t.OdoDevice)}(this,function(t,n){"use strict";function e(t){return null!=t}n=n&&n.hasOwnProperty("default")?n.default:n;var i={},o=0;function r(t,n,e){return i[o+=1]={element:t,timerId:n,listener:e},o}function s(t){delete i[t]}function u(t){if(t.jquery){if(t.length>1)throw new TypeError("This method only supports transition end for one element, not a collection");return t[0]}return t}function a(t){return t.target===t.currentTarget}function c(t){return{target:t,currentTarget:t,fake:!0}}var d={FADE:"fade",IN:"in",INVISIBLE:"invisible"};function f(){}var h=function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")},l=function(){function t(t,n){for(var e=0;e<n.length;e++){var i=n[e];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(n,e,i){return e&&t(n.prototype,e),i&&t(n,i),n}}(),p=function(){function t(n){h(this,t),this.options=Object.assign({},t.Defaults,n),this._animationAmount=this.options.end-this.options.start,this._animationStart=+new Date,this._handler=this._animateLoop.bind(this),this.onfinish=f,this._requestId=requestAnimationFrame(this._handler)}return t.prototype._animateLoop=function(){var t=(new Date).getTime(),n=1-(this._animationStart+this.options.duration-t)/this.options.duration;if(n>=1)return this.options.step.call(this.options.context,this.options.end,1),this.onfinish.call(this.options.context),void this.dispose();n=this.options.easing(n),this._requestId=requestAnimationFrame(this._handler),this.options.step.call(this.options.context,this.options.start+this._animationAmount*n,n)},t.prototype.cancel=function(){cancelAnimationFrame(this._requestId),this.dispose()},t.prototype.dispose=function(){this._handler=null,this.options.context=null},t}();p.Defaults={start:0,end:1,duration:250,step:f,context:window,easing:function(t){return-.5*(Math.cos(Math.PI*t)-1)}};var m=function t(n,e,i,o){h(this,t),this.top=n,this.right=e,this.bottom=i,this.left=o};function E(t){return n.HAS_POINTER_EVENTS?t:null}var g,T={CLICK:"click",DBLCLICK:"dblclick",MOUSEDOWN:"mousedown",MOUSEUP:"mouseup",MOUSEOVER:"mouseover",MOUSEOUT:"mouseout",MOUSEMOVE:"mousemove",SELECTSTART:"selectstart",KEYPRESS:"keypress",KEYDOWN:"keydown",KEYUP:"keyup",BLUR:"blur",FOCUS:"focus",DEACTIVATE:"deactivate",FOCUSIN:"focusin",FOCUSOUT:"focusout",CHANGE:"change",SELECT:"select",SUBMIT:"submit",INPUT:"input",PROPERTYCHANGE:"propertychange",DRAGSTART:"dragstart",DRAG:"drag",DRAGENTER:"dragenter",DRAGOVER:"dragover",DRAGLEAVE:"dragleave",DROP:"drop",DRAGEND:"dragend",TOUCHSTART:"touchstart",TOUCHMOVE:"touchmove",TOUCHEND:"touchend",TOUCHCANCEL:"touchcancel",BEFOREUNLOAD:"beforeunload",CONTEXTMENU:"contextmenu",ERROR:"error",HELP:"help",LOAD:"load",LOSECAPTURE:"losecapture",READYSTATECHANGE:"readystatechange",RESIZE:"resize",SCROLL:"scroll",UNLOAD:"unload",HASHCHANGE:"hashchange",PAGEHIDE:"pagehide",PAGESHOW:"pageshow",POPSTATE:"popstate",COPY:"copy",PASTE:"paste",CUT:"cut",BEFORECOPY:"beforecopy",BEFORECUT:"beforecut",BEFOREPASTE:"beforepaste",ONLINE:"online",OFFLINE:"offline",MESSAGE:"message",CONNECT:"connect",TRANSITIONEND:(g=document.createElement("div"),g.style.transitionProperty="width","width"!==g.style.transitionProperty&&"webkitTransition"in g.style?"webkitTransitionEnd":{WebkitTransition:"webkitTransitionEnd",transition:"transitionend"}[n.Dom.TRANSITION]),ANIMATIONEND:{WebkitAnimation:"webkitAnimationEnd",animation:"animationend"}[n.Dom.ANIMATION],POINTERCANCEL:E("pointercancel"),POINTERDOWN:E("pointerdown"),POINTERMOVE:E("pointermove"),POINTEROVER:E("pointerover"),POINTEROUT:E("pointerout"),POINTERUP:E("pointerup")};function v(t,n){var e=null;return t.reduce(function(t,i){var o=Math.abs(i-n);return o<t?(e=i,o):t},1/0),e}var O=function(){function t(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;h(this,t),this.x=n,this.y=e}return t.prototype.clone=function(){return new t(this.x,this.y)},t.prototype.scale=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t;return this.x*=t,this.y*=n,this},t.prototype.translate=function(n,e){return n instanceof t?(this.x+=n.x,this.y+=n.y):(this.x+=n,this.y+=e),this},t.equals=function(t,n){return t===n||!(!t||!n)&&(t.x===n.x&&t.y===n.y)},t.distance=function(t,n){var e=t.x-n.x,i=t.y-n.y;return Math.sqrt(e*e+i*i)},t.difference=function(n,e){return new t(n.x-e.x,n.y-e.y)},t.sum=function(n,e){return new t(n.x+e.x,n.y+e.y)},t.product=function(n,e){return new t(n.x*e.x,n.y*e.y)},t.quotient=function(n,e){return new t(n.x/e.x,n.y/e.y)},t.scale=function(n,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e;return new t(n.x*e,n.y*i)},t}();function N(t,n){return(arguments.length>2&&void 0!==arguments[2]?arguments[2]:e(t))?t:n}var y=new Promise(function(t){"complete"===document.readyState?t():window.addEventListener("load",function n(){window.removeEventListener("load",n),t()})}),S=new Promise(function(t){"interactive"===document.readyState?t():document.addEventListener("DOMContentLoaded",function n(){document.removeEventListener("DOMContentLoaded",n),t()})});function A(t,n){for(var e=t.length-1;e>=0;e--)t[e].style.height=n}function w(t,i){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:window,d=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,f=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,h=u(t),l=i.bind(o),p=void 0;function m(t){var i,o;a(t)&&(o=d,(i=t).fake||!e(o)||i.propertyName===o)&&(s(E),n.HAS_TRANSITIONS&&t.currentTarget.removeEventListener(T.TRANSITIONEND,m),l(t),clearTimeout(p))}n.HAS_TRANSITIONS?(h.addEventListener(T.TRANSITIONEND,m),f&&(p=setTimeout(function(){m(c(h))},f))):p=setTimeout(function(){m(c(h))},0);var E=r(h,p,m);return E}function I(t,n){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:f,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:window,o=arguments.length>4&&void 0!==arguments[4]&&arguments[4],r=u(t),s=e.bind(i),a=r.classList.contains(d.IN),h=r.classList.contains(d.FADE);if(!n&&a&&h||!n&&!h||n&&!a&&h){var l=c(r);return setTimeout(function(){s(l)},0),0}return!n&&o&&t.classList.remove(d.INVISIBLE),t.classList.add(d.FADE),t.classList.toggle(d.IN,!n),w(t,function(t){n&&o&&t.currentTarget.classList.add(d.INVISIBLE),s(t)},null,"opacity")}function C(t){return{width:t.offsetWidth,height:t.offsetHeight}}function R(t){return parseFloat(t)||0}function L(t,n){var e=window.getComputedStyle(t,null);return new m(R(e[n+"Top"]),R(e[n+"Right"]),R(e[n+"Bottom"]),R(e[n+"Left"]))}function b(t){return L(t,"margin")}function P(t){var n=t.match(/OS\s+([\d_]+)/i)[1].split("_");return 2===n.length&&(n[2]="0"),parseInt(n.reduce(function(t,n){return t+n},""),10)}function D(t,n){var e=parseFloat(t);return N(e,n,!Number.isNaN(e))}function x(t){return"string"==typeof t}function M(t,n){return N(t,n,x(t))}function U(t){return t.includes("Mozilla/5.0")&&t.includes("Android ")}function H(t){return t.includes("Edge/")}function _(t){return!H(t)&&t.includes("Chrome")}function k(t){return U(t)&&!_(t)}function F(t){return/(iPad|iPhone|iPod)/g.test(t)}var B=function(){function t(n,e,i,o){h(this,t),this.left=n,this.top=e,this.width=i,this.height=o}return t.intersects=function(t,n){return t.left<=n.right&&n.left<=t.right&&t.top<=n.bottom&&n.top<=t.bottom},l(t,[{key:"right",get:function(){return this.left+this.width}},{key:"bottom",get:function(){return this.top+this.height}}]),t}();function G(t){if("string"!=typeof t)throw new Error("Hash must be of type string");return t.replace(/^#/,"")}function V(t){var n=G(t),e=void 0;n||(e=window.pageYOffset),window.location.hash=n,n||window.scrollTo(0,e)}function q(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:400,e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:f,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:void 0,o={start:window.pageYOffset,end:t,duration:n,step:function(t){window.scrollTo(0,t)}};"function"==typeof i&&(o.easing=i);var r=new p(o);return r.onfinish=e,r}var W=function(){function t(n,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];h(this,t),this.timerId=null,this.startTime=null,this.isPaused=!1,this.isTicking=!1,this.isContinuous=i,this.delay=e,this.remaining=e,this.fn=n,this.resume=this.start,this.pause=this.stop}return t.prototype.start=function(){var t=this;return!this.isTicking&&(this.startTime=Date.now(),this.timerId=setTimeout(function(){t.fn(),!t.isPaused&&t.isContinuous?t.restart():t.reset()},this.remaining),this.isTicking=!0,this.isPaused=!1,this.remaining)},t.prototype.stop=function(){return this.clear(),this.remaining-=Date.now()-this.startTime,this.isPaused=!0,this.isTicking=!1,this.remaining},t.prototype.reset=function(){this.remaining=this.delay,this.clear()},t.prototype.restart=function(){this.reset(),this.resume()},t.prototype.clear=function(){clearTimeout(this.timerId),this.isPaused=!1,this.isTicking=!1},t.prototype.dispose=function(){this.clear(),this.fn=null},t}();t.getTransitions=function(){return i},t.animationClasses=d,t.Stepper=p,t.Box=m,t.cancelTransitionEnd=function(t){var e=i[t];return!!e&&(clearTimeout(e.timerId),n.HAS_TRANSITIONS&&e.element.removeEventListener(T.TRANSITIONEND,e.listener),s(t),!0)},t.capitalize=function(t){return t.charAt(0).toUpperCase()+t.slice(1)},t.causeLayout=function(t){return t.offsetWidth},t.chunk=function(t,n){if(!n)return[];for(var e=Math.ceil(t.length/n),i=new Array(e),o=0,r=0;o<e;r+=n,o++)i[o]=t.slice(r,r+n);return i},t.clamp=function(t,n,e){return Math.min(Math.max(t,n),e)},t.closestGreaterThan=function(t,n){return v(t.filter(function(t){return t>n}),n)},t.closestLessThan=function(t,n){return v(t.filter(function(t){return t<n}),n)},t.closest=v,t.Coordinate=O,t.defaultsTo=N,t.domLoaded=y,t.domReady=S,t.evenHeights=function(t){var n=Array.from(t),e=!0;n[0]&&n[0].nodeType&&(e=!1,n=[n]),n.forEach(function(t){A(t,"")});var i=n.map(function(t){return function(t){for(var n=0,e=t.length-1;e>=0;e--)t[e].offsetHeight>n&&(n=t[e].offsetHeight);return n}(t)});return n.forEach(function(t,n){A(t,i[n]+"px")}),e?i:i[0]},t.events=T,t.fadeInElement=function(t,n,e,i){return I(t,!1,n,e,i)},t.fadeOutElement=function(t,n,e,i){return I(t,!0,n,e,i)},t.forceRedraw=function(){var t=document.createElement("style");document.body.appendChild(t),document.body.removeChild(t)},t.getElementsSize=function(t,n){return t.reduce(function(t,e){var i=C(e)[n],o=b(e);return t+i+("height"===n?o.top+o.bottom:o.left+o.right)},0)},t.getIOSVersion=P,t.getMarginBox=b,t.getNthSibling=function(t,n,e){var i=!1!==e,o=0,r=t;do{r=i?r.nextElementSibling:r.previousElementSibling,o+=1}while(r&&o<n);return r},t.getNumberOption=D,t.getPaddingBox=function(t){return L(t,"padding")},t.getPercentageOption=function(t,n){return x(t)&&t.indexOf("%")>-1?M(t,n):D(t,n)},t.getRelativeDepth=function(t,n){for(var e=0,i=t;i;){if(i===n)return e;i=i.parentNode,e+=1}return-1},t.getSize=C,t.getStringOption=M,t.giveId=function(t,n){t.id||(t.id="function"==typeof n?n():n)},t.hasScrollEvents=function(t){return F(t)?P(t)>=800:!k(t)},t.hyphenate=function(t){return t?t.replace(/([A-Z])/g,function(t,n){return"-"+n.toLowerCase()}).replace(/^ms-/,"-ms-"):""},t.isAndroidOS=U,t.isChrome=_,t.isDefined=e,t.isEdge=H,t.isIE=function(t){return t.includes("Trident/")},t.isIOS=F,t.isNativeAndroid=k,t.isString=x,t.noop=f,t.onAnimationEnd=function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:window,o=u(t),r=e.bind(i);function s(t){a(t)&&(n.HAS_CSS_ANIMATIONS&&t.currentTarget.removeEventListener(T.ANIMATIONEND,s),r(t))}n.HAS_CSS_ANIMATIONS?o.addEventListener(T.ANIMATIONEND,s):setTimeout(function(){s(c(o))},0)},t.onTransitionEnd=w,t.pull=function(t,n){var e=t.indexOf(n);return-1===e?null:(t.splice(e,1),n)},t.randomString=function(){return Math.random().toString(36).substring(7)},t.Rect=B,t.removeChildren=function(t){t.textContent=""},t.replaceWithHash=function(t){var n=G(t);window.history.replaceState?(n=(n=G(n))?"#"+n:window.location.pathname+window.location.search,window.history.replaceState({},null,n)):V(n)},t.scrollToTop=q,t.scrollTo=q,t.setHash=V,t.swapElements=function(t,n){if(t&&n){var e=t.parentNode,i=t.nextSibling,o=n.parentNode,r=n.nextSibling;e.insertBefore(n,i),o.insertBefore(t,r)}},t.Timer=W,t.wrapAroundList=function(t,n,e){return(t+n+10*e)%e},Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=odo-helpers.min.js.map