Changeset 27412


Ignore:
Timestamp:
Feb 19, 2014, 6:14:59 AM (10 years ago)
Author:
rvelices
Message:

modus js optims

Location:
extensions/modus
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/modus/js/thumb.arrange.js

    r26836 r27412  
    1515                if (this.elements.length === 0)
    1616                        this.firstThumbIndex = absIndex;
    17                 if (!$elt.data("w"))
    18                 {
    19                         var w=$elt.width(), h=$elt.height();
     17                var w,h;
     18
     19                if (! (w=$elt.data("w")) ) {
     20                        if ( (w=$elt[0].getAttribute("width")) && (w=parseInt(w)) ) {
     21                                h=parseInt($elt[0].getAttribute("height"));
     22                        }
     23                        else {
     24                                w=$elt.width();
     25                                h=$elt.height();
     26                        }
    2027                        if (h > this.rowHeight) {
    2128                                w = Math.round(w * this.rowHeight/h);
     
    2532                                .data("h", h);
    2633                }
     34                else
     35                        h=$elt.data("h");
     36               
    2737
    2838                var eltObj = {
    2939                        $elt: $elt,
    30                         w: $elt.data("w"),
    31                         h: $elt.data("h")
     40                        w: w,
     41                        h: h
    3242                };
    3343                this.elements.push(eltObj);
     
    166176
    167177        reposition: function($img, imgW, imgH, liW, liH) {
    168                 $img.attr("width", imgW)
    169                         .attr("height", imgH);
     178                /* JQuery .attr and .css functions add too much overhead ...*/
     179                var elt = $img[0];
     180                elt.setAttribute("width", imgW+"");
     181                elt.setAttribute("height", imgH+"");
    170182
    171                 $img.closest("li").css( {
    172                         width: liW+"px",
    173                         height: liH+"px"
    174                 });
     183                elt = elt.parentNode;//a
     184                elt.style.left = Math.round((liW-imgW)/2)+"px";
     185                elt.style.top = Math.round((liH-imgH)/2)+"px";
    175186
    176                 $img.parent("a").css( {
    177                         left: Math.round((liW-imgW)/2)+"px",
    178                         top: Math.round((liH-imgH)/2)+"px"
    179                 });
     187                elt = elt.parentNode;//li
     188                elt.style.width = liW+"px";
     189                elt.style.height = liH+"px";
     190
    180191        }
    181192
  • extensions/modus/js/thumb.arrange.min.js

    r26836 r27412  
    11function 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);if(!a.data("w")){var 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:a.data("w"),h:a.data("h")};this.elements.push(d);d.h>this.maxHeight&&(this.maxHeight=d.h);this.width+=this.margin+d.w;this.elementsWidth+=d.w},clear:function(){this.elements.length&&(this.maxHeight=this.width=this.elementsWidth=
    3 0,this.elements.length=0)}};
     2RVGTLine.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+=
     3d.w},clear:function(){this.elements.length&&(this.maxHeight=this.width=this.elementsWidth=0,this.elements.length=0)}};
    44function 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.1,this.opts.resizeFactor=0.8);this.process();var c=this;$(window).on("resize",function(){1<Math.abs(c.$thumbs.width()-
    55c.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()})}}
    66RVGThumbs.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:
    77a.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.attr("width",c).attr("height",d);a.closest("li").css({width:b+"px",height:e+"px"});a.parent("a").css({left:Math.round((b-c)/2)+"px",top:Math.round((e-d)/2)+"px"})}};
     8b;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"}};
  • extensions/modus/themeconf.inc.php

    r27332 r27412  
    6969
    7070        if ( ($pos=strpos($source, '<ul class="categoryActions">'))!==false || ($pos=strpos($source, '<ul class=categoryActions>'))!==false){
    71                 if ( ($pos2=strpos($source, '</ul>', $pos))!==false 
     71                if ( ($pos2=strpos($source, '</ul>', $pos))!==false
    7272                        && (substr_count($source, '<li>', $pos, $pos2-$pos) > 2) )
    7373                        $source = substr_replace($source, '<a id=albumActionsSwitcher class=pwg-button><span class="pwg-icon pwg-icon-ellipsis"></span></a>{combine_script version=1 id=\'modus.async\' path="themes/`$themeconf.id`/js/modus.async.js" load=\'async\'}', $pos, 0);
     
    146146function modus_css_resolution($params)
    147147{
    148   $base = @$params['base'];
    149   $min = @$params['min'];
    150   $max = @$params['max'];
    151  
    152   $rules = array();
    153   if (!empty($base))
    154     $rules[] = $base;
    155   foreach(array('min','max') as $type)
    156   {
    157     if (!empty($$type))
    158       $rules[] = '(-webkit-'.$type.'-device-pixel-ratio:'.$$type.')';
    159   }
    160   $res = implode(' and ', $rules);
    161 
    162   $rules = array();
    163   if (!empty($base))
    164     $rules[] = $base;
    165   foreach(array('min','max') as $type)
    166   {
    167     if (!empty($$type))
    168       $rules[] = '('.$type.'-resolution:'.round(96*$$type,1).'dpi)';
    169   }
    170   $res .= ','.implode(' and ', $rules);
    171 
    172   return $res;
     148        $base = @$params['base'];
     149        $min = @$params['min'];
     150        $max = @$params['max'];
     151
     152        $rules = array();
     153        if (!empty($base))
     154                $rules[] = $base;
     155        foreach(array('min','max') as $type)
     156        {
     157                if (!empty($$type))
     158                        $rules[] = '(-webkit-'.$type.'-device-pixel-ratio:'.$$type.')';
     159        }
     160        $res = implode(' and ', $rules);
     161
     162        $rules = array();
     163        if (!empty($base))
     164                $rules[] = $base;
     165        foreach(array('min','max') as $type)
     166        {
     167                if (!empty($$type))
     168                        $rules[] = '('.$type.'-resolution:'.round(96*$$type,1).'dpi)';
     169        }
     170        $res .= ','.implode(' and ', $rules);
     171
     172        return $res;
    173173}
    174174
     
    184184        $device = get_device();
    185185        $container_margin = 5;
    186        
     186
    187187        if ('mobile'==$device)
    188188        {
     
    224224                }
    225225                while($csize[1]<$row_height-2 && $idx<count($candidates));
    226                
     226
    227227                if ($do_pop && $idx<count($candidates))
    228228                {
     
    254254
    255255        $my_base_name = basename(dirname(__FILE__));
    256   // not async to avoid visible flickering reflow
    257   $template->scriptLoader->add('modus.arange', 1, array('jquery'), 'themes/'.$my_base_name."/js/thumb.arrange.min.js", 0);
     256        // not async to avoid visible flickering reflow
     257        $template->scriptLoader->add('modus.arange', 1, array('jquery'), 'themes/'.$my_base_name."/js/thumb.arrange.min.js", 0);
    258258        if ($do_pop)
    259259                $template->scriptLoader->add('modus.pop', 2, array('jquery'), 'themes/'.$my_base_name."/js/thumb.pop.js", 0);
Note: See TracChangeset for help on using the changeset viewer.