1/*! 2 * masonryHorizontal layout mode for Isotope 3 * v1.1.0 4 * http://isotope.metafizzy.co/layout-modes/masonryhorizontal.html 5 */ 6 7/*jshint browser: true, strict: true, undef: true, unused: true */ 8 9( function( window ) { 10 11'use strict'; 12 13// -------------------------- helpers -------------------------- // 14 15var indexOf = Array.prototype.indexOf ? 16 function( items, value ) { 17 return items.indexOf( value ); 18 } : 19 function ( items, value ) { 20 for ( var i=0, len = items.length; i < len; i++ ) { 21 var item = items[i]; 22 if ( item === value ) { 23 return i; 24 } 25 } 26 return -1; 27 }; 28 29// -------------------------- definition -------------------------- // 30 31function masonryHorizontalDefinition( getSize, LayoutMode ) { 32 // create an Outlayer layout class 33 var MasonryHorizontal = LayoutMode.create('masonryHorizontal'); 34 35 MasonryHorizontal.prototype._resetLayout = function() { 36 this.getRowHeight(); 37 this._getMeasurement( 'gutter', 'outerHeight' ); 38 39 this.rowHeight += this.gutter; 40 // measure rows 41 this.rows = Math.floor( ( this.isotope.size.innerHeight + this.gutter ) / this.rowHeight ); 42 this.rows = Math.max( this.rows, 1 ); 43 44 // reset row Xs 45 var i = this.rows; 46 this.rowXs = []; 47 while (i--) { 48 this.rowXs.push( 0 ); 49 } 50 51 this.maxX = 0; 52 }; 53 54 MasonryHorizontal.prototype._getItemLayoutPosition = function( item ) { 55 item.getSize(); 56 // how many rows does this brick span 57 var rowSpan = Math.ceil( item.size.outerHeight / this.rowHeight ); 58 rowSpan = Math.min( rowSpan, this.rows ); 59 60 var rowGroup = this._getRowGroup( rowSpan ); 61 // get the minimum X value from the rows 62 var minimumX = Math.min.apply( Math, rowGroup ); 63 var shortRowIndex = indexOf( rowGroup, minimumX ); 64 65 // position the brick 66 var position = { 67 x: minimumX, 68 y: this.rowHeight * shortRowIndex 69 }; 70 71 // apply setHeight to necessary rows 72 var setWidth = minimumX + item.size.outerWidth; 73 var setSpan = this.rows + 1 - rowGroup.length; 74 for ( var i = 0; i < setSpan; i++ ) { 75 this.rowXs[ shortRowIndex + i ] = setWidth; 76 } 77 78 return position; 79 }; 80 81 /** 82 * @param {Number} rowSpan - number of rows the element spans 83 * @returns {Array} rowGroup 84 */ 85 MasonryHorizontal.prototype._getRowGroup = function( rowSpan ) { 86 if ( rowSpan < 2 ) { 87 // if brick spans only one row, use all the row Xs 88 return this.rowXs; 89 } 90 91 var rowGroup = []; 92 // how many different places could this brick fit horizontally 93 var groupCount = this.rows + 1 - rowSpan; 94 // for each group potential horizontal position 95 for ( var i = 0; i < groupCount; i++ ) { 96 // make an array of rowX values for that one group 97 var groupRowXs = this.rowXs.slice( i, i + rowSpan ); 98 // and get the max value of the array 99 rowGroup[i] = Math.max.apply( Math, groupRowXs ); 100 } 101 return rowGroup; 102 }; 103 104 MasonryHorizontal.prototype._manageStamp = function( stamp ) { 105 var stampSize = getSize( stamp ); 106 var offset = this.isotope._getElementOffset( stamp ); 107 // get the rows that this stamp affects 108 var firstY = this.isotope.options.isOriginTop ? offset.top : offset.bottom; 109 var lastY = firstY + stampSize.outerHeight; 110 var firstRow = Math.floor( firstY / this.rowHeight ); 111 firstRow = Math.max( 0, firstRow ); 112 var lastRow = Math.floor( lastY / this.rowHeight ); 113 lastRow = Math.min( this.rows - 1, lastRow ); 114 // set rowXs to outside edge of the stamp 115 var stampMaxX = ( this.isotope.options.isOriginLeft ? offset.left : offset.right ) + 116 stampSize.outerWidth; 117 for ( var i = firstRow; i <= lastRow; i++ ) { 118 this.rowXs[i] = Math.max( stampMaxX, this.rowXs[i] ); 119 } 120 }; 121 122 MasonryHorizontal.prototype._getContainerSize = function() { 123 this.maxX = Math.max.apply( Math, this.rowXs ); 124 125 return { 126 width: this.maxX 127 }; 128 }; 129 130 MasonryHorizontal.prototype.needsResizeLayout = function() { 131 return this.needsVerticalResizeLayout(); 132 }; 133 134 return MasonryHorizontal; 135 136} 137 138if ( typeof define === 'function' && define.amd ) { 139 // AMD 140 define( [ 141 'get-size/get-size', 142 'isotope/js/layout-mode' 143 ], 144 masonryHorizontalDefinition ); 145} else if ( typeof exports === 'object' ) { 146 // CommonJS 147 module.exports = masonryHorizontalDefinition( 148 require('get-size'), 149 require('isotope-layout/js/layout-mode') 150 ); 151} else { 152 // browser global 153 masonryHorizontalDefinition( 154 window.getSize, 155 window.Isotope.LayoutMode 156 ); 157} 158 159})( window );
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.