forked from franverona/loadgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadgo.min.js
17 lines (17 loc) · 5.49 KB
/
loadgo.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*
LoadGo v2.0 (http://franverona.com/loadgo)
2016 - Fran Verona
Licensed under MIT (https://github.com/franverona/loadgo/blob/master/LICENSE)
*/
if("undefined"===typeof jQuery)throw Error("LoadGo requires jQuery");
jQuery&&function(d){var h=function(a,c){return"undefined"!==typeof getComputedStyle?getComputedStyle(a).getPropertyValue(c):a.currentStyle[c]},g={init:function(a){var c=this,b=d(this);if(1<b.length)throw Error("LoadGo selector must be an id. Please, set a valid DOM id; also check if you have more than one DOM element with the same id.");a="undefined"!==typeof a?a:{};a={bgcolor:a.bgcolor?a.bgcolor:"#FFFFFF",opacity:a.opacity?a.opacity:"0.5",animated:void 0!==a.animated?a.animated:!0,image:void 0!==
a.image?a.image:null,"class":void 0!==a["class"]?a["class"]:null,resize:void 0!==a.resize?a.resize:null,direction:void 0!==a.direction?a.direction:"lr",filter:void 0!==a.filter?a.filter:null};-1===$.inArray(a.direction.toLowerCase(),["lr","rl","bt","tb"])&&(console.warn('LoadGo requires a valid direction. "'+a.direction+'" provided. Using default value: "lr".'),a.direction="lr");var e=b[0].getBoundingClientRect().width,f=b[0].getBoundingClientRect().height;b.parent().css("padding-left");var k=parseFloat(h(b[0].parentNode,
"padding-left")),g=parseFloat(h(b[0],"margin-left")),p=parseFloat(h(b[0],"padding-left"));isNaN(k)&&(k=0);isNaN(g)&&(g=0);isNaN(p)&&(p=0);$overlay=d('<div class="loadgo-overlay" style="background-color:'+a.bgcolor+";opacity:"+a.opacity+";width:"+e+"px;height:"+f+'px;top:0;position:absolute;"></div>');a.animated&&$overlay.css({transition:"width 0.6s ease, height 0.6s ease, top 0.6 ease","-webkit-transition":"width 0.6s ease, height 0.6s ease, top 0.6s ease","-moz-transition":"width 0.6s ease, height 0.6s ease, top 0.6s ease",
"-ms-transition":"width 0.6s ease, height 0.6s ease, top 0.6s ease","-o-transition":"width 0.6s ease, height 0.6s ease, top 0.6s ease"});a["class"]&&$overlay.addClass(a["class"]);if(a.filter)if(-1!==$.inArray(a.filter,"blur grayscale sepia hue-rotate invert opacity".split(" "))){switch(a.filter){case "blur":b.css({"-webkit-filter":a.filter+"(10px)"});break;case "hue-rotate":b.css({"-webkit-filter":a.filter+"(360deg)"});break;case "opacity":b.css({"-webkit-filter":a.filter+"(0)"});break;default:b.css({"-webkit-filter":a.filter+
"(1)"})}a.animated&&b.css({transition:"0.6s filter ease","-webkit-transition":"0.6s -webkit-filter ease","-moz-transition":"0.6s -moz-filter ease","-ms-transition":"0.6s -ms-filter ease","-o-transition":"0.6s -o-filter ease"})}else throw Error('Invalid value for "filter" option. Possible values: blur, grayscale, sepia, hue-rotate, invert, opacity.');if(a.image){switch(a.direction){case "lr":e="100% 0%";break;case "rl":e="0% 50%";break;case "bt":e="100% 0%";break;case "tb":e="0% 100%";break;default:e=
"100% 50%"}$overlay.css({"background-image":'url("'+a.image+'")',"background-repeat":"no-repeat","background-size":"cover","background-color":"none","background-position":e})}b.data("loadgo",{overlay:$overlay,width:$overlay.width(),height:$overlay.height(),progress:0,direction:a.direction});null===a.filter?$overlay.insertAfter(c):b.data("loadgo",{filter:a.filter});if(a.resize)d(window).on("resize",a.resize);else d(window).on("resize",function(){var a=b.data("loadgo"),d=a.overlay,e=a.progress,f=a.direction,
a=a.filter,g=b.width(),k=b.height();b.parent().css("padding-left");if(d){var l=parseFloat(h(b[0].parentNode,"padding-left")),m=parseFloat(h(b[0],"margin-left")),n=parseFloat(h(b[0],"padding-left"));isNaN(l)&&(l=0);isNaN(m)&&(m=0);isNaN(n)&&(n=0);d.css({width:g+"px",height:k+"px",left:l+m+n+"px"})}b.data("loadgo",{overlay:d,width:g,height:k,progress:e,direction:f});a&&b.data("loadgo",{filter:a});c.loadgo("setprogress",e)})},setprogress:function(a){if(0>a||100<a)console.warn("LoadGo expects progress number between 0 (0%) and 100 (100%).");
else{var c=d(this).data("loadgo"),b=c.overlay,e=c.width,f=c.height,g=c.direction;if(b)switch(g){case "lr":b.css("width",e*(1-a/100)+"px");b.css("right",b.parent().css("padding-right"));break;case "rl":b.css("width",e*(1-a/100)+"px");break;case "bt":b.css("height",f*(1-a/100)+"px");break;case "tb":e=f*(1-a/100);b.css("height",e+"px");b.css("top",f-e+"px");break;default:b.css("width",e*(1-a/100)+"px"),b.css("right","0px")}else switch(b=c.filter,b){case "blur":f=(100-a)/10;d(this).css({"-webkit-filter":b+
"("+f+"px)"});break;case "hue-rotate":f=360*a/100;d(this).css({"-webkit-filter":b+"("+f+"deg)"});break;case "opacity":f=a/100;d(this).css({"-webkit-filter":b+"("+f+")"});break;default:f=1-a/100,d(this).css({"-webkit-filter":b+"("+f+")"})}d(this).data("loadgo",d.extend({},c,{progress:a}))}},getprogress:function(){var a=d(this).data("loadgo");return a.progress?a.progress:0},resetprogress:function(){d(this).loadgo("setprogress",0)},loop:function(a){var c=d(this).data("loadgo"),b=!0,e=this;if(c.interval)return console.warn("LoadGo requires you to stop the current loop before modifying it."),
!1;c.interval=setInterval(function(){b?(c.progress+=1,100<=c.progress&&(b=!1)):(c.progress-=1,0>=c.progress&&(b=!0));c.overlay.css({transition:"none","-webkit-transition":"none","-moz-transition":"none","-ms-transition":"none","-o-transition":"none"});e.loadgo("setprogress",c.progress)},a)},stop:function(){var a=d(this).data("loadgo");a.interval=clearInterval(a.interval);this.loadgo("setprogress",100)}};d.fn.loadgo=function(a){if(g[a])return g[a].apply(this,Array.prototype.slice.call(arguments,1));
if("object"!==typeof a&&a)d.error("Method "+a+" does not exist on jQuery.loadgo");else return g.init.apply(this,arguments)}}(jQuery);