From d904c7d2c7d693a8ac56cc6833c09d3d78205bc7 Mon Sep 17 00:00:00 2001 From: David DeSandro Date: Wed, 4 Sep 2013 08:48:34 -0400 Subject: [PATCH] getSorter; getText for IE8 --- examples/filter-sort.html | 3 ++- isotope.js | 25 +++++++++++++++---------- notes.md | 11 ++--------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/examples/filter-sort.html b/examples/filter-sort.html index 004a6e4..42d811a 100644 --- a/examples/filter-sort.html +++ b/examples/filter-sort.html @@ -193,7 +193,8 @@ docReady( function() { if ( key === 'filter' && value === 'number-greater-than-50' ) { value = function( elem ) { - return parseInt( elem.querySelector('.number').textContent, 10 ) > 40; + var numberText = getText( elem.querySelector('.number') ); + return parseInt( numberText, 10 ) > 40; }; } console.log( key, value ); diff --git a/isotope.js b/isotope.js index 47f3f7b..c450b4a 100644 --- a/isotope.js +++ b/isotope.js @@ -181,9 +181,20 @@ function isotopeDefinition( Outlayer, getSize, matchesSelector, Item, layoutMode } // concat all sortBy and sortHistory var sortBys = [].concat.apply( sortByOpt, this.sortHistory ); - var sortAsc = this.options.sortAscending; // sort magic - this.filteredItems.sort( function sorter( itemA, itemB ) { + var sorter = getSorter( sortBys, this.options.sortAscending ); + this.filteredItems.sort( sorter ); + // keep track of sortBy History + var lastSortBy = this.sortHistory[ this.sortHistory.length - 1 ]; + if ( sortByOpt !== lastSortBy ) { + // add to front, oldest goes in last + this.sortHistory.unshift( sortByOpt ); + } + }; + + // returns a function used for sorting + function getSorter( sortBys, sortAsc ) { + return function sorter( itemA, itemB ) { // cycle through all sortKeys for ( var i = 0, len = sortBys.length; i < len; i++ ) { var sortBy = sortBys[i]; @@ -197,14 +208,8 @@ function isotopeDefinition( Outlayer, getSize, matchesSelector, Item, layoutMode } } return 0; - }); - // keep track of sortBy History - var lastSortBy = this.sortHistory[ this.sortHistory.length - 1 ]; - if ( sortByOpt !== lastSortBy ) { - // add to front, oldest goes in last - this.sortHistory.unshift( sortByOpt ); - } - }; + }; + } // -------------------------- methods -------------------------- // diff --git a/notes.md b/notes.md index c69b4c3..22638bf 100644 --- a/notes.md +++ b/notes.md @@ -6,13 +6,6 @@ getSortData shorthand filter -## bugs - -transitionDuration = '2s' -hide most -reveal, -then while transitioning, sort - -items jump into place :( -- could be problem with EventEmitter +updateSortData +## bugs