Changeset 12710


Ignore:
Timestamp:
12/09/11 14:24:32 (8 years ago)
Author:
patdenice
Message:

Clean code

Location:
extensions/GThumb
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/GThumb/js/gthumb.js

    r12705 r12710  
    11var GThumb = { 
    22 
    3   selector: null, 
    43  max_height: 200, 
    54  margin: 10, 
     
    1716  }), 
    1817 
    19   build: function (selector) { 
    20  
    21     this.t = new Array; 
    22     this.selector = selector; 
    23     jQuery(selector+' img.thumbnail').each(function() { 
     18  build: function () { 
     19 
     20    GThumb.t = new Array; 
     21    jQuery('#thumbnails img.thumbnail').each(function() { 
    2422      id = parseInt(this.id.substring(2)); 
    2523      width = parseInt(jQuery(this).attr('width')); 
     
    3937    jQuery.resize.throttleWindow = false; 
    4038    jQuery.resize.delay = 50; 
    41     jQuery(selector).resize(function() { GThumb.process(); }); 
    42     this.process(); 
     39    GThumb.process(); 
    4340  }, 
    4441 
    4542  addToQueue: function (id, loop) { 
    4643 
    47     this.queue.add({ 
     44    GThumb.queue.add({ 
    4845      type: 'GET',  
    4946      url: 'ws.php',  
     
    6966  process: function() { 
    7067 
    71     var width_count = this.margin; 
     68    var width_count = GThumb.margin; 
    7269    var line = 1; 
    7370    var round_rest = 0; 
    74     var main_width = jQuery(this.selector).width(); 
    75     var first_thumb = jQuery(this.selector+' img:first'); 
     71    var main_width = jQuery('#thumbnails').width(); 
     72    var first_thumb = jQuery('#thumbnails img:first'); 
    7673    var best_size = {width:1,height:1}; 
    7774 
    78     if (this.big_thumb != null && this.big_thumb.height < main_width * this.max_first_thumb_width) { 
     75    if (GThumb.big_thumb != null && GThumb.big_thumb.height < main_width * GThumb.max_first_thumb_width) { 
    7976 
    8077      // Compute best size for landscape picture (we choose bigger height) 
    81       min_ratio = Math.min(1.05, this.big_thumb.width/this.big_thumb.height); 
    82  
    83       for(width = this.big_thumb.width; width/best_size.height>=min_ratio; width--) { 
    84         width_count = this.margin; 
    85         height = this.margin; 
     78      min_ratio = Math.min(1.05, GThumb.big_thumb.width/GThumb.big_thumb.height); 
     79 
     80      for(width = GThumb.big_thumb.width; width/best_size.height>=min_ratio; width--) { 
     81        width_count = GThumb.margin; 
     82        height = GThumb.margin; 
    8683        max_height = 0; 
    87         available_width = main_width - (width + this.margin); 
     84        available_width = main_width - (width + GThumb.margin); 
    8885        line = 1; 
    89         for (i=1;i<this.t.length;i++) { 
    90  
    91           width_count += this.t[i].width + this.margin; 
    92           max_height = Math.max(this.t[i].height, max_height); 
     86        for (i=1;i<GThumb.t.length;i++) { 
     87 
     88          width_count += GThumb.t[i].width + GThumb.margin; 
     89          max_height = Math.max(GThumb.t[i].height, max_height); 
    9390 
    9491          if (width_count > available_width) { 
     
    9794            line++; 
    9895            max_height = 0; 
    99             width_count = this.margin; 
     96            width_count = GThumb.margin; 
    10097            if (line > 2) { 
    101               if (height >= best_size.height && width/height >= min_ratio && height<=this.big_thumb.height) { 
     98              if (height >= best_size.height && width/height >= min_ratio && height<=GThumb.big_thumb.height) { 
    10299                best_size = {width:width,height:height} 
    103100              } 
     
    108105        if (line <= 2) { 
    109106          if (max_height == 0 || line == 1) { 
    110             height = this.big_thumb.height; 
     107            height = GThumb.big_thumb.height; 
    111108          } else { 
    112109            height += max_height; 
    113110          } 
    114           if (height >= best_size.height && width/height >= min_ratio && height<=this.big_thumb.height) { 
     111          if (height >= best_size.height && width/height >= min_ratio && height<=GThumb.big_thumb.height) { 
    115112            best_size = {width:width,height:height} 
    116113          } 
     
    118115      } 
    119116 
    120       if (this.big_thumb.src != first_thumb.attr('src')) { 
    121         first_thumb.attr('src', this.big_thumb.src).attr({width:this.big_thumb.width,height:this.big_thumb.height}); 
    122         this.t[0].width = this.big_thumb.width; 
    123         this.t[0].height = this.big_thumb.height; 
    124       } 
    125       this.t[0].crop = best_size.width; 
    126       this.resize(first_thumb, this.big_thumb.width, this.big_thumb.height, best_size.width, best_size.height, true); 
     117      if (GThumb.big_thumb.src != first_thumb.attr('src')) { 
     118        first_thumb.attr('src', GThumb.big_thumb.src).attr({width:GThumb.big_thumb.width,height:GThumb.big_thumb.height}); 
     119        GThumb.t[0].width = GThumb.big_thumb.width; 
     120        GThumb.t[0].height = GThumb.big_thumb.height; 
     121      } 
     122      GThumb.t[0].crop = best_size.width; 
     123      GThumb.resize(first_thumb, GThumb.big_thumb.width, GThumb.big_thumb.height, best_size.width, best_size.height, true); 
    127124 
    128125    } 
    129126 
    130127    if (best_size.width == 1) { 
    131       if (this.small_thumb != null && this.small_thumb.src != first_thumb.attr('src')) {   
    132         first_thumb.prop('src', this.small_thumb.src).attr({width:this.small_thumb.width,height:this.small_thumb.height}); 
    133         this.t[0].width = this.small_thumb.width; 
    134         this.t[0].height = this.small_thumb.height; 
    135       } 
    136       this.t[0].crop = false; 
    137     } 
    138  
    139     width_count = this.margin; 
     128      if (GThumb.small_thumb != null && GThumb.small_thumb.src != first_thumb.attr('src')) {   
     129        first_thumb.prop('src', GThumb.small_thumb.src).attr({width:GThumb.small_thumb.width,height:GThumb.small_thumb.height}); 
     130        GThumb.t[0].width = GThumb.small_thumb.width; 
     131        GThumb.t[0].height = GThumb.small_thumb.height; 
     132      } 
     133      GThumb.t[0].crop = false; 
     134    } 
     135 
     136    width_count = GThumb.margin; 
    140137    max_height = 0; 
    141138    line = 1; 
    142139    thumb_process = new Array; 
    143140 
    144     for (i=this.t[0].crop!=false?1:0;i<this.t.length;i++) { 
    145  
    146       width_count += this.t[i].width + this.margin; 
    147       max_height = Math.max(this.t[i].height, max_height); 
    148       thumb_process.push(this.t[i]); 
     141    for (i=GThumb.t[0].crop!=false?1:0;i<GThumb.t.length;i++) { 
     142 
     143      width_count += GThumb.t[i].width + GThumb.margin; 
     144      max_height = Math.max(GThumb.t[i].height, max_height); 
     145      thumb_process.push(GThumb.t[i]); 
    149146 
    150147      available_width = main_width; 
    151       if (line <= 2 && this.t[0].crop !== false) { 
    152         available_width -= (this.t[0].crop + this.margin); 
     148      if (line <= 2 && GThumb.t[0].crop !== false) { 
     149        available_width -= (GThumb.t[0].crop + GThumb.margin); 
    153150      } 
    154151 
    155152      if (width_count > available_width) { 
    156153 
    157         last_thumb = this.t[i].id; 
     154        last_thumb = GThumb.t[i].id; 
    158155        ratio = width_count / available_width; 
    159156        new_height = Math.round(max_height / ratio); 
    160157        round_rest = 0; 
    161         width_count = this.margin; 
     158        width_count = GThumb.margin; 
    162159 
    163160        for (j=0;j<thumb_process.length;j++) { 
    164161 
    165162          if (thumb_process[j].id == last_thumb) { 
    166             new_width = available_width - width_count - this.margin; 
     163            new_width = available_width - width_count - GThumb.margin; 
    167164          } else { 
    168165            new_width = (thumb_process[j].width + round_rest) / ratio; 
     
    170167            new_width = Math.round(new_width); 
    171168          } 
    172           this.resize(jQuery('#gt'+thumb_process[j].id), thumb_process[j].real_width, thumb_process[j].real_height, new_width, new_height, false); 
    173  
    174           width_count += new_width + this.margin; 
     169          GThumb.resize(jQuery('#gt'+thumb_process[j].id), thumb_process[j].real_width, thumb_process[j].real_height, new_width, new_height, false); 
     170 
     171          width_count += new_width + GThumb.margin; 
    175172        } 
    176173        thumb_process = new Array; 
    177         width_count = this.margin; 
     174        width_count = GThumb.margin; 
    178175        max_height = 0; 
    179176        line++; 
     
    183180    // Last line does not need to be cropped 
    184181    for (j=0;j<thumb_process.length;j++) { 
    185       this.resize(jQuery('#gt'+thumb_process[j].id), thumb_process[j].real_width, thumb_process[j].real_height, thumb_process[j].width, max_height, false); 
    186     } 
    187  
    188     if (main_width != jQuery(this.selector).width()) { 
    189       this.process(); 
     182      GThumb.resize(jQuery('#gt'+thumb_process[j].id), thumb_process[j].real_width, thumb_process[j].real_height, thumb_process[j].width, max_height, false); 
     183    } 
     184 
     185    if (main_width != jQuery('#thumbnails').width()) { 
     186      GThumb.process(); 
    190187    } 
    191188  }, 
     
    193190  resize: function(thumb, width, height, new_width, new_height, is_big) { 
    194191 
    195     if (this.method == 'resize' || height < new_height || width < new_width) { 
     192    if (GThumb.method == 'resize' || height < new_height || width < new_width) { 
    196193      real_width = new_width; 
    197194      real_height = new_height; 
  • extensions/GThumb/main.inc.php

    r12705 r12710  
    128128  global $conf; 
    129129 
    130   if (empty($picture['width'])) 
     130  if (!in_array(get_extension($picture['file']), $conf['picture_ext'])) 
    131131  { 
    132132    $file = get_thumbnail_url($picture); 
  • extensions/GThumb/template/gthumb.css

    r12691 r12710  
    11#thumbnails { 
    2   padding: 0; 
    3   width:auto; 
    4   overflow:hidden; 
     2  overflow: hidden; 
    53} 
    64 
    75#thumbnails li { 
    86  position: relative; 
    9   overflow:hidden; 
     7  overflow: hidden; 
    108  float: left; 
    119  display: inline; 
     
    1816 
    1917.thumbnail, .thumbnail:hover { 
    20   border: 0 none; 
     18  border: 0 none !important; 
     19  margin: 0 !important; 
     20  padding: 0 !important; 
    2121} 
  • extensions/GThumb/template/gthumb.tpl

    r12705 r12710  
    1010 
    1111{combine_css path="plugins/GThumb/template/gthumb.css"} 
    12 {combine_script id='jquery.ajaxmanager' path='themes/default/js/plugins/jquery.ajaxmanager.js'} 
    13 {combine_script id='jquery.ba-resize' path='plugins/GThumb/js/jquery.ba-resize.min.js'} 
    14 {combine_script id='gthumb' require='jquery,jquery.ajaxmanager,jquery.ba-resize' path='plugins/GThumb/js/gthumb.js'} 
     12{combine_script id='jquery.ajaxmanager' path='themes/default/js/plugins/jquery.ajaxmanager.js' load="footer"} 
     13{combine_script id='jquery.ba-resize' path='plugins/GThumb/js/jquery.ba-resize.min.js' load="footer"} 
     14{combine_script id='gthumb' require='jquery,jquery.ajaxmanager,jquery.ba-resize' path='plugins/GThumb/js/gthumb.js' load="footer"} 
    1515 
    1616{footer_script require="gthumb"} 
     
    2424{/if} 
    2525 
    26 GThumb.build('#thumbnails'); 
    27 $(window).bind('RVTS_loaded', function() {ldelim} GThumb.build('#thumbnails'); }); 
     26GThumb.build(); 
     27jQuery(window).bind('RVTS_loaded', GThumb.build); 
     28jQuery('#thumbnails').resize(GThumb.process); 
    2829{/footer_script} 
    2930 
Note: See TracChangeset for help on using the changeset viewer.