summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2014-05-02 11:40:10 +0200
committerAleksander Machniak <alec@alec.pl>2014-05-02 11:40:10 +0200
commitc0037f1882dd3b669e0ac49dac272cf26435015e (patch)
tree04e13b6dc07c0d9ca40d7b2b99cc47d1e16cccd8
parent0070187e3214f22107a78fb470fcedf898e3139b (diff)
Improve rcube_find_object() performance by prefering getElementById() as this is the most common case
-rw-r--r--program/js/common.js21
1 files changed, 13 insertions, 8 deletions
diff --git a/program/js/common.js b/program/js/common.js
index 6b7d3240e..48e85558f 100644
--- a/program/js/common.js
+++ b/program/js/common.js
@@ -472,21 +472,25 @@ function urlencode(str)
function rcube_find_object(id, d)
{
var n, f, obj, e;
- if(!d) d = document;
- if(d.getElementsByName && (e = d.getElementsByName(id)))
+ if (!d) d = document;
+
+ if (d.getElementById)
+ if (obj = d.getElementById(id))
+ return obj;
+
+ if (!obj && d.getElementsByName && (e = d.getElementsByName(id)))
obj = e[0];
- if(!obj && d.getElementById)
- obj = d.getElementById(id);
- if(!obj && d.all)
+
+ if (!obj && d.all)
obj = d.all[id];
- if(!obj && d.images.length)
+ if (!obj && d.images.length)
obj = d.images[id];
if (!obj && d.forms.length) {
for (f=0; f<d.forms.length; f++) {
- if(d.forms[f].name == id)
+ if (d.forms[f].name == id)
obj = d.forms[f];
else if(d.forms[f].elements[id])
obj = d.forms[f].elements[id];
@@ -494,7 +498,8 @@ function rcube_find_object(id, d)
}
if (!obj && d.layers) {
- if (d.layers[id]) obj = d.layers[id];
+ if (d.layers[id])
+ obj = d.layers[id];
for (n=0; !obj && n<d.layers.length; n++)
obj = rcube_find_object(id, d.layers[n].document);
}