MDL-38090 JavaScript Make forms JS more resilient

This issue also corrects the way in which Y.one is called. Previously it
was called as constructor rather than as a static method so it always
returned a Y.Node, regardless of whether a node was found.

Additionally, this adds a config setting to the YUI configuration such that
debug messages are not shown in the JS console when debugging is disabled.
This commit is contained in:
Andrew Robert Nicols 2013-02-18 15:02:38 +00:00
parent f29e62cb6c
commit e691028ab6
3 changed files with 15 additions and 3 deletions

View File

@ -84,7 +84,12 @@ YUI.add('moodle-form-shortforms', function(Y) {
fieldset.toggleClass(CSS.COLLAPSED);
// Get corresponding hidden variable
// - and invert it.
var statuselement = new Y.one('input[name=mform_isexpanded_'+fieldset.get('id')+']');
var statuselement = Y.one('input[name=mform_isexpanded_'+fieldset.get('id')+']');
if (!statuselement) {
Y.log("M.form.shortforms::switch_state was called on an fieldset without a status field: '" +
fieldset.get('id') + "'", 'debug');
return;
}
statuselement.set('value', Math.abs(Number(statuselement.get('value'))-1));
}
});

View File

@ -67,7 +67,12 @@ YUI.add('moodle-form-showadvanced', function(Y) {
Y.one('#'+this.get('formid')).delegate('click', this.switch_state, SELECTORS.FIELDSETCONTAINSADVANCED+' .'+CSS.MORELESSTOGGLER);
},
process_fieldset : function(fieldset) {
var statuselement = new Y.one('input[name=mform_showmore_'+fieldset.get('id')+']');
var statuselement = Y.one('input[name=mform_showmore_'+fieldset.get('id')+']');
if (!statuselement) {
Y.log("M.form.showadvanced::process_fieldset was called on an fieldset without a status field: '" +
fieldset.get('id') + "'", 'debug');
return;
}
var morelesslink = Y.Node.create('<a href="#"></a>');
morelesslink.addClass(CSS.MORELESSTOGGLER);
if (statuselement.get('value') === '0') {

View File

@ -155,12 +155,15 @@ class page_requirements_manager {
$sep = empty($CFG->yuislasharguments) ? '?' : '/';
$this->yui3loader = new stdClass();
$this->YUI_config = new stdClass();
// Set up some loader options.
if (debugging('', DEBUG_DEVELOPER)) {
$this->yui3loader->filter = 'RAW'; // For more detailed logging info use 'DEBUG' here.
$this->YUI_config->debug = true;
} else {
$this->yui3loader->filter = null;
$this->YUI_config->debug = false;
}
if (!empty($CFG->useexternalyui) and strpos($CFG->httpswwwroot, 'https:') !== 0) {
$this->yui3loader->base = 'http://yui.yahooapis.com/' . $CFG->yui3version . '/build/';
@ -182,7 +185,6 @@ class page_requirements_manager {
}
// Set up JS YUI loader helper object.
$this->YUI_config = new stdClass();
$this->YUI_config->base = $this->yui3loader->base;
$this->YUI_config->comboBase = $this->yui3loader->comboBase;
$this->YUI_config->combine = $this->yui3loader->combine;