diff --git a/lib/javascript-static.js b/lib/javascript-static.js index b8fc705b3ea..0273f41a6ab 100644 --- a/lib/javascript-static.js +++ b/lib/javascript-static.js @@ -376,30 +376,49 @@ M.util.init_select_autosubmit = function(Y, formid, selectid, nothing) { })(); // Make sure we have the form if (form) { + var buttonflag = 0; // Create a function to handle our change event var processchange = function(e, paramobject) { if ((nothing===false || select.get('value') != nothing) && paramobject.lastindex != select.get('selectedIndex')) { - //prevent event bubbling and detach handlers to prevent multiple submissions caused by double clicking - e.halt(); - paramobject.eventkeypress.detach(); - paramobject.eventblur.detach(); - paramobject.eventchangeorblur.detach(); - - this.submit(); + // chrome doesn't pick up on a click when selecting an element in a select menu, so we use + // the on change event to fire this function. This just checks to see if a button was + // first pressed before redirecting to the appropriate page. + if (Y.UA.os == 'windows' && Y.UA.chrome){ + if (buttonflag == 1) { + buttonflag = 0; + this.submit(); + } + } else { + this.submit(); + } + } + if (e.button == 1) { + buttonflag = 1; } }; - // Attach the change event to the keypress, blur, and click actions. - // We don't use the change event because IE fires it on every arrow up/down - // event.... usability + + var changedown = function(e, paramobject) { + if ((nothing===false || select.get('value') != nothing) && paramobject.lastindex != select.get('selectedIndex')) { + if(e.keyCode == 13) { + form.submit(); + } + } + } + var paramobject = new Object(); paramobject.lastindex = select.get('selectedIndex'); - paramobject.eventkeypress = Y.on('key', processchange, select, 'press:13', form, paramobject); - paramobject.eventblur = select.on('blur', processchange, form, paramobject); - //little hack for chrome that need onChange event instead of onClick - see MDL-23224 - if (Y.UA.webkit) { - paramobject.eventchangeorblur = select.on('change', processchange, form, paramobject); + paramobject.eventchangeorblur = select.on('click', processchange, form, paramobject); + // Bad hack to circumvent problems with different browsers on different systems. + if (Y.UA.os == 'macintosh') { + if(Y.UA.webkit) { + paramobject.eventchangeorblur = select.on('change', processchange, form, paramobject); + } + paramobject.eventkeypress = Y.on('key', processchange, select, 'press:13', form, paramobject); } else { - paramobject.eventchangeorblur = select.on('click', processchange, form, paramobject); + if(Y.UA.os == 'windows' && Y.UA.chrome) { + paramobject.eventchangeorblur = select.on('change', processchange, form, paramobject); + } + paramobject.eventkeypress = Y.on('keydown', changedown, select, '', form, paramobject); } } } @@ -408,6 +427,9 @@ M.util.init_select_autosubmit = function(Y, formid, selectid, nothing) { /** * Attach handler to url_select + * Deprecated from 2.4 onwards. + * Please use @see init_select_autosubmit() for redirecting to a url (above). + * This function has accessability issues and also does not use the formid passed through as a parameter. */ M.util.init_url_select = function(Y, formid, selectid, nothing) { YUI().use('node', function(Y) { diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 28b8490a571..a02de148287 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -1490,7 +1490,7 @@ class core_renderer extends renderer_base { $go = html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('go'))); $output .= html_writer::tag('noscript', html_writer::tag('div', $go), array('style'=>'inline')); $nothing = empty($select->nothing) ? false : key($select->nothing); - $output .= $this->page->requires->js_init_call('M.util.init_url_select', array($select->formid, $select->attributes['id'], $nothing)); + $output .= $this->page->requires->js_init_call('M.util.init_select_autosubmit', array($select->formid, $select->attributes['id'], $nothing)); } else { $output .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>$select->showbutton)); }