From cf12ba5ab3eb9743c44ff32604437ab811058ccd Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Mon, 2 Jan 2012 09:21:19 +0000 Subject: [PATCH] Update: Initial work on updating state saving code to use objects rather than constructing a JSON string. Note that this has involved removing fnStateLoadCallback and fnStateSaveCallback which are now replaced with a much more effective setup using fnStateSaveParams, fnStateLoadParams and fnStateLoaded (blog post to come about this). Code documentation and tidy up yet required --- media/js/jquery.dataTables.js | 248 ++++++++++++++--------------- media/src/DataTables.js | 2 +- media/src/api/api.internal.js | 3 +- media/src/core/core.constructor.js | 7 +- media/src/core/core.state.js | 168 ++++++------------- media/src/core/core.support.js | 33 ++++ media/src/model/model.defaults.js | 31 +++- media/src/model/model.settings.js | 4 + 8 files changed, 246 insertions(+), 250 deletions(-) diff --git a/media/js/jquery.dataTables.js b/media/js/jquery.dataTables.js index 34d4e2b3..863f9b02 100644 --- a/media/js/jquery.dataTables.js +++ b/media/js/jquery.dataTables.js @@ -21,7 +21,7 @@ */ /*jslint evil: true, undef: true, browser: true */ -/*globals $, jQuery,_fnExternApiFunc,_fnInitialise,_fnInitComplete,_fnLanguageCompat,_fnAddColumn,_fnColumnOptions,_fnAddData,_fnCreateTr,_fnGatherData,_fnBuildHead,_fnDrawHead,_fnDraw,_fnReDraw,_fnAjaxUpdate,_fnAjaxParameters,_fnAjaxUpdateDraw,_fnServerParams,_fnAddOptionsHtml,_fnFeatureHtmlTable,_fnScrollDraw,_fnAdjustColumnSizing,_fnFeatureHtmlFilter,_fnFilterComplete,_fnFilterCustom,_fnFilterColumn,_fnFilter,_fnBuildSearchArray,_fnBuildSearchRow,_fnFilterCreateSearch,_fnDataToSearch,_fnSort,_fnSortAttachListener,_fnSortingClasses,_fnFeatureHtmlPaginate,_fnPageChange,_fnFeatureHtmlInfo,_fnUpdateInfo,_fnFeatureHtmlLength,_fnFeatureHtmlProcessing,_fnProcessingDisplay,_fnVisibleToColumnIndex,_fnColumnIndexToVisible,_fnNodeToDataIndex,_fnVisbleColumns,_fnCalculateEnd,_fnConvertToWidth,_fnCalculateColumnWidths,_fnScrollingWidthAdjust,_fnGetWidestNode,_fnGetMaxLenString,_fnStringToCss,_fnDetectType,_fnSettingsFromNode,_fnGetDataMaster,_fnGetTrNodes,_fnGetTdNodes,_fnEscapeRegex,_fnDeleteIndex,_fnReOrderIndex,_fnColumnOrdering,_fnLog,_fnClearTable,_fnSaveState,_fnLoadState,_fnCreateCookie,_fnReadCookie,_fnDetectHeader,_fnGetUniqueThs,_fnScrollBarWidth,_fnApplyToChildren,_fnMap,_fnGetRowData,_fnGetCellData,_fnSetCellData,_fnGetObjectDataFn,_fnSetObjectDataFn,_fnApplyColumnDefs,_fnBindAction,_fnCallbackReg,_fnCallbackFire*/ +/*globals $, jQuery,_fnExternApiFunc,_fnInitialise,_fnInitComplete,_fnLanguageCompat,_fnAddColumn,_fnColumnOptions,_fnAddData,_fnCreateTr,_fnGatherData,_fnBuildHead,_fnDrawHead,_fnDraw,_fnReDraw,_fnAjaxUpdate,_fnAjaxParameters,_fnAjaxUpdateDraw,_fnServerParams,_fnAddOptionsHtml,_fnFeatureHtmlTable,_fnScrollDraw,_fnAdjustColumnSizing,_fnFeatureHtmlFilter,_fnFilterComplete,_fnFilterCustom,_fnFilterColumn,_fnFilter,_fnBuildSearchArray,_fnBuildSearchRow,_fnFilterCreateSearch,_fnDataToSearch,_fnSort,_fnSortAttachListener,_fnSortingClasses,_fnFeatureHtmlPaginate,_fnPageChange,_fnFeatureHtmlInfo,_fnUpdateInfo,_fnFeatureHtmlLength,_fnFeatureHtmlProcessing,_fnProcessingDisplay,_fnVisibleToColumnIndex,_fnColumnIndexToVisible,_fnNodeToDataIndex,_fnVisbleColumns,_fnCalculateEnd,_fnConvertToWidth,_fnCalculateColumnWidths,_fnScrollingWidthAdjust,_fnGetWidestNode,_fnGetMaxLenString,_fnStringToCss,_fnDetectType,_fnSettingsFromNode,_fnGetDataMaster,_fnGetTrNodes,_fnGetTdNodes,_fnEscapeRegex,_fnDeleteIndex,_fnReOrderIndex,_fnColumnOrdering,_fnLog,_fnClearTable,_fnSaveState,_fnLoadState,_fnCreateCookie,_fnReadCookie,_fnDetectHeader,_fnGetUniqueThs,_fnScrollBarWidth,_fnApplyToChildren,_fnMap,_fnGetRowData,_fnGetCellData,_fnSetCellData,_fnGetObjectDataFn,_fnSetObjectDataFn,_fnApplyColumnDefs,_fnBindAction,_fnCallbackReg,_fnCallbackFire,_fnJsonString*/ (/** @lends */function($, window, document, undefined) { /** @@ -4234,60 +4234,27 @@ return; } - /* xxx - This is horrible! What we really want to do is use a proper object and - * pass that around - but jQuery doesn't have a toJson option. Either need to use - * $.param or JSON.stringify or something else - */ - /* Store the interesting variables */ - var i, iLen, sTmp; - var sValue = "{"; - sValue += '"iCreate":'+ new Date().getTime()+','; - sValue += '"iStart":'+ (oSettings.oScroll.bInfinite ? 0 : oSettings._iDisplayStart)+','; - sValue += '"iEnd":'+ (oSettings.oScroll.bInfinite ? oSettings._iDisplayLength : oSettings._iDisplayEnd)+','; - sValue += '"iLength":'+ oSettings._iDisplayLength+','; - sValue += '"sFilter":"'+ encodeURIComponent(oSettings.oPreviousSearch.sSearch)+'",'; - sValue += '"sFilterEsc":'+ !oSettings.oPreviousSearch.bRegex+','; - - sValue += '"aaSorting":[ '; - for ( i=0 ; i */function($, window, document, undefined) { /** diff --git a/media/src/api/api.internal.js b/media/src/api/api.internal.js index 055afced..82b55e49 100644 --- a/media/src/api/api.internal.js +++ b/media/src/api/api.internal.js @@ -109,7 +109,8 @@ this.oApi = { "_fnBindAction": _fnBindAction, "_fnExtend": _fnExtend, "_fnCallbackReg": _fnCallbackReg, - "_fnCallbackFire": _fnCallbackFire + "_fnCallbackFire": _fnCallbackFire, + "_fnJsonString": _fnJsonString }; $.extend( DataTable.ext.oApi, this.oApi ); diff --git a/media/src/core/core.constructor.js b/media/src/core/core.constructor.js index 0da43531..b6d78f10 100644 --- a/media/src/core/core.constructor.js +++ b/media/src/core/core.constructor.js @@ -121,13 +121,16 @@ _fnMap( oSettings, oInit, "aoSearchCols", "aoPreSearchCols" ); _fnMap( oSettings, oInit, "iDisplayLength", "_iDisplayLength" ); _fnMap( oSettings, oInit, "bJQueryUI", "bJUI" ); _fnMap( oSettings, oInit, "fnCookieCallback" ); +_fnMap( oSettings, oInit, "fnStateLoad" ); +_fnMap( oSettings, oInit, "fnStateSave" ); _fnMap( oSettings.oLanguage, oInit, "fnInfoCallback" ); /* Callback functions which are array driven */ _fnCallbackReg( oSettings, 'aoDrawCallback', oInit.fnDrawCallback, 'user' ); _fnCallbackReg( oSettings, 'aoServerParams', oInit.fnServerParams, 'user' ); -_fnCallbackReg( oSettings, 'aoStateSave', oInit.fnStateSaveCallback, 'user' ); -_fnCallbackReg( oSettings, 'aoStateLoad', oInit.fnStateLoadCallback, 'user' ); +_fnCallbackReg( oSettings, 'aoStateSaveParams', oInit.fnStateSaveParams, 'user' ); +_fnCallbackReg( oSettings, 'aoStateLoadParams', oInit.fnStateLoadParams, 'user' ); +_fnCallbackReg( oSettings, 'aoStateLoaded', oInit.fnStateLoaded, 'user' ); _fnCallbackReg( oSettings, 'aoRowCallback', oInit.fnRowCallback, 'user' ); _fnCallbackReg( oSettings, 'aoRowCreatedCallback', oInit.fnCreatedRow, 'user' ); _fnCallbackReg( oSettings, 'aoHeaderCallback', oInit.fnHeaderCallback, 'user' ); diff --git a/media/src/core/core.state.js b/media/src/core/core.state.js index 1a6a8bb4..fa8b80b3 100644 --- a/media/src/core/core.state.js +++ b/media/src/core/core.state.js @@ -12,60 +12,27 @@ function _fnSaveState ( oSettings ) return; } - /* xxx - This is horrible! What we really want to do is use a proper object and - * pass that around - but jQuery doesn't have a toJson option. Either need to use - * $.param or JSON.stringify or something else - */ - /* Store the interesting variables */ - var i, iLen, sTmp; - var sValue = "{"; - sValue += '"iCreate":'+ new Date().getTime()+','; - sValue += '"iStart":'+ (oSettings.oScroll.bInfinite ? 0 : oSettings._iDisplayStart)+','; - sValue += '"iEnd":'+ (oSettings.oScroll.bInfinite ? oSettings._iDisplayLength : oSettings._iDisplayEnd)+','; - sValue += '"iLength":'+ oSettings._iDisplayLength+','; - sValue += '"sFilter":"'+ encodeURIComponent(oSettings.oPreviousSearch.sSearch)+'",'; - sValue += '"sFilterEsc":'+ !oSettings.oPreviousSearch.bRegex+','; - - sValue += '"aaSorting":[ '; - for ( i=0 ; i