-
Notifications
You must be signed in to change notification settings - Fork 32
/
loadgo.min.js
6 lines (6 loc) · 5.82 KB
/
loadgo.min.js
1
2
3
4
5
6
/**
* @preserve LoadGo v2.2.1 (http://franverona.com/loadgo)
* 2018 - Fran Verona
* Licensed under MIT (https://github.com/franverona/loadgo/blob/master/LICENSE)
*/
if("undefined"==typeof jQuery)throw new Error("LoadGo requires jQuery. Make sure you are loading jQuery before LoadGo, or try pure Javascript version instead.");!function($){var t={init:function(t){var e=$(this);if(0!==e.length){if(!e.is("img"))throw new Error("LoadGo only works on img elements.");if(e.length>1)throw new Error("LoadGo only works on one element at a time. Try with a valid #id.");e.data("loadgo-options",{});var o=e.loadgo("options",t),r=e[0].getBoundingClientRect().width,i=e[0].getBoundingClientRect().height,a='<div class="loadgo-overlay" style="background-color:%bgcolor%;opacity:%opacity%;width:%width%px;height:%height%px;position:absolute;"></div>'.replace("%bgcolor%",o.bgcolor).replace("%opacity%",o.opacity).replace("%width%",r).replace("%height%",i);if($overlay=$(a),o.animated){var s="width 0.6s ease, height 0.6s ease, top 0.6s ease";$overlay.css({transition:s,"-webkit-transition":s,"-moz-transition":s,"-ms-transition":s,"-o-transition":s})}if(o.class&&$overlay.addClass(o.class),o.filter&&("blur"===o.filter?e.css({"-webkit-filter":o.filter+"(10px)"}):"hue-rotate"===o.filter?e.css({"-webkit-filter":o.filter+"(360deg)"}):"opacity"===o.filter?e.css({"-webkit-filter":o.filter+"(0)"}):e.css({"-webkit-filter":o.filter+"(1)"}),o.animated&&e.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"})),o.image){var n="100% 0%";"rl"===o.direction?n="0% 50%":"bt"===o.direction?n="100% 0%":"tb"===o.direction&&(n="0% 100%"),$overlay.css({"background-image":'url("'+o.image+'")',"background-repeat":"no-repeat","background-size":"cover","background-color":"none","background-position":n})}var l={progress:0};if(null===o.filter){e.wrapAll('<div class="loadgo-container" style="position: relative"></div>'),e.parent().prepend($overlay);var d=parseFloat(e.css("padding-left")),p=parseFloat(e.css("padding-right")),c=parseFloat(e.css("padding-top")),g=parseFloat(e.css("padding-bottom")),h=parseFloat(e.css("margin-left")),f=parseFloat(e.css("margin-right")),v=parseFloat(e.css("margin-top")),y=parseFloat(e.css("margin-bottom"));"lr"===o.direction?$overlay.css("right",p+f+"px"):"rl"===o.direction?$overlay.css("left",d+h+"px"):"bt"===o.direction?$overlay.css("top",c+v+"px"):"tb"===o.direction&&$overlay.css("bottom",g+y+"px"),l.overlay=$overlay,l.width=$overlay.width(),l.height=$overlay.height()}if(e.data("loadgo",l),o.resize)$(window).on("resize",o.resize);else{var u=this;$(window).on("resize",function(){var t=e,r=t.data("loadgo");t.data("loadgo-options");if(void 0!==r){var i=r.overlay,a=r.progress,s=t.width(),n=t.height();if(storedData={progress:r.progress,width:s,height:n},i){i.css({width:s+"px",height:n+"px"});var l=parseFloat(t.css("padding-left")),d=parseFloat(t.css("padding-right")),p=parseFloat(t.css("padding-top")),c=parseFloat(t.css("padding-bottom")),g=parseFloat(t.css("margin-left")),h=parseFloat(t.css("margin-right")),f=parseFloat(t.css("margin-top")),v=parseFloat(t.css("margin-bottom"));"lr"===o.direction?i.css("right",d+h+"px"):"rl"===o.direction?i.css("left",l+g+"px"):"bt"===o.direction?i.css("top",p+f+"px"):"tb"===o.direction&&i.css("bottom",c+v+"px"),storedData.overlay=i}t.data("loadgo",$.extend({},r,storedData)),u.loadgo("setprogress",a)}})}}},options:function(t){var e=$(this),o=e.data("loadgo-options"),r=void 0!==t?t:{};void 0!==r.opacity&&(r.opacity=parseFloat(r.opacity)),o="{}"===JSON.stringify(o)?$.extend({},{bgcolor:"#FFFFFF",opacity:.5,animated:!0,image:null,class:null,resize:null,direction:"lr",filter:null},r):$.extend({},o,r);if(-1===$.inArray(o.direction.toLowerCase(),["lr","rl","bt","tb"])&&(o.direction="lr"),o.filter){-1===$.inArray(o.filter.toLowerCase(),["blur","grayscale","sepia","hue-rotate","invert","opacity"])&&(o.filter=null)}return e.data("loadgo-options",o),o},setprogress:function(t){if(!(t<0||t>100)){var e={progress:t},o=$(this).data("loadgo"),r=$(this).loadgo("options"),i=o.overlay,a=o.width,s=o.height,n=r.direction;if(i){var l,d;"lr"===n?(l=a*(1-t/100),i[0].style.width=l+"px"):"rl"===n?(l=a*(1-t/100),i[0].style.width=l+"px"):"bt"===n?(d=s*(1-t/100),i[0].style.height=d+"px"):"tb"===n&&(d=s*(1-t/100),i[0].style.height=d+"px"),e.overlay=i}else{var p,c=r.filter;switch(c){case"blur":p=(100-t)/10,jQuery(this).css({"-webkit-filter":c+"("+p+"px)"});break;case"hue-rotate":p=360*t/100,jQuery(this).css({"-webkit-filter":c+"("+p+"deg)"});break;case"opacity":p=t/100,jQuery(this).css({"-webkit-filter":c+"("+p+")"});break;default:p=1-t/100,$(this).css({"-webkit-filter":c+"("+p+")"})}}$(this).data("loadgo",$.extend({},o,e))}},getprogress:function(){var t=$(this).data("loadgo");return void 0===t?0:void 0!==t.progress?t.progress:0},resetprogress:function(){$(this).loadgo("setprogress",0)},loop:function(t){var e=$(this).data("loadgo");if(e.interval)return!1;var o=!0,r=this;e.interval=setInterval(function(){o?(e.progress+=1,e.progress>=100&&(o=!1)):(e.progress-=1,e.progress<=0&&(o=!0)),e.overlay.css({transition:"none","-webkit-transition":"none","-moz-transition":"none","-ms-transition":"none","-o-transition":"none"}),r.loadgo("setprogress",e.progress)},t)},stop:function(){var t=$(this).data("loadgo");t.interval=clearInterval(t.interval),this.loadgo("setprogress",100)},destroy:function(){var t=$(this),e=t.data("loadgo");void 0!==e&&(e.overlay&&(e.overlay.remove(),t.insertBefore(t.parent()),t.siblings(".loadgo-container").remove()),$.removeData(t,"loadgo"),$.removeData(t,"loadgo-options"))}};$.fn.loadgo=function(e){if(void 0===t[e]){if("object"==typeof e||void 0===e)return t.init.apply(this,arguments);throw new Error("Method "+e+" does not exist on $.loadgo")}return t[e].apply(this,Array.prototype.slice.call(arguments,1))}}(jQuery);