MDL-64573 output: ajax form event
[moodle.git] / lib / yui / build / moodle-core-event / moodle-core-event-debug.js
CommitLineData
cc90cedc
DW
1YUI.add('moodle-core-event', function (Y, NAME) {
2
3// This file is part of Moodle - http://moodle.org/
4//
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.
9//
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.
14//
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/>.
17
18/**
19 * @module moodle-core-event
20 */
21
22var LOGNAME = 'moodle-core-event';
23
24/**
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.
27 *
441f94b2
DW
28 * @namespace M.core
29 * @class event
cc90cedc
DW
30 */
31M.core = M.core || {};
32
36e0030f 33M.core.event = M.core.event || {
260565e3 34
441f94b2
DW
35 /**
36 * This event is triggered when a page has added dynamic nodes to a page
37 * that should be processed by the filter system. An example is loading
38 * user text that could have equations in it. MathJax can typeset the equations
39 * but only if it is notified that there are new nodes in the page that need processing.
40 * To trigger this event use M.core.Event.fire(M.core.Event.FILTER_CONTENT_UPDATED, {nodes: list});
41 *
42 * @event "filter-content-updated"
43 * @param nodes {Y.NodeList} List of nodes added to the DOM.
44 */
b5594973 45 FILTER_CONTENT_UPDATED: "filter-content-updated",
260565e3 46
b5594973
AG
47 /**
48 * This event is triggered when an editor has recovered some draft text.
49 * It can be used to determine let other sections know that they should reset their
50 * form comparison for changes.
51 *
52 * @event "editor-content-restored"
53 */
260565e3
DW
54 EDITOR_CONTENT_RESTORED: "editor-content-restored",
55
56 /**
57 * This event is triggered when an mform is about to be submitted via ajax.
58 *
59 * @event "form-submit-ajax"
60 */
61 FORM_SUBMIT_AJAX: "form-submit-ajax"
62
cc90cedc
DW
63};
64
36e0030f 65M.core.globalEvents = M.core.globalEvents || {
eaec9cfe
MM
66 /**
67 * This event is triggered when form has an error
68 *
69 * @event "form_error"
70 * @param formid {string} Id of form with error.
71 * @param elementid {string} Id of element with error.
72 */
fd5466af
CB
73 FORM_ERROR: "form_error",
74
75 /**
76 * This event is triggered when the content of a block has changed
77 *
78 * @event "block_content_updated"
79 * @param instanceid ID of the block instance that was updated
80 */
81 BLOCK_CONTENT_UPDATED: "block_content_updated"
eaec9cfe
MM
82};
83
cc90cedc
DW
84
85var eventDefaultConfig = {
86 emitFacade: true,
87 defaultFn: function(e) {
88 Y.log('Event fired: ' + e.type, 'debug', LOGNAME);
89 },
90 preventedFn: function(e) {
91 Y.log('Event prevented: ' + e.type, 'debug', LOGNAME);
92 },
93 stoppedFn: function(e) {
94 Y.log('Event stopped: ' + e.type, 'debug', LOGNAME);
95 }
96};
97
eaec9cfe
MM
98// Publish events with a custom config here.
99
441f94b2
DW
100// Publish all the events with a standard config.
101var key;
102for (key in M.core.event) {
36e0030f 103 if (M.core.event.hasOwnProperty(key) && Y.getEvent(M.core.event[key]) === null) {
441f94b2
DW
104 Y.publish(M.core.event[key], eventDefaultConfig);
105 }
cc90cedc
DW
106}
107
36e0030f 108// Publish global events.
eaec9cfe 109for (key in M.core.globalEvents) {
36e0030f
JP
110 // Make sure the key exists and that the event has not yet been published. Otherwise, skip publishing.
111 if (M.core.globalEvents.hasOwnProperty(key) && Y.Global.getEvent(M.core.globalEvents[key]) === null) {
112 Y.Global.publish(M.core.globalEvents[key], Y.merge(eventDefaultConfig, {broadcast: true}));
113 Y.log('Global event published: ' + key, 'debug', LOGNAME);
eaec9cfe
MM
114 }
115}
cc90cedc
DW
116
117
118}, '@VERSION@', {"requires": ["event-custom"]});