From 8fa9229d578a9c2f265b4e46278c3f5f4329baae Mon Sep 17 00:00:00 2001 From: alecpl Date: Fri, 16 Apr 2010 13:46:54 +0000 Subject: - code formatting, cleanup and small improvements --- program/js/list.js | 222 ++++++++++++++++++++++------------------------------- 1 file changed, 93 insertions(+), 129 deletions(-) (limited to 'program/js/list.js') diff --git a/program/js/list.js b/program/js/list.js index 3e7bc6226..a39ba62dc 100644 --- a/program/js/list.js +++ b/program/js/list.js @@ -22,18 +22,18 @@ * @contructor */ function rcube_list_widget(list, p) - { +{ // static contants this.ENTER_KEY = 13; this.DELETE_KEY = 46; this.BACKSPACE_KEY = 8; - + this.list = list ? list : null; this.frame = null; this.rows = []; this.selection = []; this.rowcount = 0; - + this.subject_col = -1; this.shiftkey = false; this.multiselect = false; @@ -42,7 +42,7 @@ function rcube_list_widget(list, p) this.draggable = false; this.keyboard = false; this.toggleselect = false; - + this.dont_select = false; this.drag_active = false; this.last_selected = 0; @@ -52,12 +52,12 @@ function rcube_list_widget(list, p) this.drag_mouse_start = null; this.dblclick_time = 600; this.row_init = function(){}; - + // overwrite default paramaters - if (p && typeof(p)=='object') + if (p && typeof(p) == 'object') for (var n in p) this[n] = p[n]; - } +}; rcube_list_widget.prototype = { @@ -68,17 +68,14 @@ rcube_list_widget.prototype = { */ init: function() { - if (this.list && this.list.tBodies[0]) - { - this.rows = new Array(); + if (this.list && this.list.tBodies[0]) { + this.rows = []; this.rowcount = 0; var row; - for(var r=0; r=0; i--) if(rows[i].id && String(rows[i].id).match(/rcmrow([a-z0-9\-_=\+\/]+)/i) && this.rows[RegExp.$1] != null) + return RegExp.$1; - } + } return null; }, @@ -570,20 +562,17 @@ select_row: function(id, mod_key, with_mouse) var select_before = this.selection.join(','); if (!this.multiselect) mod_key = 0; - + if (!this.shift_start) this.shift_start = id - if (!mod_key) - { + if (!mod_key) { this.shift_start = id; this.highlight_row(id, false); this.multi_selecting = false; } - else - { - switch (mod_key) - { + else { + switch (mod_key) { case SHIFT_KEY: this.shift_select(id, false); break; @@ -612,8 +601,7 @@ select_row: function(id, mod_key, with_mouse) $(this.rows[this.last_selected].obj).removeClass('focused'); // unselect if toggleselect is active and the same row was clicked again - if (this.toggleselect && this.last_selected == id) - { + if (this.toggleselect && this.last_selected == id) { this.clear_selection(); id = null; } @@ -690,7 +678,7 @@ select_childs: function(uid) { if (!this.rows[uid] || !this.rows[uid].has_children) return; - + var depth = this.rows[uid].depth; var row = this.rows[uid].obj.nextSibling; while (row) { @@ -722,16 +710,13 @@ shift_select: function(id, control) var j = ((from_rowIndex > to_rowIndex)? from_rowIndex : to_rowIndex); // iterate through the entire message list - for (var n in this.rows) - { - if ((this.rows[n].obj.rowIndex >= i) && (this.rows[n].obj.rowIndex <= j)) - { + for (var n in this.rows) { + if ((this.rows[n].obj.rowIndex >= i) && (this.rows[n].obj.rowIndex <= j)) { if (!this.in_selection(n)) { this.highlight_row(n, true); } } - else - { + else { if (this.in_selection(n) && !control) { this.highlight_row(n, true); } @@ -763,17 +748,14 @@ select_all: function(filter) // reset but remember selection first var select_before = this.selection.join(','); - this.selection = new Array(); - - for (var n in this.rows) - { - if (!filter || (this.rows[n] && this.rows[n][filter] == true)) - { + this.selection = []; + + for (var n in this.rows) { + if (!filter || (this.rows[n] && this.rows[n][filter] == true)) { this.last_selected = n; this.highlight_row(n, true); } - else if (this.rows[n]) - { + else if (this.rows[n]) { $(this.rows[n].obj).removeClass('selected').removeClass('unfocused'); } } @@ -798,7 +780,7 @@ invert_selection: function() // remember old selection var select_before = this.selection.join(','); - + for (var n in this.rows) this.highlight_row(n, true); @@ -820,24 +802,22 @@ clear_selection: function(id) var num_select = this.selection.length; // one row - if (id) - { + if (id) { for (var n=0; n 1 || !this.in_selection(id)) - { + if (this.rows[id] && !multiple) { + if (this.selection.length > 1 || !this.in_selection(id)) { this.clear_selection(); this.selection[0] = id; $(this.rows[id].obj).addClass('selected'); } } - else if (this.rows[id]) - { - if (!this.in_selection(id)) // select row - { + else if (this.rows[id]) { + if (!this.in_selection(id)) { // select row this.selection[this.selection.length] = id; $(this.rows[id].obj).addClass('selected'); } - else // unselect row - { - var p = jQuery.inArray(id, this.selection); + else { // unselect row + var p = $.inArray(id, this.selection); var a_pre = this.selection.slice(0, p); var a_post = this.selection.slice(p+1, this.selection.length); this.selection = a_pre.concat(a_post); @@ -909,8 +884,7 @@ key_press: function(e) var keyCode = rcube_event.get_keycode(e); var mod_key = rcube_event.get_modifier(e); - switch (keyCode) - { + switch (keyCode) { case 40: case 38: case 63233: // "down", in safari keypress @@ -938,11 +912,11 @@ key_press: function(e) this.shiftkey = e.shiftKey; this.key_pressed = keyCode; this.triggerEvent('keypress'); - + if (this.key_pressed == this.BACKSPACE_KEY) return rcube_event.cancel(e); } - + return true; }, @@ -951,12 +925,11 @@ key_press: function(e) */ key_down: function(e) { - switch (rcube_event.get_keycode(e)) - { + switch (rcube_event.get_keycode(e)) { case 27: if (this.drag_active) return this.drag_mouse_up(e); - + case 40: case 38: case 63233: @@ -967,10 +940,10 @@ key_down: function(e) case 32: if (!rcube_event.get_modifier(e) && this.focused) return rcube_event.cancel(e); - + default: } - + return true; }, @@ -988,8 +961,7 @@ use_arrow_key: function(keyCode, mod_key) else if (keyCode == 38 || keyCode == 63232) // up arrow key pressed new_row = this.get_prev_row(); - if (new_row) - { + if (new_row) { this.select_row(new_row.uid, mod_key, true); this.scrollto(new_row.uid); } @@ -1034,8 +1006,7 @@ use_plusminus_key: function(keyCode, mod_key) scrollto: function(id) { var row = this.rows[id].obj; - if (row && this.frame) - { + if (row && this.frame) { var scroll_to = Number(row.offsetTop); // expand thread if target row is hidden (collapsed) @@ -1058,17 +1029,16 @@ scrollto: function(id) */ drag_mouse_move: function(e) { - if (this.drag_start) - { + if (this.drag_start) { // check mouse movement, of less than 3 pixels, don't start dragging var m = rcube_event.get_mouse_pos(e); 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)) return false; - + if (!this.draglayer) this.draglayer = $('
').attr('id', 'rcmdraglayer').css({ position:'absolute', display:'none', 'z-index':2000 }).appendTo(document.body); - + // also select childs of (collapsed) threads for dragging var selection = $.merge([], this.selection); var depth, row, uid, r; @@ -1081,42 +1051,37 @@ drag_mouse_move: function(e) // get subjects of selected messages var names = ''; var c, i, subject, obj; - for(var n=0; n12) // only show 12 lines - { + for(var n=0; n12) { names += '...'; break; } - if (obj = this.rows[this.selection[n]].obj) - { + if (obj = this.rows[this.selection[n]].obj) { subject = ''; - for (c=0, i=0; i= 0 && this.subject_col == c)) - { - var node, tmp_node, nodes = obj.childNodes[i].childNodes; - // find text node - for (m=0; m= 0 && this.subject_col == c)) { + var node, tmp_node, nodes = obj.childNodes[i].childNodes; + // find text node + for (m=0; m 50 ? subject.substring(0, 50)+'...' : subject) + '
'; + names += (subject.length > 50 ? subject.substring(0, 50)+'...' : subject) + '
'; break; } c++; @@ -1132,8 +1097,7 @@ drag_mouse_move: function(e) this.triggerEvent('dragstart'); } - if (this.drag_active && this.draglayer) - { + if (this.drag_active && this.draglayer) { var pos = rcube_event.get_mouse_pos(e); this.draglayer.css({ left:(pos.x+20)+'px', top:(pos.y-5 + (bw.ie ? document.documentElement.scrollTop : 0))+'px' }); this.triggerEvent('dragmove', e?e:window.event); -- cgit v1.2.3