diff --git a/js/isotope.js b/js/isotope.js index 210187e..6622f66 100644 --- a/js/isotope.js +++ b/js/isotope.js @@ -198,8 +198,9 @@ var trim = String.prototype.trim ? // Don't animate/transition first layout // Or don't animate/transition other layouts Isotope.prototype._getIsInstant = function() { - var isInstant = this._getOption('initLayout') !== undefined ? - this._getOption('layoutInstant') : !this._isLayoutInited; + var isLayoutInstant = this._getOption('layoutInstant') + var isInstant = isLayoutInstant !== undefined ? isLayoutInstant : + !this._isLayoutInited; this._isInstant = isInstant; return isInstant; }; diff --git a/js/layout-mode.js b/js/layout-mode.js index 012583f..ffc3589 100644 --- a/js/layout-mode.js +++ b/js/layout-mode.js @@ -47,27 +47,21 @@ * some methods should just defer to default Outlayer method * and reference the Isotope instance as `this` **/ - ( function() { - var facadeMethods = [ - '_resetLayout', - '_getItemLayoutPosition', - '_manageStamp', - '_getContainerSize', - '_getElementOffset', - 'needsResizeLayout' - ]; - - for ( var i=0, len = facadeMethods.length; i < len; i++ ) { - var methodName = facadeMethods[i]; - LayoutMode.prototype[ methodName ] = getOutlayerMethod( methodName ); - } - - function getOutlayerMethod( methodName ) { - return function() { - return Outlayer.prototype[ methodName ].apply( this.isotope, arguments ); - }; - } - })(); + var facadeMethods = [ + '_resetLayout', + '_getItemLayoutPosition', + '_manageStamp', + '_getContainerSize', + '_getElementOffset', + 'needsResizeLayout', + '_getOption' + ]; + + facadeMethods.forEach( function( methodName ) { + LayoutMode.prototype[ methodName ] = function() { + return Outlayer.prototype[ methodName ].apply( this.isotope, arguments ); + }; + }); // ----- ----- // @@ -142,7 +136,8 @@ LayoutMode.apply( this, arguments ); } - Mode.prototype = new LayoutMode(); + Mode.prototype = Object.create( LayoutMode.prototype ); + Mode.prototype.constructor = Mode; // default options if ( options ) { diff --git a/js/layout-modes/masonry.js b/js/layout-modes/masonry.js index 5f72057..95cfa27 100644 --- a/js/layout-modes/masonry.js +++ b/js/layout-modes/masonry.js @@ -31,47 +31,42 @@ }( window, function factory( LayoutMode, Masonry ) { 'use strict'; -// -------------------------- helpers -------------------------- // - -// extend objects -function extend( a, b ) { - for ( var prop in b ) { - a[ prop ] = b[ prop ]; - } - return a; -} - // -------------------------- masonryDefinition -------------------------- // // create an Outlayer layout class var MasonryMode = LayoutMode.create('masonry'); - // save on to these methods - var _getElementOffset = MasonryMode.prototype._getElementOffset; - var layout = MasonryMode.prototype.layout; - var _getMeasurement = MasonryMode.prototype._getMeasurement; + var proto = MasonryMode.prototype; - // sub-class Masonry - extend( MasonryMode.prototype, Masonry.prototype ); + var keepModeMethods = { + _getElementOffset: true, + layout: true, + _getMeasurement: true + }; - // set back, as it was overwritten by Masonry - MasonryMode.prototype._getElementOffset = _getElementOffset; - MasonryMode.prototype.layout = layout; - MasonryMode.prototype._getMeasurement = _getMeasurement; + // inherit Masonry prototype + for ( var method in Masonry.prototype ) { + // do not inherit mode methods + if ( !keepModeMethods[ method ] ) { + proto[ method ] = Masonry.prototype[ method ]; + } + } - var measureColumns = MasonryMode.prototype.measureColumns; - MasonryMode.prototype.measureColumns = function() { + var measureColumns = proto.measureColumns; + proto.measureColumns = function() { // set items, used if measuring first item this.items = this.isotope.filteredItems; measureColumns.call( this ); }; - // HACK copy over isOriginLeft/Top options - var _manageStamp = MasonryMode.prototype._manageStamp; - MasonryMode.prototype._manageStamp = function() { - this.options.isOriginLeft = this.isotope.options.isOriginLeft; - this.options.isOriginTop = this.isotope.options.isOriginTop; - _manageStamp.apply( this, arguments ); + // point to mode options for fitWidth + var _getOption = proto._getOption; + proto._getOption = function( option ) { + if ( option == 'fitWidth' ) { + return this.options.isFitWidth !== undefined ? + this.options.isFitWidth : this.options.fitWidth; + } + return _getOption.apply( this.isotope, arguments ); }; return MasonryMode;