commit | author | age
|
6b47de
|
1 |
/* |
T |
2 |
+-----------------------------------------------------------------------+ |
e019f2
|
3 |
| Roundcube List Widget | |
6b47de
|
4 |
| | |
e019f2
|
5 |
| This file is part of the Roundcube Webmail client | |
e224b0
|
6 |
| Copyright (C) 2006-2009, The Roundcube Dev Team | |
6b47de
|
7 |
| Licensed under the GNU GPL | |
T |
8 |
| | |
|
9 |
+-----------------------------------------------------------------------+ |
|
10 |
| Authors: Thomas Bruederli <roundcube@gmail.com> | |
|
11 |
| Charles McNulty <charles@charlesmcnulty.com> | |
|
12 |
+-----------------------------------------------------------------------+ |
|
13 |
| Requires: common.js | |
|
14 |
+-----------------------------------------------------------------------+ |
|
15 |
|
57ff3b
|
16 |
$Id$ |
6b47de
|
17 |
*/ |
T |
18 |
|
|
19 |
|
|
20 |
/** |
e019f2
|
21 |
* Roundcube List Widget class |
6b47de
|
22 |
* @contructor |
T |
23 |
*/ |
|
24 |
function rcube_list_widget(list, p) |
8fa922
|
25 |
{ |
6b47de
|
26 |
// static contants |
T |
27 |
this.ENTER_KEY = 13; |
|
28 |
this.DELETE_KEY = 46; |
6e6e89
|
29 |
this.BACKSPACE_KEY = 8; |
8fa922
|
30 |
|
6b47de
|
31 |
this.list = list ? list : null; |
T |
32 |
this.frame = null; |
|
33 |
this.rows = []; |
|
34 |
this.selection = []; |
0dbac3
|
35 |
this.rowcount = 0; |
b62c48
|
36 |
this.colcount = 0; |
8fa922
|
37 |
|
d24d20
|
38 |
this.subject_col = -1; |
31c171
|
39 |
this.shiftkey = false; |
6b47de
|
40 |
this.multiselect = false; |
f52c93
|
41 |
this.multiexpand = false; |
21168d
|
42 |
this.multi_selecting = false; |
6b47de
|
43 |
this.draggable = false; |
b62c48
|
44 |
this.column_movable = false; |
6b47de
|
45 |
this.keyboard = false; |
68b6a9
|
46 |
this.toggleselect = false; |
8fa922
|
47 |
|
6b47de
|
48 |
this.dont_select = false; |
T |
49 |
this.drag_active = false; |
b62c48
|
50 |
this.col_drag_active = false; |
A |
51 |
this.column_fixed = null; |
6b47de
|
52 |
this.last_selected = 0; |
b2fb95
|
53 |
this.shift_start = 0; |
6b47de
|
54 |
this.in_selection_before = false; |
T |
55 |
this.focused = false; |
|
56 |
this.drag_mouse_start = null; |
|
57 |
this.dblclick_time = 600; |
|
58 |
this.row_init = function(){}; |
8fa922
|
59 |
|
6b47de
|
60 |
// overwrite default paramaters |
ef4f59
|
61 |
if (p && typeof p === 'object') |
6b47de
|
62 |
for (var n in p) |
T |
63 |
this[n] = p[n]; |
8fa922
|
64 |
}; |
6b47de
|
65 |
|
T |
66 |
|
|
67 |
rcube_list_widget.prototype = { |
|
68 |
|
|
69 |
|
|
70 |
/** |
|
71 |
* get all message rows from HTML table and init each row |
|
72 |
*/ |
|
73 |
init: function() |
|
74 |
{ |
8fa922
|
75 |
if (this.list && this.list.tBodies[0]) { |
A |
76 |
this.rows = []; |
0dbac3
|
77 |
this.rowcount = 0; |
6b47de
|
78 |
|
0e7b66
|
79 |
var r, len, rows = this.list.tBodies[0].rows; |
6b47de
|
80 |
|
0e7b66
|
81 |
for (r=0, len=rows.length; r<len; r++) { |
A |
82 |
this.init_row(rows[r]); |
0dbac3
|
83 |
this.rowcount++; |
6b47de
|
84 |
} |
T |
85 |
|
b62c48
|
86 |
this.init_header(); |
6b47de
|
87 |
this.frame = this.list.parentNode; |
T |
88 |
|
|
89 |
// set body events |
26f5b0
|
90 |
if (this.keyboard) { |
6c11ee
|
91 |
rcube_event.add_listener({event:bw.opera?'keypress':'keydown', object:this, method:'key_press'}); |
A |
92 |
rcube_event.add_listener({event:'keydown', object:this, method:'key_down'}); |
26f5b0
|
93 |
} |
6b47de
|
94 |
} |
T |
95 |
}, |
|
96 |
|
|
97 |
|
|
98 |
/** |
c4b819
|
99 |
* Init list row and set mouse events on it |
6b47de
|
100 |
*/ |
T |
101 |
init_row: function(row) |
|
102 |
{ |
|
103 |
// make references in internal array and set event handlers |
bbd4ca
|
104 |
if (row && String(row.id).match(/^rcmrow([a-z0-9\-_=\+\/]+)/i)) { |
1633bc
|
105 |
var self = this, |
A |
106 |
uid = RegExp.$1; |
6b47de
|
107 |
row.uid = uid; |
f52c93
|
108 |
this.rows[uid] = {uid:uid, id:row.id, obj:row}; |
6b47de
|
109 |
|
T |
110 |
// set eventhandlers to table row |
8ef2f3
|
111 |
row.onmousedown = function(e){ return self.drag_row(e, this.uid); }; |
T |
112 |
row.onmouseup = function(e){ return self.click_row(e, this.uid); }; |
1ce442
|
113 |
|
8ef2f3
|
114 |
if (bw.iphone || bw.ipad) { |
T |
115 |
row.addEventListener('touchstart', function(e) { |
|
116 |
if (e.touches.length == 1) { |
|
117 |
if (!self.drag_row(rcube_event.touchevent(e.touches[0]), this.uid)) |
|
118 |
e.preventDefault(); |
|
119 |
} |
|
120 |
}, false); |
|
121 |
row.addEventListener('touchend', function(e) { |
|
122 |
if (e.changedTouches.length == 1) |
|
123 |
if (!self.click_row(rcube_event.touchevent(e.changedTouches[0]), this.uid)) |
|
124 |
e.preventDefault(); |
|
125 |
}, false); |
|
126 |
} |
6b47de
|
127 |
|
T |
128 |
if (document.all) |
|
129 |
row.onselectstart = function() { return false; }; |
|
130 |
|
|
131 |
this.row_init(this.rows[uid]); |
b62c48
|
132 |
} |
A |
133 |
}, |
|
134 |
|
|
135 |
|
|
136 |
/** |
|
137 |
* Init list column headers and set mouse events on them |
|
138 |
*/ |
|
139 |
init_header: function() |
|
140 |
{ |
|
141 |
if (this.list && this.list.tHead) { |
|
142 |
this.colcount = 0; |
|
143 |
|
|
144 |
var col, r, p = this; |
|
145 |
// add events for list columns moving |
|
146 |
if (this.column_movable && this.list.tHead && this.list.tHead.rows) { |
|
147 |
for (r=0; r<this.list.tHead.rows[0].cells.length; r++) { |
|
148 |
if (this.column_fixed == r) |
|
149 |
continue; |
|
150 |
col = this.list.tHead.rows[0].cells[r]; |
|
151 |
col.onmousedown = function(e){ return p.drag_column(e, this); }; |
|
152 |
this.colcount++; |
|
153 |
} |
|
154 |
} |
6b47de
|
155 |
} |
T |
156 |
}, |
|
157 |
|
|
158 |
|
|
159 |
/** |
c4b819
|
160 |
* Remove all list rows |
6b47de
|
161 |
*/ |
f11541
|
162 |
clear: function(sel) |
6b47de
|
163 |
{ |
91a35e
|
164 |
var tbody = document.createElement('tbody'); |
54531f
|
165 |
|
6b47de
|
166 |
this.list.insertBefore(tbody, this.list.tBodies[0]); |
T |
167 |
this.list.removeChild(this.list.tBodies[1]); |
8fa922
|
168 |
this.rows = []; |
0dbac3
|
169 |
this.rowcount = 0; |
8fa922
|
170 |
|
A |
171 |
if (sel) |
|
172 |
this.clear_selection(); |
1633bc
|
173 |
|
A |
174 |
// reset scroll position (in Opera) |
|
175 |
if (this.frame) |
|
176 |
this.frame.scrollTop = 0; |
6b47de
|
177 |
}, |
T |
178 |
|
|
179 |
|
|
180 |
/** |
|
181 |
* 'remove' message row from list (just hide it) |
|
182 |
*/ |
b62656
|
183 |
remove_row: function(uid, sel_next) |
6b47de
|
184 |
{ |
T |
185 |
if (this.rows[uid].obj) |
|
186 |
this.rows[uid].obj.style.display = 'none'; |
|
187 |
|
b62656
|
188 |
if (sel_next) |
T |
189 |
this.select_next(); |
|
190 |
|
0e7b66
|
191 |
delete this.rows[uid]; |
0dbac3
|
192 |
this.rowcount--; |
6b47de
|
193 |
}, |
T |
194 |
|
|
195 |
|
|
196 |
/** |
c4b819
|
197 |
* Add row to the list and initialize it |
6b47de
|
198 |
*/ |
T |
199 |
insert_row: function(row, attop) |
|
200 |
{ |
0e7b66
|
201 |
var tbody = this.list.tBodies[0]; |
6b47de
|
202 |
|
T |
203 |
if (attop && tbody.rows.length) |
c4b819
|
204 |
tbody.insertBefore(row, tbody.firstChild); |
6b47de
|
205 |
else |
c4b819
|
206 |
tbody.appendChild(row); |
6b47de
|
207 |
|
c4b819
|
208 |
this.init_row(row); |
0dbac3
|
209 |
this.rowcount++; |
6b47de
|
210 |
}, |
T |
211 |
|
|
212 |
|
|
213 |
|
|
214 |
/** |
25c35c
|
215 |
* Set focus to the list |
6b47de
|
216 |
*/ |
T |
217 |
focus: function(e) |
|
218 |
{ |
1633bc
|
219 |
var n, id; |
6b47de
|
220 |
this.focused = true; |
2c2000
|
221 |
|
1633bc
|
222 |
for (n in this.selection) { |
6b47de
|
223 |
id = this.selection[n]; |
cc97ea
|
224 |
if (this.rows[id] && this.rows[id].obj) { |
T |
225 |
$(this.rows[id].obj).addClass('selected').removeClass('unfocused'); |
6b47de
|
226 |
} |
T |
227 |
} |
|
228 |
|
2c2000
|
229 |
// Un-focus already focused elements |
489ffb
|
230 |
$('*:focus', window).blur(); |
1ce442
|
231 |
$('iframe').each(function() { this.blur(); }); |
2c2000
|
232 |
|
6b47de
|
233 |
if (e || (e = window.event)) |
T |
234 |
rcube_event.cancel(e); |
|
235 |
}, |
|
236 |
|
|
237 |
|
|
238 |
/** |
|
239 |
* remove focus from the list |
|
240 |
*/ |
|
241 |
blur: function() |
|
242 |
{ |
1633bc
|
243 |
var n, id; |
6b47de
|
244 |
this.focused = false; |
1633bc
|
245 |
for (n in this.selection) { |
6b47de
|
246 |
id = this.selection[n]; |
cc97ea
|
247 |
if (this.rows[id] && this.rows[id].obj) { |
T |
248 |
$(this.rows[id].obj).removeClass('selected').addClass('unfocused'); |
6b47de
|
249 |
} |
T |
250 |
} |
|
251 |
}, |
|
252 |
|
|
253 |
|
|
254 |
/** |
b62c48
|
255 |
* onmousedown-handler of message list column |
A |
256 |
*/ |
|
257 |
drag_column: function(e, col) |
|
258 |
{ |
|
259 |
if (this.colcount > 1) { |
|
260 |
this.drag_start = true; |
|
261 |
this.drag_mouse_start = rcube_event.get_mouse_pos(e); |
|
262 |
|
|
263 |
rcube_event.add_listener({event:'mousemove', object:this, method:'column_drag_mouse_move'}); |
|
264 |
rcube_event.add_listener({event:'mouseup', object:this, method:'column_drag_mouse_up'}); |
|
265 |
|
|
266 |
// enable dragging over iframes |
|
267 |
this.add_dragfix(); |
|
268 |
|
|
269 |
// find selected column number |
|
270 |
for (var i=0; i<this.list.tHead.rows[0].cells.length; i++) { |
|
271 |
if (col == this.list.tHead.rows[0].cells[i]) { |
|
272 |
this.selected_column = i; |
|
273 |
break; |
|
274 |
} |
|
275 |
} |
|
276 |
} |
|
277 |
|
|
278 |
return false; |
|
279 |
}, |
|
280 |
|
|
281 |
|
|
282 |
/** |
6b47de
|
283 |
* onmousedown-handler of message list row |
T |
284 |
*/ |
|
285 |
drag_row: function(e, id) |
|
286 |
{ |
|
287 |
// don't do anything (another action processed before) |
54531f
|
288 |
var evtarget = rcube_event.get_target(e), |
A |
289 |
tagname = evtarget.tagName.toLowerCase(); |
|
290 |
|
91a35e
|
291 |
if (this.dont_select || (evtarget && (tagname == 'input' || tagname == 'img'))) |
40d7c2
|
292 |
return true; |
8fa922
|
293 |
|
f89f03
|
294 |
// accept right-clicks |
T |
295 |
if (rcube_event.get_button(e) == 2) |
|
296 |
return true; |
8fa922
|
297 |
|
bf36a9
|
298 |
this.in_selection_before = this.in_selection(id) ? id : false; |
T |
299 |
|
6b47de
|
300 |
// selects currently unselected row |
8fa922
|
301 |
if (!this.in_selection_before) { |
6b47de
|
302 |
var mod_key = rcube_event.get_modifier(e); |
T |
303 |
this.select_row(id, mod_key, false); |
|
304 |
} |
|
305 |
|
8fa922
|
306 |
if (this.draggable && this.selection.length) { |
6b47de
|
307 |
this.drag_start = true; |
b2fb95
|
308 |
this.drag_mouse_start = rcube_event.get_mouse_pos(e); |
6c11ee
|
309 |
rcube_event.add_listener({event:'mousemove', object:this, method:'drag_mouse_move'}); |
A |
310 |
rcube_event.add_listener({event:'mouseup', object:this, method:'drag_mouse_up'}); |
8ef2f3
|
311 |
if (bw.iphone || bw.ipad) { |
T |
312 |
rcube_event.add_listener({event:'touchmove', object:this, method:'drag_mouse_move'}); |
|
313 |
rcube_event.add_listener({event:'touchend', object:this, method:'drag_mouse_up'}); |
|
314 |
} |
cf6bc5
|
315 |
|
6c11ee
|
316 |
// enable dragging over iframes |
b62c48
|
317 |
this.add_dragfix(); |
6b47de
|
318 |
} |
T |
319 |
|
|
320 |
return false; |
|
321 |
}, |
|
322 |
|
|
323 |
|
|
324 |
/** |
|
325 |
* onmouseup-handler of message list row |
|
326 |
*/ |
|
327 |
click_row: function(e, id) |
|
328 |
{ |
54531f
|
329 |
var now = new Date().getTime(), |
A |
330 |
mod_key = rcube_event.get_modifier(e), |
|
331 |
evtarget = rcube_event.get_target(e), |
|
332 |
tagname = evtarget.tagName.toLowerCase(); |
40d7c2
|
333 |
|
91a35e
|
334 |
if ((evtarget && (tagname == 'input' || tagname == 'img'))) |
40d7c2
|
335 |
return true; |
A |
336 |
|
6b47de
|
337 |
// don't do anything (another action processed before) |
8fa922
|
338 |
if (this.dont_select) { |
6b47de
|
339 |
this.dont_select = false; |
T |
340 |
return false; |
8ef2f3
|
341 |
} |
8fa922
|
342 |
|
6b47de
|
343 |
var dblclicked = now - this.rows[id].clicked < this.dblclick_time; |
T |
344 |
|
|
345 |
// unselects currently selected row |
|
346 |
if (!this.drag_active && this.in_selection_before == id && !dblclicked) |
|
347 |
this.select_row(id, mod_key, false); |
|
348 |
|
|
349 |
this.drag_start = false; |
|
350 |
this.in_selection_before = false; |
|
351 |
|
|
352 |
// row was double clicked |
|
353 |
if (this.rows && dblclicked && this.in_selection(id)) |
cc97ea
|
354 |
this.triggerEvent('dblclick'); |
6b47de
|
355 |
else |
cc97ea
|
356 |
this.triggerEvent('click'); |
6b47de
|
357 |
|
dd51b7
|
358 |
if (!this.drag_active) { |
A |
359 |
// remove temp divs |
b62c48
|
360 |
this.del_dragfix(); |
6b47de
|
361 |
rcube_event.cancel(e); |
dd51b7
|
362 |
} |
6b47de
|
363 |
|
T |
364 |
this.rows[id].clicked = now; |
|
365 |
return false; |
|
366 |
}, |
|
367 |
|
|
368 |
|
bc2acc
|
369 |
/* |
A |
370 |
* Returns thread root ID for specified row ID |
|
371 |
*/ |
|
372 |
find_root: function(uid) |
|
373 |
{ |
|
374 |
var r = this.rows[uid]; |
|
375 |
|
|
376 |
if (r && r.parent_uid) |
|
377 |
return this.find_root(r.parent_uid); |
|
378 |
else |
|
379 |
return uid; |
|
380 |
}, |
|
381 |
|
|
382 |
|
f52c93
|
383 |
expand_row: function(e, id) |
T |
384 |
{ |
54531f
|
385 |
var row = this.rows[id], |
A |
386 |
evtarget = rcube_event.get_target(e), |
|
387 |
mod_key = rcube_event.get_modifier(e); |
f52c93
|
388 |
|
T |
389 |
// Don't select this message |
|
390 |
this.dont_select = true; |
|
391 |
// Don't treat double click on the expando as double click on the message. |
|
392 |
row.clicked = 0; |
|
393 |
|
|
394 |
if (row.expanded) { |
54531f
|
395 |
evtarget.className = 'collapsed'; |
f52c93
|
396 |
if (mod_key == CONTROL_KEY || this.multiexpand) |
T |
397 |
this.collapse_all(row); |
|
398 |
else |
|
399 |
this.collapse(row); |
|
400 |
} |
|
401 |
else { |
54531f
|
402 |
evtarget.className = 'expanded'; |
f52c93
|
403 |
if (mod_key == CONTROL_KEY || this.multiexpand) |
T |
404 |
this.expand_all(row); |
|
405 |
else |
|
406 |
this.expand(row); |
|
407 |
} |
|
408 |
}, |
|
409 |
|
|
410 |
collapse: function(row) |
|
411 |
{ |
|
412 |
row.expanded = false; |
|
413 |
this.triggerEvent('expandcollapse', { uid:row.uid, expanded:row.expanded }); |
|
414 |
var depth = row.depth; |
|
415 |
var new_row = row ? row.obj.nextSibling : null; |
|
416 |
var r; |
|
417 |
|
|
418 |
while (new_row) { |
|
419 |
if (new_row.nodeType == 1) { |
|
420 |
var r = this.rows[new_row.uid]; |
|
421 |
if (r && r.depth <= depth) |
|
422 |
break; |
a3c9bd
|
423 |
$(new_row).css('display', 'none'); |
54531f
|
424 |
if (r.expanded) { |
A |
425 |
r.expanded = false; |
|
426 |
this.triggerEvent('expandcollapse', { uid:r.uid, expanded:r.expanded }); |
|
427 |
} |
f52c93
|
428 |
} |
T |
429 |
new_row = new_row.nextSibling; |
|
430 |
} |
|
431 |
|
|
432 |
return false; |
|
433 |
}, |
|
434 |
|
|
435 |
expand: function(row) |
|
436 |
{ |
1633bc
|
437 |
var r, p, depth, new_row, last_expanded_parent_depth; |
f52c93
|
438 |
|
T |
439 |
if (row) { |
|
440 |
row.expanded = true; |
|
441 |
depth = row.depth; |
|
442 |
new_row = row.obj.nextSibling; |
bc2acc
|
443 |
this.update_expando(row.uid, true); |
f52c93
|
444 |
this.triggerEvent('expandcollapse', { uid:row.uid, expanded:row.expanded }); |
T |
445 |
} |
|
446 |
else { |
|
447 |
var tbody = this.list.tBodies[0]; |
|
448 |
new_row = tbody.firstChild; |
|
449 |
depth = 0; |
|
450 |
last_expanded_parent_depth = 0; |
|
451 |
} |
|
452 |
|
|
453 |
while (new_row) { |
|
454 |
if (new_row.nodeType == 1) { |
1633bc
|
455 |
r = this.rows[new_row.uid]; |
f52c93
|
456 |
if (r) { |
T |
457 |
if (row && (!r.depth || r.depth <= depth)) |
|
458 |
break; |
|
459 |
|
|
460 |
if (r.parent_uid) { |
1633bc
|
461 |
p = this.rows[r.parent_uid]; |
f52c93
|
462 |
if (p && p.expanded) { |
T |
463 |
if ((row && p == row) || last_expanded_parent_depth >= p.depth - 1) { |
|
464 |
last_expanded_parent_depth = p.depth; |
a3c9bd
|
465 |
$(new_row).css('display', ''); |
f52c93
|
466 |
r.expanded = true; |
T |
467 |
this.triggerEvent('expandcollapse', { uid:r.uid, expanded:r.expanded }); |
|
468 |
} |
|
469 |
} |
|
470 |
else |
|
471 |
if (row && (! p || p.depth <= depth)) |
|
472 |
break; |
|
473 |
} |
|
474 |
} |
|
475 |
} |
|
476 |
new_row = new_row.nextSibling; |
|
477 |
} |
|
478 |
|
|
479 |
return false; |
|
480 |
}, |
|
481 |
|
|
482 |
|
|
483 |
collapse_all: function(row) |
|
484 |
{ |
54531f
|
485 |
var depth, new_row, r; |
f52c93
|
486 |
|
T |
487 |
if (row) { |
|
488 |
row.expanded = false; |
|
489 |
depth = row.depth; |
|
490 |
new_row = row.obj.nextSibling; |
bc2acc
|
491 |
this.update_expando(row.uid); |
f52c93
|
492 |
this.triggerEvent('expandcollapse', { uid:row.uid, expanded:row.expanded }); |
8fa922
|
493 |
|
f52c93
|
494 |
// don't collapse sub-root tree in multiexpand mode |
T |
495 |
if (depth && this.multiexpand) |
54531f
|
496 |
return false; |
f52c93
|
497 |
} |
T |
498 |
else { |
54531f
|
499 |
new_row = this.list.tBodies[0].firstChild; |
f52c93
|
500 |
depth = 0; |
T |
501 |
} |
|
502 |
|
|
503 |
while (new_row) { |
|
504 |
if (new_row.nodeType == 1) { |
54531f
|
505 |
if (r = this.rows[new_row.uid]) { |
f52c93
|
506 |
if (row && (!r.depth || r.depth <= depth)) |
T |
507 |
break; |
|
508 |
|
|
509 |
if (row || r.depth) |
a3c9bd
|
510 |
$(new_row).css('display', 'none'); |
54531f
|
511 |
if (r.has_children && r.expanded) { |
f52c93
|
512 |
r.expanded = false; |
54531f
|
513 |
this.update_expando(r.uid, false); |
f52c93
|
514 |
this.triggerEvent('expandcollapse', { uid:r.uid, expanded:r.expanded }); |
T |
515 |
} |
|
516 |
} |
|
517 |
} |
|
518 |
new_row = new_row.nextSibling; |
|
519 |
} |
|
520 |
|
|
521 |
return false; |
|
522 |
}, |
|
523 |
|
|
524 |
expand_all: function(row) |
|
525 |
{ |
54531f
|
526 |
var depth, new_row, r; |
f52c93
|
527 |
|
T |
528 |
if (row) { |
|
529 |
row.expanded = true; |
|
530 |
depth = row.depth; |
|
531 |
new_row = row.obj.nextSibling; |
bc2acc
|
532 |
this.update_expando(row.uid, true); |
f52c93
|
533 |
this.triggerEvent('expandcollapse', { uid:row.uid, expanded:row.expanded }); |
T |
534 |
} |
|
535 |
else { |
54531f
|
536 |
new_row = this.list.tBodies[0].firstChild; |
f52c93
|
537 |
depth = 0; |
T |
538 |
} |
|
539 |
|
|
540 |
while (new_row) { |
|
541 |
if (new_row.nodeType == 1) { |
54531f
|
542 |
if (r = this.rows[new_row.uid]) { |
f52c93
|
543 |
if (row && r.depth <= depth) |
T |
544 |
break; |
|
545 |
|
a3c9bd
|
546 |
$(new_row).css('display', ''); |
54531f
|
547 |
if (r.has_children && !r.expanded) { |
f52c93
|
548 |
r.expanded = true; |
54531f
|
549 |
this.update_expando(r.uid, true); |
f52c93
|
550 |
this.triggerEvent('expandcollapse', { uid:r.uid, expanded:r.expanded }); |
T |
551 |
} |
|
552 |
} |
|
553 |
} |
|
554 |
new_row = new_row.nextSibling; |
|
555 |
} |
|
556 |
return false; |
|
557 |
}, |
bc2acc
|
558 |
|
A |
559 |
update_expando: function(uid, expanded) |
|
560 |
{ |
|
561 |
var expando = document.getElementById('rcmexpando' + uid); |
|
562 |
if (expando) |
|
563 |
expando.className = expanded ? 'expanded' : 'collapsed'; |
|
564 |
}, |
|
565 |
|
f52c93
|
566 |
|
6b47de
|
567 |
/** |
49771b
|
568 |
* get first/next/previous/last rows that are not hidden |
6b47de
|
569 |
*/ |
T |
570 |
get_next_row: function() |
|
571 |
{ |
|
572 |
if (!this.rows) |
|
573 |
return false; |
|
574 |
|
54531f
|
575 |
var last_selected_row = this.rows[this.last_selected], |
A |
576 |
new_row = last_selected_row ? last_selected_row.obj.nextSibling : null; |
|
577 |
|
6b47de
|
578 |
while (new_row && (new_row.nodeType != 1 || new_row.style.display == 'none')) |
T |
579 |
new_row = new_row.nextSibling; |
|
580 |
|
|
581 |
return new_row; |
|
582 |
}, |
|
583 |
|
|
584 |
get_prev_row: function() |
|
585 |
{ |
|
586 |
if (!this.rows) |
|
587 |
return false; |
|
588 |
|
54531f
|
589 |
var last_selected_row = this.rows[this.last_selected], |
A |
590 |
new_row = last_selected_row ? last_selected_row.obj.previousSibling : null; |
|
591 |
|
6b47de
|
592 |
while (new_row && (new_row.nodeType != 1 || new_row.style.display == 'none')) |
T |
593 |
new_row = new_row.previousSibling; |
|
594 |
|
|
595 |
return new_row; |
49771b
|
596 |
}, |
A |
597 |
|
|
598 |
get_first_row: function() |
|
599 |
{ |
8fa922
|
600 |
if (this.rowcount) { |
0e7b66
|
601 |
var i, len, rows = this.list.tBodies[0].rows; |
49771b
|
602 |
|
0e7b66
|
603 |
for (i=0, len=rows.length-1; i<len; i++) |
bbd4ca
|
604 |
if (rows[i].id && String(rows[i].id).match(/^rcmrow([a-z0-9\-_=\+\/]+)/i) && this.rows[RegExp.$1] != null) |
0e7b66
|
605 |
return RegExp.$1; |
8fa922
|
606 |
} |
49771b
|
607 |
|
A |
608 |
return null; |
6b47de
|
609 |
}, |
T |
610 |
|
095d05
|
611 |
get_last_row: function() |
A |
612 |
{ |
8fa922
|
613 |
if (this.rowcount) { |
0e7b66
|
614 |
var i, rows = this.list.tBodies[0].rows; |
6b47de
|
615 |
|
0e7b66
|
616 |
for (i=rows.length-1; i>=0; i--) |
bbd4ca
|
617 |
if (rows[i].id && String(rows[i].id).match(/^rcmrow([a-z0-9\-_=\+\/]+)/i) && this.rows[RegExp.$1] != null) |
0e7b66
|
618 |
return RegExp.$1; |
8fa922
|
619 |
} |
095d05
|
620 |
|
A |
621 |
return null; |
|
622 |
}, |
|
623 |
|
|
624 |
|
|
625 |
/** |
|
626 |
* selects or unselects the proper row depending on the modifier key pressed |
|
627 |
*/ |
6b47de
|
628 |
select_row: function(id, mod_key, with_mouse) |
T |
629 |
{ |
|
630 |
var select_before = this.selection.join(','); |
|
631 |
if (!this.multiselect) |
|
632 |
mod_key = 0; |
8fa922
|
633 |
|
b2fb95
|
634 |
if (!this.shift_start) |
T |
635 |
this.shift_start = id |
6b47de
|
636 |
|
8fa922
|
637 |
if (!mod_key) { |
6b47de
|
638 |
this.shift_start = id; |
T |
639 |
this.highlight_row(id, false); |
21168d
|
640 |
this.multi_selecting = false; |
6b47de
|
641 |
} |
8fa922
|
642 |
else { |
A |
643 |
switch (mod_key) { |
6b47de
|
644 |
case SHIFT_KEY: |
b2fb95
|
645 |
this.shift_select(id, false); |
6b47de
|
646 |
break; |
T |
647 |
|
|
648 |
case CONTROL_KEY: |
|
649 |
if (!with_mouse) |
b2fb95
|
650 |
this.highlight_row(id, true); |
6b47de
|
651 |
break; |
T |
652 |
|
|
653 |
case CONTROL_SHIFT_KEY: |
|
654 |
this.shift_select(id, true); |
|
655 |
break; |
|
656 |
|
|
657 |
default: |
b2fb95
|
658 |
this.highlight_row(id, false); |
6b47de
|
659 |
break; |
T |
660 |
} |
21168d
|
661 |
this.multi_selecting = true; |
6b47de
|
662 |
} |
T |
663 |
|
|
664 |
// trigger event if selection changed |
|
665 |
if (this.selection.join(',') != select_before) |
cc97ea
|
666 |
this.triggerEvent('select'); |
6b47de
|
667 |
|
T |
668 |
if (this.last_selected != 0 && this.rows[this.last_selected]) |
cc97ea
|
669 |
$(this.rows[this.last_selected].obj).removeClass('focused'); |
a9dda5
|
670 |
|
T |
671 |
// unselect if toggleselect is active and the same row was clicked again |
8fa922
|
672 |
if (this.toggleselect && this.last_selected == id) { |
a9dda5
|
673 |
this.clear_selection(); |
T |
674 |
id = null; |
|
675 |
} |
|
676 |
else |
cc97ea
|
677 |
$(this.rows[id].obj).addClass('focused'); |
a9dda5
|
678 |
|
b2fb95
|
679 |
if (!this.selection.length) |
T |
680 |
this.shift_start = null; |
6b47de
|
681 |
|
T |
682 |
this.last_selected = id; |
|
683 |
}, |
|
684 |
|
|
685 |
|
|
686 |
/** |
|
687 |
* Alias method for select_row |
|
688 |
*/ |
|
689 |
select: function(id) |
|
690 |
{ |
|
691 |
this.select_row(id, false); |
|
692 |
this.scrollto(id); |
|
693 |
}, |
|
694 |
|
|
695 |
|
|
696 |
/** |
|
697 |
* Select row next to the last selected one. |
|
698 |
* Either below or above. |
|
699 |
*/ |
|
700 |
select_next: function() |
|
701 |
{ |
1633bc
|
702 |
var next_row = this.get_next_row(), |
A |
703 |
prev_row = this.get_prev_row(), |
|
704 |
new_row = (next_row) ? next_row : prev_row; |
|
705 |
|
6b47de
|
706 |
if (new_row) |
1ce442
|
707 |
this.select_row(new_row.uid, false, false); |
6b47de
|
708 |
}, |
T |
709 |
|
bc2acc
|
710 |
|
49771b
|
711 |
/** |
A |
712 |
* Select first row |
|
713 |
*/ |
bc2acc
|
714 |
select_first: function(mod_key) |
49771b
|
715 |
{ |
bc2acc
|
716 |
var row = this.get_first_row(); |
1633bc
|
717 |
if (row) { |
A |
718 |
if (mod_key) { |
|
719 |
this.shift_select(row, mod_key); |
|
720 |
this.triggerEvent('select'); |
|
721 |
this.scrollto(row); |
|
722 |
} |
|
723 |
else { |
|
724 |
this.select(row); |
|
725 |
} |
bc2acc
|
726 |
} |
49771b
|
727 |
}, |
bc2acc
|
728 |
|
A |
729 |
|
|
730 |
/** |
|
731 |
* Select last row |
|
732 |
*/ |
|
733 |
select_last: function(mod_key) |
|
734 |
{ |
|
735 |
var row = this.get_last_row(); |
1633bc
|
736 |
if (row) { |
A |
737 |
if (mod_key) { |
|
738 |
this.shift_select(row, mod_key); |
|
739 |
this.triggerEvent('select'); |
|
740 |
this.scrollto(row); |
|
741 |
} |
|
742 |
else { |
|
743 |
this.select(row); |
|
744 |
} |
bc2acc
|
745 |
} |
A |
746 |
}, |
|
747 |
|
49771b
|
748 |
|
84a331
|
749 |
/** |
T |
750 |
* Add all childs of the given row to selection |
|
751 |
*/ |
|
752 |
select_childs: function(uid) |
|
753 |
{ |
|
754 |
if (!this.rows[uid] || !this.rows[uid].has_children) |
|
755 |
return; |
8fa922
|
756 |
|
1633bc
|
757 |
var depth = this.rows[uid].depth, |
A |
758 |
row = this.rows[uid].obj.nextSibling; |
|
759 |
|
84a331
|
760 |
while (row) { |
T |
761 |
if (row.nodeType == 1) { |
|
762 |
if ((r = this.rows[row.uid])) { |
|
763 |
if (!r.depth || r.depth <= depth) |
|
764 |
break; |
|
765 |
if (!this.in_selection(r.uid)) |
|
766 |
this.select_row(r.uid, CONTROL_KEY); |
|
767 |
} |
|
768 |
} |
|
769 |
row = row.nextSibling; |
|
770 |
} |
|
771 |
}, |
|
772 |
|
6b47de
|
773 |
|
T |
774 |
/** |
|
775 |
* Perform selection when shift key is pressed |
|
776 |
*/ |
|
777 |
shift_select: function(id, control) |
|
778 |
{ |
b00bd0
|
779 |
if (!this.rows[this.shift_start] || !this.selection.length) |
f2892d
|
780 |
this.shift_start = id; |
A |
781 |
|
1633bc
|
782 |
var n, from_rowIndex = this.rows[this.shift_start].obj.rowIndex, |
0e7b66
|
783 |
to_rowIndex = this.rows[id].obj.rowIndex, |
A |
784 |
i = ((from_rowIndex < to_rowIndex)? from_rowIndex : to_rowIndex), |
|
785 |
j = ((from_rowIndex > to_rowIndex)? from_rowIndex : to_rowIndex); |
6b47de
|
786 |
|
T |
787 |
// iterate through the entire message list |
1633bc
|
788 |
for (n in this.rows) { |
0e7b66
|
789 |
if (this.rows[n].obj.rowIndex >= i && this.rows[n].obj.rowIndex <= j) { |
f52c93
|
790 |
if (!this.in_selection(n)) { |
6b47de
|
791 |
this.highlight_row(n, true); |
f52c93
|
792 |
} |
6b47de
|
793 |
} |
8fa922
|
794 |
else { |
1633bc
|
795 |
if (this.in_selection(n) && !control) { |
6b47de
|
796 |
this.highlight_row(n, true); |
f52c93
|
797 |
} |
6b47de
|
798 |
} |
T |
799 |
} |
|
800 |
}, |
|
801 |
|
|
802 |
|
|
803 |
/** |
|
804 |
* Check if given id is part of the current selection |
|
805 |
*/ |
|
806 |
in_selection: function(id) |
|
807 |
{ |
1633bc
|
808 |
for (var n in this.selection) |
6b47de
|
809 |
if (this.selection[n]==id) |
T |
810 |
return true; |
|
811 |
|
f52c93
|
812 |
return false; |
6b47de
|
813 |
}, |
T |
814 |
|
|
815 |
|
|
816 |
/** |
|
817 |
* Select each row in list |
|
818 |
*/ |
|
819 |
select_all: function(filter) |
|
820 |
{ |
|
821 |
if (!this.rows || !this.rows.length) |
|
822 |
return false; |
|
823 |
|
1094cd
|
824 |
// reset but remember selection first |
1633bc
|
825 |
var n, select_before = this.selection.join(','); |
8fa922
|
826 |
this.selection = []; |
A |
827 |
|
1633bc
|
828 |
for (n in this.rows) { |
0e7b66
|
829 |
if (!filter || this.rows[n][filter] == true) { |
6b47de
|
830 |
this.last_selected = n; |
T |
831 |
this.highlight_row(n, true); |
|
832 |
} |
0e7b66
|
833 |
else { |
eaacbe
|
834 |
$(this.rows[n].obj).removeClass('selected').removeClass('unfocused'); |
874717
|
835 |
} |
6b47de
|
836 |
} |
T |
837 |
|
1094cd
|
838 |
// trigger event if selection changed |
T |
839 |
if (this.selection.join(',') != select_before) |
cc97ea
|
840 |
this.triggerEvent('select'); |
1094cd
|
841 |
|
d7c226
|
842 |
this.focus(); |
A |
843 |
|
1094cd
|
844 |
return true; |
6b47de
|
845 |
}, |
T |
846 |
|
|
847 |
|
|
848 |
/** |
528185
|
849 |
* Invert selection |
A |
850 |
*/ |
|
851 |
invert_selection: function() |
|
852 |
{ |
|
853 |
if (!this.rows || !this.rows.length) |
|
854 |
return false; |
|
855 |
|
|
856 |
// remember old selection |
1633bc
|
857 |
var n, select_before = this.selection.join(','); |
8fa922
|
858 |
|
1633bc
|
859 |
for (n in this.rows) |
f52c93
|
860 |
this.highlight_row(n, true); |
528185
|
861 |
|
A |
862 |
// trigger event if selection changed |
|
863 |
if (this.selection.join(',') != select_before) |
|
864 |
this.triggerEvent('select'); |
|
865 |
|
|
866 |
this.focus(); |
|
867 |
|
|
868 |
return true; |
|
869 |
}, |
|
870 |
|
|
871 |
|
|
872 |
/** |
095d05
|
873 |
* Unselect selected row(s) |
6b47de
|
874 |
*/ |
095d05
|
875 |
clear_selection: function(id) |
6b47de
|
876 |
{ |
1633bc
|
877 |
var n, num_select = this.selection.length; |
095d05
|
878 |
|
A |
879 |
// one row |
8fa922
|
880 |
if (id) { |
1633bc
|
881 |
for (n in this.selection) |
cc97ea
|
882 |
if (this.selection[n] == id) { |
T |
883 |
this.selection.splice(n,1); |
|
884 |
break; |
|
885 |
} |
8fa922
|
886 |
} |
095d05
|
887 |
// all rows |
8fa922
|
888 |
else { |
1633bc
|
889 |
for (n in this.selection) |
cc97ea
|
890 |
if (this.rows[this.selection[n]]) { |
T |
891 |
$(this.rows[this.selection[n]].obj).removeClass('selected').removeClass('unfocused'); |
8fa922
|
892 |
} |
A |
893 |
|
|
894 |
this.selection = []; |
|
895 |
} |
6b47de
|
896 |
|
095d05
|
897 |
if (num_select && !this.selection.length) |
cc97ea
|
898 |
this.triggerEvent('select'); |
6b47de
|
899 |
}, |
T |
900 |
|
|
901 |
|
|
902 |
/** |
|
903 |
* Getter for the selection array |
|
904 |
*/ |
|
905 |
get_selection: function() |
|
906 |
{ |
|
907 |
return this.selection; |
|
908 |
}, |
|
909 |
|
|
910 |
|
|
911 |
/** |
|
912 |
* Return the ID if only one row is selected |
|
913 |
*/ |
|
914 |
get_single_selection: function() |
|
915 |
{ |
|
916 |
if (this.selection.length == 1) |
|
917 |
return this.selection[0]; |
|
918 |
else |
|
919 |
return null; |
|
920 |
}, |
|
921 |
|
|
922 |
|
|
923 |
/** |
|
924 |
* Highlight/unhighlight a row |
|
925 |
*/ |
|
926 |
highlight_row: function(id, multiple) |
|
927 |
{ |
8fa922
|
928 |
if (this.rows[id] && !multiple) { |
A |
929 |
if (this.selection.length > 1 || !this.in_selection(id)) { |
df015d
|
930 |
this.clear_selection(); |
T |
931 |
this.selection[0] = id; |
cc97ea
|
932 |
$(this.rows[id].obj).addClass('selected'); |
df015d
|
933 |
} |
6b47de
|
934 |
} |
8fa922
|
935 |
else if (this.rows[id]) { |
A |
936 |
if (!this.in_selection(id)) { // select row |
6b47de
|
937 |
this.selection[this.selection.length] = id; |
cc97ea
|
938 |
$(this.rows[id].obj).addClass('selected'); |
6b47de
|
939 |
} |
8fa922
|
940 |
else { // unselect row |
1633bc
|
941 |
var p = $.inArray(id, this.selection), |
A |
942 |
a_pre = this.selection.slice(0, p), |
|
943 |
a_post = this.selection.slice(p+1, this.selection.length); |
|
944 |
|
6b47de
|
945 |
this.selection = a_pre.concat(a_post); |
cc97ea
|
946 |
$(this.rows[id].obj).removeClass('selected').removeClass('unfocused'); |
6b47de
|
947 |
} |
T |
948 |
} |
|
949 |
}, |
|
950 |
|
|
951 |
|
|
952 |
/** |
|
953 |
* Handler for keyboard events |
|
954 |
*/ |
|
955 |
key_press: function(e) |
|
956 |
{ |
26f5b0
|
957 |
if (this.focused != true) |
6b47de
|
958 |
return true; |
T |
959 |
|
1633bc
|
960 |
var keyCode = rcube_event.get_keycode(e), |
A |
961 |
mod_key = rcube_event.get_modifier(e); |
91d1a1
|
962 |
|
8fa922
|
963 |
switch (keyCode) { |
6b47de
|
964 |
case 40: |
T |
965 |
case 38: |
26f5b0
|
966 |
case 63233: // "down", in safari keypress |
T |
967 |
case 63232: // "up", in safari keypress |
|
968 |
// Stop propagation so that the browser doesn't scroll |
|
969 |
rcube_event.cancel(e); |
6b47de
|
970 |
return this.use_arrow_key(keyCode, mod_key); |
f52c93
|
971 |
case 61: |
T |
972 |
case 107: // Plus sign on a numeric keypad (fc11 + firefox 3.5.2) |
|
973 |
case 109: |
|
974 |
case 32: |
|
975 |
// Stop propagation |
|
976 |
rcube_event.cancel(e); |
|
977 |
var ret = this.use_plusminus_key(keyCode, mod_key); |
|
978 |
this.key_pressed = keyCode; |
|
979 |
this.triggerEvent('keypress'); |
|
980 |
return ret; |
bc2acc
|
981 |
case 36: // Home |
A |
982 |
this.select_first(mod_key); |
|
983 |
return rcube_event.cancel(e); |
|
984 |
case 35: // End |
|
985 |
this.select_last(mod_key); |
|
986 |
return rcube_event.cancel(e); |
6b47de
|
987 |
default: |
110748
|
988 |
this.shiftkey = e.shiftKey; |
6b47de
|
989 |
this.key_pressed = keyCode; |
cc97ea
|
990 |
this.triggerEvent('keypress'); |
476407
|
991 |
// reset shiftkey flag, we need it only for registered events |
A |
992 |
this.shiftkey = false; |
8fa922
|
993 |
|
f89f03
|
994 |
if (this.key_pressed == this.BACKSPACE_KEY) |
6e6e89
|
995 |
return rcube_event.cancel(e); |
6b47de
|
996 |
} |
8fa922
|
997 |
|
6b47de
|
998 |
return true; |
T |
999 |
}, |
|
1000 |
|
9e7a1b
|
1001 |
/** |
T |
1002 |
* Handler for keydown events |
|
1003 |
*/ |
|
1004 |
key_down: function(e) |
|
1005 |
{ |
8fa922
|
1006 |
switch (rcube_event.get_keycode(e)) { |
91d1a1
|
1007 |
case 27: |
A |
1008 |
if (this.drag_active) |
b62c48
|
1009 |
return this.drag_mouse_up(e); |
A |
1010 |
if (this.col_drag_active) { |
|
1011 |
this.selected_column = null; |
|
1012 |
return this.column_drag_mouse_up(e); |
|
1013 |
} |
8fa922
|
1014 |
|
9e7a1b
|
1015 |
case 40: |
T |
1016 |
case 38: |
|
1017 |
case 63233: |
|
1018 |
case 63232: |
f52c93
|
1019 |
case 61: |
T |
1020 |
case 107: |
|
1021 |
case 109: |
|
1022 |
case 32: |
9e7a1b
|
1023 |
if (!rcube_event.get_modifier(e) && this.focused) |
T |
1024 |
return rcube_event.cancel(e); |
8fa922
|
1025 |
|
9e7a1b
|
1026 |
default: |
T |
1027 |
} |
8fa922
|
1028 |
|
9e7a1b
|
1029 |
return true; |
T |
1030 |
}, |
|
1031 |
|
6b47de
|
1032 |
|
T |
1033 |
/** |
|
1034 |
* Special handling method for arrow keys |
|
1035 |
*/ |
|
1036 |
use_arrow_key: function(keyCode, mod_key) |
|
1037 |
{ |
|
1038 |
var new_row; |
e9b57b
|
1039 |
// Safari uses the nonstandard keycodes 63232/63233 for up/down, if we're |
A |
1040 |
// using the keypress event (but not the keydown or keyup event). |
|
1041 |
if (keyCode == 40 || keyCode == 63233) // down arrow key pressed |
6b47de
|
1042 |
new_row = this.get_next_row(); |
e9b57b
|
1043 |
else if (keyCode == 38 || keyCode == 63232) // up arrow key pressed |
6b47de
|
1044 |
new_row = this.get_prev_row(); |
T |
1045 |
|
8fa922
|
1046 |
if (new_row) { |
6b47de
|
1047 |
this.select_row(new_row.uid, mod_key, true); |
T |
1048 |
this.scrollto(new_row.uid); |
|
1049 |
} |
f52c93
|
1050 |
|
T |
1051 |
return false; |
|
1052 |
}, |
|
1053 |
|
|
1054 |
|
|
1055 |
/** |
|
1056 |
* Special handling method for +/- keys |
|
1057 |
*/ |
|
1058 |
use_plusminus_key: function(keyCode, mod_key) |
|
1059 |
{ |
|
1060 |
var selected_row = this.rows[this.last_selected]; |
|
1061 |
if (!selected_row) |
|
1062 |
return; |
|
1063 |
|
|
1064 |
if (keyCode == 32) |
|
1065 |
keyCode = selected_row.expanded ? 109 : 61; |
|
1066 |
if (keyCode == 61 || keyCode == 107) |
|
1067 |
if (mod_key == CONTROL_KEY || this.multiexpand) |
|
1068 |
this.expand_all(selected_row); |
|
1069 |
else |
|
1070 |
this.expand(selected_row); |
|
1071 |
else |
|
1072 |
if (mod_key == CONTROL_KEY || this.multiexpand) |
|
1073 |
this.collapse_all(selected_row); |
|
1074 |
else |
|
1075 |
this.collapse(selected_row); |
|
1076 |
|
403b45
|
1077 |
this.update_expando(selected_row.uid, selected_row.expanded); |
6b47de
|
1078 |
|
T |
1079 |
return false; |
|
1080 |
}, |
|
1081 |
|
|
1082 |
|
|
1083 |
/** |
|
1084 |
* Try to scroll the list to make the specified row visible |
|
1085 |
*/ |
|
1086 |
scrollto: function(id) |
|
1087 |
{ |
|
1088 |
var row = this.rows[id].obj; |
8fa922
|
1089 |
if (row && this.frame) { |
6b47de
|
1090 |
var scroll_to = Number(row.offsetTop); |
T |
1091 |
|
bc2acc
|
1092 |
// expand thread if target row is hidden (collapsed) |
A |
1093 |
if (!scroll_to && this.rows[id].parent_uid) { |
|
1094 |
var parent = this.find_root(this.rows[id].uid); |
|
1095 |
this.expand_all(this.rows[parent]); |
|
1096 |
scroll_to = Number(row.offsetTop); |
|
1097 |
} |
|
1098 |
|
6b47de
|
1099 |
if (scroll_to < Number(this.frame.scrollTop)) |
T |
1100 |
this.frame.scrollTop = scroll_to; |
|
1101 |
else if (scroll_to + Number(row.offsetHeight) > Number(this.frame.scrollTop) + Number(this.frame.offsetHeight)) |
|
1102 |
this.frame.scrollTop = (scroll_to + Number(row.offsetHeight)) - Number(this.frame.offsetHeight); |
|
1103 |
} |
|
1104 |
}, |
|
1105 |
|
|
1106 |
|
|
1107 |
/** |
|
1108 |
* Handler for mouse move events |
|
1109 |
*/ |
|
1110 |
drag_mouse_move: function(e) |
|
1111 |
{ |
8ef2f3
|
1112 |
// convert touch event |
T |
1113 |
if (e.type == 'touchmove') { |
|
1114 |
if (e.changedTouches.length == 1) |
|
1115 |
e = rcube_event.touchevent(e.changedTouches[0]); |
|
1116 |
else |
|
1117 |
return rcube_event.cancel(e); |
|
1118 |
} |
|
1119 |
|
8fa922
|
1120 |
if (this.drag_start) { |
6b47de
|
1121 |
// check mouse movement, of less than 3 pixels, don't start dragging |
T |
1122 |
var m = rcube_event.get_mouse_pos(e); |
cf6bc5
|
1123 |
|
6b47de
|
1124 |
if (!this.drag_mouse_start || (Math.abs(m.x - this.drag_mouse_start.x) < 3 && Math.abs(m.y - this.drag_mouse_start.y) < 3)) |
T |
1125 |
return false; |
8fa922
|
1126 |
|
6b47de
|
1127 |
if (!this.draglayer) |
b62c48
|
1128 |
this.draglayer = $('<div>').attr('id', 'rcmdraglayer') |
A |
1129 |
.css({ position:'absolute', display:'none', 'z-index':2000 }) |
|
1130 |
.appendTo(document.body); |
8fa922
|
1131 |
|
2ecb7f
|
1132 |
// also select childs of (collapsed) threads for dragging |
0e7b66
|
1133 |
var n, uid, selection = $.merge([], this.selection); |
A |
1134 |
for (n in selection) { |
2ecb7f
|
1135 |
uid = selection[n]; |
84a331
|
1136 |
if (this.rows[uid].has_children && !this.rows[uid].expanded) |
T |
1137 |
this.select_childs(uid); |
2ecb7f
|
1138 |
} |
a80304
|
1139 |
|
74cd6c
|
1140 |
// reset content |
A |
1141 |
this.draglayer.html(''); |
|
1142 |
|
f52c93
|
1143 |
// get subjects of selected messages |
74cd6c
|
1144 |
var c, i, n, subject, obj; |
A |
1145 |
for (n=0; n<this.selection.length; n++) { |
8fa922
|
1146 |
// only show 12 lines |
A |
1147 |
if (n>12) { |
74cd6c
|
1148 |
this.draglayer.append('...'); |
6b47de
|
1149 |
break; |
T |
1150 |
} |
|
1151 |
|
8fa922
|
1152 |
if (obj = this.rows[this.selection[n]].obj) { |
6b47de
|
1153 |
subject = ''; |
T |
1154 |
|
8fa922
|
1155 |
for (c=0, i=0; i<obj.childNodes.length; i++) { |
A |
1156 |
if (obj.childNodes[i].nodeName == 'TD') { |
f52c93
|
1157 |
if (n == 0) |
8fa922
|
1158 |
this.drag_start_pos = $(obj.childNodes[i]).offset(); |
f52c93
|
1159 |
|
8fa922
|
1160 |
if (this.subject_col < 0 || (this.subject_col >= 0 && this.subject_col == c)) { |
74cd6c
|
1161 |
var entry, node, tmp_node, nodes = obj.childNodes[i].childNodes; |
8fa922
|
1162 |
// find text node |
A |
1163 |
for (m=0; m<nodes.length; m++) { |
|
1164 |
if ((tmp_node = obj.childNodes[i].childNodes[m]) && (tmp_node.nodeType==3 || tmp_node.nodeName=='A')) |
|
1165 |
node = tmp_node; |
|
1166 |
} |
|
1167 |
|
|
1168 |
if (!node) |
|
1169 |
break; |
f52c93
|
1170 |
|
74cd6c
|
1171 |
subject = $(node).text(); |
8fa922
|
1172 |
// remove leading spaces |
ef17c5
|
1173 |
subject = $.trim(subject); |
451637
|
1174 |
// truncate line to 50 characters |
74cd6c
|
1175 |
subject = (subject.length > 50 ? subject.substring(0, 50) + '...' : subject); |
A |
1176 |
|
|
1177 |
entry = $('<div>').text(subject); |
|
1178 |
this.draglayer.append(entry); |
d24d20
|
1179 |
break; |
T |
1180 |
} |
|
1181 |
c++; |
6b47de
|
1182 |
} |
d24d20
|
1183 |
} |
6b47de
|
1184 |
} |
T |
1185 |
} |
|
1186 |
|
cc97ea
|
1187 |
this.draglayer.show(); |
6b47de
|
1188 |
this.drag_active = true; |
cc97ea
|
1189 |
this.triggerEvent('dragstart'); |
6b47de
|
1190 |
} |
T |
1191 |
|
8fa922
|
1192 |
if (this.drag_active && this.draglayer) { |
6b47de
|
1193 |
var pos = rcube_event.get_mouse_pos(e); |
cc97ea
|
1194 |
this.draglayer.css({ left:(pos.x+20)+'px', top:(pos.y-5 + (bw.ie ? document.documentElement.scrollTop : 0))+'px' }); |
9489ad
|
1195 |
this.triggerEvent('dragmove', e?e:window.event); |
6b47de
|
1196 |
} |
T |
1197 |
|
|
1198 |
this.drag_start = false; |
|
1199 |
|
|
1200 |
return false; |
|
1201 |
}, |
|
1202 |
|
|
1203 |
|
|
1204 |
/** |
|
1205 |
* Handler for mouse up events |
|
1206 |
*/ |
|
1207 |
drag_mouse_up: function(e) |
|
1208 |
{ |
|
1209 |
document.onmousemove = null; |
8ef2f3
|
1210 |
|
T |
1211 |
if (e.type == 'touchend') { |
|
1212 |
if (e.changedTouches.length != 1) |
|
1213 |
return rcube_event.cancel(e); |
|
1214 |
} |
6b47de
|
1215 |
|
cc97ea
|
1216 |
if (this.draglayer && this.draglayer.is(':visible')) { |
T |
1217 |
if (this.drag_start_pos) |
|
1218 |
this.draglayer.animate(this.drag_start_pos, 300, 'swing').hide(20); |
|
1219 |
else |
|
1220 |
this.draglayer.hide(); |
|
1221 |
} |
6b47de
|
1222 |
|
da8f11
|
1223 |
if (this.drag_active) |
A |
1224 |
this.focus(); |
6b47de
|
1225 |
this.drag_active = false; |
6c11ee
|
1226 |
|
A |
1227 |
rcube_event.remove_listener({event:'mousemove', object:this, method:'drag_mouse_move'}); |
|
1228 |
rcube_event.remove_listener({event:'mouseup', object:this, method:'drag_mouse_up'}); |
8ef2f3
|
1229 |
|
T |
1230 |
if (bw.iphone || bw.ipad) { |
|
1231 |
rcube_event.remove_listener({event:'touchmove', object:this, method:'drag_mouse_move'}); |
|
1232 |
rcube_event.remove_listener({event:'touchend', object:this, method:'drag_mouse_up'}); |
|
1233 |
} |
6c11ee
|
1234 |
|
A |
1235 |
// remove temp divs |
b62c48
|
1236 |
this.del_dragfix(); |
6c11ee
|
1237 |
|
cc97ea
|
1238 |
this.triggerEvent('dragend'); |
da8f11
|
1239 |
|
6b47de
|
1240 |
return rcube_event.cancel(e); |
c4b819
|
1241 |
}, |
A |
1242 |
|
|
1243 |
|
|
1244 |
/** |
b62c48
|
1245 |
* Handler for mouse move events for dragging list column |
A |
1246 |
*/ |
|
1247 |
column_drag_mouse_move: function(e) |
|
1248 |
{ |
|
1249 |
if (this.drag_start) { |
|
1250 |
// check mouse movement, of less than 3 pixels, don't start dragging |
|
1251 |
var i, m = rcube_event.get_mouse_pos(e); |
|
1252 |
|
|
1253 |
if (!this.drag_mouse_start || (Math.abs(m.x - this.drag_mouse_start.x) < 3 && Math.abs(m.y - this.drag_mouse_start.y) < 3)) |
|
1254 |
return false; |
|
1255 |
|
|
1256 |
if (!this.col_draglayer) { |
|
1257 |
var lpos = $(this.list).offset(), |
|
1258 |
cells = this.list.tHead.rows[0].cells; |
|
1259 |
|
|
1260 |
// create dragging layer |
|
1261 |
this.col_draglayer = $('<div>').attr('id', 'rcmcoldraglayer') |
|
1262 |
.css(lpos).css({ position:'absolute', 'z-index':2001, |
|
1263 |
'background-color':'white', opacity:0.75, |
|
1264 |
height: (this.frame.offsetHeight-2)+'px', width: (this.frame.offsetWidth-2)+'px' }) |
|
1265 |
.appendTo(document.body) |
|
1266 |
// ... and column position indicator |
|
1267 |
.append($('<div>').attr('id', 'rcmcolumnindicator') |
|
1268 |
.css({ position:'absolute', 'border-right':'2px dotted #555', |
|
1269 |
'z-index':2002, height: (this.frame.offsetHeight-2)+'px' })); |
|
1270 |
|
|
1271 |
this.cols = []; |
|
1272 |
this.list_pos = this.list_min_pos = lpos.left; |
|
1273 |
// save columns positions |
|
1274 |
for (i=0; i<cells.length; i++) { |
|
1275 |
this.cols[i] = cells[i].offsetWidth; |
|
1276 |
if (this.column_fixed !== null && i <= this.column_fixed) { |
|
1277 |
this.list_min_pos += this.cols[i]; |
|
1278 |
} |
|
1279 |
} |
|
1280 |
} |
|
1281 |
|
|
1282 |
this.col_draglayer.show(); |
|
1283 |
this.col_drag_active = true; |
|
1284 |
this.triggerEvent('column_dragstart'); |
|
1285 |
} |
|
1286 |
|
|
1287 |
// set column indicator position |
|
1288 |
if (this.col_drag_active && this.col_draglayer) { |
|
1289 |
var i, cpos = 0, pos = rcube_event.get_mouse_pos(e); |
|
1290 |
|
|
1291 |
for (i=0; i<this.cols.length; i++) { |
|
1292 |
if (pos.x >= this.cols[i]/2 + this.list_pos + cpos) |
|
1293 |
cpos += this.cols[i]; |
|
1294 |
else |
|
1295 |
break; |
|
1296 |
} |
|
1297 |
|
|
1298 |
// handle fixed columns on left |
|
1299 |
if (i == 0 && this.list_min_pos > pos.x) |
|
1300 |
cpos = this.list_min_pos - this.list_pos; |
|
1301 |
// empty list needs some assignment |
|
1302 |
else if (!this.list.rowcount && i == this.cols.length) |
|
1303 |
cpos -= 2; |
|
1304 |
$('#rcmcolumnindicator').css({ width: cpos+'px'}); |
|
1305 |
this.triggerEvent('column_dragmove', e?e:window.event); |
|
1306 |
} |
|
1307 |
|
|
1308 |
this.drag_start = false; |
|
1309 |
|
|
1310 |
return false; |
|
1311 |
}, |
|
1312 |
|
|
1313 |
|
|
1314 |
/** |
|
1315 |
* Handler for mouse up events for dragging list columns |
|
1316 |
*/ |
|
1317 |
column_drag_mouse_up: function(e) |
|
1318 |
{ |
|
1319 |
document.onmousemove = null; |
|
1320 |
|
|
1321 |
if (this.col_draglayer) { |
|
1322 |
(this.col_draglayer).remove(); |
|
1323 |
this.col_draglayer = null; |
|
1324 |
} |
|
1325 |
|
|
1326 |
if (this.col_drag_active) |
|
1327 |
this.focus(); |
|
1328 |
this.col_drag_active = false; |
|
1329 |
|
|
1330 |
rcube_event.remove_listener({event:'mousemove', object:this, method:'column_drag_mouse_move'}); |
|
1331 |
rcube_event.remove_listener({event:'mouseup', object:this, method:'column_drag_mouse_up'}); |
|
1332 |
// remove temp divs |
|
1333 |
this.del_dragfix(); |
|
1334 |
|
|
1335 |
if (this.selected_column !== null && this.cols && this.cols.length) { |
|
1336 |
var i, cpos = 0, pos = rcube_event.get_mouse_pos(e); |
|
1337 |
|
|
1338 |
// find destination position |
|
1339 |
for (i=0; i<this.cols.length; i++) { |
|
1340 |
if (pos.x >= this.cols[i]/2 + this.list_pos + cpos) |
|
1341 |
cpos += this.cols[i]; |
|
1342 |
else |
|
1343 |
break; |
|
1344 |
} |
|
1345 |
|
|
1346 |
if (i != this.selected_column && i != this.selected_column+1) { |
|
1347 |
this.column_replace(this.selected_column, i); |
|
1348 |
} |
|
1349 |
} |
|
1350 |
|
|
1351 |
this.triggerEvent('column_dragend'); |
|
1352 |
|
|
1353 |
return rcube_event.cancel(e); |
|
1354 |
}, |
|
1355 |
|
|
1356 |
|
|
1357 |
/** |
|
1358 |
* Creates a layer for drag&drop over iframes |
|
1359 |
*/ |
|
1360 |
add_dragfix: function() |
|
1361 |
{ |
|
1362 |
$('iframe').each(function() { |
|
1363 |
$('<div class="iframe-dragdrop-fix"></div>') |
|
1364 |
.css({background: '#fff', |
|
1365 |
width: this.offsetWidth+'px', height: this.offsetHeight+'px', |
|
1366 |
position: 'absolute', opacity: '0.001', zIndex: 1000 |
|
1367 |
}) |
|
1368 |
.css($(this).offset()) |
|
1369 |
.appendTo(document.body); |
677e1f
|
1370 |
}); |
b62c48
|
1371 |
}, |
A |
1372 |
|
|
1373 |
|
|
1374 |
/** |
|
1375 |
* Removes the layer for drag&drop over iframes |
|
1376 |
*/ |
|
1377 |
del_dragfix: function() |
|
1378 |
{ |
|
1379 |
$('div.iframe-dragdrop-fix').each(function() { this.parentNode.removeChild(this); }); |
|
1380 |
}, |
|
1381 |
|
|
1382 |
|
|
1383 |
/** |
|
1384 |
* Replaces two columns |
|
1385 |
*/ |
|
1386 |
column_replace: function(from, to) |
|
1387 |
{ |
1633bc
|
1388 |
var len, cells = this.list.tHead.rows[0].cells, |
b62c48
|
1389 |
elem = cells[from], |
A |
1390 |
before = cells[to], |
|
1391 |
td = document.createElement('td'); |
|
1392 |
|
|
1393 |
// replace header cells |
|
1394 |
if (before) |
|
1395 |
cells[0].parentNode.insertBefore(td, before); |
|
1396 |
else |
|
1397 |
cells[0].parentNode.appendChild(td); |
|
1398 |
cells[0].parentNode.replaceChild(elem, td); |
|
1399 |
|
|
1400 |
// replace list cells |
1633bc
|
1401 |
for (r=0, len=this.list.tBodies[0].rows.length; r<len; r++) { |
b62c48
|
1402 |
row = this.list.tBodies[0].rows[r]; |
A |
1403 |
|
|
1404 |
elem = row.cells[from]; |
|
1405 |
before = row.cells[to]; |
|
1406 |
td = document.createElement('td'); |
|
1407 |
|
|
1408 |
if (before) |
|
1409 |
row.insertBefore(td, before); |
|
1410 |
else |
|
1411 |
row.appendChild(td); |
|
1412 |
row.replaceChild(elem, td); |
|
1413 |
} |
|
1414 |
|
|
1415 |
// update subject column position |
|
1416 |
if (this.subject_col == from) |
|
1417 |
this.subject_col = to > from ? to - 1 : to; |
8e32dc
|
1418 |
else if (this.subject_col < from && to <= this.subject_col) |
T |
1419 |
this.subject_col++; |
|
1420 |
else if (this.subject_col > from && to >= this.subject_col) |
|
1421 |
this.subject_col--; |
b62c48
|
1422 |
|
A |
1423 |
this.triggerEvent('column_replace'); |
6b47de
|
1424 |
} |
T |
1425 |
|
|
1426 |
}; |
|
1427 |
|
cc97ea
|
1428 |
rcube_list_widget.prototype.addEventListener = rcube_event_engine.prototype.addEventListener; |
T |
1429 |
rcube_list_widget.prototype.removeEventListener = rcube_event_engine.prototype.removeEventListener; |
|
1430 |
rcube_list_widget.prototype.triggerEvent = rcube_event_engine.prototype.triggerEvent; |