]> git.mjollnir.org Git - moodle.git/commitdiff
outputlib MDL-19740 Fixed up outputlib focus handling to deal with the three differen...
authorsamhemelryk <samhemelryk>
Wed, 8 Jul 2009 09:01:20 +0000 (09:01 +0000)
committersamhemelryk <samhemelryk>
Wed, 8 Jul 2009 09:01:20 +0000 (09:01 +0000)
lib/javascript-static.js
lib/outputlib.php

index 6f7d95198153dfbe4145deaa9f0d647f1c11bdbe..2c3bc83ab40a349a0142557f5a25eabe922f3742 100644 (file)
@@ -1048,9 +1048,9 @@ function focuscontrol(controlid) {
  * Transfers keyboard focus to an HTML element based on the old style style of focus
  * This function should be removed as soon as it is no longer used
  */
-function old_onload_focus(parentname, controlname) {
-    if (window[parentname]) {
-        window[parentname][controlname].focus();
+function old_onload_focus(formid, controlname) {
+    if (document.forms[formid]) {
+        document.forms[formid].elements[controlname].focus();
     }
 }
 
index 3b356f9aad96d5f3b85b4c18e33fc29d59339e7f..877b0aed1607d31a9e9ee694bc8c51254c8c4af3 100644 (file)
@@ -1573,11 +1573,14 @@ class moodle_core_renderer extends moodle_renderer_base {
 
         $focus = $this->page->focuscontrol;
         if (!empty($focus)) {
-            $pos = strpos($focus, '.');
-            if($pos !== false) {
+            if(preg_match("#forms\['([a-zA-Z0-9]+)'\].elements\['([a-zA-Z0-9]+)'\]#", $focus, $matches)) {
+                // This is a horrifically bad way to handle focus but it is passed in
+                // through messy formslib::moodleform
+                $this->page->requires->js_function_call('old_onload_focus', Array($matches[1], $matches[2]));
+            } else if (strpos($focus, '.')!==false) {
                 // Old style of focus, bad way to do it
-                debugging('This code is using the old style focus event, Please update this code to focus on an element id', DEBUG_DEVELOPER);
-                $this->page->requires->js_function_call('old_onload_focus', Array(substr($focus, 0, $pos), substr($focus, $pos)));
+                debugging('This code is using the old style focus event, Please update this code to focus on an element id or the moodleform focus method.', DEBUG_DEVELOPER);
+                $this->page->requires->js_function_call('old_onload_focus', explode('.', $focus, 2));
             } else {
                 // Focus element with given id
                 $this->page->requires->js_function_call('focuscontrol', Array($focus));