1// masonry 2var masonryLastResize; 3 4var masonryElement = { 5 init : function(passed_opts) { 6 7 var opts = { 8 'masonry_container' : '#masonry', 9 'masonry_item' : '.m_item', 10 'masonry_image' : '.m_item_image', 11 'overlay_text' : '.m_txt', 12 'masonry_layout' : 'fluid', 13 'asset_layout' : 'normal', 14 'asset_width' : 0, 15 'asset_height' : 1, 16 'gutter_width' : 10, 17 'col_widths' : [500, 800, 1200, 1500, 2100], 18 'col_num' : '', 19 'min_cols' : 0, 20 'max_cols' : 100, 21 'force_complete_rows' : false 22 }; 23 24 $.extend(opts, passed_opts); 25 26 var container = $(opts.masonry_container); 27 opts.item_list = container.find(opts.masonry_item); 28 29 // save the options as data on the container 30 $(opts.masonry_container).data('masonry-config', opts); 31 32 $(opts.masonry_container).addClass('masonryElement').addClass('masonry_'+opts.masonry_layout).addClass('assets_'+opts.asset_layout); 33 34 // masonry 35 if (opts.item_list.length) { 36 container.css({'opacity':'0.0'}); 37 38 masonryElement.prepareSettings(container, opts, passed_opts); 39 masonryElement.prepareItems(container, opts); 40 41 container.imagesLoaded(function(){ 42 masonryElement.layout(container, opts); 43 container.animate({'opacity':'1.0'}, 500); 44 }); 45 46 masonryElement.layout(container, opts); 47 48 if (mcConf.masonryPreload) { 49 container.animate({'opacity':'1.0'}, 500); 50 } 51 } else { 52 container.animate({'opacity':'1.0'}, 500); 53 } 54 55 // trigger resize if scrollbar appears 56 $(window).one('scroll', function() { 57 $(window).trigger('resize'); 58 }); 59 $(mcConf.scrollingElement).one('scroll', function() { 60 $(window).trigger('resize'); 61 }); 62 63 // highlighting the asset on touch devices 64 container.on({ 65 mouseenter: function (){ 66 $(mcConf.masonryItem).removeClass('hover'); 67 $(this).addClass('hover'); 68 },mouseleave: function(){ 69 $(this).removeClass('hover'); 70 } 71 }, opts.masonry_item); 72 }, 73 74 update : function(passed_opts) { 75 var container = $(passed_opts.masonry_container); 76 var opts = container.data('masonry-config'); 77 $.extend(opts, passed_opts); 78 79 masonryElement.prepareSettings(container, opts, passed_opts); 80 masonryElement.prepareItems(container, opts); 81 masonryElement.layout(container, opts); 82 83 $(opts.masonry_container).data('masonry-config', opts); 84 }, 85 86 prepareSettings(container, opts, passed_opts) { 87 if (!passed_opts.col_widths && (opts.masonry_layout == 'fluid' || opts.masonry_layout == 'inline_fluid')) { 88 masonryElement.setColWidths(container, opts); 89 } 90 }, 91 92 // one time sizing and loading of any new items 93 prepareItems(container, opts) { 94 opts.item_list.css('margin-bottom', opts.gutter_width); 95 96 if (opts.masonry_layout == 'fixed') { 97 // a fixed masonry only needs to be sized one time 98 opts.item_list.find(opts.masonry_image).width(opts.asset_width); 99 } else if (opts.masonry_layout == 'inline_fluid') { 100 // an inline fluid masonry is used for drag and drop that sizes to fill the area, but doesn't use isotope for the layout 101 opts.item_list.css({'margin-left': opts.gutter_width/2,'margin-right': opts.gutter_width/2}); 102 } 103 104 if (opts.masonry_layout == 'fixed') { 105 masonryElement.assetLayout(container, opts); 106 } 107 108 if(mcConf.masonryPreload) { 109 preloadAllElementImages(container, mcConf.masonryImagePrefix); 110 } 111 }, 112 113 appendedItems(container) { 114 container = $(container); 115 var opts = container.data('masonry-config'); 116 var new_items = container.find(opts.masonry_item+':not(.isotope-item)'); 117 opts.item_list = container.find(opts.masonry_item); 118 masonryElement.prepareItems(container, opts); 119 if (opts.masonry_layout != 'inline_fluid') { 120 container.isotope('appended', new_items); 121 } 122 masonryElement.layout(container, opts); 123 container.data('masonry-config', opts); 124 }, 125 126 setColWidths : function(container, opts) { 127 // create an array of the column sizes based on the average column size 128 if (!!opts.asset_width) { 129 if (opts.force_complete_rows) { 130 var colSplit = 0; 131 opts.col_widths = []; 132 // possible column counts for the number of items 133 for (i=1; i <= opts.item_list.length; i++) { 134 if (opts.item_list.length%i == 0) { 135 opts.col_widths.push([i, 5000]); 136 } 137 } 138 // find the best size at which to change between two different c
138olumn counts 139 var g = opts.gutter_width; 140 var w = opts.asset_width; // the ideal column width 141 for (i=0; colSplit < 2570; i++) { 142 if (opts.col_widths.length >= i+2) { 143 var x = opts.col_widths[i][0]; // the current column count 144 var y = opts.col_widths[i+1][0]; // the next largest column count 145 colSplit = Math.round((2*w*x+g*x*(y-1)/y+g*(x-1))/(1+x/y)); 146 opts.col_widths[i][1] = colSplit; 147 } else { 148 break; 149 } 150 } 151 } else { 152 var colSize = 0; 153 opts.col_widths = []; 154 for (i=1; colSize < 2570; i++) { 155 colSize = Math.round(opts.asset_width*(i+(i/(2*i+1))))+opts.gutter_width*i; 156 opts.col_widths.push(colSize); 157 } 158 } 159 } 160 }, 161 162 // layout isotope 163 isotope : function(container, opts) { 164 165 $(container, opts).isotope({ 166 itemSelector: opts.masonry_item, 167 animationEngine: 'css', 168 masonry: { 169 columnWidth: opts.current_col_width, 170 gutterWidth: opts.gutter_width, // isotope v1.5 171 gutter: opts.gutter_width // isotope v3 172 }, 173 transformsEnabled: !mcConf.mobile 174 }); 175 }, 176 177 // a masonry sizing function that can be used for various pages 178 sizing : function(container, opts) { 179 var colNum = opts.col_num; 180 var containerTotal = container.width() - 1; 181 if (!colNum) { 182 colNum = 1; // default for the smallest size 183 184 if (opts.force_complete_rows) { 185 // determine the proper number of columns 186 for (var i=0; i < opts.col_widths.length; i++) { 187 if (containerTotal < opts.col_widths[i][1]) { 188 colNum = opts.col_widths[i][0]; 189 break; 190 } 191 } 192 if (colNum > opts.max_cols) { 193 for (var i=0; i < opts.col_widths.length; i++) { 194 if (opts.col_widths.length[i][0] > opts.max_cols) { 195 colNum = opts.col_widths.length[i-1][0]; 196 break; 197 } 198 } 199 } else if (colNum < opts.min_cols) { 200 for (var i=opts.col_widths.length-1; i >= 0; i--) { 201 if (opts.col_widths.length[i][0] < opts.min_cols) { 202 colNum = opts.col_widths.length[i+1][0]; 203 break; 204 } 205 } 206 } 207 } else { 208 for (var i=opts.col_widths.length - 1; i >= 0; i--) { 209 if (containerTotal > opts.col_widths[i]) { 210 colNum = i+2; 211 break; 212 } 213 } 214 if (colNum > opts.max_cols) { 215 colNum = opts.max_cols; 216 } else if (colNum < opts.min_cols) { 217 colNum = opts.min_cols; 218 } 219 } 220 } 221 var gutterTotal = opts.gutter_width*(colNum-1); 222 if (opts.masonry_layout == 'inline_fluid') { 223 gutterTotal = opts.gutter_width*colNum; // an additional gutter compared to using isotope 224 } 225 var columnWidth = Math.floor((containerTotal - gutterTotal)/colNum); 226 opts.item_list.width(columnWidth); 227 if(colNum > 1) { 228 opts.item_list.filter('.doublewidth').width(2*columnWidth + opts.gutter_width); 229 } 230 opts.current_col_width = columnWidth; 231 opts.current_col_number = colNum; 232 container.trigger('masonry_multiple_sizing'); 233 $(container).data('masonry-cols', colNum); 234 $(container).data('masonry-col-width', columnWidth); 235 236 }, 237 238 layout : function(container, opts) { 239 if (opts.masonry_layout == 'fluid' || opts.masonry_layout == 'inline_fluid') { 240 masonryElement.sizing(container, opts); 241 masonryElement.assetLayout(container, opts); 242 } 243 if (opts.masonry_layout != 'inline_fluid') { 244 if(mcConf.masonryPreload && opts.asset_layout == 'normal'){ masonryElement.setItemHeight(container, opts); } 245 masonryElement.isotope(container, opts); 246 //if(mcConf.masonryPreload && opts.asset_layout == 'normal'){ masonryElement.clearItemHeight(container, opts); } 247 } 248 container.trigger('masonry_multiple_layout'); 249 }, 250 251 assetLayout : function(container, opts) { 252 var c_ratio = opts.asset_width/opts.asset_height; 253 var c_width, 254 double_width; 255 if (opts.masonry_layout == 'fixed') { 256 c_width = opts.asset_width; 257 } else { 258 c_width = opts.current_col_width; 259 } 260 double_width = c_width*2 + opts.gutter_width; 261 if (opts.asset_layout == 'cropped' || opts.asset_layout == 'fit') { 262 opts.item_list.find(opts.masonry_image).width(c_width).height(Math.floor(c_width/c_ratio)); 263 if ($(opts.overlay_text).length) { 264 opts.item_list.find(opts.overlay_text).width(c_width).height(Math.floor(c_width/c_ratio)); 265 } 266 if(opts.current_col_number > 1) { 267 opts.item_list.filter('.doublewidth').find(opts.masonry_image).width(double_width); 268 if ($(opts.overlay_text).length) { 269 opts.item_list.filter('.doublewidth').find(opts.overlay_text).width(double_width); 270 } 271 } 272 } 273 if (opts.asset_layout == 'cropped') { 274 cropImages(opts.item_list.find(opts.masonry_image)); 275 } else if (opts.asset_layout == 'fit') { 276 opts.item_list.find(opts.masonry_image).find('img').css({maxWidth: c_width, maxHeight: c_width/c_ratio}); 277 if(opts.current_col_number > 1) { 278 opts.item_list.filter('.doublewidth').find(opts.masonry_image).find('img').css({maxWidth: double_width}); 279 } 280 } 281 container.trigger('masonry_multiple_assets_layout'); 282 }, 283 284 setItemHeight : function(container, opts) { 285 opts.item_list.each(function(){ 286 $('img, video', this).each( function() { 287 var img = $(this); 288 if(img.attr('data-width') && img.attr('data-height')) { 289 var iHeight = Math.floor(img.width() * img.attr('data-height') / img.attr('data-width')); 290 } 291 if(img.attr('imgW') && img.attr('imgH')) { 292 var iHeight = Math.floor(img.width() * img.attr('imgH') / img.attr('imgW')) 293 } 294 img.height(iHeight); 295 if ($(this).parents(opts.masonry_item).find(opts.overlay_text).length) { 296 $(this).parents(opts.masonry_item).find(opts.overlay_text).height(iHeight).width(img.width()); 297 } 298 }); 299 }); 300 }, 301 302 clearItemHeight : function(container, opts) { 303 opts.item_list.each(function(){ 304 $('img, video', this).each( function() { 305 var img = $(this); 306 if(img.attr('data-width') && img.attr('data-height')) { 307 img.css("height", ""); 308 } 309 if(img.attr('imgW') && img.attr('imgH')) { 310 img.css("height", ""); 311 } 312 }); 313 }); 314 } 315} 316 317$(document).bind('core.imagePreloaded', function(e, image_selector) { 318 var img = $(image_selector); 319 if(img.attr('data-width') && img.attr('data-height')) { 320 img.css("height", ""); 321 } 322 if(img.attr('imgW') && img.attr('imgH')) { 323 img.css("height", ""); 324 } 325}); 326 327function masonryMultipleResizeAll() { 328 $(document).trigger('masonry_multiple_before_resize'); 329 $('.masonryElement').each( function() { 330 if ($(this).data('masonry-config')) { 331 masonryElement.layout($(this), $(this).data('masonry-config')); 332 } 333 }); 334} 335 336$(document).ready( function() { 337 $(window).bind('resize',function() { 338 masonryMultipleResizeAll(); 339 clearTimeout(masonryLastResize); 340 masonryLastResize = setTimeout(function() { 341 masonryMultipleResizeAll(); 342 }, 50); 343 }) 344});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.