1 | function RVGTLine(a,c){this.elements=[];this.margin=a;this.rowHeight=c;this.maxHeight=0} |
---|
2 | RVGTLine.prototype={width:0,elementsWidth:0,firstThumbIndex:0,add:function(a,c){0===this.elements.length&&(this.firstThumbIndex=c);var d,b;(d=a.data("w"))?b=a.data("h"):((d=a[0].getAttribute("width"))&&(d=parseInt(d))?b=parseInt(a[0].getAttribute("height")):(d=a.width(),b=a.height()),b>this.rowHeight&&(d=Math.round(d*this.rowHeight/b),b=this.rowHeight),a.data("w",d).data("h",b));d={$elt:a,w:d,h:b};this.elements.push(d);d.h>this.maxHeight&&(this.maxHeight=d.h);this.width+=this.margin+d.w;this.elementsWidth+= |
---|
3 | d.w},clear:function(){this.elements.length&&(this.maxHeight=this.width=this.elementsWidth=0,this.elements.length=0)}}; |
---|
4 | function RVGThumbs(a){this.opts=a;this.$thumbs=$("#thumbnails");if(0!=this.$thumbs.length){this.$thumbs.css("text-align","left");this.opts.extraRowHeight=0;1<window.devicePixelRatio?(a=window.devicePixelRatio,this.opts.resizeThreshold=1.01,this.opts.resizeFactor=0.95,this.opts.extraRowHeight=6,this.opts.rowHeight=Math.round(this.opts.rowHeight/a)+this.opts.extraRowHeight):(this.opts.resizeThreshold=1.12,this.opts.resizeFactor=0.8);this.process();var c=this;$(window).on("resize",function(){1<Math.abs(c.$thumbs.width()- |
---|
5 | c.prevContainerWidth)&&c.process()}).on("RVTS_loaded",function(a,b){c.process(b&&c.$thumbs.width()==c.prevContainerWidth?c.prevLastLineFirstThumbIndex:0)});$.isReady||$(document).ready(function(){c.$thumbs.width()<c.prevContainerWidth&&c.process()})}} |
---|
6 | RVGThumbs.prototype={prevContainerWidth:0,prevLastLineFirstThumbIndex:0,process:function(a){a=a?a:0;var c=this.$thumbs.width();this.prevContainerWidth=c;for(var d=$("li>a>img",this.$thumbs),b=new RVGTLine(this.opts.hMargin,this.opts.rowHeight);a<d.length;a++){var e=$(d[a]);b.add(e,a);b.width>=c-1*b.elements.length&&(this.processLine(b,c),b.clear())}b.elements.length&&this.processLine(b,c,!0);this.prevLastLineFirstThumbIndex=b.firstThumbIndex},processLine:function(a,c,d){var b,e,f=a.maxHeight?a.maxHeight: |
---|
7 | a.elements[0].h;a.width/c>this.opts.resizeThreshold?(e=a.elementsWidth/(a.elementsWidth+c-a.width),b=f/(1+(e-1)*this.opts.resizeFactor),b=6*Math.round(b/6),b<f/e&&(b=Math.ceil(f/e),e=this.opts.rowHeight-this.opts.extraRowHeight-b,0<e&&6>e&&(b+=e)),b<f&&(f=b)):d&&(f=Math.min(f,this.opts.rowHeight-this.opts.extraRowHeight));c=a.width-c;d&&(c=0);for(var k=0;k<a.elements.length;k++){var h=a.elements[k];b=h.w;e=h.h;var g;g=k==a.elements.length-1?c:Math.round(c*b/a.elementsWidth);c-=g;a.elementsWidth-= |
---|
8 | b;e>f&&(b=Math.round(b*f/h.h),e=f,g-=h.w-b,d&&(g=0));this.reposition(h.$elt,b,e,b-g,f)}},reposition:function(a,c,d,b,e){a=a[0];a.setAttribute("width",c+"");a.setAttribute("height",d+"");a=a.parentNode;a.style.left=Math.round((b-c)/2)+"px";a.style.top=Math.round((e-d)/2)+"px";a=a.parentNode;a.style.width=b+"px";a.style.height=e+"px"}}; |
---|