forked from jordansinger/Hook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook.min.js
1 lines (1 loc) · 2.01 KB
/
hook.min.js
1
(function(c,f,g,b){var d=c(this),i=d.scrollTop()||f.pageYOffset,h=false;var e=function(){return !!("ontouchstart" in f)||!!("onmsgesturechange" in f)};var a={init:function(j){return this.each(function(){var q=c(this),m=q.data("hook");if(typeof(m)==="undefined"){var p={reloadPage:true,dynamic:true,textRequired:false,scrollWheelSelected:false,swipeDistance:50,loaderClass:"hook-loader",spinnerClass:"hook-spinner",loaderTextClass:"hook-text",loaderText:"Reloading...",reloadEl:function(){}};m=c.extend({},p,j);q.data("hook",m)}else{m=c.extend({},m,j)}if(m.dynamic===true){var k="<div class="+m.loaderClass+">";k+="<div class="+m.spinnerClass+"/>";k+="</div>";var o="<span class="+m.loaderTextClass+">"+m.loaderText+"</span>";q.append(k);if(m.textRequired===true){q.addClass("hook-with-text");q.append(o)}}if(!e()){if(m.scrollWheelSelected===true){d.on("mousewheel",function(r,s){a.onScroll(q,m,s)})}else{d.on("scroll",function(){a.onScroll(q,m)})}}else{var n=0,l=0;d.on("touchstart",function(r){n=r.originalEvent.touches[0].pageY});d.on("touchmove",function(r){l=r.originalEvent.touches[0].pageY+n;i=c(this).scrollTop();if(l<m.swipeDistance){r.preventDefault()}if(l>m.swipeDistance&&n<=40){a.onSwipe(q,m)}});d.on("touchend",function(){l=0})}})},onScroll:function(k,j,l){i=d.scrollTop();if(j.scrollWheelSelected===true&&(l>=150&&i<=0)){if(h===false){a.reload(k,j);h=true}}if(j.scrollWheelSelected===false&&i<=0){if(h===false){a.reload(k,j);h=true}}},onSwipe:function(k,j){if(i<=0){a.reload(k,j)}},reload:function(k,j){k.show();k.animate({marginTop:"0px"},200);k.delay(500).slideUp(200,function(){if(j.reloadPage){f.location.reload(true)}h=false});if(!j.reloadPage){j.reloadEl()}},destroy:function(){return c(this).each(function(){var j=c(this);j.empty();j.removeData("hook")})}};c.fn.hook=function(){var j=arguments[0];if(a[j]){j=a[j];arguments=Array.prototype.slice.call(arguments,1)}else{if(typeof(j)==="object"||!j){j=a.init}else{c.error("Method "+j+" does not exist on jQuery.pluginName");return this}}return j.apply(this,arguments)}})(jQuery,window,document);