-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.uniloader.min.js
15 lines (15 loc) · 4.82 KB
/
jquery.uniloader.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*!
* Uniloader
* Shows mouse or overlay loaders (with a modal window optionally)
*
* @requires jQuery v1.4.3 or newer
*
* @author Grigory Zarubin (http://craigy.ru/)
* @version 1.1.13
* @date 30.03.2018
*
* Dual licensed under the MIT or GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
(function(a){var b={APNGSupported:false,actualResizer:"resize",scrollbarWidth:0,init:function(){if("throttledresize" in jQuery.event.special){this.actualResizer="throttledresize"}this._checkAPNGSupport()},_checkAPNGSupport:function(){var d=new Image(),c=document.createElement("canvas");d.onload=function(){if(c.getContext){var e=c.getContext("2d");e.drawImage(d,0,0);b.APNGSupported=(e.getImageData(0,0,1,1).data[3]===0)}};d.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACGFjVEwAAAABAAAAAcMq2TYAAAANSURBVAiZY2BgYPgPAAEEAQB9ssjfAAAAGmZjVEwAAAAAAAAAAQAAAAEAAAAAAAAAAAD6A+gBAbNU+2sAAAARZmRBVAAAAAEImWNgYGBgAAAABQAB6MzFdgAAAABJRU5ErkJggg=="},_getWindowDimensions:function(){return{width:(a(window)[0].innerWidth||a(window).width())-this.scrollbarWidth,height:a(window)[0].innerHeight||a(window).height()}},_getScrollbarWidth:function(){var f=a(window).width();a("html").addClass("uniloader-overlay-html");var c=a(window).width()-f;if(c>0){var d=a('<div style="width:50px;height:50px;overflow:scroll"></div>').appendTo("body"),e=d[0].offsetWidth-d[0].clientWidth;d.remove();this.scrollbarWidth=Math.max(c,e)}a("html").removeClass("uniloader-overlay-html")},_centerNode:function(g,i){var f=this._getWindowDimensions(),d=g.outerWidth(true),e=g.outerHeight(true),c=(i?a(window).scrollLeft():0)+f.width/2,j=(i?a(window).scrollTop():0)+f.height/2;return{left:(c-d/2)<1?0:(c-d/2)+"px",top:(j-e/2)<1?0:(j-e/2)+"px"}},defaults:{hideSelector:".modal-close",effectSpeed:200,fixedElements:false,replaceWindowScrollbar:true,onStart:a.noop,onShow:a.noop,onHide:a.noop}};a.mouseLoader=function(g,d){var c=a("#uniloader-mouse");var e=a.extend(true,{},b.defaults,d);if(g){if(!c.length){c=a('<div id="uniloader-mouse" />').data({"uniloader-mousemove":function(h){c.css({top:h.pageY-(c.outerHeight(true)/2),left:h.pageX-(c.outerWidth(true)/2)})},"uniloader-onHide":e.onHide});a(document.body).append(c);if(b.APNGSupported){c.addClass("uniloader-apng-supported")}}if(c.is(":visible")){return}e.onStart();var f=b._centerNode(c,true);c.css({top:f.top,left:f.left}).show(e.effectSpeed,function(){e.onShow()});a(document.body).on("mousemove.uniloader scroll.uniloader",c.data("uniloader-mousemove"))}else{c.hide(e.effectSpeed,function(){try{c.data("uniloader-onHide")()}catch(h){}});a(document.body).off("mousemove.uniloader scroll.uniloader",c.data("uniloader-mousemove"))}};a.overlayLoader=function(g,e){var c=a("#uniloader-overlay"),d=a("#uniloader-overlay-content"),h=false;if(e&&e.node){d=a(e.node);h=true;delete e.node}var f=a.extend(true,{},b.defaults,e);if(g){if(!c.length){c=a('<div id="uniloader-overlay" />');a(document.body).append(c)}if(!d.length){d=a('<div id="uniloader-overlay-content"><div class="uniloader-overlay-content-text" /></div>')}if(c.is(":visible")){a.overlayLoader(false,{effectSpeed:0})}f.onStart(d);if(h){c.on("click.uniloader",function(){a.overlayLoader()});a(document.body).on("keypress.uniloader",function(i){if(i.keyCode==27){a.overlayLoader()}});d.on("click",function(i){i.stopPropagation()}).find(f.hideSelector).on("click.uniloader",function(i){i.preventDefault();a.overlayLoader()})}a(window).on(b.actualResizer+".uniloader gestureend.uniloader",function(){var i=b._centerNode(d);d.css({top:i.top,left:i.left})});b._getScrollbarWidth();if(f.replaceWindowScrollbar){a("html").css("margin-right",b.scrollbarWidth).addClass("uniloader-overlay-html");c.addClass("append-scrollbars").data("uniloader-replaceWindowScrollbar",true);if(f.fixedElements){a(f.fixedElements).each(function(){a(this).css("padding-right",b.scrollbarWidth)});c.data("uniloader-fixedElements",f.fixedElements)}}c.data({"uniloader-ismodal":h,"uniloader-node":d,"uniloader-node-parent":d.parent().length?d.parent():a(document.body),"uniloader-onHide":f.onHide}).append(d).fadeTo(f.effectSpeed,1,function(){var i=b._centerNode(d);d.css({top:i.top,left:i.left}).show(f.effectSpeed,function(){f.onShow(d)})})}else{d=a(c.data("uniloader-node"));if(c.data("uniloader-ismodal")){c.off(".uniloader");a(document.body).off("keypress.uniloader");d.find(f.hideSelector).off(".uniloader")}a(window).off(b.actualResizer+".uniloader gestureend.uniloader");d.hide(f.effectSpeed);c.fadeOut(f.effectSpeed,function(){a(c.data("uniloader-node-parent")).append(d);if(c.data("uniloader-replaceWindowScrollbar")){a("html").removeClass("uniloader-overlay-html").css("margin-right","");c.removeClass("append-scrollbars")}var i=c.data("uniloader-fixedElements");if(i){a(i).each(function(){a(this).css("padding-right","")})}try{c.data("uniloader-onHide")(d)}catch(j){}})}};b.init()})(jQuery);