Browse Source

refactor outlayer methods in LayoutMode

pull/563/head
David DeSandro 12 years ago
parent
commit
3e2eb7b0f0
  1. 1
      examples/basic.html
  2. 5
      examples/masonry.html
  3. 24
      isotope.js
  4. 74
      layout-mode.js
  5. 27
      layout-modes/fit-rows.js

1
examples/basic.html

@ -46,6 +46,7 @@
<script src="../bower_components/outlayer/item.js"></script>
<script src="../bower_components/outlayer/outlayer.js"></script>
<script src="../layout-mode.js"></script>
<script src="../item.js"></script>
<script src="../isotope.js"></script>
<script src="../layout-modes/fit-rows.js"></script>

5
examples/masonry.html

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>sorting</title>
<title>masonry</title>
<link rel="stylesheet" href="examples.css" />
<style>
@ -159,11 +159,14 @@
<script src="../layout-mode.js"></script>
<script src="../isotope.js"></script>
<script src="../layout-modes/masonry.js"></script>
<script src="../layout-modes/fit-rows.js"></script>
<script>
docReady( function() {
var container = document.querySelector('#container');
var iso = window.iso = new Isotope( container, {
// sortBy: 'symbol',
// filter: '.metal',
layoutMode: 'masonry',
masonry: {
columnWidth: 90

24
isotope.js

@ -214,31 +214,23 @@ function isotopeDefinition( Outlayer, getSize, matchesSelector, Item, layoutMode
// -------------------------- methods -------------------------- //
Isotope.prototype._resetLayout = function() {
this._modeMethod( '_resetLayout', arguments );
this._mode()._resetLayout();
};
Isotope.prototype._getItemLayoutPosition = function( /* item */) {
return this._modeMethod( '_getItemLayoutPosition', arguments );
Isotope.prototype._getItemLayoutPosition = function( item ) {
return this._mode()._getItemLayoutPosition( item );
};
Isotope.prototype._manageStamp = function(/* stamp */) {
this._modeMethod( '_manageStamp', arguments );
Isotope.prototype._manageStamp = function( stamp ) {
this._mode()._manageStamp( stamp );
};
Isotope.prototype._getContainerSize = function() {
return this._modeMethod( '_getContainerSize', arguments );
return this._mode()._getContainerSize();
};
Isotope.prototype._modeMethod = function( methodName, args ) {
var mode = this._mode();
var modeMethod = mode[ methodName ];
// use mode's method, if there
if ( modeMethod ) {
return modeMethod.apply( mode, args );
} else {
// otherwise, default to Outlayer prototype
return Outlayer.prototype[ methodName ].apply( this, args );
}
Isotope.prototype.resize = function() {
this._mode().resize();
};
return Isotope;

74
layout-mode.js

@ -6,9 +6,10 @@
// var Isotope = window.Isotope;
function layoutModeDefinition( Outlayer ) {
var layoutMode = {};
layoutMode.options = {};
layoutMode.modes = {};
layoutMode.create = function( namespace, options ) {
@ -31,34 +32,59 @@ layoutMode.create = function( namespace, options ) {
LayoutMode.options = options;
}
// Outlayer.prototype._getMeasurement = function( measurement, size ) {
// var option = this.options[ measurement ];
// var elem;
// if ( !option ) {
// // default to 0
// this[ measurement ] = 0;
// } else {
// if ( typeof option === 'string' ) {
// elem = this.element.querySelector( option );
// } else if ( isElement( option ) ) {
// elem = option;
// }
// // use size of element, if element
// this[ measurement ] = elem ? getSize( elem )[ size ] : option;
// }
// };
LayoutMode.prototype.namespace = namespace;
// set default options
// layoutMode.options[ namespace ] = options || {};
// register in Isotope
layoutMode.modes[ namespace ] = LayoutMode;
// -------------------------- methods -------------------------- //
// default method handler
// trigger Outlayer method with Isotope as this
LayoutMode.prototype._outlayerMethod = function( methodName, args ) {
return Outlayer.prototype[ methodName ].apply( this.isotope, args );
};
LayoutMode.prototype._resetLayout = function() {
this._outlayerMethod( '_resetLayout', arguments );
};
LayoutMode.prototype._getItemLayoutPosition = function( /* item */) {
return this._outlayerMethod( '_getItemLayoutPosition', arguments );
};
LayoutMode.prototype._manageStamp = function(/* stamp */) {
this._outlayerMethod( '_manageStamp', arguments );
};
LayoutMode.prototype._getContainerSize = function() {
return this._outlayerMethod( '_getContainerSize', arguments );
};
LayoutMode.prototype.resize = function() {
this._outlayerMethod( 'resize', arguments );
};
return LayoutMode;
};
var Isotope = window.Isotope = window.Isotope || {};
Isotope.layoutMode = layoutMode;
return layoutMode;
}
if ( typeof define === 'function' && define.amd ) {
// AMD
define( [
'outlayer/outlayer'
],
layoutModeDefinition );
} else {
// browser global
window.Isotope = window.Isotope || {};
window.Isotope.layoutMode = layoutModeDefinition(
window.Outlayer
);
}
})( window );

27
layout-modes/fit-rows.js

@ -2,14 +2,16 @@
'use strict';
var Isotope = window.Isotope;
var Outlayer = window.Outlayer;
var FitRows = Isotope.createLayoutMode( 'fitRows', {
function fitRowsDefinition( layoutMode ) {
var FitRows = layoutMode.create( 'fitRows', {
foo: 'bar'
});
var __resetLayout = FitRows.prototype._resetLayout;
FitRows.prototype._resetLayout = function() {
Outlayer.prototype._resetLayout.apply( this.isotope, arguments );
// call original _resetLayout
__resetLayout.call( this );
this.x = 0;
this.y = 0;
this.maxY = 0;
@ -39,4 +41,21 @@ FitRows.prototype._getContainerSize = function() {
return { height: this.maxY };
};
return FitRows;
}
if ( typeof define === 'function' && define.amd ) {
// AMD
define( [
'../layout-mode'
],
fitRowsDefinition );
} else {
// browser global
fitRowsDefinition(
window.Isotope.layoutMode
);
}
})( window );

Loading…
Cancel
Save