- code formatting, cleanup and small improvements

release-0.6
alecpl 15 years ago
parent 186537b2c6
commit 8fa9229d57

File diff suppressed because it is too large Load Diff

@ -72,7 +72,6 @@ function roundcube_browser()
else if(this.konq && window.RegExp)
this.vendver = (/khtml\/([0-9\.]+)/i.test(this.agent)) ? parseFloat(RegExp.$1) : 0;
// get real language out of safari's user agent
if(this.safari && (/;\s+([a-z]{2})-[a-z]{2}\)/i.test(this.agent)))
this.lang = RegExp.$1;
@ -85,13 +84,12 @@ function roundcube_browser()
this.cookies = navigator.cookieEnabled;
// test for XMLHTTP support
this.xmlhttp_test = function()
{
this.xmlhttp_test = function() {
var activeX_test = new Function("try{var o=new ActiveXObject('Microsoft.XMLHTTP');return true;}catch(err){return false;}");
this.xmlhttp = (window.XMLHttpRequest || (window.ActiveXObject && activeX_test())) ? true : false;
return this.xmlhttp;
}
}
};
// static functions for DOM event handling
@ -132,13 +130,11 @@ get_modifier: function(e)
var opcode = 0;
e = e || window.event;
if (bw.mac && e)
{
if (bw.mac && e) {
opcode += (e.metaKey && CONTROL_KEY) + (e.shiftKey && SHIFT_KEY);
return opcode;
}
if (e)
{
if (e) {
opcode += (e.ctrlKey && CONTROL_KEY) + (e.shiftKey && SHIFT_KEY);
return opcode;
}
@ -153,8 +149,7 @@ get_mouse_pos: function(e)
var mX = (e.pageX) ? e.pageX : e.clientX;
var mY = (e.pageY) ? e.pageY : e.clientY;
if (document.body && document.all)
{
if (document.body && document.all) {
mX += document.body.scrollLeft;
mY += document.body.scrollTop;
}
@ -186,8 +181,7 @@ add_listener: function(p)
if (p.element.addEventListener)
p.element.addEventListener(p.event, p.object._rc_events[key], false);
else if (p.element.attachEvent)
{
else if (p.element.attachEvent) {
// IE allows multiple events with the same function to be applied to the same object
// forcibly detach the event, then attach
p.element.detachEvent('on'+p.event, p.object._rc_events[key]);
@ -241,7 +235,7 @@ cancel: function(evt)
function rcube_event_engine()
{
this._events = {};
}
};
rcube_event_engine.prototype = {
@ -313,7 +307,7 @@ triggerEvent: function(evt, e)
return ret;
}
} // end rcube_event_engine.prototype
}; // end rcube_event_engine.prototype
@ -340,11 +334,9 @@ function rcube_layer(id, attributes)
obj = document.createElement('DIV');
with(obj)
{
with(obj) {
id = this.name;
with(style)
{
with(style) {
position = 'absolute';
visibility = (vis) ? (vis==2) ? 'inherit' : 'visible' : 'hidden';
left = l+'px';
@ -365,17 +357,14 @@ function rcube_layer(id, attributes)
this.elm = obj;
};
// create new layer
if(attributes!=null)
{
if(attributes != null) {
this.create(attributes);
this.name = this.elm.id;
}
else // just refer to the object
this.elm = document.getElementById(id);
if(!this.elm)
return false;
@ -393,7 +382,6 @@ function rcube_layer(id, attributes)
// ********* layer object methods *********
// move the layer to a specific position
this.move = function(x, y)
{
@ -401,7 +389,7 @@ function rcube_layer(id, attributes)
this.y = y;
this.css.left = Math.round(this.x)+'px';
this.css.top = Math.round(this.y)+'px';
}
};
// change the layers width and height
this.resize = function(w,h)
@ -410,37 +398,32 @@ function rcube_layer(id, attributes)
this.css.height = h+'px';
this.width = w;
this.height = h;
}
};
// show or hide the layer
this.show = function(a)
{
if(a==1)
{
if(a == 1) {
this.css.visibility = 'visible';
this.visible = true;
}
else if(a==2)
{
else if(a == 2) {
this.css.visibility = 'inherit';
this.visible = true;
}
else
{
else {
this.css.visibility = 'hidden';
this.visible = false;
}
}
};
// write new content into a Layer
this.write = function(cont)
{
this.elm.innerHTML = cont;
}
};
}
};
// check if input is a valid email address
@ -448,8 +431,7 @@ function rcube_layer(id, attributes)
// http://code.iamcal.com/php/rfc822/
function rcube_check_email(input, inline)
{
if (input && window.RegExp)
{
if (input && window.RegExp) {
var qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
var dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
var atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
@ -466,7 +448,7 @@ function rcube_check_email(input, inline)
return reg1.test(input) ? true : false;
}
return false;
}
};
// recursively copy an object
@ -482,13 +464,13 @@ function rcube_clone_object(obj)
}
return out;
}
};
// make a string URL safe
function urlencode(str)
{
return window.encodeURIComponent ? encodeURIComponent(str) : escape(str);
}
};
// get any type of html objects by id/name
@ -523,7 +505,7 @@ function rcube_find_object(id, d)
}
return obj;
}
};
// determine whether the mouse is over the given object or not
function rcube_mouse_is_over(ev, obj)
@ -533,7 +515,7 @@ function rcube_mouse_is_over(ev, obj)
return ((mouse.x >= pos.left) && (mouse.x < (pos.left + obj.offsetWidth)) &&
(mouse.y >= pos.top) && (mouse.y < (pos.top + obj.offsetHeight)));
}
};
// cookie functions by GoogieSpell
@ -545,17 +527,14 @@ function setCookie(name, value, expires, path, domain, secure)
(domain ? "; domain=" + domain : "") +
(secure ? "; secure" : "");
document.cookie = curCookie;
}
roundcube_browser.prototype.set_cookie = setCookie;
};
function getCookie(name)
{
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1)
{
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
}
@ -565,8 +544,9 @@ function getCookie(name)
if (end == -1)
end = dc.length;
return unescape(dc.substring(begin + prefix.length, end));
}
};
roundcube_browser.prototype.set_cookie = setCookie;
roundcube_browser.prototype.get_cookie = getCookie;
// tiny replacement for Firebox functionality
@ -597,7 +577,7 @@ function rcube_console()
if (box)
box.innerText = box.value = '';
};
}
};
var bw = new roundcube_browser();
if (!window.console)
@ -609,7 +589,7 @@ if (!window.console)
RegExp.escape = function(str)
{
return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
}
};
// Make getElementById() case-sensitive on IE
@ -627,4 +607,4 @@ if (bw.ie)
return o;
}
}
};

