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