fix focus problems on login inputs
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Wed, 12 Nov 2008 16:09:03 +0100
changeset 29 7d14f1eadded
parent 28 9b7067bfaa15
child 30 25ef1dddaab8
fix focus problems on login inputs
web/data/cubicweb.htmlhelpers.js
web/views/basecomponents.py
web/views/basetemplates.py
--- a/web/data/cubicweb.htmlhelpers.js	Wed Nov 12 16:07:40 2008 +0100
+++ b/web/data/cubicweb.htmlhelpers.js	Wed Nov 12 16:09:03 2008 +0100
@@ -113,7 +113,7 @@
 /* builds an url from an object (used as a dictionnary)
  * Notable difference with MochiKit's queryString: as_url does not
  * *url_quote* each value found in the dictionnary
- * 
+ *
  * >>> as_url({'rql' : "RQL", 'x': [1, 2], 'itemvid' : "oneline"})
  * rql=RQL&vid=list&itemvid=oneline&x=1&x=2
  */
@@ -133,7 +133,7 @@
     return chunks.join('&');
 }
 
-/* return selected value of a combo box if any 
+/* return selected value of a combo box if any
  */
 function firstSelected(selectNode) {
     var selection = filter(attrgetter('selected'), selectNode.options);
@@ -146,6 +146,13 @@
     jqNode(elemId).toggleClass('hidden');
 }
 
+
+/* toggles visibility of login popup div */
+function popupLoginBox() {
+    toggleVisibility('popupLoginBox');
+    jQuery('#__login:visible').focus();
+}
+
 /*
  * return true (resp. false) if <element> (resp. doesn't) matches <properties>
  */
@@ -160,7 +167,7 @@
 
 /* returns the list of elements in the document matching the tag name
  * and the properties provided
- * 
+ *
  * @param tagName the tag's name
  * @param properties a js Object used as a dict
  * @return an iterator (if a *real* array is needed, you can use the
@@ -173,7 +180,7 @@
 }
 
 /*
- * sets checked/unchecked status of checkboxes 
+ * sets checked/unchecked status of checkboxes
  */
 function setCheckboxesState(nameprefix, checked){
     // XXX: this looks in *all* the document for inputs
@@ -242,14 +249,14 @@
 
 //============= page loading events ==========================================//
 function roundedCornersOnLoad() {
-    roundClass("div", "sideBox", {corners: "bottom", compact:false}); 
-    roundClass("div", "boxTitle", {corners: "top",  compact:true}); 
-    roundClass("div", "boxPrefTitle", {corners: "top",  compact:true}); 
-    roundClass("div", "sideBoxTitle", {corners: "top",  compact:true}); 
+    roundClass("div", "sideBox", {corners: "bottom", compact:false});
+    roundClass("div", "boxTitle", {corners: "top",  compact:true});
+    roundClass("div", "boxPrefTitle", {corners: "top",  compact:true});
+    roundClass("div", "sideBoxTitle", {corners: "top",  compact:true});
     roundClass("th", "month", {corners: "top",  compact:true});
 }
 
-// jQuery(document).ready(roundedCornersOnLoad); 
+// jQuery(document).ready(roundedCornersOnLoad);
 
 
 CubicWeb.provide('htmlhelpers.js');
--- a/web/views/basecomponents.py	Wed Nov 12 16:07:40 2008 +0100
+++ b/web/views/basecomponents.py	Wed Nov 12 16:09:03 2008 +0100
@@ -102,7 +102,7 @@
     def anon_user_link(self):
         if self.config['auth-mode'] == 'cookie':
             self.w(self.req._('anonymous'))
-            self.w(u'''&nbsp;[<a class="logout" href="javascript:toggleVisibility('popupLoginBox'); document.login_form.__login.focus() ">%s</a>]'''
+            self.w(u'''&nbsp;[<a class="logout" href="javascript: popupLoginBox();">%s</a>]'''
                    % (self.req._('i18n_login_popup')))
         else:
             self.w(self.req._('anonymous'))
--- a/web/views/basetemplates.py	Wed Nov 12 16:07:40 2008 +0100
+++ b/web/views/basetemplates.py	Wed Nov 12 16:09:03 2008 +0100
@@ -502,9 +502,7 @@
         self.w(u'</tr>\n')
         self.w(u'</table>\n')
         self.w(u'</form>\n')
-        # XXX doesn't seem to work, rewrite this
-        self.w(u'''<script type="text/javascript">if(document.getElementById("%s").className != "hidden")
-                   {$('login_form').__login.focus()}</script>''' % id)
+        self.req.html_headers.add_onload('jQuery("#__login:visible").focus()')
 
     
 def login_form_url(config, req):