annotate DataTables-1.9.4/media/src/core/core.support.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 * Return the settings object for a particular table
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
4 * @param {node} nTable table we are using as a dataTable
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
5 * @returns {object} Settings object - or null if not found
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 _fnSettingsFromNode ( nTable )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
9 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
10 for ( var i=0 ; i<DataTable.settings.length ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
11 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
12 if ( DataTable.settings[i].nTable === nTable )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
13 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
14 return DataTable.settings[i];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
15 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
16 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
17
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
18 return null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
19 }
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 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
23 * Return an array with the TR nodes for the table
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
24 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
25 * @returns {array} TR array
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
26 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
27 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
28 function _fnGetTrNodes ( oSettings )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
29 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
30 var aNodes = [];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
31 var aoData = oSettings.aoData;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
32 for ( var i=0, iLen=aoData.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
33 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
34 if ( aoData[i].nTr !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
35 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
36 aNodes.push( aoData[i].nTr );
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 return aNodes;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
40 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
41
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 * Return an flat array with all TD nodes for the table, or row
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
45 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
46 * @param {int} [iIndividualRow] aoData index to get the nodes for - optional
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
47 * if not given then the return array will contain all nodes for the table
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
48 * @returns {array} TD array
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
49 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
50 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
51 function _fnGetTdNodes ( oSettings, iIndividualRow )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
52 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
53 var anReturn = [];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
54 var iCorrector;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
55 var anTds, nTd;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
56 var iRow, iRows=oSettings.aoData.length,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
57 iColumn, iColumns, oData, sNodeName, iStart=0, iEnd=iRows;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
58
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
59 /* Allow the collection to be limited to just one row */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
60 if ( iIndividualRow !== undefined )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
61 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
62 iStart = iIndividualRow;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
63 iEnd = iIndividualRow+1;
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 for ( iRow=iStart ; iRow<iEnd ; iRow++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
67 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
68 oData = oSettings.aoData[iRow];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
69 if ( oData.nTr !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
70 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
71 /* get the TD child nodes - taking into account text etc nodes */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
72 anTds = [];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
73 nTd = oData.nTr.firstChild;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
74 while ( nTd )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
75 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
76 sNodeName = nTd.nodeName.toLowerCase();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
77 if ( sNodeName == 'td' || sNodeName == 'th' )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
78 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
79 anTds.push( nTd );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
80 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
81 nTd = nTd.nextSibling;
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 iCorrector = 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
85 for ( iColumn=0, iColumns=oSettings.aoColumns.length ; iColumn<iColumns ; iColumn++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
86 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
87 if ( oSettings.aoColumns[iColumn].bVisible )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
88 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
89 anReturn.push( anTds[iColumn-iCorrector] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
90 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
91 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
92 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
93 anReturn.push( oData._anHidden[iColumn] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
94 iCorrector++;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
95 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
96 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
97 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
98 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
99
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
100 return anReturn;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
101 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
102
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 * Log an error message
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
106 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
107 * @param {int} iLevel log error messages, or display them to the user
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
108 * @param {string} sMesg error message
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
109 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
110 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
111 function _fnLog( oSettings, iLevel, sMesg )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
112 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
113 var sAlert = (oSettings===null) ?
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
114 "DataTables warning: "+sMesg :
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
115 "DataTables warning (table id = '"+oSettings.sTableId+"'): "+sMesg;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
116
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
117 if ( iLevel === 0 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
118 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
119 if ( DataTable.ext.sErrMode == 'alert' )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
120 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
121 alert( sAlert );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
122 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
123 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
124 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
125 throw new Error(sAlert);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
126 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
127 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
128 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
129 else if ( window.console && console.log )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
130 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
131 console.log( sAlert );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
132 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
133 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
134
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
135
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
136 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
137 * See if a property is defined on one object, if so assign it to the other object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
138 * @param {object} oRet target object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
139 * @param {object} oSrc source object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
140 * @param {string} sName property
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
141 * @param {string} [sMappedName] name to map too - optional, sName used if not given
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
142 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
143 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
144 function _fnMap( oRet, oSrc, sName, sMappedName )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
145 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
146 if ( sMappedName === undefined )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
147 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
148 sMappedName = sName;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
149 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
150 if ( oSrc[sName] !== undefined )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
151 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
152 oRet[sMappedName] = oSrc[sName];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
153 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
154 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
155
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
156
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
157 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
158 * Extend objects - very similar to jQuery.extend, but deep copy objects, and shallow
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
159 * copy arrays. The reason we need to do this, is that we don't want to deep copy array
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
160 * init values (such as aaSorting) since the dev wouldn't be able to override them, but
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
161 * we do want to deep copy arrays.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
162 * @param {object} oOut Object to extend
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
163 * @param {object} oExtender Object from which the properties will be applied to oOut
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
164 * @returns {object} oOut Reference, just for convenience - oOut === the return.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
165 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
166 * @todo This doesn't take account of arrays inside the deep copied objects.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
167 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
168 function _fnExtend( oOut, oExtender )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
169 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
170 var val;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
171
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
172 for ( var prop in oExtender )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
173 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
174 if ( oExtender.hasOwnProperty(prop) )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
175 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
176 val = oExtender[prop];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
177
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
178 if ( typeof oInit[prop] === 'object' && val !== null && $.isArray(val) === false )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
179 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
180 $.extend( true, oOut[prop], val );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
181 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
182 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
183 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
184 oOut[prop] = val;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
185 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
186 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
187 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
188
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
189 return oOut;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
190 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
191
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
192
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
193 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
194 * Bind an event handers to allow a click or return key to activate the callback.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
195 * This is good for accessibility since a return on the keyboard will have the
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
196 * same effect as a click, if the element has focus.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
197 * @param {element} n Element to bind the action to
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
198 * @param {object} oData Data object to pass to the triggered function
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
199 * @param {function} fn Callback function for when the event is triggered
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
200 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
201 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
202 function _fnBindAction( n, oData, fn )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
203 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
204 $(n)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
205 .bind( 'click.DT', oData, function (e) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
206 n.blur(); // Remove focus outline for mouse users
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
207 fn(e);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
208 } )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
209 .bind( 'keypress.DT', oData, function (e){
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
210 if ( e.which === 13 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
211 fn(e);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
212 } } )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
213 .bind( 'selectstart.DT', function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
214 /* Take the brutal approach to cancelling text selection */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
215 return false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
216 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
217 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
218
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
219
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
220 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
221 * Register a callback function. Easily allows a callback function to be added to
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
222 * an array store of callback functions that can then all be called together.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
223 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
224 * @param {string} sStore Name of the array storage for the callbacks in oSettings
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
225 * @param {function} fn Function to be called back
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
226 * @param {string} sName Identifying name for the callback (i.e. a label)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
227 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
228 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
229 function _fnCallbackReg( oSettings, sStore, fn, sName )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
230 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
231 if ( fn )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
232 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
233 oSettings[sStore].push( {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
234 "fn": fn,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
235 "sName": sName
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
236 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
237 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
238 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
239
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
240
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
241 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
242 * Fire callback functions and trigger events. Note that the loop over the callback
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
243 * array store is done backwards! Further note that you do not want to fire off triggers
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
244 * in time sensitive applications (for example cell creation) as its slow.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
245 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
246 * @param {string} sStore Name of the array storage for the callbacks in oSettings
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
247 * @param {string} sTrigger Name of the jQuery custom event to trigger. If null no trigger
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
248 * is fired
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
249 * @param {array} aArgs Array of arguments to pass to the callback function / trigger
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
250 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
251 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
252 function _fnCallbackFire( oSettings, sStore, sTrigger, aArgs )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
253 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
254 var aoStore = oSettings[sStore];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
255 var aRet =[];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
256
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
257 for ( var i=aoStore.length-1 ; i>=0 ; i-- )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
258 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
259 aRet.push( aoStore[i].fn.apply( oSettings.oInstance, aArgs ) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
260 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
261
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
262 if ( sTrigger !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
263 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
264 $(oSettings.oInstance).trigger(sTrigger, aArgs);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
265 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
266
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
267 return aRet;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
268 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
269
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
270
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
271 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
272 * JSON stringify. If JSON.stringify it provided by the browser, json2.js or any other
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
273 * library, then we use that as it is fast, safe and accurate. If the function isn't
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
274 * available then we need to built it ourselves - the inspiration for this function comes
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
275 * from Craig Buckler ( http://www.sitepoint.com/javascript-json-serialization/ ). It is
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
276 * not perfect and absolutely should not be used as a replacement to json2.js - but it does
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
277 * do what we need, without requiring a dependency for DataTables.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
278 * @param {object} o JSON object to be converted
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
279 * @returns {string} JSON string
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
280 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
281 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
282 var _fnJsonString = (window.JSON) ? JSON.stringify : function( o )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
283 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
284 /* Not an object or array */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
285 var sType = typeof o;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
286 if (sType !== "object" || o === null)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
287 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
288 // simple data type
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
289 if (sType === "string")
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
290 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
291 o = '"'+o+'"';
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
292 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
293 return o+"";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
294 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
295
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
296 /* If object or array, need to recurse over it */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
297 var
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
298 sProp, mValue,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
299 json = [],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
300 bArr = $.isArray(o);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
301
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
302 for (sProp in o)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
303 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
304 mValue = o[sProp];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
305 sType = typeof mValue;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
306
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
307 if (sType === "string")
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
308 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
309 mValue = '"'+mValue+'"';
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
310 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
311 else if (sType === "object" && mValue !== null)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
312 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
313 mValue = _fnJsonString(mValue);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
314 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
315
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
316 json.push((bArr ? "" : '"'+sProp+'":') + mValue);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
317 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
318
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
319 return (bArr ? "[" : "{") + json + (bArr ? "]" : "}");
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
320 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
321
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
322
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
323 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
324 * From some browsers (specifically IE6/7) we need special handling to work around browser
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
325 * bugs - this function is used to detect when these workarounds are needed.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
326 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
327 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
328 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
329 function _fnBrowserDetect( oSettings )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
330 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
331 /* IE6/7 will oversize a width 100% element inside a scrolling element, to include the
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
332 * width of the scrollbar, while other browsers ensure the inner element is contained
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
333 * without forcing scrolling
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
334 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
335 var n = $(
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
336 '<div style="position:absolute; top:0; left:0; height:1px; width:1px; overflow:hidden">'+
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
337 '<div style="position:absolute; top:1px; left:1px; width:100px; overflow:scroll;">'+
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
338 '<div id="DT_BrowserTest" style="width:100%; height:10px;"></div>'+
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
339 '</div>'+
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
340 '</div>')[0];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
341
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
342 document.body.appendChild( n );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
343 oSettings.oBrowser.bScrollOversize = $('#DT_BrowserTest', n)[0].offsetWidth === 100 ? true : false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
344 document.body.removeChild( n );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
345 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
346