mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-01 13:39:22 +03:00
1 line
4.1 KiB
JavaScript
1 line
4.1 KiB
JavaScript
(e=>{function t(e){void 0!==e.length?this._targetElement=e:this._targetElement=[e],void 0===window._progressjsId&&(window._progressjsId=1),void 0===window._progressjsIntervals&&(window._progressjsIntervals={}),this._options={theme:"rainloop",overlayMode:!1,considerTransition:!0}}function r(){void 0!==this._onBeforeStartCallback&&this._onBeforeStartCallback.call(this),function(){if(!document.querySelector(".progressjs-container")){var e=document.createElement("div");e.className="progressjs-container",document.body.appendChild(e)}}.call(this);for(var e=0,t=this._targetElement.length;e<t;e++)s.call(this,this._targetElement[e])}function s(e){if(!e.hasAttribute("data-progressjs")){var t=function(e){var t={};"body"===e.tagName.toLowerCase()?(t.width=e.clientWidth,t.height=e.clientHeight):(t.width=e.offsetWidth,t.height=e.offsetHeight);var r=0,s=0;for(;e&&!isNaN(e.offsetLeft)&&!isNaN(e.offsetTop);)r+=e.offsetLeft,s+=e.offsetTop,e=e.offsetParent;return t.top=s,t.left=r,t}.call(this,e);e.setAttribute("data-progressjs",window._progressjsId);var r=document.createElement("div");r.className="progressjs-progress progressjs-theme-"+this._options.theme,"body"===e.tagName.toLowerCase()?r.style.position="fixed":r.style.position="absolute",r.setAttribute("data-progressjs",window._progressjsId);var s=document.createElement("div");s.className="progressjs-inner";var o=document.createElement("div");o.className="progressjs-percent",o.innerHTML="1%",s.appendChild(o),this._options.overlayMode&&"body"===e.tagName.toLowerCase()?(r.style.left=0,r.style.right=0,r.style.top=0,r.style.bottom=0):(r.style.left=t.left+"px",r.style.top=t.top+"px",r.style.width=t.width+"px",this._options.overlayMode&&(r.style.height=t.height+"px")),r.appendChild(s),document.querySelector(".progressjs-container").appendChild(r),n(e,1),++window._progressjsId}}function n(e,t){t>=100&&(t=100),e.hasAttribute("data-progressjs")&&setTimeout(function(){var r=o(e);r.style.width=parseInt(t)+"%",r=r.querySelector(".progressjs-percent");var s=parseInt(r.innerHTML.replace("%",""));!function(e,t,r){var s=!0;t>r&&(s=!1);var n=10;!function e(t,r,o){var i=Math.abs(r-o);n=i<3?30:i<20?20:1,r-o!=0&&(t.innerHTML=(s?++r:--r)+"%",setTimeout(function(){e(t,r,o)},n))}(e,t,r)}(r,s,parseInt(t))},50)}function o(e){var t=parseInt(e.getAttribute("data-progressjs"));return document.querySelector('.progressjs-container > .progressjs-progress[data-progressjs="'+t+'"] > .progressjs-inner')}function i(){void 0!==this._onBeforeEndCallback&&(!0===this._options.considerTransition?o(this._targetElement[0]).addEventListener(function(){var e,t=document.createElement("fakeelement"),r={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(e in r)if(void 0!==t.style[e])return r[e]}(),this._onBeforeEndCallback,!1):this._onBeforeEndCallback.call(this));for(var e=parseInt(this._targetElement[0].getAttribute("data-progressjs")),t=0,r=this._targetElement.length;t<r;t++){var s=this._targetElement[t],i=o(s);if(!i)return;var a=parseInt(i.style.width.replace("%","")),l=1;a<100&&(n.call(this,s,100),l=500),function(e,t){setTimeout(function(){e.parentNode.className+=" progressjs-end",setTimeout(function(){e.parentNode.parentNode.removeChild(e.parentNode),t.removeAttribute("data-progressjs")},1e3)},l)}(i,s)}if(window._progressjsIntervals[e])try{clearInterval(window._progressjsIntervals[e]),window._progressjsIntervals[e]=null,delete window._progressjsIntervals[e]}catch(e){}}var a=function(e){if("object"==typeof e)return new t(e);if("string"==typeof e){var r=document.querySelectorAll(e);if(r)return new t(r);throw new Error("There is no element with given selector.")}return new t(document.body)};a.version="0.1.0",a.fn=t.prototype={start:function(){return r.call(this),this},set:function(e){return function(e){for(var t=0,r=this._targetElement.length;t<r;t++)n.call(this,this._targetElement[t],e)}.call(this,e),this},end:function(){return i.call(this),this},onbeforeend:function(e){if("function"!=typeof e)throw new Error("Provided callback for onbeforeend was not a function");return this._onBeforeEndCallback=e,this}},e.progressJs=a})(this);
|