From 69176590d4b0a3f81e7cdf963c008ef44efeed51 Mon Sep 17 00:00:00 2001 From: Fabien Morin <fabien@nexedi.com> Date: Tue, 18 Mar 2008 16:48:10 +0000 Subject: [PATCH] use XPath expression in erp5.js to put the focus on the good field instead of DOM. This is more clear, and I think more performant. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20000 20353a03-c40f-0410-a6d1-a30d3c3de9de --- .../portal_skins/erp5_xhtml_style/erp5.js.xml | 25 +++++++------------ .../bootstrap/erp5_xhtml_style/bt/revision | 2 +- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/erp5.js.xml b/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/erp5.js.xml index 5fa02e81db..36fdb29c1f 100644 --- a/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/erp5.js.xml +++ b/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/erp5.js.xml @@ -77,24 +77,17 @@ function clickSaveButton(act) {\n // else if no element have autofocus class, the first element wich is not the\n // search field will get the focus. This is generaly the title input text of\n // a view\n -\n function autoFocus() {\n - var inputs = document.getElementsByTagName("input");\n - var input_to_focus = 0;\n - for (i=0;i<inputs.length;i++) {\n - if (inputs[i].className == "autofocus") {\n - input_to_focus = inputs[i];\n - }\n - }\n - if (input_to_focus != 0) {\n - input_to_focus.focus();\n + var first_autofocus_expr = ".//input[@class=\'autofocus\']"\n + var FIRST_RESULT = XPathResult.FIRST_ORDERED_NODE_TYPE\n +\n + var input = document.evaluate(first_autofocus_expr, document, null, FIRST_RESULT, null).singleNodeValue;\n + if (input) {\n + input.focus();\n }else{\n - for ( var i=0; i<inputs.length; i++ ){\n - if (inputs[i].getAttribute("type") == "text" && inputs[i].getAttribute("name") != "field_your_search_text"){\n - inputs[i].focus();\n - break;\n - }\n - }\n + var first_text_input_expr = ".//input[@type=\'text\'][@name != \'field_your_search_text\']"\n + var first_text_input = document.evaluate(first_text_input_expr, document, null, FIRST_RESULT, null).singleNodeValue;\n + first_text_input.focus();\n }\n }\n \n diff --git a/product/ERP5/bootstrap/erp5_xhtml_style/bt/revision b/product/ERP5/bootstrap/erp5_xhtml_style/bt/revision index 37e6f1741c..430faa64e7 100644 --- a/product/ERP5/bootstrap/erp5_xhtml_style/bt/revision +++ b/product/ERP5/bootstrap/erp5_xhtml_style/bt/revision @@ -1 +1 @@ -515 \ No newline at end of file +511 \ No newline at end of file -- 2.30.9