diff --git a/media/src/DataTables.js b/media/src/DataTables.js index 74c050e1..23e09d4e 100644 --- a/media/src/DataTables.js +++ b/media/src/DataTables.js @@ -108,7 +108,7 @@ return this; }; - require('api.core.js'); + require('api.base.js'); require('api.table.js'); require('api.draw.js'); require('api.page.js'); @@ -120,6 +120,7 @@ require('api.columns.js'); require('api.search.js'); require('api.static.js'); + require('api.core.js'); /** * Version string for plug-ins to check compatibility. Allowed format is diff --git a/media/src/api/api.base.js b/media/src/api/api.base.js new file mode 100644 index 00000000..fed37c37 --- /dev/null +++ b/media/src/api/api.base.js @@ -0,0 +1,608 @@ + + +(/** @lends */function() { + + +/** + * Computed structure of the DataTables API, defined by the options passed to + * `DataTable.Api.register()` when building the API. + * + * The structure is built in order to speed creation and extension of the Api + * objects since the extensions are effectively pre-parsed. + * + * The array is an array of objects with the following structure, where this + * base array represents the Api prototype base: + * + * [ + * { + * name: 'data' -- string - Property name + * val: function () {}, -- function - Api method (or undefined if just an object + * methodExt: [ ... ], -- array - Array of Api object definitions to extend the method result + * propExt: [ ... ] -- array - Array of Api object definitions to extend the property + * }, + * { + * name: 'row' + * val: {}, + * methodExt: [ ... ], + * propExt: [ + * { + * name: 'data' + * val: function () {}, + * methodExt: [ ... ], + * propExt: [ ... ] + * }, + * ... + * ] + * } + * ] + * + * @type {Array} + * @ignore + */ +var _apiStruct = []; + + +/** + * Api object reference. + * + * @type object + * @ignore + */ +var _Api; + + +/** + * `Array.prototype` reference. + * + * @type object + * @ignore + */ +var _arrayProto = Array.prototype; + + + + +/** + * Abstraction for `context` parameter of the `Api` constructor to allow it to + * take several different forms for ease of use. + * + * Each of the input parameter types will be converted to a DataTables settings + * object where possible. + * + * @param {string|node|jQuery|object} mixed DataTable identifier. Can be one + * of: + * + * * `string` - jQuery selector. Any DataTables' matching the given selector + * with be found and used. + * * `node` - `TABLE` node which has already been formed into a DataTable. + * * `jQuery` - A jQuery object of `TABLE` nodes. + * * `object` - DataTables settings object + * @return {array|null} Matching DataTables settings objects. `null` or + * `undefined` is returned if no matching DataTable is found. + * @ignore + */ +var _toSettings = function ( mixed ) +{ + var idx, jq; + var settings = DataTable.settings; + var tables = $.map( settings, function (el, i) { + return el.nTable; + } ); + + if ( mixed.nTable && mixed.oApi ) { + // DataTables settings object + return [ mixed ]; + } + else if ( mixed.nodeName && mixed.nodeName.toLowerCase() === 'table' ) { + // Table node + idx = $.inArray( mixed, tables ); + return idx !== -1 ? [ settings[idx] ] : null; + } + else if ( typeof mixed === 'string' ) { + // jQuery selector + jq = $(mixed); + } + else if ( mixed instanceof $ ) { + // jQuery object (also DataTables instance) + jq = mixed; + } + + if ( jq ) { + return jq.map( function(i) { + idx = $.inArray( this, tables ); + return idx !== -1 ? settings[idx] : null; + } ); + } +}; + + +/** + * Find the unique elements in a source array. + * + * @param {array} src Source array + * @return {array} Array of unique items + * @ignore + */ +var _unique = function ( src ) +{ + // A faster unique method is to use object keys to identify used values, + // but this doesn't work with arrays or objects, which we must also + // consider. See jsperf.com/compare-array-unique-versions/4 for more + // information. + var + out = [], + val, + i, ien=src.length, + j, k=0; + + again: for ( i=0 ; i 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; + }, + + reverse: _arrayProto.reverse, + + + // Object with rows, columns and opts + selector: null, + + + shift: _arrayProto.shift, + + + sort: _arrayProto.sort, // ? name - order? + + + splice: _arrayProto.splice, + + + toArray: function () + { + return _arrayProto.slice.call( this ); + }, + + + unique: function () + { + return new _Api( this.context, _unique(this) ); + }, + + + unshift: _arrayProto.unshift +}; + + + + + _Api.extend = function ( scope, obj, ext ) +{ + if ( ! obj instanceof _Api ) { + return; + } + + var + i, ien, + j, jen, + struct, + methodScoping = function ( fn, struc ) { + return function () { + var ret = fn.apply( scope, arguments ); + + // Method extension + _Api.extend( ret, ret, struc.methodExt ); + return ret; + }; + }; + + for ( i=0, ien=ext.length ; i */function() { - -/** - * Computed structure of the DataTables API, defined by the options passed to - * `DataTable.Api.register()` when building the API. - * - * The structure is built in order to speed creation and extension of the Api - * objects since the extensions are effectively pre-parsed. - * - * The array is an array of objects with the following structure, where this - * base array represents the Api prototype base: - * - * [ - * { - * name: 'data' -- string - Property name - * val: function () {}, -- function - Api method (or undefined if just an object - * methodExt: [ ... ], -- array - Array of Api object definitions to extend the method result - * propExt: [ ... ] -- array - Array of Api object definitions to extend the property - * }, - * { - * name: 'row' - * val: {}, - * methodExt: [ ... ], - * propExt: [ - * { - * name: 'data' - * val: function () {}, - * methodExt: [ ... ], - * propExt: [ ... ] - * }, - * ... - * ] - * } - * ] - * - * @type {Array} - * @ignore - */ -var _apiStruct = []; +var _api = DataTable.Api; /** - * Api object reference. * - * @type object - * @ignore */ -var _Api; +_api.register( '$()', function ( selector, opts ) { + var + rows = this.rows( opts ).nodes(), // Get all rows + jqRows = $(rows); + + return $( [].concat( + jqRows.filter( selector ).toArray(), + jqRows.find( selector ).toArray() + ) ); +} ); -/** - * `Array.prototype` reference. - * - * @type object - * @ignore - */ -var _arrayProto = Array.prototype; - - - - -/** - * Abstraction for `context` parameter of the `Api` constructor to allow it to - * take several different forms for ease of use. - * - * Each of the input parameter types will be converted to a DataTables settings - * object where possible. - * - * @param {string|node|jQuery|object} mixed DataTable identifier. Can be one - * of: - * - * * `string` - jQuery selector. Any DataTables' matching the given selector - * with be found and used. - * * `node` - `TABLE` node which has already been formed into a DataTable. - * * `jQuery` - A jQuery object of `TABLE` nodes. - * * `object` - DataTables settings object - * @return {array|null} Matching DataTables settings objects. `null` or - * `undefined` is returned if no matching DataTable is found. - * @ignore - */ -var _toSettings = function ( mixed ) -{ - var idx, jq; - var settings = DataTable.settings; - var tables = $.map( settings, function (el, i) { - return el.nTable; +// jQuery functions to operate on the tables +$.each( [ 'on', 'one', 'off' ], function (i, key) { + _api.register( key+'()', function ( /* ... */ ) { + var inst = $( this.tables().nodes() ); + inst[key].apply( inst, arguments ); + return this; } ); +} ); - if ( mixed.nTable && mixed.oApi ) { - // DataTables settings object - return [ mixed ]; - } - else if ( mixed.nodeName && mixed.nodeName.toLowerCase() === 'table' ) { - // Table node - idx = $.inArray( mixed, tables ); - return idx !== -1 ? [ settings[idx] ] : null; - } - else if ( typeof mixed === 'string' ) { - // jQuery selector - jq = $(mixed); - } - else if ( mixed instanceof $ ) { - // jQuery object (also DataTables instance) - jq = mixed; - } - if ( jq ) { - return jq.map( function(i) { - idx = $.inArray( this, tables ); - return idx !== -1 ? settings[idx] : null; - } ); - } -}; +_api.register( 'clear()', function ( selector, opts ) { + return this.iterator( 'table', function ( settings ) { + _fnClearTable( settings ); + } ); +} ); -/** - * Find the unique elements in a source array. - * - * @param {array} src Source array - * @return {array} Array of unique items - * @ignore - */ -var _unique = function ( src ) -{ - // A faster unique method is to use object keys to identify used values, - // but this doesn't work with arrays or objects, which we must also - // consider. See jsperf.com/compare-array-unique-versions/4 for more - // information. - var - out = [], - val, - i, ien=src.length, - j, k=0; +_api.register( 'settings()', function ( selector, opts ) { + return this.iterator( 'table', function ( settings ) { + return settings; + } ); +} ); - again: for ( i=0 ; i 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; - }, - - reverse: _arrayProto.reverse, - - - // Object with rows, columns and opts - selector: null, - - - shift: _arrayProto.shift, - - - sort: _arrayProto.sort, // ? name - order? - - - splice: _arrayProto.splice, - - - toArray: function () - { - return _arrayProto.slice.call( this ); - }, - - - unique: function () - { - return new _Api( this.context, _unique(this) ); - }, - - - unshift: _arrayProto.unshift -}; - - - - - _Api.extend = function ( scope, obj, ext ) -{ - if ( ! obj instanceof _Api ) { - return; - } - - var - i, ien, - j, jen, - struct, - methodScoping = function ( fn, struc ) { - return function () { - var ret = fn.apply( scope, arguments ); - - // Method extension - _Api.extend( ret, ret, struc.methodExt ); - return ret; - }; - }; - - for ( i=0, ien=ext.length ; i