-
Notifications
You must be signed in to change notification settings - Fork 7
/
jquery.gridnav.min.js
1 lines (1 loc) · 11.3 KB
/
jquery.gridnav.min.js
1
(function(c){jQuery.fn.reverse=Array.prototype.reverse;var a={setup:function(i,j,e){i.css("position","relative");a.saveInitialPosition(j);j.each(function(o){var n=c(this);n.css({position:"absolute",left:n.data("left"),top:n.data("top")})});var k=Math.floor(i.width()/j.width()),l=k*e.rows,m=Math.ceil(j.length/k);var f={};f.currentRow=1;f.totalRows=m;f.rowCount=k;f.shownItems=l;f.rowsForPage=e.rows;i.data("config",f);i.children(":gt("+(l-1)+")").hide();j.each(function(o){var n=c(this),p=Math.ceil((o+1)/k);n.addClass("tj_row_"+p)});if($d_nav.length>0){var h=[];for(var g=0;g<a.get_pages(i);g++){h.push(c("<li />"))}$d_nav.html(h).find("li:first-child").addClass("active");delete h}d.setup(i,j,e)},saveInitialPosition:function(e){e.each(function(g){var f=c(this);f.data({left:f.position().left+"px",top:f.position().top+"px"})})},get_page:function(f){var e=f.data("config");return Math.ceil(e.currentRow/e.rowsForPage)},get_pages:function(f){var e=f.data("config");return Math.ceil(e.totalRows/e.rowsForPage)},has_next:function(e){return a.get_page(e)<a.get_pages(e)?true:false},has_prev:function(e){return a.get_page(e)>1?true:false},activateDot:function(g,f){try{c(f.navL).removeClass("disabled").addClass(a.has_prev(g)?"":"disabled");c(f.navR).removeClass("disabled").addClass(a.has_next(g)?"":"disabled");c(f.navDots).find("li").removeClass("active").end().find("li:nth-child("+a.get_page(g)+")").addClass("active")}catch(h){}}},d={setup:function(f,g,e){d[e.type.mode].setup(f,g,e)},def:{setup:function(g,h,f){var e=g.data("config");h.each(function(l){var j=c(this),n=Math.ceil((l+1)/e.rowCount),k,m=n%f.rows;if(m===1){k="0px"}else{if(m===0){k=(f.rows-1)*h.height()+"px"}else{k=(m-1)*h.height()+"px"}}j.css({top:k})})},pagination:function(l,g,k){var f=l.data("config");if((g===1&&f.currentRow+k.rows>f.totalRows)||(g===-1&&f.currentRow-k.rows<=0)){l.data("anim",false);return false}var j=[],e=[];for(var h=0;h<k.rows;++h){j.push(".tj_row_"+(f.currentRow+h));e.push(g===1?".tj_row_"+(f.currentRow+k.rows+h):".tj_row_"+(f.currentRow-1-h))}j=j.join(","),e=e.join(",");l.children(j).hide();l.children(e).show();(g===1)?f.currentRow+=k.rows:f.currentRow-=k.rows;l.data("anim",false);l.data("config",f);a.activateDot(l,k)}},fade:{setup:function(f,g,e){d.def.setup(f,g,e)},pagination:function(l,j,e){var h=l.data("config");if((j===1&&h.currentRow+e.rows>h.totalRows)||(j===-1&&h.currentRow-e.rows<=0)){l.data("anim",false);return false}var n=[],f=[];for(var k=0;k<e.rows;++k){n.push(".tj_row_"+(h.currentRow+k));f.push(j===1?".tj_row_"+(h.currentRow+e.rows+k):".tj_row_"+(h.currentRow-1-k))}f=f.join(",");l.children(n).fadeOut(e.type.speed,e.type.easing);var o=l.children(f),m=o.length,g=0;o.fadeIn(e.type.speed,e.type.easing,function(){++g;if(g===m){l.data("anim",false)}});(j===1)?h.currentRow+=e.rows:h.currentRow-=e.rows;l.data("config",h);a.activateDot(l,e)}},seqfade:{setup:function(f,g,e){d.def.setup(f,g,e)},pagination:function(m,k,e){var j=m.data("config");if((k===1&&j.currentRow+e.rows>j.totalRows)||(k===-1&&j.currentRow-e.rows<=0)){m.data("anim",false);return false}var p=[],f=[];for(var l=0;l<e.rows;++l){p.push(".tj_row_"+(j.currentRow+l));f.push(k===1?".tj_row_"+(j.currentRow+e.rows+l):".tj_row_"+(j.currentRow-1-l))}p=p.join(","),f=f.join(",");var g=e.type.factor;var n;(k===1)?n=m.children(p):n=m.children(p).reverse();n.each(function(s){var r=c(this);setTimeout(function(){r.fadeOut(e.type.speed,e.type.easing)},g+s*g)});var q;(k===1)?q=m.children(f):q=m.children(f).reverse();var o=q.length,h=0;q.each(function(s){var r=c(this);setTimeout(function(){r.fadeIn(e.type.speed,e.type.easing,function(){++h;if(h===o){m.data("anim",false)}})},(g*2)+s*g)});(k===1)?j.currentRow+=e.rows:j.currentRow-=e.rows;m.data("config",j);a.activateDot(m,e)}},updown:{setup:function(g,h,f){var e=g.data("config");g.children(":gt("+(e.shownItems-1)+")").css("opacity",0);h.each(function(l){var j=c(this),n=Math.ceil((l+1)/e.rowCount),k=j.position().top,m=n%f.rows;if(n>f.rows){k=(f.rows*h.height())}j.css({top:k+"px"})})},pagination:function(k,h,e){var g=k.data("config");if((h===1&&g.currentRow+e.rows>g.totalRows)||(h===-1&&g.currentRow-1<=0)){k.data("anim",false);return false}var n=[];for(var j=0;j<=e.rows;++j){n.push(h===1?".tj_row_"+(g.currentRow+j):".tj_row_"+(g.currentRow+(j-1)))}n=n.join(",");var l;(h===1)?l=k.children(n):l=k.children(n).reverse();var m=l.length,f=0;l.each(function(q){var p=c(this),s=p.attr("class").split(" ").pop(),r={},o=g.currentRow;if(h===1){if(s==="tj_row_"+(o)){r.opacity=0}else{if(s==="tj_row_"+(o+e.rows)){r.opacity=1}}}else{if(s==="tj_row_"+(o-1)){r.opacity=1}else{if(s==="tj_row_"+(o+e.rows-1)){r.opacity=0}}}p.show();(h===1)?r.top=p.position().top-p.height()+"px":r.top=p.position().top+p.height()+"px";p.stop().animate(r,e.type.speed,e.type.easing,function(){if(parseInt(r.top)<0||parseInt(r.top)>p.height()*(e.rows-1)){p.hide()}++f;if(f===m){k.data("anim",false)}})});(h===1)?g.currentRow+=1:g.currentRow-=1;k.data("config",g);a.activateDot(k,e)}},sequpdown:{setup:function(f,g,e){d.updown.setup(f,g,e)},pagination:function(m,k,e){var j=m.data("config");if((k===1&&j.currentRow+e.rows>j.totalRows)||(k===-1&&j.currentRow-1<=0)){m.data("anim",false);return false}var p=[];for(var l=0;l<=e.rows;++l){p.push(k===1?".tj_row_"+(j.currentRow+l):".tj_row_"+(j.currentRow+(l-1)))}p=p.join(",");var f=e.type.factor,n;var g=1;if(e.type.reverse){g=-1}(k===g)?n=m.children(p):n=m.children(p).reverse();var o=n.length,h=0;n.each(function(s){var r=c(this),u=r.attr("class").split(" ").pop(),t={},q=j.currentRow;setTimeout(function(){if(k===1){if(u==="tj_row_"+(q)){t.opacity=0}else{if(u==="tj_row_"+(q+e.rows)){t.opacity=1}}}else{if(u==="tj_row_"+(q-1)){t.opacity=1}else{if(u==="tj_row_"+(q+e.rows-1)){t.opacity=0}}}r.show();(k===1)?t.top=r.position().top-r.height()+"px":t.top=r.position().top+r.height()+"px";r.stop().animate(t,e.type.speed,e.type.easing,function(){if(parseInt(t.top)<0||parseInt(t.top)>r.height()*(e.rows-1)){r.hide()}++h;if(h===o){m.data("anim",false)}})},f+s*f)});(k===1)?j.currentRow+=1:j.currentRow-=1;m.data("config",j);a.activateDot(m,e)}},showhide:{setup:function(g,h,f){var e=g.data("config");h.each(function(l){var j=c(this),n=Math.ceil((l+1)/e.rowCount),k,m=n%f.rows;if(m===1){k="0px"}else{if(m===0){k=(f.rows-1)*h.height()+"px"}else{k=(m-1)*h.height()+"px"}}j.css({top:k})})},pagination:function(l,j,e){var h=l.data("config");if((j===1&&h.currentRow+e.rows>h.totalRows)||(j===-1&&h.currentRow-e.rows<=0)){l.data("anim",false);return false}var n=[],f=[];for(var k=0;k<e.rows;++k){n.push(".tj_row_"+(h.currentRow+k));f.push(j===1?".tj_row_"+(h.currentRow+e.rows+k):".tj_row_"+(h.currentRow-1-k))}n=n.join(","),f=f.join(",");l.children(n).hide(e.type.speed,e.type.easing);var o=l.children(f),m=o.length,g=0;o.show(e.type.speed,e.type.easing,function(){++g;if(g===m){l.data("anim",false)}});(j===1)?h.currentRow+=e.rows:h.currentRow-=e.rows;l.data("config",h);a.activateDot(l,e)}},disperse:{setup:function(g,h,f){var e=g.data("config");h.each(function(l){var j=c(this),n=Math.ceil((l+1)/e.rowCount),k,m=n%f.rows;if(m===1){k="0px"}else{if(m===0){k=(f.rows-1)*h.height()+"px"}else{k=(m-1)*h.height()+"px"}}j.css({top:k}).data("top",k)})},pagination:function(m,h,l){var g=m.data("config");if((h===1&&g.currentRow+l.rows>g.totalRows)||(h===-1&&g.currentRow-l.rows<=0)){m.data("anim",false);return false}var k=[],e=[];for(var j=0;j<l.rows;++j){k.push(".tj_row_"+(g.currentRow+j));e.push(h===1?".tj_row_"+(g.currentRow+l.rows+j):".tj_row_"+(g.currentRow-1-j))}k=k.join(","),e=e.join(",");m.children(k).each(function(o){var n=c(this);n.stop().animate({left:n.position().left+Math.floor(Math.random()*101)-50+"px",top:n.position().top+Math.floor(Math.random()*101)-50+"px",opacity:0},l.type.speed,l.type.easing,function(){n.css({left:n.data("left"),top:n.data("top")}).hide()})});var f=m.children(e);total_elems=f.length,cnt=0;f.each(function(o){var n=c(this);n.css({left:parseInt(n.data("left"))+Math.floor(Math.random()*301)-150+"px",top:parseInt(n.data("top"))+Math.floor(Math.random()*301)-150+"px",opacity:0}).show().animate({left:n.data("left"),top:n.data("top"),opacity:1},l.type.speed,l.type.easing,function(){++cnt;if(cnt===total_elems){m.data("anim",false)}})});(h===1)?g.currentRow+=l.rows:g.currentRow-=l.rows;m.data("config",g);a.activateDot(m,l)}},rows:{setup:function(f,g,e){d.def.setup(f,g,e)},pagination:function(m,h,l){var g=m.data("config");if((h===1&&g.currentRow+l.rows>g.totalRows)||(h===-1&&g.currentRow-l.rows<=0)){m.data("anim",false);return false}var k=[],e=[];for(var j=0;j<l.rows;++j){k.push(".tj_row_"+(g.currentRow+j));e.push(h===1?".tj_row_"+(g.currentRow+l.rows+j):".tj_row_"+(g.currentRow-1-j))}k=k.join(","),e=e.join(",");m.children(k).each(function(o){var n=c(this),q=n.attr("class").split(" ").pop().match(/tj_row_(\d+)/)[1],p;if(q%2===0){p=l.type.factor}else{p=-l.type.factor}n.stop().animate({left:n.position().left+p+"px",opacity:0},l.type.speed,l.type.easing,function(){n.css({left:n.data("left")}).hide()})});var f=m.children(e);total_elems=f.length,cnt=0;f.each(function(o){var n=c(this),q=n.attr("class").split(" ").pop().match(/tj_row_(\d+)/)[1],p;if(q%2===0){p=l.type.factor}else{p=-l.type.factor}n.css({left:parseInt(n.data("left"))+p+"px",opacity:0}).show().animate({left:n.data("left"),opacity:1},l.type.speed,l.type.easing,function(){++cnt;if(cnt===total_elems){m.data("anim",false)}})});(h===1)?g.currentRow+=l.rows:g.currentRow-=l.rows;m.data("config",g);a.activateDot(m,l)}}},b={init:function(e){if(this.length){var f={rows:2,navL:"#tj_prev",navR:"#tj_next",navDots:"#tj_dots",type:{mode:"def",speed:500,easing:"jswing",factor:50,reverse:false,timeout:3000}};return this.each(function(){if(e){c.extend(f,e)}var o=c(this).css("visibility","hidden"),k=o.find("ul.tj_gallery"),g=k.children("li"),m=g.length,j=c(f.navL),l=c(f.navR);$d_nav=c(f.navDots);$timeout=f.type.timeout;$backToTop=true;j.addClass("disabled");k.data("anim",false);var i=0;g.find("img").each(function(q){var p=c(this);c("<img/>").load(function(){++i;if(i===m){a.setup(k,g,f);o.css("visibility","visible");if(j.length){j.bind("click.gridnav",function(r){clearInterval(h);if(k.data("anim")){return false}k.data("anim",true);d[f.type.mode].pagination(k,-1,f);return false})}if(l.length){l.bind("click.gridnav",function(r){clearInterval(h);if(k.data("anim")){return false}k.data("anim",true);d[f.type.mode].pagination(k,1,f);return false})}o.bind("mousewheel.gridnav",function(r,s){if(s>0){if(k.data("anim")){return false}k.data("anim",true);d[f.type.mode].pagination(k,-1,f)}else{if(k.data("anim")){return false}k.data("anim",true);d[f.type.mode].pagination(k,1,f)}return false})}}).attr("src",p.attr("src"))});function n(){if(k.data("anim")){return false}config=k.data("config");if((config.totalRows)===config.currentRow){if($backToTop===false){$backToTop=true}k.data("anim",true);d[f.type.mode].pagination(k,-1,f);return false}else{if($backToTop===true){if(config.currentRow===1){$backToTop=false;k.data("anim",true);d[f.type.mode].pagination(k,1,f)}else{k.data("anim",true);d[f.type.mode].pagination(k,-1,f)}return false}else{if($backToTop===false){k.data("anim",true);d[f.type.mode].pagination(k,1,f);return false}}}}if($timeout>0){var h=setInterval(n,$timeout);k.hover(function(){clearInterval(h)},function(){h=setInterval(n,f.type.timeout)})}})}}};c.fn.gridnav=function(e){if(b[e]){return b[e].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof e==="object"||!e){return b.init.apply(this,arguments)}else{c.error("Method "+e+" does not exist on jQuery.gridnav")}}}})(jQuery);