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

13
js/item.js

@ -34,16 +34,17 @@ function Item() {
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
this.id = this.layout.itemGUID++;
Outlayer.Item.prototype._create.call( this );
_create.call( this );
this.sortData = {};
};
Item.prototype.updateSortData = function() {
proto.updateSortData = function() {
if ( this.isIgnored ) {
return;
}
@ -61,8 +62,8 @@ Item.prototype.updateSortData = function() {
}
};
var _destroy = Item.prototype.destroy;
Item.prototype.destroy = function() {
var _destroy = proto.destroy;
proto.destroy = function() {
// call super
_destroy.apply( this, arguments );
// 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
* and reference the Isotope instance as `this`
@ -58,7 +60,7 @@
];
facadeMethods.forEach( function( methodName ) {
LayoutMode.prototype[ methodName ] = function() {
proto[ methodName ] = function() {
return Outlayer.prototype[ methodName ].apply( this.isotope, arguments );
};
});
@ -66,7 +68,7 @@
// ----- ----- //
// for horizontal layout modes, check vertical size
LayoutMode.prototype.needsVerticalResizeLayout = function() {
proto.needsVerticalResizeLayout = function() {
// don't trigger if size did not change
var size = getSize( this.isotope.element );
// check that this.size and size are there
@ -77,15 +79,15 @@
// ----- measurements ----- //
LayoutMode.prototype._getMeasurement = function() {
proto._getMeasurement = function() {
this.isotope._getMeasurement.apply( this, arguments );
};
LayoutMode.prototype.getColumnWidth = function() {
proto.getColumnWidth = function() {
this.getSegmentSize( 'column', 'Width' );
};
LayoutMode.prototype.getRowHeight = function() {
proto.getRowHeight = function() {
this.getSegmentSize( 'row', 'Height' );
};
@ -94,7 +96,7 @@
* segment: 'column' or 'row'
* size 'Width' or 'Height'
**/
LayoutMode.prototype.getSegmentSize = function( segment, size ) {
proto.getSegmentSize = function( segment, size ) {
var segmentName = segment + size;
var outerSize = 'outer' + size;
// columnWidth / outerWidth // rowHeight / outerHeight
@ -110,18 +112,18 @@
this.isotope.size[ 'inner' + size ];
};
LayoutMode.prototype.getFirstItemSize = function() {
proto.getFirstItemSize = function() {
var firstItem = this.isotope.filteredItems[0];
return firstItem && firstItem.element && getSize( firstItem.element );
};
// ----- methods that should reference isotope ----- //
LayoutMode.prototype.layout = function() {
proto.layout = function() {
this.isotope.layout.apply( this.isotope, arguments );
};
LayoutMode.prototype.getSize = function() {
proto.getSize = function() {
this.isotope.getSize();
this.size = this.isotope.size;
};
@ -136,7 +138,7 @@
LayoutMode.apply( this, arguments );
}
Mode.prototype = Object.create( LayoutMode.prototype );
Mode.prototype = Object.create( proto );
Mode.prototype.constructor = Mode;
// default options

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

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

8
js/layout-modes/vertical.js

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

Loading…
Cancel
Save