From c2c54d054107a29eb1ee477f2dbb30b4da1bc3fe Mon Sep 17 00:00:00 2001 From: David DeSandro Date: Mon, 13 Jan 2014 18:42:38 -0500 Subject: [PATCH] refactor updateSortData: ref #602 + add Isotope._getSorters() + add Isotope._updateItemsSortData + change updateSortData() to public method only --- js/isotope.js | 34 +++++++++++++++++++++++++--------- js/item.js | 3 +++ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/js/isotope.js b/js/isotope.js index 8583c83..332642e 100644 --- a/js/isotope.js +++ b/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(); } }; diff --git a/js/item.js b/js/item.js index 3a04fde..de5bac5 100644 --- a/js/item.js +++ b/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