You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by id...@apache.org on 2008/02/08 19:04:33 UTC

svn commit: r619962 - /myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js

Author: idus
Date: Fri Feb  8 10:04:21 2008
New Revision: 619962

URL: http://svn.apache.org/viewvc?rev=619962&view=rev
Log:
TOBAGO-615: take fields with implicit tab index 0 into account for automatic focus

Modified:
    myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js

Modified: myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js?rev=619962&r1=619961&r2=619962&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js (original)
+++ myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js Fri Feb  8 10:04:21 2008
@@ -1014,7 +1014,6 @@
     */
   setFocus: function() {
     var focusElement = this.element(this.focusId);
-
     if (focusElement) {
       try { // focus() on not visible elements breaks IE
         focusElement.focus();
@@ -1024,6 +1023,7 @@
     } else if (typeof this.focusId == "undefined") {
       var lowestTabIndex = 32768; // HTML max tab index value + 1
       var candidate = null;
+      var candidateWithTabIndexZero = null;
       foriLoop: for (var i = 0 ; i < document.forms.length ; i++) {
         var form = document.forms[i];
         if (form != null){
@@ -1032,13 +1032,17 @@
             if (element != null) {
               if (!element.disabled && !element.readOnly
                   && this.isFocusType(element.type)) {
-                if (lowestTabIndex > element.tabIndex) {
+                if (lowestTabIndex > element.tabIndex && element.tabIndex > 0) {
                   lowestTabIndex = element.tabIndex;
                   candidate = element;
                   if (lowestTabIndex == 1) {
+                    // optimization: stop on first field with lowest possible tab index 1
                     break foriLoop;
                   }
                 }
+                if (candidateWithTabIndexZero == null && element.tabIndex == 0) {
+                  candidateWithTabIndexZero = element;
+                }
               }
             }
           }
@@ -1048,6 +1052,11 @@
         try {
           // focus() on not visible elements breaks IE
           candidate.focus();
+        } catch(ex) { }
+      } else if (candidateWithTabIndexZero != null) {
+        try {
+          // focus() on not visible elements breaks IE
+          candidateWithTabIndexZero.focus();
         } catch(ex) { }
       }
     } else if (this.focusId.length > 0) {