Changeset 12710
- Timestamp:
- Dec 9, 2011, 2:24:32 PM (12 years ago)
- Location:
- extensions/GThumb
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/GThumb/js/gthumb.js
r12705 r12710 1 1 var GThumb = { 2 2 3 selector: null,4 3 max_height: 200, 5 4 margin: 10, … … 17 16 }), 18 17 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() { 24 22 id = parseInt(this.id.substring(2)); 25 23 width = parseInt(jQuery(this).attr('width')); … … 39 37 jQuery.resize.throttleWindow = false; 40 38 jQuery.resize.delay = 50; 41 jQuery(selector).resize(function() { GThumb.process(); }); 42 this.process(); 39 GThumb.process(); 43 40 }, 44 41 45 42 addToQueue: function (id, loop) { 46 43 47 this.queue.add({44 GThumb.queue.add({ 48 45 type: 'GET', 49 46 url: 'ws.php', … … 69 66 process: function() { 70 67 71 var width_count = this.margin;68 var width_count = GThumb.margin; 72 69 var line = 1; 73 70 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'); 76 73 var best_size = {width:1,height:1}; 77 74 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) { 79 76 80 77 // 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; 86 83 max_height = 0; 87 available_width = main_width - (width + this.margin);84 available_width = main_width - (width + GThumb.margin); 88 85 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); 93 90 94 91 if (width_count > available_width) { … … 97 94 line++; 98 95 max_height = 0; 99 width_count = this.margin;96 width_count = GThumb.margin; 100 97 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) { 102 99 best_size = {width:width,height:height} 103 100 } … … 108 105 if (line <= 2) { 109 106 if (max_height == 0 || line == 1) { 110 height = this.big_thumb.height;107 height = GThumb.big_thumb.height; 111 108 } else { 112 109 height += max_height; 113 110 } 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) { 115 112 best_size = {width:width,height:height} 116 113 } … … 118 115 } 119 116 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); 127 124 128 125 } 129 126 130 127 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; 140 137 max_height = 0; 141 138 line = 1; 142 139 thumb_process = new Array; 143 140 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]); 149 146 150 147 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); 153 150 } 154 151 155 152 if (width_count > available_width) { 156 153 157 last_thumb = this.t[i].id;154 last_thumb = GThumb.t[i].id; 158 155 ratio = width_count / available_width; 159 156 new_height = Math.round(max_height / ratio); 160 157 round_rest = 0; 161 width_count = this.margin;158 width_count = GThumb.margin; 162 159 163 160 for (j=0;j<thumb_process.length;j++) { 164 161 165 162 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; 167 164 } else { 168 165 new_width = (thumb_process[j].width + round_rest) / ratio; … … 170 167 new_width = Math.round(new_width); 171 168 } 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; 175 172 } 176 173 thumb_process = new Array; 177 width_count = this.margin;174 width_count = GThumb.margin; 178 175 max_height = 0; 179 176 line++; … … 183 180 // Last line does not need to be cropped 184 181 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(); 190 187 } 191 188 }, … … 193 190 resize: function(thumb, width, height, new_width, new_height, is_big) { 194 191 195 if ( this.method == 'resize' || height < new_height || width < new_width) {192 if (GThumb.method == 'resize' || height < new_height || width < new_width) { 196 193 real_width = new_width; 197 194 real_height = new_height; -
extensions/GThumb/main.inc.php
r12705 r12710 128 128 global $conf; 129 129 130 if ( empty($picture['width']))130 if (!in_array(get_extension($picture['file']), $conf['picture_ext'])) 131 131 { 132 132 $file = get_thumbnail_url($picture); -
extensions/GThumb/template/gthumb.css
r12691 r12710 1 1 #thumbnails { 2 padding: 0; 3 width:auto; 4 overflow:hidden; 2 overflow: hidden; 5 3 } 6 4 7 5 #thumbnails li { 8 6 position: relative; 9 overflow: hidden;7 overflow: hidden; 10 8 float: left; 11 9 display: inline; … … 18 16 19 17 .thumbnail, .thumbnail:hover { 20 border: 0 none; 18 border: 0 none !important; 19 margin: 0 !important; 20 padding: 0 !important; 21 21 } -
extensions/GThumb/template/gthumb.tpl
r12705 r12710 10 10 11 11 {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"} 15 15 16 16 {footer_script require="gthumb"} … … 24 24 {/if} 25 25 26 GThumb.build('#thumbnails'); 27 $(window).bind('RVTS_loaded', function() {ldelim} GThumb.build('#thumbnails'); }); 26 GThumb.build(); 27 jQuery(window).bind('RVTS_loaded', GThumb.build); 28 jQuery('#thumbnails').resize(GThumb.process); 28 29 {/footer_script} 29 30
Note: See TracChangeset
for help on using the changeset viewer.