annotate DataTables-1.9.4/media/unit_testing/unit_test.js @ 2:e8755431a0cd draft

fixed missing dependencies
author saskia-hiltemann
date Tue, 30 Sep 2014 09:47:14 -0400
parents ac5f9272033b
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 * File: unit_test.js
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
3 * Version: 0.0.1
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
4 * CVS: $Id$
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
5 * Description: Unit test framework
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
6 * Author: Allan Jardine (www.sprymedia.co.uk)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
7 * Created: Sun Mar 8 22:02:49 GMT 2009
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
8 * Modified: $Date$ by $Author$
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
9 * Language: Javascript
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
10 * License: GPL v2 or BSD 3 point style
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
11 * Project: DataTables
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
12 * Contact: allan.jardine@sprymedia.co.uk
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
13 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
14 * Copyright 2009 Allan Jardine, all rights reserved.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
15 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
16 * Description:
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
17 * This is a javascript library suitable for use as a unit testing framework. Employing a queuing
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
18 * mechanisim to take account of async events in javascript, this library will communicates with
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
19 * a controller frame (to report individual test status).
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
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
24 var oTest = {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
25 /* Block further tests from occuring - might be end of tests or due to async wait */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
26 bBlock: false,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
27
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
28 /* Number of times to try retesting for a blocking test */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
29 iReTestLimit: 20,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
30
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
31 /* Amount of time to wait between trying for an async test */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
32 iReTestDelay: 150,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
33
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
34 /* End tests - external control */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
35 bEnd: false,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
36
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
37 /* Internal variables */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
38 _aoQueue: [],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
39 _iReTest: 0,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
40 _bFinished: false,
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 * Recommened public functions
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
45 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
46
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
47 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
48 * Function: fnTest
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
49 * Purpose: Add a test to the queue
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
50 * Returns: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
51 * Inputs: string:sMessage - name of the test
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
52 * function:fnTest - function which will be evaludated to get the test result
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
53 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
54 "fnTest": function ( sMessage, fnSetup, fnTest )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
55 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
56 this._aoQueue.push( {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
57 "sMessage": sMessage,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
58 "fnSetup": fnSetup,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
59 "fnTest": fnTest,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
60 "bPoll": false
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
61 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
62 this._fnNext();
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 * Function: fnWaitTest
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
67 * Purpose: Add a test to the queue which has a re-test cycle
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
68 * Returns: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
69 * Inputs: string:sMessage - name of the test
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
70 * function:fnTest - function which will be evaludated to get the test result
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
71 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
72 "fnWaitTest": function ( sMessage, fnSetup, fnTest )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
73 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
74 this._aoQueue.push( {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
75 "sMessage": sMessage,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
76 "fnSetup": fnSetup,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
77 "fnTest": fnTest,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
78 "bPoll": true
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
79 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
80 this._fnNext();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
81 },
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 * Function: fnStart
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
85 * Purpose: Indicate that this is a new unit and what it is testing (message to end user)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
86 * Returns: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
87 * Inputs: string:sMessage - message to give to the user about this unit
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
88 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
89 "fnStart": function ( sMessage )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
90 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
91 window.parent.controller.fnStartMessage( sMessage );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
92 },
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 * Function: fnComplete
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
96 * Purpose: Tell the controller that we are all done here
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
97 * Returns: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
98 * Inputs: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
99 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
100 "fnComplete": function ()
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
101 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
102 this._bFinished = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
103 this._fnNext();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
104 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
105
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
106 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
107 * Function: fnCookieDestroy
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
108 * Purpose: Destroy a cookie of a given name
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
109 * Returns: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
110 * Inputs: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
111 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
112 "fnCookieDestroy": function ( oTable )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
113 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
114 var sName = oTable.fnSettings().sCookiePrefix+oTable.fnSettings().sInstance;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
115 var aParts = window.location.pathname.split('/');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
116 var sNameFile = sName + '_' + aParts.pop().replace(/[\/:]/g,"").toLowerCase();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
117 document.cookie = sNameFile+"=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path="+
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
118 aParts.join('/') + "/";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
119 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
120
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
121
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
122
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
123 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
124 * Internal functions
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
125 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
126
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
127
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
128 "_fnReTest": function ( oTestInfo )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
129 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
130 var bResult = oTestInfo.fnTest( );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
131 if ( bResult )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
132 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
133 /* Test passed on retry */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
134 this._fnResult( true );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
135 this._fnNext();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
136 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
137 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
138 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
139 if ( this._iReTest < this.iReTestLimit )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
140 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
141 this._iReTest++;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
142 setTimeout( function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
143 oTest._fnReTest( oTestInfo );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
144 }, this.iReTestDelay );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
145 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
146 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
147 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
148 this._fnResult( false );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
149 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
150 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
151 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
152
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
153 "_fnNext": function ()
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
154 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
155 if ( this.bEnd )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
156 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
157 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
158 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
159
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
160 if ( !this.bBlock && this._aoQueue.length > 0 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
161 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
162 var oNextTest = this._aoQueue.shift();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
163 window.parent.controller.fnTestStart( oNextTest.sMessage );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
164 this.bBlock = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
165
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
166 if ( typeof oNextTest.fnSetup == 'function' )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
167 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
168 oNextTest.fnSetup( );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
169 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
170 var bResult = oNextTest.fnTest( );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
171 //bResult = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
172
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
173 if ( oNextTest.bPoll )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
174 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
175 if ( bResult )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
176 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
177 this._fnResult( true );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
178 this._fnNext();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
179 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
180 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
181 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
182 _iReTest = 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
183 setTimeout( function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
184 oTest._fnReTest( oNextTest );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
185 }, this.iReTestDelay );
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 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
189 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
190 this._fnResult( bResult );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
191 this._fnNext();
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 else if ( !this.bBlock && this._aoQueue.length == 0 && this._bFinished )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
195 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
196 window.parent.controller.fnUnitComplete( );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
197 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
198 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
199
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
200 "_fnResult": function ( b )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
201 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
202 window.parent.controller.fnTestResult( b );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
203 this.bBlock = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
204 if ( !b )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
205 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
206 this.bEnd = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
207 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
208 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
209 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
210
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
211
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
212 var oDispacher = {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
213 "click": function ( nNode, oSpecial )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
214 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
215 var evt = this.fnCreateEvent( 'click', nNode, oSpecial );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
216 if ( nNode.dispatchEvent )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
217 nNode.dispatchEvent(evt);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
218 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
219 nNode.fireEvent('onclick', evt);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
220 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
221
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
222 "change": function ( nNode )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
223 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
224 var evt = this.fnCreateEvent( 'change', nNode );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
225 if ( nNode.dispatchEvent )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
226 nNode.dispatchEvent(evt);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
227 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
228 nNode.fireEvent('onchange', evt);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
229 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
230
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
231
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
232 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
233 * Function: fnCreateEvent
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
234 * Purpose: Create an event oject based on the type to trigger an event - x-platform
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
235 * Returns: event:evt
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
236 * Inputs: string:sType - type of event
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
237 * node:nTarget - target node of the event
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
238 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
239 fnCreateEvent: function( sType, nTarget, oSpecial )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
240 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
241 var evt = null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
242 var oTargetPos = this._fnGetPos( nTarget );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
243 var sTypeGroup = this._fnEventTypeGroup( sType );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
244 if ( typeof oSpecial == 'undefined' )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
245 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
246 oSpecial = {};
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
247 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
248
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
249 var ctrlKey = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
250 var altKey = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
251 var shiftKey = (typeof oSpecial.shift != 'undefined') ? oSpecial.shift : false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
252 var metaKey = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
253 var button = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
254
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
255 if ( document.createEvent )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
256 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
257 switch ( sTypeGroup )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
258 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
259 case 'mouse':
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
260 evt = document.createEvent( "MouseEvents" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
261 evt.initMouseEvent( sType, true, true, window, 0, oTargetPos[0], oTargetPos[1],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
262 oTargetPos[0], oTargetPos[1], ctrlKey, altKey, shiftKey,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
263 metaKey, button, null );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
264 break;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
265
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
266 case 'html':
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
267 evt = document.createEvent( "HTMLEvents" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
268 evt.initEvent( sType, true, true );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
269 break;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
270
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
271 case 'ui':
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
272 evt = document.createEvent( "UIEvents" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
273 evt.initUIEvent( sType, true, true, window, 0 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
274 break;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
275
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
276 default:
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
277 break;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
278 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
279 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
280 else if ( document.createEventObject )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
281 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
282 switch ( sTypeGroup )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
283 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
284 case 'mouse':
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
285 evt = document.createEventObject();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
286 evt.screenX = oTargetPos[0];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
287 evt.screenX = oTargetPos[1];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
288 evt.clientX = oTargetPos[0];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
289 evt.clientY = oTargetPos[1];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
290 evt.ctrlKey = ctrlKey;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
291 evt.altKey = altKey;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
292 evt.shiftKey = shiftKey;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
293 evt.metaKey = metaKey;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
294 evt.button = button;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
295 evt.relatedTarget = null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
296 break;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
297
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
298 case 'html':
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
299 /* fall through to basic event object */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
300
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
301 case 'ui':
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
302 evt = document.createEventObject();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
303 break;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
304
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
305 default:
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
306 break;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
307 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
308 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
309
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
310 return evt;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
311 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
312
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
313 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
314 * Function: DesignCore.fnGetPos
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
315 * Purpose: Get the position of an element on the page
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
316 * Returns: array[ 0-int:left, 1-int:top ]
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
317 * Inputs: node:obj - node to analyse
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
318 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
319 _fnGetPos: function ( obj )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
320 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
321 var curleft = 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
322 var curtop = 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
323
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
324 if (obj.offsetParent)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
325 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
326 curleft = obj.offsetLeft;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
327 curtop = obj.offsetTop;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
328 while (obj = obj.offsetParent )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
329 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
330 curleft += obj.offsetLeft;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
331 curtop += obj.offsetTop;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
332 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
333 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
334 return [curleft,curtop];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
335 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
336
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
337
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
338 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
339 * Function: _fnEventTypeGroup
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
340 * Purpose: Group the event types as per w3c groupings
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
341 * Returns: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
342 * Inputs: string:sType
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
343 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
344 _fnEventTypeGroup: function ( sType )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
345 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
346 switch ( sType )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
347 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
348 case 'click':
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
349 case 'dblclick':
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
350 case 'mousedown':
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
351 case 'mousemove':
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
352 case 'mouseout':
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
353 case 'mouseover':
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
354 case 'mouseup':
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
355 return 'mouse';
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
356
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
357 case 'change':
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
358 case 'focus':
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
359 case 'blur':
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
360 case 'select':
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
361 case 'submit':
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
362 return 'html';
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
363
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
364 case 'keydown':
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
365 case 'keypress':
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
366 case 'keyup':
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
367 case 'load':
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
368 case 'unload':
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
369 return 'ui';
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
370
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
371 default:
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
372 return 'custom';
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
373 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
374 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
375 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
376
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
377
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
378 var oSession = {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
379 nTable: null,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
380
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
381 fnCache: function ()
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
382 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
383 this.nTable = document.getElementById('demo').cloneNode(true);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
384 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
385
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
386 fnRestore: function ()
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
387 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
388 while( $.fn.dataTableSettings.length > 0 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
389 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
390 try {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
391 $.fn.dataTableSettings[0].oInstance.fnDestroy();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
392 } catch (e) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
393 $.fn.dataTableSettings.splice( 0, 1 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
394 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
395 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
396 //$.fn.dataTableSettings.splice( 0, $.fn.dataTableSettings.length );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
397 var nDemo = document.getElementById('demo');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
398 nDemo.innerHTML = "";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
399 for ( var i=0, iLen=this.nTable.childNodes.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
400 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
401 nDemo.appendChild( this.nTable.childNodes[0] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
402 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
403 this.fnCache();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
404 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
405 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
406
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
407 $(document).ready( function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
408 oSession.fnCache();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
409 } );