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