From aa70a483d4833d3362dde99e1b189cc565f98afd Mon Sep 17 00:00:00 2001 From: Tim Tucker Date: Wed, 15 May 2013 07:58:25 -0300 Subject: [PATCH] Make fewer calls to $.inArray when assigning sort classes Only call once each to check to see sort ascending / sort descending is is active. (And only check for the descending class if we didn't find the ascending class) Should also lead to smaller minified code. --- media/src/core/core.columns.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/media/src/core/core.columns.js b/media/src/core/core.columns.js index ef730715..6a9d5770 100644 --- a/media/src/core/core.columns.js +++ b/media/src/core/core.columns.js @@ -1,4 +1,3 @@ - /** * Add a column to the list used for the table with default values * @param {object} oSettings dataTables settings object @@ -114,23 +113,24 @@ function _fnColumnOptions( oSettings, iCol, oOptions ) } /* Check that the class assignment is correct for sorting */ - if ( !oCol.bSortable || - ($.inArray('asc', oCol.asSorting) == -1 && $.inArray('desc', oCol.asSorting) == -1) ) + var bAsc = $.inArray('asc', oCol.asSorting) !== -1; + var bDesc = !bAsc && $.inArray('desc', oCol.asSorting) !== -1; + if ( !oCol.bSortable || (!bAsc && !bDesc) ) { oCol.sSortingClass = oSettings.oClasses.sSortableNone; oCol.sSortingClassJUI = ""; } - else if ( $.inArray('asc', oCol.asSorting) == -1 && $.inArray('desc', oCol.asSorting) == -1 ) + else if ( !bAsc && !bDesc ) { oCol.sSortingClass = oSettings.oClasses.sSortable; oCol.sSortingClassJUI = oSettings.oClasses.sSortJUI; } - else if ( $.inArray('asc', oCol.asSorting) != -1 && $.inArray('desc', oCol.asSorting) == -1 ) + else if ( bAsc && !bDesc ) { oCol.sSortingClass = oSettings.oClasses.sSortableAsc; oCol.sSortingClassJUI = oSettings.oClasses.sSortJUIAscAllowed; } - else if ( $.inArray('asc', oCol.asSorting) == -1 && $.inArray('desc', oCol.asSorting) != -1 ) + else if ( !bAsc && bDesc ) { oCol.sSortingClass = oSettings.oClasses.sSortableDesc; oCol.sSortingClassJUI = oSettings.oClasses.sSortJUIDescAllowed;