mirror of
https://github.com/DataTables/DataTables.git
synced 2024-11-29 11:24:10 +01:00
Dev - refactoring _fnMap to improve compression. Saves about 500 bytes
This commit is contained in:
parent
fd10532f94
commit
c1eeed8e1a
@ -2,7 +2,7 @@
|
|||||||
var i=0, iLen, j, jLen, k, kLen;
|
var i=0, iLen, j, jLen, k, kLen;
|
||||||
var sId = this.getAttribute( 'id' );
|
var sId = this.getAttribute( 'id' );
|
||||||
var bInitHandedOff = false;
|
var bInitHandedOff = false;
|
||||||
var bUsePassedData = false;
|
var defaults = DataTable.defaults
|
||||||
var oInitEmpty = oInit === undefined ? true : false;
|
var oInitEmpty = oInit === undefined ? true : false;
|
||||||
|
|
||||||
|
|
||||||
@ -14,37 +14,38 @@ if ( this.nodeName.toLowerCase() != 'table' )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Convert the camel-case defaults to Hungarian */
|
/* Convert the camel-case defaults to Hungarian */
|
||||||
_fnCamelToHungarian( DataTable.defaults, DataTable.defaults, true );
|
_fnCamelToHungarian( defaults, defaults, true );
|
||||||
_fnCamelToHungarian( DataTable.defaults.column, DataTable.defaults.column, true );
|
_fnCamelToHungarian( defaults.column, defaults.column, true );
|
||||||
|
|
||||||
/* Setting up the initialisation object */
|
/* Setting up the initialisation object */
|
||||||
if ( !oInit )
|
if ( !oInit )
|
||||||
{
|
{
|
||||||
oInit = {};
|
oInit = {};
|
||||||
}
|
}
|
||||||
_fnCamelToHungarian( DataTable.defaults, oInit );
|
_fnCamelToHungarian( defaults, oInit );
|
||||||
|
|
||||||
/* Check to see if we are re-initialising a table */
|
/* Check to see if we are re-initialising a table */
|
||||||
for ( i=0, iLen=DataTable.settings.length ; i<iLen ; i++ )
|
var allSettings = DataTable.settings;
|
||||||
|
for ( i=0, iLen=allSettings.length ; i<iLen ; i++ )
|
||||||
{
|
{
|
||||||
/* Base check on table node */
|
/* Base check on table node */
|
||||||
if ( DataTable.settings[i].nTable == this )
|
if ( allSettings[i].nTable == this )
|
||||||
{
|
{
|
||||||
var bRetrieve = oInit.bRetrieve !== undefined ? oInit.bRetrieve : DataTable.defaults.bRetrieve;
|
var bRetrieve = oInit.bRetrieve !== undefined ? oInit.bRetrieve : defaults.bRetrieve;
|
||||||
var bDestroy = oInit.bDestroy !== undefined ? oInit.bDestroy : DataTable.defaults.bDestroy;
|
var bDestroy = oInit.bDestroy !== undefined ? oInit.bDestroy : defaults.bDestroy;
|
||||||
|
|
||||||
if ( oInitEmpty || bRetrieve )
|
if ( oInitEmpty || bRetrieve )
|
||||||
{
|
{
|
||||||
return DataTable.settings[i].oInstance;
|
return allSettings[i].oInstance;
|
||||||
}
|
}
|
||||||
else if ( bDestroy )
|
else if ( bDestroy )
|
||||||
{
|
{
|
||||||
DataTable.settings[i].oInstance.fnDestroy();
|
allSettings[i].oInstance.fnDestroy();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_fnLog( DataTable.settings[i], 0, 'Cannot reinitialise DataTable', 3 );
|
_fnLog( allSettings[i], 0, 'Cannot reinitialise DataTable', 3 );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -54,9 +55,9 @@ for ( i=0, iLen=DataTable.settings.length ; i<iLen ; i++ )
|
|||||||
* instance by simply deleting it. This is under the assumption that the table has been
|
* instance by simply deleting it. This is under the assumption that the table has been
|
||||||
* destroyed by other methods. Anyone using non-id selectors will need to do this manually
|
* destroyed by other methods. Anyone using non-id selectors will need to do this manually
|
||||||
*/
|
*/
|
||||||
if ( DataTable.settings[i].sTableId == this.id )
|
if ( allSettings[i].sTableId == this.id )
|
||||||
{
|
{
|
||||||
DataTable.settings.splice( i, 1 );
|
allSettings.splice( i, 1 );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,7 +78,7 @@ var oSettings = $.extend( true, {}, DataTable.models.oSettings, {
|
|||||||
"sInstance": sId,
|
"sInstance": sId,
|
||||||
"sTableId": sId
|
"sTableId": sId
|
||||||
} );
|
} );
|
||||||
DataTable.settings.push( oSettings );
|
allSettings.push( oSettings );
|
||||||
|
|
||||||
// Need to add the instance after the instance after the settings object has been added
|
// Need to add the instance after the instance after the settings object has been added
|
||||||
// to the settings array, so we can self reference the table instance if more than one
|
// to the settings array, so we can self reference the table instance if more than one
|
||||||
@ -96,49 +97,55 @@ if ( oInit.aLengthMenu && ! oInit.iDisplayLength )
|
|||||||
oInit.aLengthMenu[0][0] : oInit.aLengthMenu[0];
|
oInit.aLengthMenu[0][0] : oInit.aLengthMenu[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
oInit = _fnExtend( $.extend(true, {}, DataTable.defaults), oInit );
|
oInit = _fnExtend( $.extend(true, {}, defaults), oInit );
|
||||||
|
|
||||||
// Map the initialisation options onto the settings object
|
// Map the initialisation options onto the settings object
|
||||||
_fnMap( oSettings.oFeatures, oInit, "bPaginate" );
|
_fnMap( oSettings.oFeatures, oInit, [
|
||||||
_fnMap( oSettings.oFeatures, oInit, "bLengthChange" );
|
"bPaginate",
|
||||||
_fnMap( oSettings.oFeatures, oInit, "bFilter" );
|
"bLengthChange",
|
||||||
_fnMap( oSettings.oFeatures, oInit, "bSort" );
|
"bFilter",
|
||||||
_fnMap( oSettings.oFeatures, oInit, "bSortMulti" );
|
"bSort",
|
||||||
_fnMap( oSettings.oFeatures, oInit, "bInfo" );
|
"bSortMulti",
|
||||||
_fnMap( oSettings.oFeatures, oInit, "bProcessing" );
|
"bInfo",
|
||||||
_fnMap( oSettings.oFeatures, oInit, "bAutoWidth" );
|
"bProcessing",
|
||||||
_fnMap( oSettings.oFeatures, oInit, "bSortClasses" );
|
"bAutoWidth",
|
||||||
_fnMap( oSettings.oFeatures, oInit, "bServerSide" );
|
"bSortClasses",
|
||||||
_fnMap( oSettings.oFeatures, oInit, "bDeferRender" );
|
"bServerSide",
|
||||||
_fnMap( oSettings.oScroll, oInit, "sScrollX", "sX" );
|
"bDeferRender"
|
||||||
_fnMap( oSettings.oScroll, oInit, "sScrollXInner", "sXInner" );
|
] );
|
||||||
_fnMap( oSettings.oScroll, oInit, "sScrollY", "sY" );
|
_fnMap( oSettings, oInit, [
|
||||||
_fnMap( oSettings.oScroll, oInit, "bScrollCollapse", "bCollapse" );
|
"asStripeClasses",
|
||||||
_fnMap( oSettings.oScroll, oInit, "bScrollInfinite", "bInfinite" );
|
"ajax",
|
||||||
_fnMap( oSettings.oScroll, oInit, "iScrollLoadGap", "iLoadGap" );
|
"fnServerData",
|
||||||
_fnMap( oSettings.oScroll, oInit, "bScrollAutoCss", "bAutoCss" );
|
"fnFormatNumber",
|
||||||
_fnMap( oSettings, oInit, "asStripeClasses" );
|
"sServerMethod",
|
||||||
_fnMap( oSettings, oInit, "ajax" );
|
"aaSorting",
|
||||||
_fnMap( oSettings, oInit, "fnServerData" );
|
"aaSortingFixed",
|
||||||
_fnMap( oSettings, oInit, "fnFormatNumber" );
|
"aLengthMenu",
|
||||||
_fnMap( oSettings, oInit, "sServerMethod" );
|
"sPaginationType",
|
||||||
_fnMap( oSettings, oInit, "aaSorting" );
|
"sAjaxSource",
|
||||||
_fnMap( oSettings, oInit, "aaSortingFixed" );
|
"sAjaxDataProp",
|
||||||
_fnMap( oSettings, oInit, "aLengthMenu" );
|
"iStateDuration",
|
||||||
_fnMap( oSettings, oInit, "sPaginationType" );
|
"sDom",
|
||||||
_fnMap( oSettings, oInit, "sAjaxSource" );
|
"bSortCellsTop",
|
||||||
_fnMap( oSettings, oInit, "sAjaxDataProp" );
|
"iTabIndex",
|
||||||
_fnMap( oSettings, oInit, "iCookieDuration", "iStateDuration" ); // backwards compat
|
"fnStateLoadCallback",
|
||||||
_fnMap( oSettings, oInit, "iStateDuration" );
|
"fnStateSaveCallback",
|
||||||
_fnMap( oSettings, oInit, "sDom" );
|
[ "iCookieDuration", "iStateDuration" ], // backwards compat
|
||||||
_fnMap( oSettings, oInit, "bSortCellsTop" );
|
[ "oSearch", "oPreviousSearch" ],
|
||||||
_fnMap( oSettings, oInit, "iTabIndex" );
|
[ "aoSearchCols", "aoPreSearchCols" ],
|
||||||
_fnMap( oSettings, oInit, "oSearch", "oPreviousSearch" );
|
[ "iDisplayLength", "_iDisplayLength" ],
|
||||||
_fnMap( oSettings, oInit, "aoSearchCols", "aoPreSearchCols" );
|
[ "bJQueryUI", "bJUI" ]
|
||||||
_fnMap( oSettings, oInit, "iDisplayLength", "_iDisplayLength" );
|
] );
|
||||||
_fnMap( oSettings, oInit, "bJQueryUI", "bJUI" );
|
_fnMap( oSettings.oScroll, oInit, [
|
||||||
_fnMap( oSettings, oInit, "fnStateLoadCallback" );
|
[ "sScrollX", "sX" ],
|
||||||
_fnMap( oSettings, oInit, "fnStateSaveCallback" );
|
[ "sScrollXInner", "sXInner" ],
|
||||||
|
[ "sScrollY", "sY" ],
|
||||||
|
[ "bScrollCollapse", "bCollapse" ],
|
||||||
|
[ "bScrollInfinite", "bInfinite" ],
|
||||||
|
[ "iScrollLoadGap", "iLoadGap" ],
|
||||||
|
[ "bScrollAutoCss", "bAutoCss" ]
|
||||||
|
] );
|
||||||
_fnMap( oSettings.oLanguage, oInit, "fnInfoCallback" );
|
_fnMap( oSettings.oLanguage, oInit, "fnInfoCallback" );
|
||||||
|
|
||||||
/* Callback functions which are array driven */
|
/* Callback functions which are array driven */
|
||||||
@ -162,7 +169,7 @@ if ( oInit.bJQueryUI )
|
|||||||
*/
|
*/
|
||||||
$.extend( oSettings.oClasses, DataTable.ext.oJUIClasses, oInit.oClasses );
|
$.extend( oSettings.oClasses, DataTable.ext.oJUIClasses, oInit.oClasses );
|
||||||
|
|
||||||
if ( oInit.sDom === DataTable.defaults.sDom && DataTable.defaults.sDom === "lfrtip" )
|
if ( oInit.sDom === defaults.sDom && defaults.sDom === "lfrtip" )
|
||||||
{
|
{
|
||||||
/* Set the DOM to use a layout suitable for jQuery UI's theming */
|
/* Set the DOM to use a layout suitable for jQuery UI's theming */
|
||||||
oSettings.sDom = '<"H"lfr>t<"F"ip>';
|
oSettings.sDom = '<"H"lfr>t<"F"ip>';
|
||||||
@ -202,11 +209,6 @@ if ( oInit.iDeferLoading !== null )
|
|||||||
oSettings._iRecordsTotal = tmp ? oInit.iDeferLoading[1] : oInit.iDeferLoading;
|
oSettings._iRecordsTotal = tmp ? oInit.iDeferLoading[1] : oInit.iDeferLoading;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( oInit.aaData !== null )
|
|
||||||
{
|
|
||||||
bUsePassedData = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Language definitions */
|
/* Language definitions */
|
||||||
if ( oInit.oLanguage.sUrl !== "" )
|
if ( oInit.oLanguage.sUrl !== "" )
|
||||||
{
|
{
|
||||||
@ -217,7 +219,7 @@ if ( oInit.oLanguage.sUrl !== "" )
|
|||||||
oSettings.oLanguage.sUrl = oInit.oLanguage.sUrl;
|
oSettings.oLanguage.sUrl = oInit.oLanguage.sUrl;
|
||||||
$.getJSON( oSettings.oLanguage.sUrl, null, function( json ) {
|
$.getJSON( oSettings.oLanguage.sUrl, null, function( json ) {
|
||||||
_fnLanguageCompat( json );
|
_fnLanguageCompat( json );
|
||||||
_fnCamelToHungarian( DataTable.defaults.oLanguage, json );
|
_fnCamelToHungarian( defaults.oLanguage, json );
|
||||||
$.extend( true, oSettings.oLanguage, oInit.oLanguage, json );
|
$.extend( true, oSettings.oLanguage, oInit.oLanguage, json );
|
||||||
_fnInitialise( oSettings );
|
_fnInitialise( oSettings );
|
||||||
} );
|
} );
|
||||||
@ -433,7 +435,7 @@ if ( tfoot.length > 0 )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check if there is data passing into the constructor */
|
/* Check if there is data passing into the constructor */
|
||||||
if ( bUsePassedData )
|
if ( oInit.aaData )
|
||||||
{
|
{
|
||||||
for ( i=0 ; i<oInit.aaData.length ; i++ )
|
for ( i=0 ; i<oInit.aaData.length ; i++ )
|
||||||
{
|
{
|
||||||
|
@ -50,21 +50,33 @@ function _fnLog( settings, level, msg, tn )
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* See if a property is defined on one object, if so assign it to the other object
|
* See if a property is defined on one object, if so assign it to the other object
|
||||||
* @param {object} oRet target object
|
* @param {object} ret target object
|
||||||
* @param {object} oSrc source object
|
* @param {object} src source object
|
||||||
* @param {string} sName property
|
* @param {string} name property
|
||||||
* @param {string} [sMappedName] name to map too - optional, sName used if not given
|
* @param {string} [mappedName] name to map too - optional, name used if not given
|
||||||
* @memberof DataTable#oApi
|
* @memberof DataTable#oApi
|
||||||
*/
|
*/
|
||||||
function _fnMap( oRet, oSrc, sName, sMappedName )
|
function _fnMap( ret, src, name, mappedName )
|
||||||
{
|
{
|
||||||
if ( sMappedName === undefined )
|
if ( $.isArray( name ) ) {
|
||||||
{
|
$.each( name, function (i, val) {
|
||||||
sMappedName = sName;
|
if ( $.isArray( val ) ) {
|
||||||
|
_fnMap( ret, src, val[0], val[1] );
|
||||||
}
|
}
|
||||||
if ( oSrc[sName] !== undefined )
|
else {
|
||||||
{
|
_fnMap( ret, src, val[0] );
|
||||||
oRet[sMappedName] = oSrc[sName];
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( mappedName === undefined ) {
|
||||||
|
mappedName = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( src[name] !== undefined ) {
|
||||||
|
ret[mappedName] = src[name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user