mirror of
https://github.com/DataTables/DataTables.git
synced 2025-03-15 16:29:16 +01:00
Alter the extending of the initialisation parameter with the defaults a little such that objects are deep copied and arrays are not (code needs tidied a little - want to get it passing all unit tests first). The thing here is that we can't use jQuery's $.extend for a full deep copy since we don't want to deep copy arrays (for example aaSorting, where the default sort would always be applied), but we do want to deep copy objects (and not just take a reference to the default object). Thus we can't use $.extend :-(.
This commit is contained in:
parent
94539913a5
commit
6a7a7151b8
87
media/js/jquery.dataTables.js
vendored
87
media/js/jquery.dataTables.js
vendored
@ -57,7 +57,7 @@
|
|||||||
* } );
|
* } );
|
||||||
* } );
|
* } );
|
||||||
*/
|
*/
|
||||||
var DataTable = function( oInit )
|
window.DataTable = function( oInit )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
@ -2507,6 +2507,27 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// xxx - needs to be called for Ajax as well
|
||||||
|
function _fnLanguageCompat( oLanguage )
|
||||||
|
{
|
||||||
|
/* Backwards compatibility - if there is no sEmptyTable given, then use the same as
|
||||||
|
* sZeroRecords - assuming that is given.
|
||||||
|
*/
|
||||||
|
if ( typeof oLanguage.sEmptyTable == 'undefined' &&
|
||||||
|
typeof oLanguage.sZeroRecords != 'undefined' )
|
||||||
|
{
|
||||||
|
_fnMap( oLanguage, oLanguage, 'sZeroRecords', 'sEmptyTable' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Likewise with loading records */
|
||||||
|
if ( typeof oLanguage.sLoadingRecords == 'undefined' &&
|
||||||
|
typeof oLanguage.sZeroRecords != 'undefined' )
|
||||||
|
{
|
||||||
|
_fnMap( oLanguage, oLanguage, 'sZeroRecords', 'sLoadingRecords' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy language variables from remote object to a local one
|
* Copy language variables from remote object to a local one
|
||||||
* @param {object} oSettings dataTables settings object
|
* @param {object} oSettings dataTables settings object
|
||||||
@ -2518,21 +2539,6 @@
|
|||||||
{
|
{
|
||||||
oSettings.oLanguage = $.extend( true, oSettings.oLanguage, oLanguage );
|
oSettings.oLanguage = $.extend( true, oSettings.oLanguage, oLanguage );
|
||||||
|
|
||||||
/* Backwards compatibility - if there is no sEmptyTable given, then use the same as
|
|
||||||
* sZeroRecords - assuming that is given.
|
|
||||||
*/
|
|
||||||
if ( typeof oLanguage.sEmptyTable == 'undefined' &&
|
|
||||||
typeof oLanguage.sZeroRecords != 'undefined' )
|
|
||||||
{
|
|
||||||
_fnMap( oSettings.oLanguage, oLanguage, 'sZeroRecords', 'sEmptyTable' );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Likewise with loading records */
|
|
||||||
if ( typeof oLanguage.sLoadingRecords == 'undefined' &&
|
|
||||||
typeof oLanguage.sZeroRecords != 'undefined' )
|
|
||||||
{
|
|
||||||
_fnMap( oSettings.oLanguage, oLanguage, 'sZeroRecords', 'sLoadingRecords' );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( bInit )
|
if ( bInit )
|
||||||
{
|
{
|
||||||
@ -5773,13 +5779,50 @@
|
|||||||
oSettings.sDestroyWidth = $(this).width();
|
oSettings.sDestroyWidth = $(this).width();
|
||||||
|
|
||||||
|
|
||||||
|
if (typeof oInit === 'undefined' || oInit === null)
|
||||||
|
{
|
||||||
|
oInit = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Need a backwards compatibility function for mapping old parameters to the new - specifically
|
||||||
|
// the language records. Perhaps should have an event? Sounds sensible...
|
||||||
|
|
||||||
|
if ( typeof oInit.oLanguage != 'undefined' ) {
|
||||||
|
_fnLanguageCompat( oInit.oLanguage );
|
||||||
|
}
|
||||||
|
|
||||||
|
var oFullInit = $.extend( true, {}, DataTable.models.oInit );
|
||||||
|
|
||||||
|
for ( var initProp in oFullInit ) {
|
||||||
|
if ( oFullInit.hasOwnProperty(initProp) ) {
|
||||||
|
if ( typeof oInit[initProp] != 'undefined' ) {
|
||||||
|
if ( typeof oInit[initProp] == 'object' && $.isArray(oInit[initProp]) === false ) {
|
||||||
|
$.extend( true, oFullInit[initProp], oInit[initProp] );
|
||||||
|
} else {
|
||||||
|
oFullInit[initProp] = oInit[initProp];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
oInit = oFullInit;
|
||||||
|
|
||||||
|
// Can't use deep extend as we don't want to copy the array values
|
||||||
|
// Can't use shallow extend as that copies object references (i.e. the default object IS the object in use)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Store the initialisation object that was passed in, useful for debugging */
|
/* Store the initialisation object that was passed in, useful for debugging */
|
||||||
oSettings.oInit = oInit;
|
//oSettings.oInit = oInit;
|
||||||
|
//
|
||||||
oInit = (typeof oInit === 'undefined' || oInit === null) ?
|
//console.log( DataTable.models.oInit.oSearch.sSearch );
|
||||||
$.extend( true, {}, DataTable.models.oInit ) :
|
//oInit = (typeof oInit === 'undefined' || oInit === null) ?
|
||||||
$.extend( true, {}, DataTable.models.oInit, oInit );
|
// $.extend( {}, DataTable.models.oInit ) :
|
||||||
|
// $.extend( {}, DataTable.models.oInit, oInit );
|
||||||
|
//console.log( oInit.oSearch === DataTable.models.oInit.oSearch );
|
||||||
|
//console.log( oInit.oSearch === DataTable.models.oSearch );
|
||||||
|
//console.log( DataTable.models.oSearch === DataTable.models.oInit.oSearch );
|
||||||
|
|
||||||
_fnMap( oSettings.oFeatures, oInit, "bPaginate" );
|
_fnMap( oSettings.oFeatures, oInit, "bPaginate" );
|
||||||
_fnMap( oSettings.oFeatures, oInit, "bLengthChange" );
|
_fnMap( oSettings.oFeatures, oInit, "bLengthChange" );
|
||||||
|
@ -57,7 +57,7 @@
|
|||||||
* } );
|
* } );
|
||||||
* } );
|
* } );
|
||||||
*/
|
*/
|
||||||
var DataTable = function( oInit )
|
window.DataTable = function( oInit )
|
||||||
{
|
{
|
||||||
require('core.columns.js');
|
require('core.columns.js');
|
||||||
require('core.data.js');
|
require('core.data.js');
|
||||||
|
@ -84,13 +84,50 @@ oSettings.oApi = _that.oApi;
|
|||||||
oSettings.sDestroyWidth = $(this).width();
|
oSettings.sDestroyWidth = $(this).width();
|
||||||
|
|
||||||
|
|
||||||
|
if (typeof oInit === 'undefined' || oInit === null)
|
||||||
|
{
|
||||||
|
oInit = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Need a backwards compatibility function for mapping old parameters to the new - specifically
|
||||||
|
// the language records. Perhaps should have an event? Sounds sensible...
|
||||||
|
|
||||||
|
if ( typeof oInit.oLanguage != 'undefined' ) {
|
||||||
|
_fnLanguageCompat( oInit.oLanguage );
|
||||||
|
}
|
||||||
|
|
||||||
|
var oFullInit = $.extend( true, {}, DataTable.models.oInit );
|
||||||
|
|
||||||
|
for ( var initProp in oFullInit ) {
|
||||||
|
if ( oFullInit.hasOwnProperty(initProp) ) {
|
||||||
|
if ( typeof oInit[initProp] != 'undefined' ) {
|
||||||
|
if ( typeof oInit[initProp] == 'object' && $.isArray(oInit[initProp]) === false ) {
|
||||||
|
$.extend( true, oFullInit[initProp], oInit[initProp] );
|
||||||
|
} else {
|
||||||
|
oFullInit[initProp] = oInit[initProp];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
oInit = oFullInit;
|
||||||
|
|
||||||
|
// Can't use deep extend as we don't want to copy the array values
|
||||||
|
// Can't use shallow extend as that copies object references (i.e. the default object IS the object in use)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Store the initialisation object that was passed in, useful for debugging */
|
/* Store the initialisation object that was passed in, useful for debugging */
|
||||||
oSettings.oInit = oInit;
|
//oSettings.oInit = oInit;
|
||||||
|
//
|
||||||
oInit = (typeof oInit === 'undefined' || oInit === null) ?
|
//console.log( DataTable.models.oInit.oSearch.sSearch );
|
||||||
$.extend( true, {}, DataTable.models.oInit ) :
|
//oInit = (typeof oInit === 'undefined' || oInit === null) ?
|
||||||
$.extend( true, {}, DataTable.models.oInit, oInit );
|
// $.extend( {}, DataTable.models.oInit ) :
|
||||||
|
// $.extend( {}, DataTable.models.oInit, oInit );
|
||||||
|
//console.log( oInit.oSearch === DataTable.models.oInit.oSearch );
|
||||||
|
//console.log( oInit.oSearch === DataTable.models.oSearch );
|
||||||
|
//console.log( DataTable.models.oSearch === DataTable.models.oInit.oSearch );
|
||||||
|
|
||||||
_fnMap( oSettings.oFeatures, oInit, "bPaginate" );
|
_fnMap( oSettings.oFeatures, oInit, "bPaginate" );
|
||||||
_fnMap( oSettings.oFeatures, oInit, "bLengthChange" );
|
_fnMap( oSettings.oFeatures, oInit, "bLengthChange" );
|
||||||
|
@ -131,6 +131,27 @@ function _fnInitComplete ( oSettings, json )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// xxx - needs to be called for Ajax as well
|
||||||
|
function _fnLanguageCompat( oLanguage )
|
||||||
|
{
|
||||||
|
/* Backwards compatibility - if there is no sEmptyTable given, then use the same as
|
||||||
|
* sZeroRecords - assuming that is given.
|
||||||
|
*/
|
||||||
|
if ( typeof oLanguage.sEmptyTable == 'undefined' &&
|
||||||
|
typeof oLanguage.sZeroRecords != 'undefined' )
|
||||||
|
{
|
||||||
|
_fnMap( oLanguage, oLanguage, 'sZeroRecords', 'sEmptyTable' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Likewise with loading records */
|
||||||
|
if ( typeof oLanguage.sLoadingRecords == 'undefined' &&
|
||||||
|
typeof oLanguage.sZeroRecords != 'undefined' )
|
||||||
|
{
|
||||||
|
_fnMap( oLanguage, oLanguage, 'sZeroRecords', 'sLoadingRecords' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy language variables from remote object to a local one
|
* Copy language variables from remote object to a local one
|
||||||
* @param {object} oSettings dataTables settings object
|
* @param {object} oSettings dataTables settings object
|
||||||
@ -142,21 +163,6 @@ function _fnLanguageProcess( oSettings, oLanguage, bInit )
|
|||||||
{
|
{
|
||||||
oSettings.oLanguage = $.extend( true, oSettings.oLanguage, oLanguage );
|
oSettings.oLanguage = $.extend( true, oSettings.oLanguage, oLanguage );
|
||||||
|
|
||||||
/* Backwards compatibility - if there is no sEmptyTable given, then use the same as
|
|
||||||
* sZeroRecords - assuming that is given.
|
|
||||||
*/
|
|
||||||
if ( typeof oLanguage.sEmptyTable == 'undefined' &&
|
|
||||||
typeof oLanguage.sZeroRecords != 'undefined' )
|
|
||||||
{
|
|
||||||
_fnMap( oSettings.oLanguage, oLanguage, 'sZeroRecords', 'sEmptyTable' );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Likewise with loading records */
|
|
||||||
if ( typeof oLanguage.sLoadingRecords == 'undefined' &&
|
|
||||||
typeof oLanguage.sZeroRecords != 'undefined' )
|
|
||||||
{
|
|
||||||
_fnMap( oSettings.oLanguage, oLanguage, 'sZeroRecords', 'sLoadingRecords' );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( bInit )
|
if ( bInit )
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user