MDL-54796 forms: Editor restore event created.
[moodle.git] / lib / yui / src / event / js / event.js
CommitLineData
cc90cedc
DW
1// This file is part of Moodle - http://moodle.org/
2//
3// Moodle is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7//
8// Moodle is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
15
16/**
17 * @module moodle-core-event
18 */
19
20var LOGNAME = 'moodle-core-event';
21
22/**
23 * List of published global JS events in Moodle. This is a collection
24 * of global events that can be subscribed to, or fired from any plugin.
25 *
441f94b2
DW
26 * @namespace M.core
27 * @class event
cc90cedc
DW
28 */
29M.core = M.core || {};
30
36e0030f 31M.core.event = M.core.event || {
441f94b2
DW
32 /**
33 * This event is triggered when a page has added dynamic nodes to a page
34 * that should be processed by the filter system. An example is loading
35 * user text that could have equations in it. MathJax can typeset the equations
36 * but only if it is notified that there are new nodes in the page that need processing.
37 * To trigger this event use M.core.Event.fire(M.core.Event.FILTER_CONTENT_UPDATED, {nodes: list});
38 *
39 * @event "filter-content-updated"
40 * @param nodes {Y.NodeList} List of nodes added to the DOM.
41 */
b5594973
AG
42 FILTER_CONTENT_UPDATED: "filter-content-updated",
43 /**
44 * This event is triggered when an editor has recovered some draft text.
45 * It can be used to determine let other sections know that they should reset their
46 * form comparison for changes.
47 *
48 * @event "editor-content-restored"
49 */
50 EDITOR_CONTENT_RESTORED: "editor-content-restored"
cc90cedc
DW
51};
52
36e0030f 53M.core.globalEvents = M.core.globalEvents || {
eaec9cfe
MM
54 /**
55 * This event is triggered when form has an error
56 *
57 * @event "form_error"
58 * @param formid {string} Id of form with error.
59 * @param elementid {string} Id of element with error.
60 */
fd5466af
CB
61 FORM_ERROR: "form_error",
62
63 /**
64 * This event is triggered when the content of a block has changed
65 *
66 * @event "block_content_updated"
67 * @param instanceid ID of the block instance that was updated
68 */
69 BLOCK_CONTENT_UPDATED: "block_content_updated"
eaec9cfe
MM
70};
71
cc90cedc
DW
72
73var eventDefaultConfig = {
74 emitFacade: true,
75 defaultFn: function(e) {
76 Y.log('Event fired: ' + e.type, 'debug', LOGNAME);
77 },
78 preventedFn: function(e) {
79 Y.log('Event prevented: ' + e.type, 'debug', LOGNAME);
80 },
81 stoppedFn: function(e) {
82 Y.log('Event stopped: ' + e.type, 'debug', LOGNAME);
83 }
84};
85
eaec9cfe
MM
86// Publish events with a custom config here.
87
441f94b2
DW
88// Publish all the events with a standard config.
89var key;
90for (key in M.core.event) {
36e0030f 91 if (M.core.event.hasOwnProperty(key) && Y.getEvent(M.core.event[key]) === null) {
441f94b2
DW
92 Y.publish(M.core.event[key], eventDefaultConfig);
93 }
cc90cedc
DW
94}
95
36e0030f 96// Publish global events.
eaec9cfe 97for (key in M.core.globalEvents) {
36e0030f
JP
98 // Make sure the key exists and that the event has not yet been published. Otherwise, skip publishing.
99 if (M.core.globalEvents.hasOwnProperty(key) && Y.Global.getEvent(M.core.globalEvents[key]) === null) {
100 Y.Global.publish(M.core.globalEvents[key], Y.merge(eventDefaultConfig, {broadcast: true}));
101 Y.log('Global event published: ' + key, 'debug', LOGNAME);
eaec9cfe
MM
102 }
103}