mirror of https://github.com/metafizzy/isotope
11 changed files with 21 additions and 387 deletions
@ -1,61 +0,0 @@
|
||||
( function( window ) { |
||||
|
||||
'use strict'; |
||||
|
||||
function cellsByColumnDefinition( LayoutMode ) { |
||||
|
||||
var CellsByColumn = LayoutMode.create( 'cellsByColumn' ); |
||||
|
||||
CellsByColumn.prototype._resetLayout = function() { |
||||
// reset properties
|
||||
this.itemIndex = 0; |
||||
// measurements
|
||||
this.getColumnWidth(); |
||||
this.getRowHeight(); |
||||
// set rows
|
||||
this.rows = Math.floor( this.isotope.size.innerHeight / this.rowHeight ); |
||||
this.rows = Math.max( this.rows, 1 ); |
||||
}; |
||||
|
||||
CellsByColumn.prototype._getItemLayoutPosition = function( item ) { |
||||
item.getSize(); |
||||
var col = Math.floor( this.itemIndex / this.rows ); |
||||
var row = this.itemIndex % this.rows; |
||||
// center item within cell
|
||||
var x = ( col + 0.5 ) * this.columnWidth - item.size.outerWidth / 2; |
||||
var y = ( row + 0.5 ) * this.rowHeight - item.size.outerHeight / 2; |
||||
this.itemIndex++; |
||||
return { x: x, y: y }; |
||||
}; |
||||
|
||||
CellsByColumn.prototype._getContainerSize = function() { |
||||
return { |
||||
width: Math.ceil( this.itemIndex / this.rows ) * this.columnWidth |
||||
}; |
||||
}; |
||||
|
||||
CellsByColumn.prototype.resize = function() { |
||||
this.resizeVertical(); |
||||
}; |
||||
|
||||
return CellsByColumn; |
||||
|
||||
} |
||||
|
||||
if ( typeof define === 'function' && define.amd ) { |
||||
// AMD
|
||||
define( [ |
||||
'../layout-mode' |
||||
], |
||||
cellsByColumnDefinition ); |
||||
} else { |
||||
// browser global
|
||||
cellsByColumnDefinition( |
||||
window.Isotope.LayoutMode |
||||
); |
||||
} |
||||
|
||||
|
||||
})( window ); |
||||
|
||||
|
@ -1,59 +0,0 @@
|
||||
( function( window ) { |
||||
|
||||
'use strict'; |
||||
|
||||
function cellsByRowDefinition( LayoutMode ) { |
||||
|
||||
var CellsByRow = LayoutMode.create( 'cellsByRow' ); |
||||
|
||||
CellsByRow.prototype._resetLayout = function() { |
||||
// reset properties
|
||||
this.itemIndex = 0; |
||||
// measurements
|
||||
this.getColumnWidth(); |
||||
this.getRowHeight(); |
||||
// set cols
|
||||
this.cols = Math.floor( this.isotope.size.innerWidth / this.columnWidth ); |
||||
this.cols = Math.max( this.cols, 1 ); |
||||
}; |
||||
|
||||
CellsByRow.prototype._getItemLayoutPosition = function( item ) { |
||||
item.getSize(); |
||||
var col = this.itemIndex % this.cols; |
||||
var row = Math.floor( this.itemIndex / this.cols ); |
||||
// center item within cell
|
||||
var x = ( col + 0.5 ) * this.columnWidth - item.size.outerWidth / 2; |
||||
var y = ( row + 0.5 ) * this.rowHeight - item.size.outerHeight / 2; |
||||
this.itemIndex++; |
||||
return { x: x, y: y }; |
||||
}; |
||||
|
||||
CellsByRow.prototype._getContainerSize = function() { |
||||
return { |
||||
height: Math.ceil( this.itemIndex / this.cols ) * this.rowHeight |
||||
}; |
||||
}; |
||||
|
||||
return CellsByRow; |
||||
|
||||
} |
||||
|
||||
if ( typeof define === 'function' && define.amd ) { |
||||
// AMD
|
||||
define( [ |
||||
'../layout-mode', |
||||
'get-size/get-size' |
||||
], |
||||
cellsByRowDefinition ); |
||||
} else { |
||||
// browser global
|
||||
cellsByRowDefinition( |
||||
window.Isotope.LayoutMode, |
||||
window.getSize |
||||
); |
||||
} |
||||
|
||||
|
||||
})( window ); |
||||
|
||||
|
@ -1,60 +0,0 @@
|
||||
( function( window ) { |
||||
|
||||
'use strict'; |
||||
|
||||
function fitColumnsDefinition( LayoutMode ) { |
||||
|
||||
var FitColumns = LayoutMode.create('fitColumns'); |
||||
|
||||
FitColumns.prototype._resetLayout = function() { |
||||
this.x = 0; |
||||
this.y = 0; |
||||
this.maxX = 0; |
||||
}; |
||||
|
||||
FitColumns.prototype._getItemLayoutPosition = function( item ) { |
||||
item.getSize(); |
||||
|
||||
// if this element cannot fit in the current row
|
||||
if ( this.y !== 0 && item.size.outerHeight + this.y > this.isotope.size.innerHeight ) { |
||||
this.y = 0; |
||||
this.x = this.maxX; |
||||
} |
||||
|
||||
var position = { |
||||
x: this.x, |
||||
y: this.y |
||||
}; |
||||
|
||||
this.maxX = Math.max( this.maxX, this.x + item.size.outerWidth ); |
||||
this.y += item.size.outerHeight; |
||||
|
||||
return position; |
||||
}; |
||||
|
||||
FitColumns.prototype._getContainerSize = function() { |
||||
return { width: this.maxX }; |
||||
}; |
||||
|
||||
FitColumns.prototype.resize = function() { |
||||
this.resizeVertical(); |
||||
}; |
||||
|
||||
return FitColumns; |
||||
|
||||
} |
||||
|
||||
if ( typeof define === 'function' && define.amd ) { |
||||
// AMD
|
||||
define( [ |
||||
'../layout-mode' |
||||
], |
||||
fitColumnsDefinition ); |
||||
} else { |
||||
// browser global
|
||||
fitColumnsDefinition( |
||||
window.Isotope.LayoutMode |
||||
); |
||||
} |
||||
|
||||
})( window ); |
@ -1,49 +0,0 @@
|
||||
( function( window ) { |
||||
|
||||
'use strict'; |
||||
|
||||
function horizontalDefinition( LayoutMode ) { |
||||
|
||||
var Horizontal = LayoutMode.create( 'horizontal', { |
||||
verticalAlignment: 0 |
||||
}); |
||||
|
||||
Horizontal.prototype._resetLayout = function() { |
||||
this.x = 0; |
||||
}; |
||||
|
||||
Horizontal.prototype._getItemLayoutPosition = function( item ) { |
||||
item.getSize(); |
||||
var y = ( this.isotope.size.innerHeight - item.size.outerHeight ) * |
||||
this.options.verticalAlignment; |
||||
var x = this.x; |
||||
this.x += item.size.outerWidth; |
||||
return { x: x, y: y }; |
||||
}; |
||||
|
||||
Horizontal.prototype._getContainerSize = function() { |
||||
return { width: this.x }; |
||||
}; |
||||
|
||||
Horizontal.prototype.resize = function() { |
||||
this.resizeVertical(); |
||||
}; |
||||
|
||||
return Horizontal; |
||||
|
||||
} |
||||
|
||||
if ( typeof define === 'function' && define.amd ) { |
||||
// AMD
|
||||
define( [ |
||||
'../layout-mode' |
||||
], |
||||
horizontalDefinition ); |
||||
} else { |
||||
// browser global
|
||||
horizontalDefinition( |
||||
window.Isotope.LayoutMode |
||||
); |
||||
} |
||||
|
||||
})( window ); |
@ -1,145 +0,0 @@
|
||||
( function( window ) { |
||||
|
||||
'use strict'; |
||||
|
||||
// -------------------------- helpers -------------------------- //
|
||||
|
||||
var indexOf = Array.prototype.indexOf ? |
||||
function( items, value ) { |
||||
return items.indexOf( value ); |
||||
} : |
||||
function ( items, value ) { |
||||
for ( var i=0, len = items.length; i < len; i++ ) { |
||||
var item = items[i]; |
||||
if ( item === value ) { |
||||
return i; |
||||
} |
||||
} |
||||
return -1; |
||||
}; |
||||
|
||||
// -------------------------- definition -------------------------- //
|
||||
|
||||
function masonryHorizontalDefinition( getSize, LayoutMode ) { |
||||
// create an Outlayer layout class
|
||||
var MasonryHorizontal = LayoutMode.create('masonryHorizontal'); |
||||
|
||||
MasonryHorizontal.prototype._resetLayout = function() { |
||||
this.getRowHeight(); |
||||
this._getMeasurement( 'gutter', 'outerHeight' ); |
||||
|
||||
this.rowHeight += this.gutter; |
||||
// measure rows
|
||||
this.rows = Math.floor( ( this.isotope.size.innerHeight + this.gutter ) / this.rowHeight ); |
||||
this.rows = Math.max( this.rows, 1 ); |
||||
|
||||
// reset row Xs
|
||||
var i = this.rows; |
||||
this.rowXs = []; |
||||
while (i--) { |
||||
this.rowXs.push( 0 ); |
||||
} |
||||
|
||||
this.maxX = 0; |
||||
}; |
||||
|
||||
MasonryHorizontal.prototype._getItemLayoutPosition = function( item ) { |
||||
item.getSize(); |
||||
// how many rows does this brick span
|
||||
var rowSpan = Math.ceil( item.size.outerHeight / this.rowHeight ); |
||||
rowSpan = Math.min( rowSpan, this.rows ); |
||||
|
||||
var rowGroup = this._getRowGroup( rowSpan ); |
||||
// get the minimum Y value from the rows
|
||||
var minimumX = Math.min.apply( Math, rowGroup ); |
||||
var shortRowIndex = indexOf( rowGroup, minimumX ); |
||||
|
||||
// position the brick
|
||||
var position = { |
||||
x: minimumX, |
||||
y: this.rowHeight * shortRowIndex |
||||
}; |
||||
|
||||
// apply setHeight to necessary rows
|
||||
var setWidth = minimumX + item.size.outerWidth; |
||||
var setSpan = this.rows + 1 - rowGroup.length; |
||||
for ( var i = 0; i < setSpan; i++ ) { |
||||
this.rowXs[ shortRowIndex + i ] = setWidth; |
||||
} |
||||
|
||||
return position; |
||||
}; |
||||
|
||||
/** |
||||
* @param {Number} rowSpan - number of rows the element spans |
||||
* @returns {Array} rowGroup |
||||
*/ |
||||
MasonryHorizontal.prototype._getRowGroup = function( rowSpan ) { |
||||
if ( rowSpan < 2 ) { |
||||
// if brick spans only one row, use all the row Xs
|
||||
return this.rowXs; |
||||
} |
||||
|
||||
var rowGroup = []; |
||||
// how many different places could this brick fit horizontally
|
||||
var groupCount = this.rows + 1 - rowSpan; |
||||
// for each group potential horizontal position
|
||||
for ( var i = 0; i < groupCount; i++ ) { |
||||
// make an array of rowX values for that one group
|
||||
var groupRowXs = this.rowXs.slice( i, i + rowSpan ); |
||||
// and get the max value of the array
|
||||
rowGroup[i] = Math.max.apply( Math, groupRowXs ); |
||||
} |
||||
return rowGroup; |
||||
}; |
||||
|
||||
MasonryHorizontal.prototype._manageStamp = function( stamp ) { |
||||
var stampSize = getSize( stamp ); |
||||
var offset = this.isotope._getElementOffset( stamp ); |
||||
// get the rows that this stamp affects
|
||||
var firstY = this.isotope.options.isOriginTop ? offset.top : offset.bottom; |
||||
var lastY = firstY + stampSize.outerHeight; |
||||
var firstRow = Math.floor( firstY / this.rowHeight ); |
||||
firstRow = Math.max( 0, firstRow ); |
||||
var lastRow = Math.floor( lastY / this.rowHeight ); |
||||
lastRow = Math.min( this.rows - 1, lastRow ); |
||||
// set rowXs to outside edge of the stamp
|
||||
var stampMaxX = ( this.isotope.options.isOriginLeft ? offset.left : offset.right ) + |
||||
stampSize.outerWidth; |
||||
for ( var i = firstRow; i <= lastRow; i++ ) { |
||||
this.rowXs[i] = Math.max( stampMaxX, this.rowXs[i] ); |
||||
} |
||||
}; |
||||
|
||||
MasonryHorizontal.prototype._getContainerSize = function() { |
||||
this.maxX = Math.max.apply( Math, this.rowXs ); |
||||
|
||||
return { |
||||
width: this.maxX |
||||
}; |
||||
}; |
||||
|
||||
MasonryHorizontal.prototype.resize = function() { |
||||
this.resizeVertical(); |
||||
}; |
||||
|
||||
return MasonryHorizontal; |
||||
|
||||
} |
||||
|
||||
if ( typeof define === 'function' && define.amd ) { |
||||
// AMD
|
||||
define( [ |
||||
'get-size/get-size', |
||||
'../layout-mode' |
||||
], |
||||
masonryHorizontalDefinition ); |
||||
} else { |
||||
// browser global
|
||||
masonryHorizontalDefinition( |
||||
window.getSize, |
||||
window.Isotope.LayoutMode |
||||
); |
||||
} |
||||
|
||||
})( window ); |
Loading…
Reference in new issue