-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathwdtLoading.min.js
8 lines (8 loc) · 3.76 KB
/
wdtLoading.min.js
1
2
3
4
5
6
7
8
/*!
@package wdtLoading - Application loading screen
@version version: 0.1.0
@contributors https://github.com/needim/wdtLoading/graphs/contributors
@documentation Examples and Documentation - http://ned.im/wdtLoading/
@license Licensed under the MIT licenses: http://www.opensource.org/licenses/mit-license.php
*/
!function(e,t){"function"==typeof define&&define.amd?define(t):"object"==typeof exports?module.exports=t():e.wdtLoading=t()}(this,function(){function e(e,t){var r="string"==typeof e?e:n(e);return r.indexOf(" "+t+" ")>=0}function t(t,r){var a=n(t),s=a+r;e(a,r)||(t.className=s.substring(1))}function r(t,r){var a,s=n(t);e(t,r)&&(a=s.replace(" "+r+" "," "),t.className=a.substring(1,a.length-1))}function n(e){return(" "+(e&&e.className||"")+" ").replace(/\s+/gi," ")}function a(e){e&&e.parentNode&&e.parentNode.removeChild(e)}var s={};s.defaults={category:"default",speed:2e3},s.start=function(e){this.options=o(s.defaults,e),this.wdtLoadingScreen=document.querySelector(".wdt-loading-screen");for(var t=document.querySelectorAll(".wdt-loading-phrase-category"),r=0;r<t.length;r++)i(t[r],{display:"none"});this.wdtPhraseActiveCat=document.querySelector('.wdt-loading-phrase-category[data-category="'+this.options.category+'"]'),i(this.wdtPhraseActiveCat,{display:"block"}),this.activePhrases=this.wdtPhraseActiveCat.querySelectorAll(".wdt-loading-phrase"),this.activePhrasesCount=this.activePhrases.length,this.activePhrasesCount<5&&console.warn("wdtLoading -->","Add more phrase for better spin animation!");for(var n=[],r=0;r<this.activePhrases.length;r++)n.push(this.activePhrases[r]),a(this.activePhrases[r]);n=s.shuffle(n);for(var r=0;r<n.length;r++)this.wdtPhraseActiveCat.appendChild(n[r]);return i(this.wdtLoadingScreen,{display:"block"}),s.spin(),this},s.spin=function(){var e=this;this.phraseHeight=e.wdtPhraseActiveCat.querySelector(".wdt-loading-phrase").scrollHeight,e.currentIndex=0,e.currentTransform=0,e.spinInternal=setInterval(function(){if(e.activePhrases=e.wdtPhraseActiveCat.querySelectorAll(".wdt-loading-phrase"),t(e.activePhrases[e.currentIndex],"wdt-checked"),e.currentIndex++,e.currentTransform=e.currentTransform-e.phraseHeight,i(e.wdtPhraseActiveCat,{transform:"translateY("+e.currentTransform+"px)"}),e.currentIndex>1){var n=e.activePhrases[e.currentIndex-2],a=n.cloneNode(!0);r(a,"wdt-checked"),t(a,"wdt-cloned-phrase"),a.style.transform="",e.wdtPhraseActiveCat.appendChild(a)}},this.options.speed)},s.done=function(){this.spinInternal&&clearInterval(this.spinInternal),i(this.wdtLoadingScreen,{display:"none"});for(var e=document.querySelectorAll(".wdt-cloned-phrase"),t=document.querySelectorAll(".wdt-loading-phrase"),n=0;n<t.length;n++)r(t[n],"wdt-checked");this.wdtPhraseActiveCat.style.transform="";for(var n=0;n<e.length;n++)a(e[n]);clearInterval(this.spinInternal)},s.shuffle=function(e){for(var t,r,n=e.length;n;)r=Math.floor(Math.random()*n--),t=e[n],e[n]=e[r],e[r]=t;return e};var o=function(){var e={},t=!1,r=0,n=arguments.length;"[object Boolean]"===Object.prototype.toString.call(arguments[0])&&(t=arguments[0],r++);for(var a=function(r){for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t&&"[object Object]"===Object.prototype.toString.call(r[n])?e[n]=o(!0,e[n],r[n]):e[n]=r[n])};n>r;r++){var s=arguments[r];a(s)}return e},i=function(){function e(e){return e.replace(/^-ms-/,"ms-").replace(/-([\da-z])/gi,function(e,t){return t.toUpperCase()})}function t(e){var t=document.body.style;if(e in t)return e;for(var r,n=a.length,s=e.charAt(0).toUpperCase()+e.slice(1);n--;)if(r=a[n]+s,r in t)return r;return e}function r(r){return r=e(r),s[r]||(s[r]=t(r))}function n(e,t,n){t=r(t),e.style[t]=n}var a=["Webkit","O","Moz","ms"],s={};return function(e,t){var r,a,s=arguments;if(2==s.length)for(r in t)a=t[r],void 0!==a&&t.hasOwnProperty(r)&&n(e,r,a);else n(e,s[1],s[2])}}();return s});