annotate DataTables-1.9.4/media/src/core/core.info.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 * Generate the node required for the info display
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
4 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
5 * @returns {node} Information element
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
6 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
7 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
8 function _fnFeatureHtmlInfo ( oSettings )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
9 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
10 var nInfo = document.createElement( 'div' );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
11 nInfo.className = oSettings.oClasses.sInfo;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
12
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
13 /* Actions that are to be taken once only for this feature */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
14 if ( !oSettings.aanFeatures.i )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
15 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
16 /* Add draw callback */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
17 oSettings.aoDrawCallback.push( {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
18 "fn": _fnUpdateInfo,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
19 "sName": "information"
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
20 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
21
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
22 /* Add id */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
23 nInfo.id = oSettings.sTableId+'_info';
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
24 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
25 oSettings.nTable.setAttribute( 'aria-describedby', oSettings.sTableId+'_info' );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
26
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
27 return nInfo;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
28 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
29
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
30
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
31 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
32 * Update the information elements in the display
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
33 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
34 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
35 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
36 function _fnUpdateInfo ( oSettings )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
37 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
38 /* Show information about the table */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
39 if ( !oSettings.oFeatures.bInfo || oSettings.aanFeatures.i.length === 0 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
40 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
41 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
42 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
43
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
44 var
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
45 oLang = oSettings.oLanguage,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
46 iStart = oSettings._iDisplayStart+1,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
47 iEnd = oSettings.fnDisplayEnd(),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
48 iMax = oSettings.fnRecordsTotal(),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
49 iTotal = oSettings.fnRecordsDisplay(),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
50 sOut;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
51
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
52 if ( iTotal === 0 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
53 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
54 /* Empty record set */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
55 sOut = oLang.sInfoEmpty;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
56 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
57 else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
58 /* Normal record set */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
59 sOut = oLang.sInfo;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
60 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
61
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
62 if ( iTotal != iMax )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
63 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
64 /* Record set after filtering */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
65 sOut += ' ' + oLang.sInfoFiltered;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
66 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
67
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
68 // Convert the macros
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
69 sOut += oLang.sInfoPostFix;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
70 sOut = _fnInfoMacros( oSettings, sOut );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
71
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
72 if ( oLang.fnInfoCallback !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
73 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
74 sOut = oLang.fnInfoCallback.call( oSettings.oInstance,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
75 oSettings, iStart, iEnd, iMax, iTotal, sOut );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
76 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
77
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
78 var n = oSettings.aanFeatures.i;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
79 for ( var i=0, iLen=n.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
80 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
81 $(n[i]).html( sOut );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
82 }
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
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
86 function _fnInfoMacros ( oSettings, str )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
87 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
88 var
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
89 iStart = oSettings._iDisplayStart+1,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
90 sStart = oSettings.fnFormatNumber( iStart ),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
91 iEnd = oSettings.fnDisplayEnd(),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
92 sEnd = oSettings.fnFormatNumber( iEnd ),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
93 iTotal = oSettings.fnRecordsDisplay(),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
94 sTotal = oSettings.fnFormatNumber( iTotal ),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
95 iMax = oSettings.fnRecordsTotal(),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
96 sMax = oSettings.fnFormatNumber( iMax );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
97
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
98 // When infinite scrolling, we are always starting at 1. _iDisplayStart is used only
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
99 // internally
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
100 if ( oSettings.oScroll.bInfinite )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
101 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
102 sStart = oSettings.fnFormatNumber( 1 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
103 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
104
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
105 return str.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
106 replace(/_START_/g, sStart).
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
107 replace(/_END_/g, sEnd).
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
108 replace(/_TOTAL_/g, sTotal).
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
109 replace(/_MAX_/g, sMax);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
110 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
111