@ -57,7 +57,7 @@ function rcube_list_widget(list, p)
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<this.list.tBodies[0].childNodes.length; r++)
{
for(var r=0; r<this.list.tBodies[0].childNodes.length; r++) {
row = this.list.tBodies[0].childNodes[r];
while (row && row.nodeType != 1)
{
while (row && row.nodeType != 1) {
row = row.nextSibling;
r++;
}
@ -104,8 +101,7 @@ init: function()
init_row: function(row)
{
// make references in internal array and set event handlers
if (row && String(row.id).match(/rcmrow([a-z0-9\-_=\+\/]+)/i))
{
if (row && String(row.id).match(/rcmrow([a-z0-9\-_=\+\/]+)/i)) {
var p = this;
var uid = RegExp.$1;
row.uid = uid;
@ -131,10 +127,11 @@ clear: function(sel)
var tbody = document.createElement('tbody');
this.list.insertBefore(tbody, this.list.tBodies[0]);
this.list.removeChild(this.list.tBodies[1]);
this.rows = new Array();
this.rows = [];
this.rowcount = 0;
if (sel) this.clear_selection();
if (sel)
this.clear_selection();
},
@ -181,8 +178,7 @@ insert_row: function(row, attop)
focus: function(e)
{
this.focused = true;
for (var n=0; n<this.selection.length; n++)
{
for (var n=0; n<this.selection.length; n++) {
id = this.selection[n];
if (this.rows[id] && this.rows[id].obj) {
$(this.rows[id].obj).addClass('selected').removeClass('unfocused');
@ -201,8 +197,7 @@ blur: function()
{
var id;
this.focused = false;
for (var n=0; n<this.selection.length; n++)
{
for (var n=0; n<this.selection.length; n++) {
id = this.selection[n];
if (this.rows[id] && this.rows[id].obj) {
$(this.rows[id].obj).removeClass('selected').addClass('unfocused');
@ -229,14 +224,12 @@ drag_row: function(e, id)
this.in_selection_before = this.in_selection(id) ? id : false;
// selects currently unselected row
if (!this.in_selection_before)
{
if (!this.in_selection_before) {
var mod_key = rcube_event.get_modifier(e);
this.select_row(id, mod_key, false);
}
if (this.draggable && this.selection.length)
{
if (this.draggable && this.selection.length) {
this.drag_start = true;
this.drag_mouse_start = rcube_event.get_mouse_pos(e);
rcube_event.add_listener({event:'mousemove', object:this, method:'drag_mouse_move'});
@ -272,8 +265,7 @@ click_row: function(e, id)
return true;
// don't do anything (another action processed before)
if (this.dont_select)
{
if (this.dont_select) {
this.dont_select = false;
return false;
}
@ -535,12 +527,12 @@ get_prev_row: function()
get_first_row: function()
{
if (this.rowcount)
{
if (this.rowcount) {
var rows = this.list.tBodies[0].rows;
for(var i=0; i<rows.length-1; i++)
if(rows[i].id && String(rows[i].id).match(/rcmrow([a-z0-9\-_=\+\/]+)/i) && this.rows[RegExp.$1] != null)
return RegExp.$1;
}
@ -549,12 +541,12 @@ get_first_row: function()
get_last_row: function()
{
if (this.rowcount)
{
if (this.rowcount) {
var rows = this.list.tBodies[0].rows;
for(var i=rows.length-1; i>=0; i--)
if(rows[i].id && String(rows[i].id).match(/rcmrow([a-z0-9\-_=\+\/]+)/i) && this.rows[RegExp.$1] != null)
return RegExp.$1;
}
@ -574,16 +566,13 @@ select_row: function(id, mod_key, with_mouse)
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;
}
@ -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();
this.selection = [];
for (var n in this.rows)
{
if (!filter || (this.rows[n] && this.rows[n][filter] == true))
{
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');
}
}
@ -820,8 +802,7 @@ clear_selection: function(id)
var num_select = this.selection.length;
// one row
if (id)
{
if (id) {
for (var n=0; n<this.selection.length; n++)
if (this.selection[n] == id) {
this.selection.splice(n,1);
@ -829,14 +810,13 @@ clear_selection: function(id)
}
}
// all rows
else
{
else {
for (var n=0; n<this.selection.length; n++)
if (this.rows[this.selection[n]]) {
$(this.rows[this.selection[n]].obj).removeClass('selected').removeClass('unfocused');
}
this.selection = new Array();
this.selection = [];
}
if (num_select && !this.selection.length)
@ -870,25 +850,20 @@ get_single_selection: function()
*/
highlight_row: function(id, multiple)
{
if (this.rows[id] && !multiple)
{
if (this.selection.length > 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
@ -951,8 +925,7 @@ 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);
@ -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,8 +1029,7 @@ 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);
@ -1081,27 +1051,22 @@ drag_mouse_move: function(e)
// get subjects of selected messages
var names = '';
var c, i, subject, obj;
for(var n=0; n<this.selection.length; n++)
{
if (n>12) // only show 12 lines
{
for(var n=0; n<this.selection.length; n++) {
// only show 12 lines
if (n>12) {
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<obj.childNodes.length; i++)
{
if (obj.childNodes[i].nodeName == 'TD')
{
for (c=0, i=0; i<obj.childNodes.length; i++) {
if (obj.childNodes[i].nodeName == 'TD') {
if (n == 0)
this.drag_start_pos = $(obj.childNodes[i]).offset();
if (this.subject_col < 0 || (this.subject_col >= 0 && this.subject_col == c))
{
if (this.subject_col < 0 || (this.subject_col >= 0 && this.subject_col == c)) {
var node, tmp_node, nodes = obj.childNodes[i].childNodes;
// find text node
for (m=0; m<nodes.length; m++) {
@ -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);

Loading…
Cancel
Save