Browse Source

🛠 Class.prototype -> proto

pull/1127/head
David DeSandro 9 years ago
parent
commit
9028ae6e65
  1. 68
      js/isotope.js
  2. 13
      js/item.js
  3. 22
      js/layout-mode.js
  4. 8
      js/layout-modes/fit-rows.js
  5. 8
      js/layout-modes/vertical.js

68
js/isotope.js

@ -80,7 +80,7 @@ var trim = String.prototype.trim ?
// create an Outlayer layout class // create an Outlayer layout class
var Isotope = Outlayer.create( 'isotope', { var Isotope = Outlayer.create( 'isotope', {
layoutMode: "masonry", layoutMode: 'masonry',
isJQueryFiltering: true, isJQueryFiltering: true,
sortAscending: true sortAscending: true
}); });
@ -88,7 +88,9 @@ var trim = String.prototype.trim ?
Isotope.Item = Item; Isotope.Item = Item;
Isotope.LayoutMode = LayoutMode; Isotope.LayoutMode = LayoutMode;
Isotope.prototype._create = function() { var proto = Isotope.prototype;
proto._create = function() {
this.itemGUID = 0; this.itemGUID = 0;
// functions that sort items // functions that sort items
this._sorters = {}; this._sorters = {};
@ -108,14 +110,14 @@ var trim = String.prototype.trim ?
} }
}; };
Isotope.prototype.reloadItems = function() { proto.reloadItems = function() {
// reset item ID counter // reset item ID counter
this.itemGUID = 0; this.itemGUID = 0;
// call super // call super
Outlayer.prototype.reloadItems.call( this ); Outlayer.prototype.reloadItems.call( this );
}; };
Isotope.prototype._itemize = function() { proto._itemize = function() {
var items = Outlayer.prototype._itemize.apply( this, arguments ); var items = Outlayer.prototype._itemize.apply( this, arguments );
// assign ID for original-order // assign ID for original-order
for ( var i=0; i < items.length; i++ ) { for ( var i=0; i < items.length; i++ ) {
@ -129,7 +131,7 @@ var trim = String.prototype.trim ?
// -------------------------- layout -------------------------- // // -------------------------- layout -------------------------- //
Isotope.prototype._initLayoutMode = function( name ) { proto._initLayoutMode = function( name ) {
var Mode = LayoutMode.modes[ name ]; var Mode = LayoutMode.modes[ name ];
// set mode options // set mode options
// HACK extend initial options, back-fill in default options // HACK extend initial options, back-fill in default options
@ -141,7 +143,7 @@ var trim = String.prototype.trim ?
}; };
Isotope.prototype.layout = function() { proto.layout = function() {
// if first time doing layout, do all magic // if first time doing layout, do all magic
if ( !this._isLayoutInited && this._getOption('initLayout') ) { if ( !this._isLayoutInited && this._getOption('initLayout') ) {
this.arrange(); this.arrange();
@ -151,7 +153,7 @@ var trim = String.prototype.trim ?
}; };
// private method to be used in layout() & magic() // private method to be used in layout() & magic()
Isotope.prototype._layout = function() { proto._layout = function() {
// don't animate first layout // don't animate first layout
var isInstant = this._getIsInstant(); var isInstant = this._getIsInstant();
// layout flow // layout flow
@ -164,7 +166,7 @@ var trim = String.prototype.trim ?
}; };
// filter + sort + layout // filter + sort + layout
Isotope.prototype.arrange = function( opts ) { proto.arrange = function( opts ) {
// set any options pass // set any options pass
this.option( opts ); this.option( opts );
this._getIsInstant(); this._getIsInstant();
@ -186,9 +188,9 @@ var trim = String.prototype.trim ?
this._layout(); this._layout();
}; };
// alias to _init for main plugin method // alias to _init for main plugin method
Isotope.prototype._init = Isotope.prototype.arrange; proto._init = proto.arrange;
Isotope.prototype._hideReveal = function( filtered ) { proto._hideReveal = function( filtered ) {
this.reveal( filtered.needReveal ); this.reveal( filtered.needReveal );
this.hide( filtered.needHide ); this.hide( filtered.needHide );
}; };
@ -196,7 +198,7 @@ var trim = String.prototype.trim ?
// HACK // HACK
// Don't animate/transition first layout // Don't animate/transition first layout
// Or don't animate/transition other layouts // Or don't animate/transition other layouts
Isotope.prototype._getIsInstant = function() { proto._getIsInstant = function() {
var isLayoutInstant = this._getOption('layoutInstant'); var isLayoutInstant = this._getOption('layoutInstant');
var isInstant = isLayoutInstant !== undefined ? isLayoutInstant : var isInstant = isLayoutInstant !== undefined ? isLayoutInstant :
!this._isLayoutInited; !this._isLayoutInited;
@ -206,7 +208,7 @@ var trim = String.prototype.trim ?
// listen for layoutComplete, hideComplete and revealComplete // listen for layoutComplete, hideComplete and revealComplete
// to trigger arrangeComplete // to trigger arrangeComplete
Isotope.prototype._bindArrangeComplete = function() { proto._bindArrangeComplete = function() {
// listen for 3 events to trigger arrangeComplete // listen for 3 events to trigger arrangeComplete
var isLayoutComplete, isHideComplete, isRevealComplete; var isLayoutComplete, isHideComplete, isRevealComplete;
var _this = this; var _this = this;
@ -231,7 +233,7 @@ var trim = String.prototype.trim ?
// -------------------------- filter -------------------------- // // -------------------------- filter -------------------------- //
Isotope.prototype._filter = function( items ) { proto._filter = function( items ) {
var filter = this.options.filter; var filter = this.options.filter;
filter = filter || '*'; filter = filter || '*';
var matches = []; var matches = [];
@ -270,7 +272,7 @@ var trim = String.prototype.trim ?
}; };
// get a jQuery, function, or a matchesSelector test given the filter // get a jQuery, function, or a matchesSelector test given the filter
Isotope.prototype._getFilterTest = function( filter ) { proto._getFilterTest = function( filter ) {
if ( jQuery && this.options.isJQueryFiltering ) { if ( jQuery && this.options.isJQueryFiltering ) {
// use jQuery // use jQuery
return function( item ) { return function( item ) {
@ -295,7 +297,7 @@ var trim = String.prototype.trim ?
* @params {Array} elems * @params {Array} elems
* @public * @public
*/ */
Isotope.prototype.updateSortData = function( elems ) { proto.updateSortData = function( elems ) {
// get items // get items
var items; var items;
if ( elems ) { if ( elems ) {
@ -310,7 +312,7 @@ var trim = String.prototype.trim ?
this._updateItemsSortData( items ); this._updateItemsSortData( items );
}; };
Isotope.prototype._getSorters = function() { proto._getSorters = function() {
var getSortData = this.options.getSortData; var getSortData = this.options.getSortData;
for ( var key in getSortData ) { for ( var key in getSortData ) {
var sorter = getSortData[ key ]; var sorter = getSortData[ key ];
@ -322,7 +324,7 @@ var trim = String.prototype.trim ?
* @params {Array} items - of Isotope.Items * @params {Array} items - of Isotope.Items
* @private * @private
*/ */
Isotope.prototype._updateItemsSortData = function( items ) { proto._updateItemsSortData = function( items ) {
// do not update if no items // do not update if no items
var len = items && items.length; var len = items && items.length;
@ -400,7 +402,7 @@ var trim = String.prototype.trim ?
// ----- sort method ----- // // ----- sort method ----- //
// sort filteredItem order // sort filteredItem order
Isotope.prototype._sort = function() { proto._sort = function() {
var sortByOpt = this.options.sortBy; var sortByOpt = this.options.sortBy;
if ( !sortByOpt ) { if ( !sortByOpt ) {
return; return;
@ -439,7 +441,7 @@ var trim = String.prototype.trim ?
// -------------------------- methods -------------------------- // // -------------------------- methods -------------------------- //
// get layout mode // get layout mode
Isotope.prototype._mode = function() { proto._mode = function() {
var layoutMode = this.options.layoutMode; var layoutMode = this.options.layoutMode;
var mode = this.modes[ layoutMode ]; var mode = this.modes[ layoutMode ];
if ( !mode ) { if ( !mode ) {
@ -452,32 +454,32 @@ var trim = String.prototype.trim ?
return mode; return mode;
}; };
Isotope.prototype._resetLayout = function() { proto._resetLayout = function() {
// trigger original reset layout // trigger original reset layout
Outlayer.prototype._resetLayout.call( this ); Outlayer.prototype._resetLayout.call( this );
this._mode()._resetLayout(); this._mode()._resetLayout();
}; };
Isotope.prototype._getItemLayoutPosition = function( item ) { proto._getItemLayoutPosition = function( item ) {
return this._mode()._getItemLayoutPosition( item ); return this._mode()._getItemLayoutPosition( item );
}; };
Isotope.prototype._manageStamp = function( stamp ) { proto._manageStamp = function( stamp ) {
this._mode()._manageStamp( stamp ); this._mode()._manageStamp( stamp );
}; };
Isotope.prototype._getContainerSize = function() { proto._getContainerSize = function() {
return this._mode()._getContainerSize(); return this._mode()._getContainerSize();
}; };
Isotope.prototype.needsResizeLayout = function() { proto.needsResizeLayout = function() {
return this._mode().needsResizeLayout(); return this._mode().needsResizeLayout();
}; };
// -------------------------- adding & removing -------------------------- // // -------------------------- adding & removing -------------------------- //
// HEADS UP overwrites default Outlayer appended // HEADS UP overwrites default Outlayer appended
Isotope.prototype.appended = function( elems ) { proto.appended = function( elems ) {
var items = this.addItems( elems ); var items = this.addItems( elems );
if ( !items.length ) { if ( !items.length ) {
return; return;
@ -489,7 +491,7 @@ var trim = String.prototype.trim ?
}; };
// HEADS UP overwrites default Outlayer prepended // HEADS UP overwrites default Outlayer prepended
Isotope.prototype.prepended = function( elems ) { proto.prepended = function( elems ) {
var items = this._itemize( elems ); var items = this._itemize( elems );
if ( !items.length ) { if ( !items.length ) {
return; return;
@ -506,7 +508,7 @@ var trim = String.prototype.trim ?
this.items = items.concat( this.items ); this.items = items.concat( this.items );
}; };
Isotope.prototype._filterRevealAdded = function( items ) { proto._filterRevealAdded = function( items ) {
var filtered = this._filter( items ); var filtered = this._filter( items );
this.hide( filtered.needHide ); this.hide( filtered.needHide );
// reveal all new items // reveal all new items
@ -520,7 +522,7 @@ var trim = String.prototype.trim ?
* Filter, sort, and layout newly-appended item elements * Filter, sort, and layout newly-appended item elements
* @param {Array or NodeList or Element} elems * @param {Array or NodeList or Element} elems
*/ */
Isotope.prototype.insert = function( elems ) { proto.insert = function( elems ) {
var items = this.addItems( elems ); var items = this.addItems( elems );
if ( !items.length ) { if ( !items.length ) {
return; return;
@ -546,8 +548,8 @@ var trim = String.prototype.trim ?
this.reveal( filteredInsertItems ); this.reveal( filteredInsertItems );
}; };
var _remove = Isotope.prototype.remove; var _remove = proto.remove;
Isotope.prototype.remove = function( elems ) { proto.remove = function( elems ) {
elems = utils.makeArray( elems ); elems = utils.makeArray( elems );
var removeItems = this.getItems( elems ); var removeItems = this.getItems( elems );
// do regular thing // do regular thing
@ -565,7 +567,7 @@ var trim = String.prototype.trim ?
} }
}; };
Isotope.prototype.shuffle = function() { proto.shuffle = function() {
// update random sortData // update random sortData
for ( var i=0; i < this.items.length; i++ ) { for ( var i=0; i < this.items.length; i++ ) {
var item = this.items[i]; var item = this.items[i];
@ -584,7 +586,7 @@ var trim = String.prototype.trim ?
* @returns ret * @returns ret
* @private * @private
*/ */
Isotope.prototype._noTransition = function( fn, args ) { proto._noTransition = function( fn, args ) {
// save transitionDuration before disabling // save transitionDuration before disabling
var transitionDuration = this.options.transitionDuration; var transitionDuration = this.options.transitionDuration;
// disable transition // disable transition
@ -602,7 +604,7 @@ var trim = String.prototype.trim ?
* getter method for getting filtered item elements * getter method for getting filtered item elements
* @returns {Array} elems - collection of item elements * @returns {Array} elems - collection of item elements
*/ */
Isotope.prototype.getFilteredItemElements = function() { proto.getFilteredItemElements = function() {
return this.filteredItems.map( function( item ) { return this.filteredItems.map( function( item ) {
return item.element; return item.element;
}); });

13
js/item.js

@ -34,16 +34,17 @@ function Item() {
Outlayer.Item.apply( this, arguments ); Outlayer.Item.apply( this, arguments );
} }
Item.prototype = new Outlayer.Item(); var proto = Item.prototype = Object.create( Outlayer.Item.prototype );
Item.prototype._create = function() { var _create = proto._create;
proto._create = function() {
// assign id, used for original-order sorting // assign id, used for original-order sorting
this.id = this.layout.itemGUID++; this.id = this.layout.itemGUID++;
Outlayer.Item.prototype._create.call( this ); _create.call( this );
this.sortData = {}; this.sortData = {};
}; };
Item.prototype.updateSortData = function() { proto.updateSortData = function() {
if ( this.isIgnored ) { if ( this.isIgnored ) {
return; return;
} }
@ -61,8 +62,8 @@ Item.prototype.updateSortData = function() {
} }
}; };
var _destroy = Item.prototype.destroy; var _destroy = proto.destroy;
Item.prototype.destroy = function() { proto.destroy = function() {
// call super // call super
_destroy.apply( this, arguments ); _destroy.apply( this, arguments );
// reset display, #741 // reset display, #741

22
js/layout-mode.js

@ -43,6 +43,8 @@
} }
} }
var proto = LayoutMode.prototype;
/** /**
* some methods should just defer to default Outlayer method * some methods should just defer to default Outlayer method
* and reference the Isotope instance as `this` * and reference the Isotope instance as `this`
@ -58,7 +60,7 @@
]; ];
facadeMethods.forEach( function( methodName ) { facadeMethods.forEach( function( methodName ) {
LayoutMode.prototype[ methodName ] = function() { proto[ methodName ] = function() {
return Outlayer.prototype[ methodName ].apply( this.isotope, arguments ); return Outlayer.prototype[ methodName ].apply( this.isotope, arguments );
}; };
}); });
@ -66,7 +68,7 @@
// ----- ----- // // ----- ----- //
// for horizontal layout modes, check vertical size // for horizontal layout modes, check vertical size
LayoutMode.prototype.needsVerticalResizeLayout = function() { proto.needsVerticalResizeLayout = function() {
// don't trigger if size did not change // don't trigger if size did not change
var size = getSize( this.isotope.element ); var size = getSize( this.isotope.element );
// check that this.size and size are there // check that this.size and size are there
@ -77,15 +79,15 @@
// ----- measurements ----- // // ----- measurements ----- //
LayoutMode.prototype._getMeasurement = function() { proto._getMeasurement = function() {
this.isotope._getMeasurement.apply( this, arguments ); this.isotope._getMeasurement.apply( this, arguments );
}; };
LayoutMode.prototype.getColumnWidth = function() { proto.getColumnWidth = function() {
this.getSegmentSize( 'column', 'Width' ); this.getSegmentSize( 'column', 'Width' );
}; };
LayoutMode.prototype.getRowHeight = function() { proto.getRowHeight = function() {
this.getSegmentSize( 'row', 'Height' ); this.getSegmentSize( 'row', 'Height' );
}; };
@ -94,7 +96,7 @@
* segment: 'column' or 'row' * segment: 'column' or 'row'
* size 'Width' or 'Height' * size 'Width' or 'Height'
**/ **/
LayoutMode.prototype.getSegmentSize = function( segment, size ) { proto.getSegmentSize = function( segment, size ) {
var segmentName = segment + size; var segmentName = segment + size;
var outerSize = 'outer' + size; var outerSize = 'outer' + size;
// columnWidth / outerWidth // rowHeight / outerHeight // columnWidth / outerWidth // rowHeight / outerHeight
@ -110,18 +112,18 @@
this.isotope.size[ 'inner' + size ]; this.isotope.size[ 'inner' + size ];
}; };
LayoutMode.prototype.getFirstItemSize = function() { proto.getFirstItemSize = function() {
var firstItem = this.isotope.filteredItems[0]; var firstItem = this.isotope.filteredItems[0];
return firstItem && firstItem.element && getSize( firstItem.element ); return firstItem && firstItem.element && getSize( firstItem.element );
}; };
// ----- methods that should reference isotope ----- // // ----- methods that should reference isotope ----- //
LayoutMode.prototype.layout = function() { proto.layout = function() {
this.isotope.layout.apply( this.isotope, arguments ); this.isotope.layout.apply( this.isotope, arguments );
}; };
LayoutMode.prototype.getSize = function() { proto.getSize = function() {
this.isotope.getSize(); this.isotope.getSize();
this.size = this.isotope.size; this.size = this.isotope.size;
}; };
@ -136,7 +138,7 @@
LayoutMode.apply( this, arguments ); LayoutMode.apply( this, arguments );
} }
Mode.prototype = Object.create( LayoutMode.prototype ); Mode.prototype = Object.create( proto );
Mode.prototype.constructor = Mode; Mode.prototype.constructor = Mode;
// default options // default options

8
js/layout-modes/fit-rows.js

@ -28,14 +28,16 @@
var FitRows = LayoutMode.create('fitRows'); var FitRows = LayoutMode.create('fitRows');
FitRows.prototype._resetLayout = function() { var proto = FitRows.prototype;
proto._resetLayout = function() {
this.x = 0; this.x = 0;
this.y = 0; this.y = 0;
this.maxY = 0; this.maxY = 0;
this._getMeasurement( 'gutter', 'outerWidth' ); this._getMeasurement( 'gutter', 'outerWidth' );
}; };
FitRows.prototype._getItemLayoutPosition = function( item ) { proto._getItemLayoutPosition = function( item ) {
item.getSize(); item.getSize();
var itemWidth = item.size.outerWidth + this.gutter; var itemWidth = item.size.outerWidth + this.gutter;
@ -57,7 +59,7 @@ FitRows.prototype._getItemLayoutPosition = function( item ) {
return position; return position;
}; };
FitRows.prototype._getContainerSize = function() { proto._getContainerSize = function() {
return { height: this.maxY }; return { height: this.maxY };
}; };

8
js/layout-modes/vertical.js

@ -30,11 +30,13 @@ var Vertical = LayoutMode.create( 'vertical', {
horizontalAlignment: 0 horizontalAlignment: 0
}); });
Vertical.prototype._resetLayout = function() { var proto = Vertical.prototype;
proto._resetLayout = function() {
this.y = 0; this.y = 0;
}; };
Vertical.prototype._getItemLayoutPosition = function( item ) { proto._getItemLayoutPosition = function( item ) {
item.getSize(); item.getSize();
var x = ( this.isotope.size.innerWidth - item.size.outerWidth ) * var x = ( this.isotope.size.innerWidth - item.size.outerWidth ) *
this.options.horizontalAlignment; this.options.horizontalAlignment;
@ -43,7 +45,7 @@ Vertical.prototype._getItemLayoutPosition = function( item ) {
return { x: x, y: y }; return { x: x, y: y };
}; };
Vertical.prototype._getContainerSize = function() { proto._getContainerSize = function() {
return { height: this.y }; return { height: this.y };
}; };

Loading…
Cancel
Save