forked from xlune/jQuery-vGrid-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.vgrid.min.js
executable file
·20 lines (20 loc) · 5.4 KB
/
jquery.vgrid.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
* jQuery VGrid v0.1.9 - variable grid layout plugin
*
* Terms of Use - jQuery VGrid
* under the MIT (http://www.opensource.org/licenses/mit-license.php) License.
*
* Copyright 2009-2012 xlune.com All rights reserved.
* (http://blog.xlune.com/2009/09/jqueryvgrid.html)
*/
(function(g){function j(a){var b=a.data("_vgchild"),f=[[0,a.width(),0]],i=0,e,c,h;b.each(function(){e=g(this);if("none"==e.css("display"))return!0;var a=e.width(),d=e.height(),a=a+(Number(e.css("margin-left").replace("px",""))+Number(e.css("padding-left").replace("px",""))+Number(e.get(0).style.borderLeftWidth.replace("px",""))+Number(e.css("margin-right").replace("px",""))+Number(e.css("padding-right").replace("px",""))+Number(e.get(0).style.borderRightWidth.replace("px",""))),d=d+(Number(e.css("margin-top").replace("px",
""))+Number(e.css("padding-top").replace("px",""))+Number(e.get(0).style.borderTopWidth.replace("px",""))+Number(e.css("margin-bottom").replace("px",""))+Number(e.css("padding-bottom").replace("px",""))+Number(e.get(0).style.borderBottomWidth.replace("px","")));c=[a,d];a:{for(var a=c[0],d=f.concat().sort(q),b=d[d.length-1][2],k=0,o=d.length;k<o&&!(d[k][2]>=b);k++)if(d[k][1]-d[k][0]>=a){h=[d[k][0],d[k][2]];break a}h=[0,b]}d=h;a=f.concat().sort(q);d=[d[0],d[0]+c[0],d[1]+c[1]];b=0;for(k=a.length;b<k;b++)if(d[0]<=
a[b][0]&&a[b][1]<=d[1])delete a[b];else{var o=a,j=b,l=a[b],m=d;if(l[0]>=m[0]&&l[0]<m[1]||l[1]>=m[0]&&l[1]<m[1])l[0]>=m[0]&&l[0]<m[1]?l[0]=m[1]:l[1]=m[0];o[j]=l}a=a.concat([d]).sort(s);d=[];b=0;for(k=a.length;b<k;b++)a[b]&&(0<d.length&&d[d.length-1][1]==a[b][0]&&d[d.length-1][2]==a[b][2]?d[d.length-1][1]=a[b][1]:d.push(a[b]));f=d;i=Math.max(i,h[1]+c[1]);e.data("_vgleft",h[0]);e.data("_vgtop",h[1])});a.data("_vgwrapheight",i);b=a.data("_vgchild").length*(a.data("_vgopt").delay||0)+a.data("_vgopt").time||
500;a.stop();a.height()<a.data("_vgwrapheight")?g.browser.msie?a.height(a.data("_vgwrapheight")):a.animate({height:a.data("_vgwrapheight")+"px"},a.data("_vgopt").time||500,"easeOutQuart"):(clearTimeout(a.data("_vgwraptimeout")),a.data("_vgwraptimeout",setTimeout(function(){g.browser.msie?a.height(a.data("_vgwrapheight")):a.animate({height:a.data("_vgwrapheight")+"px"},a.data("_vgopt").time||500,"easeOutQuart")},b)))}function q(a,b){return!a||!b?0:a[2]==b[2]&&a[0]>b[0]||a[2]>b[2]?1:-1}function s(a,
b){return!a||!b?0:a[0]>b[0]?1:-1}function p(a,b,f,i){var e=g(a).parent(),c=!1,h=a.length,j,d,n;for(j=0;j<h;j++)if(d=g(a[j]),n=d.position(),n.left!=d.data("_vgleft")||n.top!=d.data("_vgtop"))c=!0;if(c){if("function"==typeof e.data("_vgopt").onStart)e.data("_vgopt").onStart();a.each(function(d){var c=g(this),h={duration:f,easing:b};a.size()-1==d&&(h.complete=e.data("_vgopt").onFinish||null);clearTimeout(c.data("_vgtimeout"));c.data("_vgtimeout",setTimeout(function(){c.animate({left:c.data("_vgleft")+
"px",top:c.data("_vgtop")+"px"},h)},d*i))})}}function n(a){a.each(function(){var a=g(this);clearTimeout(a.data("_vgtimeout"));a.data("_vgtimeout",setTimeout(function(){j(a);p(a.data("_vgchild"),a.data("_vgopt").easing||"linear",a.data("_vgopt").time||500,a.data("_vgopt").delay||0)},500))})}function r(a,b){a.data("vgrid-image-event-added")||(a.data("vgrid-image-event-added",1),a.bind("vgrid-added",function(){a.find("img").each(function(){var e=g(this);e.data("vgrid-image-handler")||(e.data("vgrid-image-handler",
1),e.bind("load",function(){b(a)}))})}));a.trigger("vgrid-added");var f=a.append,i=a.prepend;a.append=function(){f.apply(a,arguments);a.trigger("vgrid-added")};a.prepend=function(){i.apply(a,arguments);a.trigger("vgrid-added")}}g.fn.extend({vgrid:function(a){var b=g(this),f=a||{};f.easeing&&(f.easing=f.easeing);b.each(function(){var a=g(this);a.data("_vgopt",f);a.data("_vgchild",a.find("> *"));a.data("_vgdefchild",a.data("_vgchild"));a.css({position:"relative",width:"auto"});a.data("_vgchild").css("position",
"absolute");j(a);var b;a.data("_vgchild").each(function(){b=g(this);b.css("left",b.data("_vgleft")+"px");b.css("top",b.data("_vgtop")+"px")});if(a.data("_vgopt").fadeIn){var c=typeof a.data("_vgopt").fadeIn=="object"?a.data("_vgopt").fadeIn:{time:a.data("_vgopt").fadeIn};a.data("_vgchild").each(function(a){var b=g(this);if(b.css("display")=="none")return true;b.stop().css({opacity:0});setTimeout(function(){b.stop().fadeTo(c.time||250,1)},a*(c.delay||0))})}g(window).resize(function(){n(a)});f.useLoadImageEvent&&
r(a,n);if(f.useFontSizeListener){var h=g("<span />").text(" ").attr("id","_vgridspan").hide().appendTo("body");h.data("size",h.css("font-size"));h.data("timer",setInterval(function(){if(h.css("font-size")!=h.data("size")){h.data("size",h.css("font-size"));n(a)}},1E3))}});return b},vgrefresh:function(a,b,f,i){var e=g(this);e.each(function(){var c=g(this),e=c.data("_vgopt")||{};c.data("_vgchild")&&(c.data("_vgchild",c.find("> *")),c.data("_vgchild").css("position","absolute"),j(c),b="number"==typeof b?
b:c.data("_vgopt").time||500,f="number"==typeof f?f:c.data("_vgopt").delay||0,p(c.data("_vgchild"),a||c.data("_vgopt").easing||"linear",b,f),"function"==typeof i&&setTimeout(i,c.data("_vgchild").length*f+b));e.useLoadImageEvent&&r(c,n)});return e},vgsort:function(a,b,f,i){var e=g(this);e.each(function(){var c=g(this);c.data("_vgchild")&&(c.data("_vgchild",c.data("_vgchild").sort(a)),c.data("_vgchild").each(function(){g(this).appendTo(c)}),j(c),p(c.data("_vgchild"),b||c.data("_vgopt").easing||"linear",
"number"==typeof f?f:c.data("_vgopt").time||500,"number"==typeof i?i:c.data("_vgopt").delay||0))});return e}})})(jQuery);