comparison DataTables-1.9.4/media/src/api/api.static.js @ 0:ac5f9272033b draft

first upload
author saskia-hiltemann
date Tue, 01 Jul 2014 11:42:23 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:ac5f9272033b
1
2
3 /**
4 * Provide a common method for plug-ins to check the version of DataTables being used, in order
5 * to ensure compatibility.
6 * @param {string} sVersion Version string to check for, in the format "X.Y.Z". Note that the
7 * formats "X" and "X.Y" are also acceptable.
8 * @returns {boolean} true if this version of DataTables is greater or equal to the required
9 * version, or false if this version of DataTales is not suitable
10 * @static
11 * @dtopt API-Static
12 *
13 * @example
14 * alert( $.fn.dataTable.fnVersionCheck( '1.9.0' ) );
15 */
16 DataTable.fnVersionCheck = function( sVersion )
17 {
18 /* This is cheap, but effective */
19 var fnZPad = function (Zpad, count)
20 {
21 while(Zpad.length < count) {
22 Zpad += '0';
23 }
24 return Zpad;
25 };
26 var aThis = DataTable.ext.sVersion.split('.');
27 var aThat = sVersion.split('.');
28 var sThis = '', sThat = '';
29
30 for ( var i=0, iLen=aThat.length ; i<iLen ; i++ )
31 {
32 sThis += fnZPad( aThis[i], 3 );
33 sThat += fnZPad( aThat[i], 3 );
34 }
35
36 return parseInt(sThis, 10) >= parseInt(sThat, 10);
37 };
38
39
40 /**
41 * Check if a TABLE node is a DataTable table already or not.
42 * @param {node} nTable The TABLE node to check if it is a DataTable or not (note that other
43 * node types can be passed in, but will always return false).
44 * @returns {boolean} true the table given is a DataTable, or false otherwise
45 * @static
46 * @dtopt API-Static
47 *
48 * @example
49 * var ex = document.getElementById('example');
50 * if ( ! $.fn.DataTable.fnIsDataTable( ex ) ) {
51 * $(ex).dataTable();
52 * }
53 */
54 DataTable.fnIsDataTable = function ( nTable )
55 {
56 var o = DataTable.settings;
57
58 for ( var i=0 ; i<o.length ; i++ )
59 {
60 if ( o[i].nTable === nTable || o[i].nScrollHead === nTable || o[i].nScrollFoot === nTable )
61 {
62 return true;
63 }
64 }
65
66 return false;
67 };
68
69
70 /**
71 * Get all DataTable tables that have been initialised - optionally you can select to
72 * get only currently visible tables.
73 * @param {boolean} [bVisible=false] Flag to indicate if you want all (default) or
74 * visible tables only.
75 * @returns {array} Array of TABLE nodes (not DataTable instances) which are DataTables
76 * @static
77 * @dtopt API-Static
78 *
79 * @example
80 * var table = $.fn.dataTable.fnTables(true);
81 * if ( table.length > 0 ) {
82 * $(table).dataTable().fnAdjustColumnSizing();
83 * }
84 */
85 DataTable.fnTables = function ( bVisible )
86 {
87 var out = [];
88
89 jQuery.each( DataTable.settings, function (i, o) {
90 if ( !bVisible || (bVisible === true && $(o.nTable).is(':visible')) )
91 {
92 out.push( o.nTable );
93 }
94 } );
95
96 return out;
97 };
98