From: Janusz Dobrowolski Date: Tue, 17 Mar 2009 20:20:17 +0000 (+0000) Subject: Focus js optimizations. X-Git-Tag: v2.4.2~19^2~1473 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=499e0e615d1a845c6c519754b3a213fdda0513ba;p=fa-stable.git Focus js optimizations. --- diff --git a/js/inserts.js b/js/inserts.js index 7450c199..aee2d7eb 100644 --- a/js/inserts.js +++ b/js/inserts.js @@ -73,7 +73,7 @@ function _set_combo_input(e) { } else if(this.className=='combo2') { this.style.display = 'none'; select.style.display = 'inline'; - setFocus(select.name); + setFocus(select); } return false; }; @@ -149,7 +149,7 @@ function _set_combo_select(e) { this.style.display = 'none'; box.style.display = 'inline'; box.value=''; - setFocus(box.name); + setFocus(box); return false; } if (this.getAttribute('aspect') == 'editable' && key==115) { @@ -274,7 +274,7 @@ var inserts = { save_focus(this); }; e.onmouseover = function(e) { - if (this.id) setFocus(this.id, 1); + setFocus(this); return false; } } diff --git a/js/utils.js b/js/utils.js index 97200cfb..dc2b523d 100644 --- a/js/utils.js +++ b/js/utils.js @@ -214,18 +214,21 @@ function goBack() { function setFocus(name, byId) { - if(!name) { // page load/ajax update - if (_focus) - name = _focus; // last focus set in onfocus handlers - else - if (document.forms.length) { // no current focus (first page display) - set it from from last form - var cur = document.getElementsByName('_focus')[document.forms.length-1]; - if(cur) name = cur.value; - } + if(typeof(name)=='object') + el = name; + else { + if(!name) { // page load/ajax update + if (_focus) + name = _focus; // last focus set in onfocus handlers + else + if (document.forms.length) { // no current focus (first page display) - set it from from last form + var cur = document.getElementsByName('_focus')[document.forms.length-1]; + if(cur) name = cur.value; + } + } + if(byId || !(el = document.getElementsByName(name)[0])) + el = document.getElementById(name); } - if(byId || !(el = document.getElementsByName(name)[0])) - el = document.getElementById(name); - if(el && el.focus) { // The timeout is needed to prevent unpredictable behaviour on IE & Gecko. // Using tmp var prevents crash on IE5 @@ -254,10 +257,8 @@ function move_focus(dir, e, neighbours) } } } - if (t) { - var tmp = function() {t.focus(); if (t.select) t.select();}; - setTimeout(tmp, 0); - } + if (t) + setFocus(t); return t; }