From 0372298773a65bda323e68db78f21df5258c1b95 Mon Sep 17 00:00:00 2001 From: David DeSandro Date: Mon, 13 Jan 2014 18:50:14 -0500 Subject: [PATCH] add Isotope.sortDataParsers Allows for user to add custom parsers fort getSortData shortcut strings --- js/isotope.js | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/js/isotope.js b/js/isotope.js index 332642e..f1b0f2d 100644 --- a/js/isotope.js +++ b/js/isotope.js @@ -319,7 +319,7 @@ function isotopeDefinition( Outlayer, getSize, matchesSelector, Item, LayoutMode var attr = attrMatch && attrMatch[1]; var getValue = getValueGetter( attr, query ); // use second argument as a parser - var parser = getParser( args[1] ); + var parser = Isotope.sortDataParsers[ args[1] ]; // parse the value, if there was a parser sorter = parser ? function( elem ) { return elem && parser( getValue( elem ) ); @@ -350,33 +350,18 @@ function isotopeDefinition( Outlayer, getSize, matchesSelector, Item, LayoutMode return getValue; } - // return a parser function if arg matches - function getParser( arg ) { - var parser; - switch ( arg ) { - case 'parseInt' : - parser = function( val ) { - return parseInt( val, 10 ); - }; - break; - case 'parseFloat' : - parser = function( val ) { - return parseFloat( val ); - }; - break; - default : - // just return val if parser isn't one of these - // TODO - console log that that parser doesn't exist - parser = function( val ) { - return val; - }; - } - return parser; - } - return mungeSorter; })(); + // parsers used in getSortData shortcut strings + Isotope.sortDataParsers = { + 'parseInt': function( val ) { + return parseInt( val, 10 ); + }, + 'parseFloat': function( val ) { + return parseFloat( val ); + } + }; // ----- sort method ----- //