1/* 2 * Isotope custom layout mode that extends masonry in order to work with percentage-sized columns 3 */ 4 5(function(window, $) { 6 $.extend($.Isotope.prototype, { 7 _sloppyMasonryReset : function() { 8 // layout-specific props 9 var containerSize = this.element.width(), 10 segmentSize = this.options.sloppyMasonry && this.options.sloppyMasonry.columnWidth || 11 // or use the size of the first item, i.e. outerWidth 12 this.$filteredAtoms.outerWidth(true) || 13 // if there's no items, use size of container 14 containerSize; 15 this.sloppyMasonry = { 16 cols : Math.round(containerSize / segmentSize), 17 columnWidth : segmentSize 18 }; 19 var i = this.sloppyMasonry.cols; 20 this.sloppyMasonry.colYs = []; 21 while (i--) { 22 this.sloppyMasonry.colYs.push(0); 23 } 24 }, 25 _sloppyMasonryLayout : function($elems) { 26 var instance = this, props = instance.sloppyMasonry; 27 $elems.each(function() { 28 var $this = $(this), 29 // how many columns does this brick span 30 colSpan = Math.round($this.outerWidth(true) / props.columnWidth); 31 colSpan = Math.min(colSpan, props.cols); 32 if (colSpan === 1) { 33 // if brick spans only one column, 34 // just like singleMode 35 instance._sloppyMasonryPlaceBrick($this, props.colYs); 36 } else { 37 // brick spans more than one column 38 // how many different places could 39 // this brick fit horizontally 40 var groupCount = props.cols + 1 - colSpan, groupY = [], groupColY, i; 41 42 // for each group potential 43 // horizontal position 44 for (i = 0; i < groupCount; i++) { 45 // make an array of colY values 46 // for that one group 47 groupColY = props.colYs.slice(i, i + colSpan); 48 // and get the max value of the 49 // array 50 groupY[i] = Math.max.apply(Math, groupColY); 51 } 52 53 instance._sloppyMasonryPlaceBrick($this, groupY); 54 } 55 }); 56 }, 57 _sloppyMasonryPlaceBrick : function($brick, setY) { 58 // get the minimum Y value from the columns 59 var minimumY = Math.min.apply(Math, setY), shortCol = 0; 60 61 // Find index of short column, the first from the left 62 for ( var i = 0, len = setY.length; i < len; i++) { 63 if (setY[i] === minimumY) { 64 shortCol = i; 65 break; 66 } 67 } 68 69 // position the brick 70 var x = this.sloppyMasonry.columnWidth * shortCol, y = minimumY; 71 this._pushPosition($brick, x, y); 72 73 // apply setHeight to necessary columns 74 var setHeight = minimumY + $brick.outerHeight(true), setSpan = this.sloppyMasonry.cols + 1 - len; 75 for (i = 0; i < setSpan; i++) { 76 this.sloppyMasonry.colYs[shortCol + i] = setHeight; 77 } 78 79 }, 80 _sloppyMasonryGetContainerSize : function() { 81 var containerHeight = Math.max.apply(Math, this.sloppyMasonry.colYs); 82 return { 83 height : containerHeight 84 }; 85 }, 86 _sloppyMasonryResizeChanged : function() { 87 return true; 88 } 89 }); 90})(this, this.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.