annotate DataTables-1.9.4/extras/KeyTable/js/KeyTable.js @ 3:4a6ebda2a3ae draft

fixed tool dependency issue
author saskia-hiltemann
date Tue, 30 Sep 2014 09:56:12 -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: KeyTable.js
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
3 * Version: 1.1.7
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
4 * CVS: $Idj$
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
5 * Description: Keyboard navigation for HTML tables
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: Fri Mar 13 21:24:02 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: Just a little bit of fun :-)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
12 * Contact: www.sprymedia.co.uk/contact
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
13 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
14 * Copyright 2009-2011 Allan Jardine, all rights reserved.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
15 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
16 * This source file is free software, under either the GPL v2 license or a
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
17 * BSD style license, available at:
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
18 * http://datatables.net/license_gpl2
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
19 * http://datatables.net/license_bsd
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 function KeyTable ( oInit )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
24 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
25 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
26 * API parameters
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
27 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
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 * Variable: block
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
31 * Purpose: Flag whether or not KeyTable events should be processed
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
32 * Scope: KeyTable - public
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
33 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
34 this.block = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
35
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
36 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
37 * Variable: event
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
38 * Purpose: Container for all event application methods
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
39 * Scope: KeyTable - public
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
40 * Notes: This object contains all the public methods for adding and removing events - these
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
41 * are dynamically added later on
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
42 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
43 this.event = {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
44 "remove": {}
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 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
49 * API methods
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
50 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
51
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
52 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
53 * Function: fnGetCurrentPosition
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
54 * Purpose: Get the currently focused cell's position
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
55 * Returns: array int: [ x, y ]
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
56 * Inputs: void
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
57 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
58 this.fnGetCurrentPosition = function ()
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
59 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
60 return [ _iOldX, _iOldY ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
61 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
62
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 * Function: fnGetCurrentData
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
66 * Purpose: Get the currently focused cell's data (innerHTML)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
67 * Returns: string: - data requested
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
68 * Inputs: void
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
69 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
70 this.fnGetCurrentData = function ()
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
71 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
72 return _nOldFocus.innerHTML;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
73 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
74
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
75
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
76 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
77 * Function: fnGetCurrentTD
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
78 * Purpose: Get the currently focused cell
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
79 * Returns: node: - focused element
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
80 * Inputs: void
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
81 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
82 this.fnGetCurrentTD = function ()
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
83 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
84 return _nOldFocus;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
85 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
86
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
87
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
88 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
89 * Function: fnSetPosition
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
90 * Purpose: Set the position of the focused cell
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
91 * Returns: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
92 * Inputs: int:x - x coordinate
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
93 * int:y - y coordinate
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
94 * Notes: Thanks to Rohan Daxini for the basis of this function
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
95 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
96 this.fnSetPosition = function( x, y )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
97 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
98 if ( typeof x == 'object' && x.nodeName )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
99 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
100 _fnSetFocus( x );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
101 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
102 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
103 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
104 _fnSetFocus( _fnCellFromCoords(x, y) );
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
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
108
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
109 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
110 * Private parameters
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
111 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
112
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
113 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
114 * Variable: _nBody
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
115 * Purpose: Body node of the table - cached for renference
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
116 * Scope: KeyTable - private
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
117 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
118 var _nBody = null;
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 * Variable:
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
122 * Purpose:
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
123 * Scope: KeyTable - private
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
124 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
125 var _nOldFocus = null;
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 * Variable: _iOldX and _iOldY
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
129 * Purpose: X and Y coords of the old elemet that was focused on
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
130 * Scope: KeyTable - private
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
131 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
132 var _iOldX = null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
133 var _iOldY = null;
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 * Variable: _that
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
137 * Purpose: Scope saving for 'this' after a jQuery event
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
138 * Scope: KeyTable - private
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
139 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
140 var _that = null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
141
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
142 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
143 * Variable: sFocusClass
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
144 * Purpose: Class that should be used for focusing on a cell
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
145 * Scope: KeyTable - private
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
146 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
147 var _sFocusClass = "focus";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
148
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
149 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
150 * Variable: _bKeyCapture
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
151 * Purpose: Flag for should KeyTable capture key events or not
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
152 * Scope: KeyTable - private
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
153 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
154 var _bKeyCapture = false;
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 * Variable: _oaoEvents
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
158 * Purpose: Event cache object, one array for each supported event for speed of searching
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
159 * Scope: KeyTable - private
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
160 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
161 var _oaoEvents = {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
162 "action": [],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
163 "esc": [],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
164 "focus": [],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
165 "blur": []
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
166 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
167
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
168 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
169 * Variable: _oDatatable
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
170 * Purpose: DataTables object for if we are actually using a DataTables table
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
171 * Scope: KeyTable - private
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
172 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
173 var _oDatatable = null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
174
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
175 var _bForm;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
176 var _nInput;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
177 var _bInputFocused = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
178
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
179
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
180 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
181 * Private methods
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
182 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
183
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
184 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
185 * Key table events
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 * Function: _fnEventAddTemplate
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
190 * Purpose: Create a function (with closure for sKey) event addition API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
191 * Returns: function: - template function
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
192 * Inputs: string:sKey - type of event to detect
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
193 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
194 function _fnEventAddTemplate( sKey )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
195 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
196 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
197 * Function: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
198 * Purpose: API function for adding event to cache
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
199 * Returns: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
200 * Inputs: 1. node:x - target node to add event for
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
201 * 2. function:y - callback function to apply
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
202 * or
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
203 * 1. int:x - x coord. of target cell (can be null for live events)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
204 * 2. int:y - y coord. of target cell (can be null for live events)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
205 * 3. function:z - callback function to apply
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
206 * Notes: This function is (interally) overloaded (in as much as javascript allows for
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
207 * that) - the target cell can be given by either node or coords.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
208 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
209 return function ( x, y, z ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
210 if ( (x===null || typeof x == "number") &&
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
211 (y===null || typeof y == "number") &&
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
212 typeof z == "function" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
213 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
214 _fnEventAdd( sKey, x, y, z );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
215 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
216 else if ( typeof x == "object" && typeof y == "function" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
217 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
218 var aCoords = _fnCoordsFromCell( x );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
219 _fnEventAdd( sKey, aCoords[0], aCoords[1], y );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
220 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
221 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
222 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
223 alert( "Unhandable event type was added: x" +x+ " y:" +y+ " z:" +z );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
224 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
225 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
226 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
227
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
228
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
229 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
230 * Function: _fnEventRemoveTemplate
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
231 * Purpose: Create a function (with closure for sKey) event removal API
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
232 * Returns: function: - template function
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
233 * Inputs: string:sKey - type of event to detect
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
234 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
235 function _fnEventRemoveTemplate( sKey )
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 * Function: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
239 * Purpose: API function for removing event from cache
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
240 * Returns: int: - number of events removed
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
241 * Inputs: 1. node:x - target node to remove event from
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
242 * 2. function:y - callback function to apply
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
243 * or
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
244 * 1. int:x - x coord. of target cell (can be null for live events)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
245 * 2. int:y - y coord. of target cell (can be null for live events)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
246 * 3. function:z - callback function to remove - optional
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
247 * Notes: This function is (interally) overloaded (in as much as javascript allows for
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
248 * that) - the target cell can be given by either node or coords and the function
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
249 * to remove is optional
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
250 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
251 return function ( x, y, z ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
252 if ( (x===null || typeof arguments[0] == "number") &&
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
253 (y===null || typeof arguments[1] == "number" ) )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
254 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
255 if ( typeof arguments[2] == "function" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
256 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
257 _fnEventRemove( sKey, x, y, z );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
258 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
259 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
260 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
261 _fnEventRemove( sKey, x, y );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
262 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
263 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
264 else if ( typeof arguments[0] == "object" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
265 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
266 var aCoords = _fnCoordsFromCell( x );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
267 if ( typeof arguments[1] == "function" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
268 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
269 _fnEventRemove( sKey, aCoords[0], aCoords[1], y );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
270 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
271 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
272 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
273 _fnEventRemove( sKey, aCoords[0], aCoords[1] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
274 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
275 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
276 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
277 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
278 alert( "Unhandable event type was removed: x" +x+ " y:" +y+ " z:" +z );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
279 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
280 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
281 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
282
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
283 /* Use the template functions to add the event API functions */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
284 for ( var sKey in _oaoEvents )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
285 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
286 if ( sKey )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
287 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
288 this.event[sKey] = _fnEventAddTemplate( sKey );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
289 this.event.remove[sKey] = _fnEventRemoveTemplate( sKey );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
290 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
291 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
292
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
293
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
294 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
295 * Function: _fnEventAdd
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
296 * Purpose: Add an event to the internal cache
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
297 * Returns: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
298 * Inputs: string:sType - type of event to add, given by the available elements in _oaoEvents
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
299 * int:x - x-coords to add event to - can be null for "blanket" event
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
300 * int:y - y-coords to add event to - can be null for "blanket" event
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
301 * function:fn - callback function for when triggered
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
302 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
303 function _fnEventAdd( sType, x, y, fn )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
304 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
305 _oaoEvents[sType].push( {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
306 "x": x,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
307 "y": y,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
308 "fn": fn
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
309 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
310 }
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: _fnEventRemove
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
315 * Purpose: Remove an event from the event cache
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
316 * Returns: int: - number of matching events removed
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
317 * Inputs: string:sType - type of event to look for
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
318 * node:nTarget - target table cell
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
319 * function:fn - optional - remove this function. If not given all handlers of this
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
320 * type will be removed
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
321 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
322 function _fnEventRemove( sType, x, y, fn )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
323 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
324 var iCorrector = 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
325
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
326 for ( var i=0, iLen=_oaoEvents[sType].length ; i<iLen-iCorrector ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
327 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
328 if ( typeof fn != 'undefined' )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
329 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
330 if ( _oaoEvents[sType][i-iCorrector].x == x &&
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
331 _oaoEvents[sType][i-iCorrector].y == y &&
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
332 _oaoEvents[sType][i-iCorrector].fn == fn )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
333 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
334 _oaoEvents[sType].splice( i-iCorrector, 1 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
335 iCorrector++;
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 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
339 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
340 if ( _oaoEvents[sType][i-iCorrector].x == x &&
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
341 _oaoEvents[sType][i-iCorrector].y == y )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
342 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
343 _oaoEvents[sType].splice( i, 1 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
344 return 1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
345 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
346 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
347 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
348 return iCorrector;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
349 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
350
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
351
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
352 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
353 * Function: _fnEventFire
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
354 * Purpose: Look thought the events cache and fire off the event of interest
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
355 * Returns: int:iFired - number of events fired
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
356 * Inputs: string:sType - type of event to look for
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
357 * int:x - x coord of cell
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
358 * int:y - y coord of ell
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
359 * Notes: It might be more efficient to return after the first event has been tirggered,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
360 * but that would mean that only one function of a particular type can be
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
361 * subscribed to a particular node.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
362 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
363 function _fnEventFire ( sType, x, y )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
364 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
365 var iFired = 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
366 var aEvents = _oaoEvents[sType];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
367 for ( var i=0 ; i<aEvents.length ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
368 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
369 if ( (aEvents[i].x == x && aEvents[i].y == y ) ||
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
370 (aEvents[i].x === null && aEvents[i].y == y ) ||
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
371 (aEvents[i].x == x && aEvents[i].y === null ) ||
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
372 (aEvents[i].x === null && aEvents[i].y === null )
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 aEvents[i].fn( _fnCellFromCoords(x,y), x, y );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
376 iFired++;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
377 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
378 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
379 return iFired;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
380 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
381
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
382
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
383
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
384 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
385 * Focus functions
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
386 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
387
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
388 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
389 * Function: _fnSetFocus
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
390 * Purpose: Set focus on a node, and remove from an old node if needed
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
391 * Returns: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
392 * Inputs: node:nTarget - node we want to focus on
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
393 * bool:bAutoScroll - optional - should we scroll the view port to the display
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
394 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
395 function _fnSetFocus( nTarget, bAutoScroll )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
396 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
397 /* If node already has focus, just ignore this call */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
398 if ( _nOldFocus == nTarget )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
399 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
400 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
401 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
402
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
403 if ( typeof bAutoScroll == 'undefined' )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
404 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
405 bAutoScroll = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
406 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
407
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
408 /* Remove old focus (with blur event if needed) */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
409 if ( _nOldFocus !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
410 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
411 _fnRemoveFocus( _nOldFocus );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
412 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
413
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
414 /* Add the new class to highlight the focused cell */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
415 jQuery(nTarget).addClass( _sFocusClass );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
416 jQuery(nTarget).parent().addClass( _sFocusClass );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
417
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
418 /* If it's a DataTable then we need to jump the paging to the relevant page */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
419 var oSettings;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
420 if ( _oDatatable )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
421 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
422 oSettings = _oDatatable.fnSettings();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
423 var iRow = _fnFindDtCell( nTarget )[1];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
424 var bKeyCaptureCache = _bKeyCapture;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
425
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
426 /* Page forwards */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
427 while ( iRow >= oSettings.fnDisplayEnd() )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
428 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
429 if ( oSettings._iDisplayLength >= 0 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
430 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
431 /* Make sure we are not over running the display array */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
432 if ( oSettings._iDisplayStart + oSettings._iDisplayLength < oSettings.fnRecordsDisplay() )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
433 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
434 oSettings._iDisplayStart += oSettings._iDisplayLength;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
435 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
436 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
437 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
438 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
439 oSettings._iDisplayStart = 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
440 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
441 _oDatatable.oApi._fnCalculateEnd( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
442 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
443
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
444 /* Page backwards */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
445 while ( iRow < oSettings._iDisplayStart )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
446 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
447 oSettings._iDisplayStart = oSettings._iDisplayLength>=0 ?
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
448 oSettings._iDisplayStart - oSettings._iDisplayLength :
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
449 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
450
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
451 if ( oSettings._iDisplayStart < 0 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
452 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
453 oSettings._iDisplayStart = 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
454 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
455 _oDatatable.oApi._fnCalculateEnd( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
456 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
457
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
458 /* Re-draw the table */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
459 _oDatatable.oApi._fnDraw( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
460
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
461 /* Restore the key capture */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
462 _bKeyCapture = bKeyCaptureCache;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
463 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
464
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
465 /* Cache the information that we are interested in */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
466 var aNewPos = _fnCoordsFromCell( nTarget );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
467 _nOldFocus = nTarget;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
468 _iOldX = aNewPos[0];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
469 _iOldY = aNewPos[1];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
470
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
471 var iViewportHeight, iViewportWidth, iScrollTop, iScrollLeft, iHeight, iWidth, aiPos;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
472 if ( bAutoScroll )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
473 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
474 /* Scroll the viewport such that the new cell is fully visible in the rendered window */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
475 iViewportHeight = document.documentElement.clientHeight;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
476 iViewportWidth = document.documentElement.clientWidth;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
477 iScrollTop = document.body.scrollTop || document.documentElement.scrollTop;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
478 iScrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
479 iHeight = nTarget.offsetHeight;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
480 iWidth = nTarget.offsetWidth;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
481 aiPos = _fnGetPos( nTarget );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
482
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
483 /* Take account of scrolling in DataTables 1.7 - remove scrolling since that would add to
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
484 * the positioning calculation
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
485 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
486 if ( _oDatatable && typeof oSettings.oScroll != 'undefined' &&
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
487 (oSettings.oScroll.sX !== "" || oSettings.oScroll.sY !== "") )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
488 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
489 aiPos[1] -= $(oSettings.nTable.parentNode).scrollTop();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
490 aiPos[0] -= $(oSettings.nTable.parentNode).scrollLeft();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
491 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
492
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
493 /* Correct viewport positioning for vertical scrolling */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
494 if ( aiPos[1]+iHeight > iScrollTop+iViewportHeight )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
495 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
496 /* Displayed element if off the bottom of the viewport */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
497 _fnSetScrollTop( aiPos[1]+iHeight - iViewportHeight );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
498 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
499 else if ( aiPos[1] < iScrollTop )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
500 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
501 /* Displayed element if off the top of the viewport */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
502 _fnSetScrollTop( aiPos[1] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
503 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
504
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
505 /* Correct viewport positioning for horizontal scrolling */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
506 if ( aiPos[0]+iWidth > iScrollLeft+iViewportWidth )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
507 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
508 /* Displayed element is off the bottom of the viewport */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
509 _fnSetScrollLeft( aiPos[0]+iWidth - iViewportWidth );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
510 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
511 else if ( aiPos[0] < iScrollLeft )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
512 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
513 /* Displayed element if off the Left of the viewport */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
514 _fnSetScrollLeft( aiPos[0] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
515 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
516 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
517
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
518 /* Take account of scrolling in DataTables 1.7 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
519 if ( _oDatatable && typeof oSettings.oScroll != 'undefined' &&
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
520 (oSettings.oScroll.sX !== "" || oSettings.oScroll.sY !== "") )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
521 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
522 var dtScrollBody = oSettings.nTable.parentNode;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
523 iViewportHeight = dtScrollBody.clientHeight;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
524 iViewportWidth = dtScrollBody.clientWidth;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
525 iScrollTop = dtScrollBody.scrollTop;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
526 iScrollLeft = dtScrollBody.scrollLeft;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
527 iHeight = nTarget.offsetHeight;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
528 iWidth = nTarget.offsetWidth;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
529
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
530 /* Correct for vertical scrolling */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
531 if ( nTarget.offsetTop + iHeight > iViewportHeight+iScrollTop )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
532 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
533 dtScrollBody.scrollTop = (nTarget.offsetTop + iHeight) - iViewportHeight;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
534 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
535 else if ( nTarget.offsetTop < iScrollTop )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
536 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
537 dtScrollBody.scrollTop = nTarget.offsetTop;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
538 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
539
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
540 /* Correct for horizontal scrolling */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
541 if ( nTarget.offsetLeft + iWidth > iViewportWidth+iScrollLeft )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
542 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
543 dtScrollBody.scrollLeft = (nTarget.offsetLeft + iWidth) - iViewportWidth;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
544 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
545 else if ( nTarget.offsetLeft < iScrollLeft )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
546 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
547 dtScrollBody.scrollLeft = nTarget.offsetLeft;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
548 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
549 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
550
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
551 /* Focused - so we want to capture the keys */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
552 _fnCaptureKeys();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
553
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
554 /* Fire of the focus event if there is one */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
555 _fnEventFire( "focus", _iOldX, _iOldY );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
556 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
557
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
558
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
559 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
560 * Function: _fnBlur
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
561 * Purpose: Blur focus from the whole table
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
562 * Returns: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
563 * Inputs: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
564 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
565 function _fnBlur()
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
566 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
567 _fnRemoveFocus( _nOldFocus );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
568 _iOldX = null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
569 _iOldY = null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
570 _nOldFocus = null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
571 _fnReleaseKeys();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
572 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
573
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
574
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
575 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
576 * Function: _fnRemoveFocus
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
577 * Purpose: Remove focus from a cell and fire any blur events which are attached
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
578 * Returns: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
579 * Inputs: node:nTarget - cell of interest
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
580 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
581 function _fnRemoveFocus( nTarget )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
582 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
583 jQuery(nTarget).removeClass( _sFocusClass );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
584 jQuery(nTarget).parent().removeClass( _sFocusClass );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
585 _fnEventFire( "blur", _iOldX, _iOldY );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
586 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
587
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
588
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
589 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
590 * Function: _fnClick
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
591 * Purpose: Focus on the element that has been clicked on by the user
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
592 * Returns: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
593 * Inputs: event:e - click event
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
594 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
595 function _fnClick ( e )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
596 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
597 var nTarget = this;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
598 while ( nTarget.nodeName != "TD" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
599 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
600 nTarget = nTarget.parentNode;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
601 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
602
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
603 _fnSetFocus( nTarget );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
604 _fnCaptureKeys();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
605 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
606
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
607
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
608
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
609 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
610 * Key events
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
611 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
612
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
613 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
614 * Function: _fnKey
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
615 * Purpose: Deal with a key events, be it moving the focus or return etc.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
616 * Returns: bool: - allow browser default action
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
617 * Inputs: event:e - key event
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
618 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
619 function _fnKey ( e )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
620 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
621 /* If user or system has blocked KeyTable from doing anything, just ignore this event */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
622 if ( _that.block || !_bKeyCapture )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
623 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
624 return true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
625 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
626
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
627 /* If a modifier key is pressed (exapct shift), ignore the event */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
628 if ( e.metaKey || e.altKey || e.ctrlKey )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
629 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
630 return true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
631 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
632 var
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
633 x, y,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
634 iTableWidth = _nBody.getElementsByTagName('tr')[0].getElementsByTagName('td').length,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
635 iTableHeight;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
636
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
637 /* Get table height and width - done here so as to be dynamic (if table is updated) */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
638 if ( _oDatatable )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
639 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
640 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
641 * Locate the current node in the DataTable overriding the old positions - the reason for
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
642 * is is that there might have been some DataTables interaction between the last focus and
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
643 * now
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
644 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
645 var oSettings = _oDatatable.fnSettings();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
646 iTableHeight = oSettings.aiDisplay.length;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
647
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
648 var aDtPos = _fnFindDtCell( _nOldFocus );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
649 if ( aDtPos === null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
650 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
651 /* If the table has been updated such that the focused cell can't be seen - do nothing */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
652 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
653 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
654 _iOldX = aDtPos[ 0 ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
655 _iOldY = aDtPos[ 1 ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
656 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
657 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
658 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
659 iTableHeight = _nBody.getElementsByTagName('tr').length;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
660 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
661
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
662 /* Capture shift+tab to match the left arrow key */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
663 var iKey = (e.keyCode == 9 && e.shiftKey) ? -1 : e.keyCode;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
664
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
665 switch( iKey )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
666 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
667 case 13: /* return */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
668 e.preventDefault();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
669 e.stopPropagation();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
670 _fnEventFire( "action", _iOldX, _iOldY );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
671 return true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
672
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
673 case 27: /* esc */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
674 if ( !_fnEventFire( "esc", _iOldX, _iOldY ) )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
675 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
676 /* Only lose focus if there isn't an escape handler on the cell */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
677 _fnBlur();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
678 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
679 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
680 x = _iOldX;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
681 y = _iOldY;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
682 break;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
683
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
684 case -1:
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
685 case 37: /* left arrow */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
686 if ( _iOldX > 0 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
687 x = _iOldX - 1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
688 y = _iOldY;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
689 } else if ( _iOldY > 0 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
690 x = iTableWidth-1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
691 y = _iOldY - 1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
692 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
693 /* at start of table */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
694 if ( iKey == -1 && _bForm )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
695 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
696 /* If we are in a form, return focus to the 'input' element such that tabbing will
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
697 * follow correctly in the browser
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
698 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
699 _bInputFocused = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
700 _nInput.focus();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
701
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
702 /* This timeout is a little nasty - but IE appears to have some asyhnc behaviour for
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
703 * focus
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
704 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
705 setTimeout( function(){ _bInputFocused = false; }, 0 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
706 _bKeyCapture = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
707 _fnBlur();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
708 return true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
709 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
710 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
711 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
712 return false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
713 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
714 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
715 break;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
716
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
717 case 38: /* up arrow */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
718 if ( _iOldY > 0 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
719 x = _iOldX;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
720 y = _iOldY - 1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
721 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
722 return false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
723 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
724 break;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
725
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
726 case 9: /* tab */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
727 case 39: /* right arrow */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
728 if ( _iOldX < iTableWidth-1 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
729 x = _iOldX + 1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
730 y = _iOldY;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
731 } else if ( _iOldY < iTableHeight-1 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
732 x = 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
733 y = _iOldY + 1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
734 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
735 /* at end of table */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
736 if ( iKey == 9 && _bForm )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
737 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
738 /* If we are in a form, return focus to the 'input' element such that tabbing will
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
739 * follow correctly in the browser
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
740 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
741 _bInputFocused = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
742 _nInput.focus();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
743
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
744 /* This timeout is a little nasty - but IE appears to have some asyhnc behaviour for
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
745 * focus
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
746 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
747 setTimeout( function(){ _bInputFocused = false; }, 0 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
748 _bKeyCapture = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
749 _fnBlur();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
750 return true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
751 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
752 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
753 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
754 return false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
755 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
756 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
757 break;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
758
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
759 case 40: /* down arrow */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
760 if ( _iOldY < iTableHeight-1 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
761 x = _iOldX;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
762 y = _iOldY + 1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
763 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
764 return false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
765 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
766 break;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
767
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
768 default: /* Nothing we are interested in */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
769 return true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
770 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
771
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
772 _fnSetFocus( _fnCellFromCoords(x, y) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
773 return false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
774 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
775
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
776
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
777 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
778 * Function: _fnCaptureKeys
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
779 * Purpose: Start capturing key events for this table
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
780 * Returns: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
781 * Inputs: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
782 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
783 function _fnCaptureKeys( )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
784 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
785 if ( !_bKeyCapture )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
786 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
787 _bKeyCapture = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
788 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
789 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
790
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
791
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
792 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
793 * Function: _fnReleaseKeys
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
794 * Purpose: Stop capturing key events for this table
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
795 * Returns: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
796 * Inputs: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
797 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
798 function _fnReleaseKeys( )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
799 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
800 _bKeyCapture = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
801 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
802
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
803
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
804
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
805 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
806 * Support functions
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
807 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
808
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
809 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
810 * Function: _fnCellFromCoords
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
811 * Purpose: Calulate the target TD cell from x and y coordinates
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
812 * Returns: node: - TD target
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
813 * Inputs: int:x - x coordinate
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
814 * int:y - y coordinate
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
815 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
816 function _fnCellFromCoords( x, y )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
817 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
818 if ( _oDatatable )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
819 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
820 var oSettings = _oDatatable.fnSettings();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
821 if ( typeof oSettings.aoData[ oSettings.aiDisplay[ y ] ] != 'undefined' )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
822 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
823 return oSettings.aoData[ oSettings.aiDisplay[ y ] ].nTr.getElementsByTagName('td')[x];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
824 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
825 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
826 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
827 return null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
828 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
829 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
830 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
831 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
832 return jQuery('tr:eq('+y+')>td:eq('+x+')', _nBody )[0];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
833 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
834 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
835
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
836
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
837 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
838 * Function: _fnCoordsFromCell
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
839 * Purpose: Calculate the x and y position in a table from a TD cell
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
840 * Returns: array[2] int: [x, y]
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
841 * Inputs: node:n - TD cell of interest
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
842 * Notes: Not actually interested in this for DataTables since it might go out of date
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
843 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
844 function _fnCoordsFromCell( n )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
845 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
846 if ( _oDatatable )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
847 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
848 var oSettings = _oDatatable.fnSettings();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
849 return [
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
850 jQuery('td', n.parentNode).index(n),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
851 jQuery('tr', n.parentNode.parentNode).index(n.parentNode) + oSettings._iDisplayStart
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
852 ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
853 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
854 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
855 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
856 return [
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
857 jQuery('td', n.parentNode).index(n),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
858 jQuery('tr', n.parentNode.parentNode).index(n.parentNode)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
859 ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
860 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
861 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
862
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
863
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
864 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
865 * Function: _fnSetScrollTop
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
866 * Purpose: Set the vertical scrolling position
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
867 * Returns: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
868 * Inputs: int:iPos - scrolltop
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
869 * Notes: This is so nasty, but without browser detection you can't tell which you should set
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
870 * So on browsers that support both, the scroll top will be set twice. I can live with
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
871 * that :-)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
872 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
873 function _fnSetScrollTop( iPos )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
874 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
875 document.documentElement.scrollTop = iPos;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
876 document.body.scrollTop = iPos;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
877 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
878
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
879
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
880 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
881 * Function: _fnSetScrollLeft
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
882 * Purpose: Set the horizontal scrolling position
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
883 * Returns: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
884 * Inputs: int:iPos - scrollleft
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
885 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
886 function _fnSetScrollLeft( iPos )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
887 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
888 document.documentElement.scrollLeft = iPos;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
889 document.body.scrollLeft = iPos;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
890 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
891
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
892
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
893 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
894 * Function: _fnGetPos
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
895 * Purpose: Get the position of an object on the rendered page
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
896 * Returns: array[2] int: [left, right]
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
897 * Inputs: node:obj - element of interest
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
898 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
899 function _fnGetPos ( obj )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
900 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
901 var iLeft = 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
902 var iTop = 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
903
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
904 if (obj.offsetParent)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
905 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
906 iLeft = obj.offsetLeft;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
907 iTop = obj.offsetTop;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
908 obj = obj.offsetParent;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
909 while (obj)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
910 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
911 iLeft += obj.offsetLeft;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
912 iTop += obj.offsetTop;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
913 obj = obj.offsetParent;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
914 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
915 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
916 return [iLeft,iTop];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
917 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
918
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
919
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
920 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
921 * Function: _fnFindDtCell
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
922 * Purpose: Get the coords. of a cell from the DataTables internal information
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
923 * Returns: array[2] int: [x, y] coords. or null if not found
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
924 * Inputs: node:nTarget - the node of interest
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
925 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
926 function _fnFindDtCell( nTarget )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
927 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
928 var oSettings = _oDatatable.fnSettings();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
929 for ( var i=0, iLen=oSettings.aiDisplay.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
930 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
931 var nTr = oSettings.aoData[ oSettings.aiDisplay[i] ].nTr;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
932 var nTds = nTr.getElementsByTagName('td');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
933 for ( var j=0, jLen=nTds.length ; j<jLen ; j++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
934 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
935 if ( nTds[j] == nTarget )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
936 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
937 return [ j, i ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
938 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
939 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
940 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
941 return null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
942 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
943
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
944
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
945
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
946 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
947 * Initialisation
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
948 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
949
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
950 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
951 * Function: _fnInit
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
952 * Purpose: Initialise the KeyTable
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
953 * Returns: -
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
954 * Inputs: object:oInit - optional - Initalisation object with the following parameters:
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
955 * array[2] int:focus - x and y coordinates of the initial target
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
956 * or
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
957 * node:focus - the node to set initial focus on
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
958 * node:table - the table to use, if not given, first table with class 'KeyTable' will be used
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
959 * string:focusClass - focusing class to give to table elements
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
960 * object:that - focus
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
961 * bool:initScroll - scroll the view port on load, default true
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
962 * int:tabIndex - the tab index to give the hidden input element
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
963 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
964 function _fnInit( oInit, that )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
965 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
966 /* Save scope */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
967 _that = that;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
968
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
969 /* Capture undefined initialisation and apply the defaults */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
970 if ( typeof oInit == 'undefined' ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
971 oInit = {};
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
972 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
973
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
974 if ( typeof oInit.focus == 'undefined' ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
975 oInit.focus = [0,0];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
976 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
977
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
978 if ( typeof oInit.table == 'undefined' ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
979 oInit.table = jQuery('table.KeyTable')[0];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
980 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
981 $(oInit.table).addClass('KeyTable');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
982 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
983
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
984 if ( typeof oInit.focusClass != 'undefined' ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
985 _sFocusClass = oInit.focusClass;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
986 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
987
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
988 if ( typeof oInit.datatable != 'undefined' ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
989 _oDatatable = oInit.datatable;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
990 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
991
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
992 if ( typeof oInit.initScroll == 'undefined' ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
993 oInit.initScroll = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
994 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
995
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
996 if ( typeof oInit.form == 'undefined' ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
997 oInit.form = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
998 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
999 _bForm = oInit.form;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1000
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1001 /* Cache the tbody node of interest */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1002 _nBody = oInit.table.getElementsByTagName('tbody')[0];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1003
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1004 /* If the table is inside a form, then we need a hidden input box which can be used by the
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1005 * browser to catch the browser tabbing for our table
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1006 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1007 if ( _bForm )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1008 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1009 var nDiv = document.createElement('div');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1010 _nInput = document.createElement('input');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1011 nDiv.style.height = "1px"; /* Opera requires a little something */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1012 nDiv.style.width = "0px";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1013 nDiv.style.overflow = "hidden";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1014 if ( typeof oInit.tabIndex != 'undefined' )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1015 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1016 _nInput.tabIndex = oInit.tabIndex;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1017 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1018 nDiv.appendChild(_nInput);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1019 oInit.table.parentNode.insertBefore( nDiv, oInit.table.nextSibling );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1020
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1021 jQuery(_nInput).focus( function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1022 /* See if we want to 'tab into' the table or out */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1023 if ( !_bInputFocused )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1024 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1025 _bKeyCapture = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1026 _bInputFocused = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1027 if ( typeof oInit.focus.nodeName != "undefined" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1028 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1029 _fnSetFocus( oInit.focus, oInit.initScroll );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1030 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1031 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1032 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1033 _fnSetFocus( _fnCellFromCoords( oInit.focus[0], oInit.focus[1]), oInit.initScroll );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1034 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1035
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1036 /* Need to interup the thread for this to work */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1037 setTimeout( function() { _nInput.blur(); }, 0 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1038 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1039 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1040 _bKeyCapture = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1041 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1042 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1043 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1044 /* Set the initial focus on the table */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1045 if ( typeof oInit.focus.nodeName != "undefined" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1046 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1047 _fnSetFocus( oInit.focus, oInit.initScroll );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1048 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1049 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1050 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1051 _fnSetFocus( _fnCellFromCoords( oInit.focus[0], oInit.focus[1]), oInit.initScroll );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1052 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1053 _fnCaptureKeys();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1054 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1055
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1056 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1057 * Add event listeners
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1058 * Well - I hate myself for doing this, but it would appear that key events in browsers are
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1059 * a complete mess, particulay when you consider arrow keys, which of course are one of the
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1060 * main areas of interest here. So basically for arrow keys, there is no keypress event in
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1061 * Safari and IE, while there is in Firefox and Opera. But Firefox and Opera don't repeat the
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1062 * keydown event for an arrow key. OUCH. See the following two articles for more:
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1063 * http://www.quirksmode.org/dom/events/keys.html
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1064 * https://lists.webkit.org/pipermail/webkit-dev/2007-December/002992.html
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1065 * http://unixpapa.com/js/key.html
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1066 * PPK considers the IE / Safari method correct (good enough for me!) so we (urgh) detect
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1067 * Mozilla and Opera and apply keypress for them, while everything else gets keydown. If
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1068 * Mozilla or Opera change their implemention in future, this will need to be updated...
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1069 * although at the time of writing (14th March 2009) Minefield still uses the 3.0 behaviour.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1070 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1071 if ( jQuery.browser.mozilla || jQuery.browser.opera )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1072 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1073 jQuery(document).bind( "keypress", _fnKey );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1074 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1075 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1076 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1077 jQuery(document).bind( "keydown", _fnKey );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1078 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1079
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1080 if ( _oDatatable )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1081 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1082 jQuery('tbody td', _oDatatable.fnSettings().nTable).live( 'click', _fnClick );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1083 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1084 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1085 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1086 jQuery('td', _nBody).live( 'click', _fnClick );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1087 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1088
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1089 /* Loose table focus when click outside the table */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1090 jQuery(document).click( function(e) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1091 var nTarget = e.target;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1092 var bTableClick = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1093 while ( nTarget )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1094 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1095 if ( nTarget == oInit.table )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1096 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1097 bTableClick = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1098 break;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1099 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1100 nTarget = nTarget.parentNode;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1101 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1102 if ( !bTableClick )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1103 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1104 _fnBlur();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1105 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1106 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1107 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1108
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1109 /* Initialise our new object */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1110 _fnInit( oInit, this );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1111 }