1(function(window, $, undefined){ 2'use strict'; 3var $event=$.event, 4resizeTimeout; 5$event.special.smartresize={ 6setup: function(){ 7$(this).bind("resize", $event.special.smartresize.handler); 8}, 9teardown: function(){ 10$(this).unbind("resize", $event.special.smartresize.handler); 11}, 12handler: function(event, execAsap){ 13var context=this, 14args=arguments; 15event.type="smartresize"; 16if(resizeTimeout){ clearTimeout(resizeTimeout); } 17resizeTimeout=setTimeout(function(){ 18$event.dispatch.apply(context, args); 19}, execAsap==="execAsap"? 0:100); 20}}; 21$.fn.smartresize=function(fn){ 22return fn ? this.bind("smartresize", fn):this.trigger("smartresize", ["execAsap"]); 23}; 24$.Mason=function(options, element){ 25this.element=$(element); 26this._create(options); 27this._init(); 28}; 29$.Mason.settings={ 30isResizable: true, 31isAnimated: false, 32animationOptions: { 33queue: false, 34duration: 500 35}, 36gutterWidth: 0, 37isRTL: false, 38isFitWidth: false, 39containerStyle: { 40position: 'relative' 41}}; 42$.Mason.prototype={ 43_filterFindBricks: function($elems){ 44var selector=this.options.itemSelector; 45return !selector ? $elems:$elems.filter(selector).add($elems.find(selector)); 46}, 47_getBricks: function($elems){ 48var $bricks=this._filterFindBricks($elems); 49return $bricks; 50}, 51_create:function(options){ 52this.options=$.extend(true, {}, $.Mason.settings, options); 53this.styleQueue=[]; 54var elemStyle=this.element[0].style; 55this.originalStyle={ 56height: elemStyle.height||'' 57}; 58var containerStyle=this.options.containerStyle; 59for(var prop in containerStyle){ 60this.originalStyle[ prop ]=elemStyle[ prop ]||''; 61} 62this.element.css(containerStyle); 63this.horizontalDirection=this.options.isRTL ? 'right':'left'; 64var x=this.element.css('padding-' + this.horizontalDirection); 65var y=this.element.css('padding-top'); 66this.offset={ 67x: x ? parseInt(x, 10):0, 68y: y ? parseInt(y, 10):0 69}; 70this.isFluid=this.options.columnWidth&&typeof this.options.columnWidth==='function'; 71var instance=this; 72setTimeout(function(){ 73instance.element.addClass('masonry'); 74}, 0); 75if(this.options.isResizable){ 76$(window).bind('smartresize.masonry', function(){ 77instance.resize(); 78}); 79} 80this.reloadItems(); 81}, 82_init:function(callback){ 83this._getColumns(); 84this._reLayout(callback); 85}, 86option: function(key, value){ 87if($.isPlainObject(key)){ 88this.options=$.extend(true, this.options, key); 89}}, 90layout:function($bricks, callback){ 91for (var i=0, len=$bricks.length; i < len; i++){ 92this._placeBrick($bricks[i]); 93} 94var containerSize={}; 95containerSize.height=Math.max.apply(Math, this.colYs); 96if(this.options.isFitWidth){ 97var unusedCols=0; 98i=this.cols; 99while(--i){ 100if(this.colYs[i]!==0){ 101break; 102} 103unusedCols++; 104} 105containerSize.width=(this.cols - unusedCols) * this.columnWidth - this.options.gutterWidth; 106} 107this.styleQueue.push({ $el: this.element, style: containerSize }); 108var styleFn = !this.isLaidOut ? 'css':( 109this.options.isAnimated ? 'animate':'css' 110), 111animOpts=this.options.animationOptions; 112var obj; 113for (i=0, len=this.styleQueue.length; i < len; i++){ 114obj=this.styleQueue[i]; 115obj.$el[ styleFn ](obj.style, animOpts); 116} 117this.styleQueue=[]; 118if(callback){ 119callback.call($bricks); 120} 121this.isLaidOut=true; 122}, 123_getColumns:function(){ 124var container=this.options.isFitWidth ? this.element.parent():this.element, 125containerWidth=container.width(); 126this.columnWidth=this.isFluid ? this.options.columnWidth(containerWidth) : 127this.options.columnWidth || 128this.$bricks.outerWidth(true) || 129containerWidth; 130this.columnWidth +=this.options.gutterWidth; 131this.cols=Math.floor(( containerWidth + this.options.gutterWidth) / this.columnWidth); 132this.cols=Math.max(this.cols, 1); 133}, 134_placeBrick: function(brick){ 135var $brick=$(brick), 136colSpan, groupCount, groupY, groupColY, j; 137colSpan=Math.ceil($brick.outerWidth(true) / this.columnWidth); 138colSpan=Math.min(colSpan, this.cols); 139if(colSpan===1){ 140groupY=this.colYs; 141}else{ 142groupCount=this.cols + 1 - colSpan; 143groupY=[]; 144for(j=0; j < groupCount; j++){ 145groupColY=this.colYs.slice(j, j+colSpan); 146groupY[j]=Math.max.apply(Math, groupColY); 147}} 148var minimumY=Math.min.apply(Math, groupY), 149shortCol=0; 150for (var i=0, len=groupY.length; i < len; i++){ 151if(groupY[i]===minimumY){ 152shortCol=i; 153break; 154}} 155var position={ 156top: minimumY + this.offset.y 157}; 158position[ this.horizontalDirection ]=this.columnWidth * shortCol + this.offset.x; 159this.styleQueue.push({ $el: $brick, style: position }); 160var setHeight=minimumY + $brick.outerHeight(true), 161setSpan=this.cols + 1 - len; 162for(i=0; i < setSpan; i++){ 163this.colYs[ shortCol + i ]=setHeight; 164}}, 165resize: function(){ 166var prevColCount=this.cols; 167this._getColumns(); 168if(this.isFluid||this.cols!==prevColCount){ 169this._reLayout(); 170}}, 171_reLayout:function(callback){ 172var i=this.cols; 173this.colYs=[]; 174while (i--){ 175this.colYs.push(0); 176} 177this.layout(this.$bricks, callback); 178}, 179reloadItems:function(){ 180this.$bricks=this._getBricks(this.element.children()); 181}, 182reload:function(callback){ 183this.reloadItems(); 184this._init(callback); 185}, 186appended:function($content, isAnimatedFromBottom, callback){ 187if(isAnimatedFromBottom){ 188this._filterFindBricks($content).css({ top: this.element.height() }); 189var instance=this; 190setTimeout(function(){ 191instance._appended($content, callback); 192}, 1); 193}else{ 194this._appended($content, callback); 195}}, 196_appended:function($content, callback){ 197var $newBricks=this._getBricks($content); 198this.$bricks=this.$bricks.add($newBricks); 199this.layout($newBricks, callback); 200}, 201remove:function($content){ 202this.$bricks=this.$bricks.not($content); 203$content.remove(); 204}, 205destroy:function(){ 206this.$bricks 207.removeClass('masonry-brick') 208.each(function(){ 209this.style.position=''; 210this.style.top=''; 211this.style.left=''; 212}); 213var elemStyle=this.element[0].style; 214for(var prop in this.originalStyle){ 215elemStyle[ prop ]=this.originalStyle[ prop ]; 216} 217this.element 218.unbind('.masonry') 219.removeClass('masonry') 220.removeData('masonry'); 221$(window).unbind('.masonry'); 222}}; 223$.fn.imagesLoaded=function(callback){ 224var $this=this, 225$images=$this.find('img').add($this.filter('img')), 226len=$images.length, 227blank='data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==', 228loaded=[]; 229function triggerCallback(){ 230callback.call($this, $images); 231} 232function imgLoaded(event){ 233var img=event.target; 234if(img.src!==blank&&$.inArray(img, loaded)===-1){ 235loaded.push(img); 236if(--len <=0){ 237setTimeout(triggerCallback); 238$images.unbind('.imagesLoaded', imgLoaded); 239}} 240} 241if(!len){ 242triggerCallback(); 243} 244$images.bind('load.imagesLoaded error.imagesLoaded', imgLoaded).each(function(){ 245var src=this.src; 246this.src=blank; 247this.src=src; 248}); 249return $this; 250}; 251var logError=function(message){ 252if(window.console){ 253window.console.error(message); 254}}; 255$.fn.masonry=function(options){ 256if(typeof options==='string'){ 257var args=Array.prototype.slice.call(arguments, 1); 258this.each(function(){ 259var instance=$.data(this, 'masonry'); 260if(!instance){ 261logError("cannot call methods on masonry prior to initialization; " + 262"attempted to call method '" + options + "'"); 263return; 264} 265if(!$.isFunction(instance[options])||options.charAt(0)==="_"){ 266logError("no such method '" + options + "' for masonry instance"); 267return; 268} 269instance[ options ].apply(instance, args); 270}); 271}else{ 272this.each(function(){ 273var instance=$.data(this, 'masonry'); 274if(instance){ 275instance.option(options||{}); 276instance._init(); 277}else{ 278$.data(this, 'masonry', new $.Mason(options, this)); 279}}); 280} 281return this; 282};})(window, jQuery);
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.