Browse Source

refactor updateSortData: ref #602

+ add Isotope._getSorters()
+ add Isotope._updateItemsSortData
+ change updateSortData() to public method only
pull/726/head
David DeSandro 11 years ago
parent
commit
c2c54d0541
  1. 34
      js/isotope.js
  2. 3
      js/item.js

34
js/isotope.js

@ -100,6 +100,7 @@ function isotopeDefinition( Outlayer, getSize, matchesSelector, Item, LayoutMode
this.itemGUID = 0;
// functions that sort items
this._sorters = {};
this._getSorters();
// call super
Outlayer.prototype._create.call( this );
@ -129,7 +130,7 @@ function isotopeDefinition( Outlayer, getSize, matchesSelector, Item, LayoutMode
var item = items[i];
item.id = this.itemGUID++;
}
this.updateSortData( items );
this._updateItemsSortData( items );
return items;
};
@ -261,21 +262,36 @@ function isotopeDefinition( Outlayer, getSize, matchesSelector, Item, LayoutMode
// -------------------------- sorting -------------------------- //
Isotope.prototype.updateSortData = function( items ) {
// update sorters
/**
* @params {Array} elems
* @public
*/
Isotope.prototype.updateSortData = function( elems ) {
this._getSorters();
// update item sort data
// default to all items if none are passed in
elems = makeArray( elems );
var items = this.getItems( elems );
// if no items found, update all items
items = items.length ? items : this.items;
this._updateItemsSortData( items );
};
Isotope.prototype._getSorters = function() {
var getSortData = this.options.getSortData;
for ( var key in getSortData ) {
var sorter = getSortData[ key ];
this._sorters[ key ] = mungeSorter( sorter );
}
// update item sort data
// default to all items if none are passed in
items = items || this.items;
};
/**
* @params {Array} items - of Isotope.Items
* @private
*/
Isotope.prototype._updateItemsSortData = function( items ) {
for ( var i=0, len = items.length; i < len; i++ ) {
var item = items[i];
if ( item.isIgnored ) {
continue;
}
item.updateSortData();
}
};

3
js/item.js

@ -25,6 +25,9 @@ Item.prototype._create = function() {
};
Item.prototype.updateSortData = function() {
if ( this.isIgnored ) {
return;
}
// default sorters
this.sortData.id = this.id;
// for backward compatibility

Loading…
Cancel
Save