1 YUI.add('moodle-core-event', function (Y, NAME) {
3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * @module moodle-core-event
22 var LOGNAME = 'moodle-core-event';
25 * List of published global JS events in Moodle. This is a collection
26 * of global events that can be subscribed to, or fired from any plugin.
31 M.core = M.core || {};
33 M.core.event = M.core.event || {
35 * This event is triggered when a page has added dynamic nodes to a page
36 * that should be processed by the filter system. An example is loading
37 * user text that could have equations in it. MathJax can typeset the equations
38 * but only if it is notified that there are new nodes in the page that need processing.
39 * To trigger this event use M.core.Event.fire(M.core.Event.FILTER_CONTENT_UPDATED, {nodes: list});
41 * @event "filter-content-updated"
42 * @param nodes {Y.NodeList} List of nodes added to the DOM.
44 FILTER_CONTENT_UPDATED: "filter-content-updated",
46 * This event is triggered when an editor has recovered some draft text.
47 * It can be used to determine let other sections know that they should reset their
48 * form comparison for changes.
50 * @event "editor-content-restored"
52 EDITOR_CONTENT_RESTORED: "editor-content-restored"
55 M.core.globalEvents = M.core.globalEvents || {
57 * This event is triggered when form has an error
60 * @param formid {string} Id of form with error.
61 * @param elementid {string} Id of element with error.
63 FORM_ERROR: "form_error",
66 * This event is triggered when the content of a block has changed
68 * @event "block_content_updated"
69 * @param instanceid ID of the block instance that was updated
71 BLOCK_CONTENT_UPDATED: "block_content_updated"
75 var eventDefaultConfig = {
77 defaultFn: function(e) {
78 Y.log('Event fired: ' + e.type, 'debug', LOGNAME);
80 preventedFn: function(e) {
81 Y.log('Event prevented: ' + e.type, 'debug', LOGNAME);
83 stoppedFn: function(e) {
84 Y.log('Event stopped: ' + e.type, 'debug', LOGNAME);
88 // Publish events with a custom config here.
90 // Publish all the events with a standard config.
92 for (key in M.core.event) {
93 if (M.core.event.hasOwnProperty(key) && Y.getEvent(M.core.event[key]) === null) {
94 Y.publish(M.core.event[key], eventDefaultConfig);
98 // Publish global events.
99 for (key in M.core.globalEvents) {
100 // Make sure the key exists and that the event has not yet been published. Otherwise, skip publishing.
101 if (M.core.globalEvents.hasOwnProperty(key) && Y.Global.getEvent(M.core.globalEvents[key]) === null) {
102 Y.Global.publish(M.core.globalEvents[key], Y.merge(eventDefaultConfig, {broadcast: true}));
103 Y.log('Global event published: ' + key, 'debug', LOGNAME);
108 }, '@VERSION@', {"requires": ["event-custom"]});