From 505a2b37a318172aed12992eb3f9a3c845b17d49 Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Fri, 25 Apr 2014 16:42:36 +0100 Subject: [PATCH] Dev: Minor changes to reduce code size. - This commit trims about 400 bytes off the min library size --- .datatables-commit-sync | 2 +- bower.json | 2 +- composer.json | 2 +- dataTables.jquery.json | 2 +- media/js/jquery.dataTables.js | 154 +++++++++++++++------------------- package.json | 2 +- 6 files changed, 74 insertions(+), 90 deletions(-) diff --git a/.datatables-commit-sync b/.datatables-commit-sync index 39231471..60904fee 100644 --- a/.datatables-commit-sync +++ b/.datatables-commit-sync @@ -1 +1 @@ -c130b9f411733d6d400b07d3187efe3334ea2ed6 +94a1eb9efabca609076f75f8fc4ce05fdc00f6d4 diff --git a/bower.json b/bower.json index 7422f7d9..4c0270b7 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "datatables", - "version": "1.10.0-beta.3.dev", + "version": "1.10.0-rc.1", "main": [ "media/js/jquery.dataTables.js", "media/css/jquery.dataTables.css" diff --git a/composer.json b/composer.json index 847e97ad..caae7934 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "datatables/datatables", - "version": "1.10.0-beta.3.dev", + "version": "1.10.0-rc.1", "description": "DataTables is a plug-in for the jQuery Javascript library. It is a highly flexible tool, based upon the foundations of progressive enhancement, which will add advanced interaction controls to any HTML table.", "homepage": "http://www.datatables.net/", "author": "SpryMedia", diff --git a/dataTables.jquery.json b/dataTables.jquery.json index 9c86db1d..549f2d1d 100644 --- a/dataTables.jquery.json +++ b/dataTables.jquery.json @@ -1,6 +1,6 @@ { "name": "DataTables", - "version": "1.10.0-beta.3.dev", + "version": "1.10.0-rc.1", "description": "DataTables enhances HTML tables with the ability to sort, filter and page the data in the table very easily. It provides a comprehensive API and set of configuration options, allowing you to consume data from virtually any data source.", "homepage": "http://datatables.net/", "docs": "http://datatables.net/", diff --git a/media/js/jquery.dataTables.js b/media/js/jquery.dataTables.js index 2f7dbf70..9224df37 100644 --- a/media/js/jquery.dataTables.js +++ b/media/js/jquery.dataTables.js @@ -505,6 +505,41 @@ n.remove(); } + + /** + * Array.prototype reduce[Right] method, used for browsers which don't support + * JS 1.6. Done this way to reduce code size, since we iterate either way + * @param {object} settings dataTables settings object + * @memberof DataTable#oApi + */ + function _fnReduce ( that, fn, init, start, end, inc ) + { + var + i = start, + value, + isSet = false; + + if ( init !== undefined ) { + value = init; + isSet = true; + } + + while ( i !== end ) { + if ( ! that.hasOwnProperty(i) ) { + continue; + } + + value = isSet ? + fn( value, that[i], i, that ) : + that[i]; + + isSet = true; + i += inc; + } + + return value; + } + /** * Add a column to the list used for the table with default values * @param {object} oSettings dataTables settings object @@ -513,6 +548,7 @@ */ function _fnAddColumn( oSettings, nTh ) { + // Add column to aoColumns array var oDefaults = DataTable.defaults.column; var iCol = oSettings.aoColumns.length; var oCol = $.extend( {}, DataTable.models.oColumn, oDefaults, { @@ -524,33 +560,13 @@ } ); oSettings.aoColumns.push( oCol ); - /* Add a column specific filter */ - if ( oSettings.aoPreSearchCols[ iCol ] === undefined || oSettings.aoPreSearchCols[ iCol ] === null ) - { - oSettings.aoPreSearchCols[ iCol ] = $.extend( true, {}, DataTable.models.oSearch ); - } - else - { - var oPre = oSettings.aoPreSearchCols[ iCol ]; + // Add search object for column specific search. Note that the `searchCols[ iCol ]` + // passed into extend can be undefined. This allows the user to give a default + // with only some of the parameters defined, and also not give a default + var searchCols = oSettings.aoPreSearchCols; + searchCols[ iCol ] = $.extend( {}, DataTable.models.oSearch, searchCols[ iCol ] ); - /* Don't require that the user must specify bRegex, bSmart or bCaseInsensitive */ - if ( oPre.bRegex === undefined ) - { - oPre.bRegex = true; - } - - if ( oPre.bSmart === undefined ) - { - oPre.bSmart = true; - } - - if ( oPre.bCaseInsensitive === undefined ) - { - oPre.bCaseInsensitive = true; - } - } - - /* Use the column options function to initialise classes etc */ + // Use the default column options function to initialise classes etc _fnColumnOptions( oSettings, iCol, null ); } @@ -776,6 +792,11 @@ } + /** + * Calculate the 'type' of a column + * @param {object} settings dataTables settings object + * @memberof DataTable#oApi + */ function _fnColumnTypes ( settings ) { var columns = settings.aoColumns; @@ -843,6 +864,7 @@ function _fnApplyColumnDefs( oSettings, aoColDefs, aoCols, fn ) { var i, iLen, j, jLen, k, kLen, def; + var columns = oSettings.aoColumns; // Column definitions with aTargets if ( aoColDefs ) @@ -867,7 +889,7 @@ if ( typeof aTargets[j] === 'number' && aTargets[j] >= 0 ) { /* Add columns that we don't yet know about */ - while( oSettings.aoColumns.length <= aTargets[j] ) + while( columns.length <= aTargets[j] ) { _fnAddColumn( oSettings ); } @@ -878,15 +900,15 @@ else if ( typeof aTargets[j] === 'number' && aTargets[j] < 0 ) { /* Negative integer, right to left column counting */ - fn( oSettings.aoColumns.length+aTargets[j], def ); + fn( columns.length+aTargets[j], def ); } else if ( typeof aTargets[j] === 'string' ) { /* Class name matching on TH element */ - for ( k=0, kLen=oSettings.aoColumns.length ; k 0 ) { oSettings.nTFoot = tfoot[0]; @@ -6685,57 +6710,16 @@ // Does not return an API instance reduce: __arrayProto.reduce || function ( fn, init ) { - var - value, - isSet = false; - - if ( arguments.length > 1 ) { - value = init; - isSet = true; - } - - for ( var i=0, ien=this.length ; i 1 ) { - value = init; - isSet = true; - } - - for ( var i=this.length-1 ; i>=0 ; i-- ) { - if ( ! this.hasOwnProperty(i) ) { - continue; - } - - value = isSet ? - fn( value, this[i], i, this ) : - this[i]; - - isSet = true; - } - - return value; + return _fnReduce( this, fn, init, this.length-1, -1, -1 ); }, + reverse: __arrayProto.reverse, @@ -10228,7 +10212,7 @@ "fnStateLoadCallback": function ( settings ) { try { return JSON.parse( - localStorage.getItem('DataTables_'+settings.sInstance+'_'+window.location.pathname) + localStorage.getItem('DataTables_'+settings.sInstance+'_'+location.pathname) ); } catch (e) {} }, @@ -10328,7 +10312,7 @@ "fnStateSaveCallback": function ( settings, data ) { try { localStorage.setItem( - 'DataTables_'+settings.sInstance+'_'+window.location.pathname, + 'DataTables_'+settings.sInstance+'_'+location.pathname, JSON.stringify(data) ); } catch (e) {} diff --git a/package.json b/package.json index 6e4c6be0..c16f3f83 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "DataTables", - "version": "1.10.0-beta.3.dev", + "version": "1.10.0-rc.1", "title": "DataTables", "author": { "name": "Allan Jardine",