outputlib MDL-19740 Fixed up outputlib focus handling to deal with the three different ways of requesting focus.

This commit is contained in:
samhemelryk 2009-07-08 09:01:20 +00:00
parent b2f8adf4e5
commit 428acddb72
2 changed files with 10 additions and 7 deletions

View 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();
}
}

View 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));