diff --git a/lib/formslib.php b/lib/formslib.php index f4930bd8980..8fc5a7e0e7d 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -2233,9 +2233,11 @@ function validate_' . $this->_formName . '_' . $escapedElementName . '(element, ret = validate_' . $this->_formName . '_' . $escapedElementName.'(frm.elements[\''.$elementName.'\'], \''.$escapedElementName.'\') && ret; if (!ret && !first_focus) { first_focus = true; - Y.Global.fire(M.core.globalEvents.FORM_ERROR, {formid: \''. $this->_attributes['id'] .'\', - elementid: \'id_error_'.$escapedElementName.'\'}); - document.getElementById(\'id_error_'.$escapedElementName.'\').focus(); + Y.use(\'moodle-core-event\', function() { + Y.Global.fire(M.core.globalEvents.FORM_ERROR, {formid: \'' . $this->_attributes['id'] . '\', + elementid: \'id_error_' . $escapedElementName . '\'}); + document.getElementById(\'id_error_' . $escapedElementName . '\').focus(); + }); } '; diff --git a/lib/yui/build/moodle-core-event/moodle-core-event-debug.js b/lib/yui/build/moodle-core-event/moodle-core-event-debug.js index cbf3e398621..ca46f73f23b 100644 --- a/lib/yui/build/moodle-core-event/moodle-core-event-debug.js +++ b/lib/yui/build/moodle-core-event/moodle-core-event-debug.js @@ -30,7 +30,7 @@ var LOGNAME = 'moodle-core-event'; */ M.core = M.core || {}; -M.core.event = { +M.core.event = M.core.event || { /** * This event is triggered when a page has added dynamic nodes to a page * that should be processed by the filter system. An example is loading @@ -44,7 +44,7 @@ M.core.event = { FILTER_CONTENT_UPDATED: "filter-content-updated" }; -M.core.globalEvents = { +M.core.globalEvents = M.core.globalEvents || { /** * This event is triggered when form has an error * @@ -74,15 +74,17 @@ var eventDefaultConfig = { // Publish all the events with a standard config. var key; for (key in M.core.event) { - if (M.core.event.hasOwnProperty(key)) { + if (M.core.event.hasOwnProperty(key) && Y.getEvent(M.core.event[key]) === null) { Y.publish(M.core.event[key], eventDefaultConfig); } } -//Publish all the global events. +// Publish global events. for (key in M.core.globalEvents) { - if (M.core.globalEvents.hasOwnProperty(key)) { - Y.Global.publish(M.core.globalEvents[key], Y.merge(eventDefaultConfig, {broadcast: 2})); + // Make sure the key exists and that the event has not yet been published. Otherwise, skip publishing. + if (M.core.globalEvents.hasOwnProperty(key) && Y.Global.getEvent(M.core.globalEvents[key]) === null) { + Y.Global.publish(M.core.globalEvents[key], Y.merge(eventDefaultConfig, {broadcast: true})); + Y.log('Global event published: ' + key, 'debug', LOGNAME); } } diff --git a/lib/yui/build/moodle-core-event/moodle-core-event-min.js b/lib/yui/build/moodle-core-event/moodle-core-event-min.js index 426af2f01e0..ced026ee1a2 100644 --- a/lib/yui/build/moodle-core-event/moodle-core-event-min.js +++ b/lib/yui/build/moodle-core-event/moodle-core-event-min.js @@ -1 +1 @@ -YUI.add("moodle-core-event",function(e,t){var n="moodle-core-event";M.core=M.core||{},M.core.event={FILTER_CONTENT_UPDATED:"filter-content-updated"},M.core.globalEvents={FORM_ERROR:"form_error"};var r={emitFacade:!0,defaultFn:function(e){},preventedFn:function(e){},stoppedFn:function(e){}},i;for(i in M.core.event)M.core.event.hasOwnProperty(i)&&e.publish(M.core.event[i],r);for(i in M.core.globalEvents)M.core.globalEvents.hasOwnProperty(i)&&e.Global.publish(M.core.globalEvents[i],e.merge(r,{broadcast:2}))},"@VERSION@",{requires:["event-custom"]}); +YUI.add("moodle-core-event",function(e,t){var n="moodle-core-event";M.core=M.core||{},M.core.event=M.core.event||{FILTER_CONTENT_UPDATED:"filter-content-updated"},M.core.globalEvents=M.core.globalEvents||{FORM_ERROR:"form_error"};var r={emitFacade:!0,defaultFn:function(e){},preventedFn:function(e){},stoppedFn:function(e){}},i;for(i in M.core.event)M.core.event.hasOwnProperty(i)&&e.getEvent(M.core.event[i])===null&&e.publish(M.core.event[i],r);for(i in M.core.globalEvents)M.core.globalEvents.hasOwnProperty(i)&&e.Global.getEvent(M.core.globalEvents[i])===null&&e.Global.publish(M.core.globalEvents[i],e.merge(r,{broadcast:!0}))},"@VERSION@",{requires:["event-custom"]}); diff --git a/lib/yui/build/moodle-core-event/moodle-core-event.js b/lib/yui/build/moodle-core-event/moodle-core-event.js index 2a9e77668ce..6a18fe68aa4 100644 --- a/lib/yui/build/moodle-core-event/moodle-core-event.js +++ b/lib/yui/build/moodle-core-event/moodle-core-event.js @@ -30,7 +30,7 @@ var LOGNAME = 'moodle-core-event'; */ M.core = M.core || {}; -M.core.event = { +M.core.event = M.core.event || { /** * This event is triggered when a page has added dynamic nodes to a page * that should be processed by the filter system. An example is loading @@ -44,7 +44,7 @@ M.core.event = { FILTER_CONTENT_UPDATED: "filter-content-updated" }; -M.core.globalEvents = { +M.core.globalEvents = M.core.globalEvents || { /** * This event is triggered when form has an error * @@ -71,15 +71,16 @@ var eventDefaultConfig = { // Publish all the events with a standard config. var key; for (key in M.core.event) { - if (M.core.event.hasOwnProperty(key)) { + if (M.core.event.hasOwnProperty(key) && Y.getEvent(M.core.event[key]) === null) { Y.publish(M.core.event[key], eventDefaultConfig); } } -//Publish all the global events. +// Publish global events. for (key in M.core.globalEvents) { - if (M.core.globalEvents.hasOwnProperty(key)) { - Y.Global.publish(M.core.globalEvents[key], Y.merge(eventDefaultConfig, {broadcast: 2})); + // Make sure the key exists and that the event has not yet been published. Otherwise, skip publishing. + if (M.core.globalEvents.hasOwnProperty(key) && Y.Global.getEvent(M.core.globalEvents[key]) === null) { + Y.Global.publish(M.core.globalEvents[key], Y.merge(eventDefaultConfig, {broadcast: true})); } } diff --git a/lib/yui/src/event/js/event.js b/lib/yui/src/event/js/event.js index 6f6a28adb9d..5a51c2a1ef9 100644 --- a/lib/yui/src/event/js/event.js +++ b/lib/yui/src/event/js/event.js @@ -28,7 +28,7 @@ var LOGNAME = 'moodle-core-event'; */ M.core = M.core || {}; -M.core.event = { +M.core.event = M.core.event || { /** * This event is triggered when a page has added dynamic nodes to a page * that should be processed by the filter system. An example is loading @@ -42,7 +42,7 @@ M.core.event = { FILTER_CONTENT_UPDATED: "filter-content-updated" }; -M.core.globalEvents = { +M.core.globalEvents = M.core.globalEvents || { /** * This event is triggered when form has an error * @@ -72,14 +72,16 @@ var eventDefaultConfig = { // Publish all the events with a standard config. var key; for (key in M.core.event) { - if (M.core.event.hasOwnProperty(key)) { + if (M.core.event.hasOwnProperty(key) && Y.getEvent(M.core.event[key]) === null) { Y.publish(M.core.event[key], eventDefaultConfig); } } -//Publish all the global events. +// Publish global events. for (key in M.core.globalEvents) { - if (M.core.globalEvents.hasOwnProperty(key)) { - Y.Global.publish(M.core.globalEvents[key], Y.merge(eventDefaultConfig, {broadcast: 2})); + // Make sure the key exists and that the event has not yet been published. Otherwise, skip publishing. + if (M.core.globalEvents.hasOwnProperty(key) && Y.Global.getEvent(M.core.globalEvents[key]) === null) { + Y.Global.publish(M.core.globalEvents[key], Y.merge(eventDefaultConfig, {broadcast: true})); + Y.log('Global event published: ' + key, 'debug', LOGNAME); } }