MDL-70990 core: Rewrite core/event as ES6
This commit is contained in:
Vendored
+1
-1
@@ -1,2 +1,2 @@
|
||||
define ("core/event",["jquery","core/yui"],function(a,b){return{Events:{FORM_FIELD_VALIDATION:"core_form-field-validation"},getLegacyEvents:function getLegacyEvents(){var c=a.Deferred();b.use("event","moodle-core-event",function(){c.resolve(window.M.core.event)});return c.promise()},notifyFilterContentUpdated:function notifyFilterContentUpdated(c){c=a(c);b.use("event","moodle-core-event",function(b){a(document).trigger(M.core.event.FILTER_CONTENT_UPDATED,[c]);var d=new b.NodeList(c.get());b.fire(M.core.event.FILTER_CONTENT_UPDATED,{nodes:d})})},notifyFormSubmitAjax:function notifyFormSubmitAjax(c,d){d=d||!1;b.use("event","moodle-core-event",function(b){if(d){window.skipClientValidation=!0}a(c).trigger(M.core.event.FORM_SUBMIT_AJAX);b.one(c).fire(M.core.event.FORM_SUBMIT_AJAX,{currentTarget:b.one(c)});if(d){window.skipClientValidation=!1}})},notifyEditorContentRestored:function notifyEditorContentRestored(){b.use("event","moodle-core-event",function(b){a(document).trigger(M.core.event.EDITOR_CONTENT_RESTORED);b.fire(M.core.event.EDITOR_CONTENT_RESTORED)})}}});
|
||||
define ("core/event",["exports","jquery","core/yui"],function(a,b,c){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;b=d(b);c=d(c);function d(a){return a&&a.__esModule?a:{default:a}}var e=function(){var a=b.default.Deferred();c.default.use("event","moodle-core-event",function(){a.resolve(window.M.core.event)});return a.promise()},f=function(a){a=(0,b.default)(a);c.default.use("event","moodle-core-event",function(c){(0,b.default)(document).trigger(M.core.event.FILTER_CONTENT_UPDATED,[a]);var d=new c.NodeList(a.get());c.fire(M.core.event.FILTER_CONTENT_UPDATED,{nodes:d})})},g=function(a,d){d=d||!1;c.default.use("event","moodle-core-event",function(c){if(d){window.skipClientValidation=!0}(0,b.default)(a).trigger(M.core.event.FORM_SUBMIT_AJAX);c.one(a).fire(M.core.event.FORM_SUBMIT_AJAX,{currentTarget:c.one(a)});if(d){window.skipClientValidation=!1}})},h=function(){c.default.use("event","moodle-core-event",function(a){(0,b.default)(document).trigger(M.core.event.EDITOR_CONTENT_RESTORED);a.fire(M.core.event.EDITOR_CONTENT_RESTORED)})};a.default={Events:{FORM_FIELD_VALIDATION:"core_form-field-validation"},getLegacyEvents:e,notifyFilterContentUpdated:f,notifyFormSubmitAjax:g,notifyEditorContentRestored:h};return a.default});
|
||||
//# sourceMappingURL=event.min.js.map
|
||||
|
||||
File diff suppressed because one or more lines are too long
+81
-79
@@ -18,99 +18,101 @@
|
||||
*
|
||||
* @module core/event
|
||||
* @package core
|
||||
* @class event
|
||||
* @copyright 2015 Damyon Wiese <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since 3.0
|
||||
*/
|
||||
define(['jquery', 'core/yui'],
|
||||
function($, Y) {
|
||||
|
||||
return /** @alias module:core/event */ {
|
||||
import $ from 'jquery';
|
||||
import Y from 'core/yui';
|
||||
|
||||
// Public variables and functions.
|
||||
// These are AMD only events - no backwards compatibility for new things.
|
||||
const Events = {
|
||||
FORM_FIELD_VALIDATION: "core_form-field-validation"
|
||||
};
|
||||
|
||||
// Public variables and functions.
|
||||
// These are AMD only events - no backwards compatibility for new things.
|
||||
Events: {
|
||||
FORM_FIELD_VALIDATION: "core_form-field-validation"
|
||||
},
|
||||
/**
|
||||
* Load the legacy YUI module which defines events in M.core.event and return it.
|
||||
*
|
||||
* @method getLegacyEvents
|
||||
* @return {Promise}
|
||||
*/
|
||||
const getLegacyEvents = () => {
|
||||
const result = $.Deferred();
|
||||
Y.use('event', 'moodle-core-event', function() {
|
||||
result.resolve(window.M.core.event);
|
||||
});
|
||||
return result.promise();
|
||||
};
|
||||
|
||||
/**
|
||||
* Load the legacy YUI module which defines events in M.core.event and return it.
|
||||
*
|
||||
* @method getLegacyEvents
|
||||
* @return {Promise}
|
||||
*/
|
||||
getLegacyEvents: function() {
|
||||
var result = $.Deferred();
|
||||
Y.use('event', 'moodle-core-event', function() {
|
||||
result.resolve(window.M.core.event);
|
||||
});
|
||||
return result.promise();
|
||||
},
|
||||
/**
|
||||
* Trigger an event using both JQuery and YUI
|
||||
*
|
||||
* @method notifyFilterContentUpdated
|
||||
* @param {string|JQuery} nodes - Selector or list of elements that were inserted.
|
||||
*/
|
||||
const notifyFilterContentUpdated = nodes => {
|
||||
nodes = $(nodes);
|
||||
Y.use('event', 'moodle-core-event', function(Y) {
|
||||
// Trigger it the JQuery way.
|
||||
$(document).trigger(M.core.event.FILTER_CONTENT_UPDATED, [nodes]);
|
||||
|
||||
/**
|
||||
* Trigger an event using both JQuery and YUI
|
||||
*
|
||||
* @method notifyFilterContentUpdated
|
||||
* @param {string|JQuery} nodes - Selector or list of elements that were inserted.
|
||||
*/
|
||||
notifyFilterContentUpdated: function(nodes) {
|
||||
nodes = $(nodes);
|
||||
Y.use('event', 'moodle-core-event', function(Y) {
|
||||
// Trigger it the JQuery way.
|
||||
$(document).trigger(M.core.event.FILTER_CONTENT_UPDATED, [nodes]);
|
||||
// Create a YUI NodeList from our JQuery Object.
|
||||
var yuiNodes = new Y.NodeList(nodes.get());
|
||||
|
||||
// Create a YUI NodeList from our JQuery Object.
|
||||
var yuiNodes = new Y.NodeList(nodes.get());
|
||||
// And again for YUI.
|
||||
Y.fire(M.core.event.FILTER_CONTENT_UPDATED, {nodes: yuiNodes});
|
||||
});
|
||||
};
|
||||
|
||||
// And again for YUI.
|
||||
Y.fire(M.core.event.FILTER_CONTENT_UPDATED, {nodes: yuiNodes});
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Trigger an event using both JQuery and YUI
|
||||
*
|
||||
* @method notifyFormSubmittedAjax
|
||||
* @param {DOMElement} form
|
||||
* @param {boolean} skipValidation Submit the form without validation. E.g. "Cancel".
|
||||
*/
|
||||
const notifyFormSubmitAjax = (form, skipValidation) => {
|
||||
// Argument is optional.
|
||||
skipValidation = skipValidation || false;
|
||||
|
||||
/**
|
||||
* Trigger an event using both JQuery and YUI
|
||||
*
|
||||
* @method notifyFormSubmittedAjax
|
||||
* @param {DOMElement} form
|
||||
* @param {boolean} skipValidation Submit the form without validation. E.g. "Cancel".
|
||||
*/
|
||||
notifyFormSubmitAjax: function(form, skipValidation) {
|
||||
Y.use('event', 'moodle-core-event', function(Y) {
|
||||
if (skipValidation) {
|
||||
window.skipClientValidation = true;
|
||||
}
|
||||
// Trigger it the JQuery way.
|
||||
$(form).trigger(M.core.event.FORM_SUBMIT_AJAX);
|
||||
|
||||
// Argument is optional.
|
||||
skipValidation = skipValidation || false;
|
||||
// And again for YUI.
|
||||
Y.one(form).fire(M.core.event.FORM_SUBMIT_AJAX, {currentTarget: Y.one(form)});
|
||||
|
||||
Y.use('event', 'moodle-core-event', function(Y) {
|
||||
if (skipValidation) {
|
||||
window.skipClientValidation = true;
|
||||
}
|
||||
// Trigger it the JQuery way.
|
||||
$(form).trigger(M.core.event.FORM_SUBMIT_AJAX);
|
||||
if (skipValidation) {
|
||||
window.skipClientValidation = false;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// And again for YUI.
|
||||
Y.one(form).fire(M.core.event.FORM_SUBMIT_AJAX, {currentTarget: Y.one(form)});
|
||||
/**
|
||||
* Trigger an event using both JQuery and YUI
|
||||
* This event alerts the world that the editor has restored some content.
|
||||
*
|
||||
* @method notifyEditorContentRestored
|
||||
*/
|
||||
const notifyEditorContentRestored = () => {
|
||||
Y.use('event', 'moodle-core-event', function(Y) {
|
||||
// Trigger it the JQuery way.
|
||||
$(document).trigger(M.core.event.EDITOR_CONTENT_RESTORED);
|
||||
|
||||
if (skipValidation) {
|
||||
window.skipClientValidation = false;
|
||||
}
|
||||
});
|
||||
},
|
||||
// And again for YUI.
|
||||
Y.fire(M.core.event.EDITOR_CONTENT_RESTORED);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Trigger an event using both JQuery and YUI
|
||||
* This event alerts the world that the editor has restored some content.
|
||||
*
|
||||
* @method notifyEditorContentRestored
|
||||
*/
|
||||
notifyEditorContentRestored: function() {
|
||||
Y.use('event', 'moodle-core-event', function(Y) {
|
||||
// Trigger it the JQuery way.
|
||||
$(document).trigger(M.core.event.EDITOR_CONTENT_RESTORED);
|
||||
|
||||
// And again for YUI.
|
||||
Y.fire(M.core.event.EDITOR_CONTENT_RESTORED);
|
||||
});
|
||||
},
|
||||
};
|
||||
});
|
||||
export default {
|
||||
Events,
|
||||
getLegacyEvents,
|
||||
notifyFilterContentUpdated,
|
||||
notifyFormSubmitAjax,
|
||||
notifyEditorContentRestored,
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@ information provided here is intended especially for developers.
|
||||
will be called. The following behaviour will be the new standard for nodes added via callbacks:
|
||||
- Module nodes added will be appended to the end and will appear within the hamburger option.
|
||||
- Course nodes added will also be appended and appear within the 'More' option/page.
|
||||
* The core/event events have been renamed and now fire native events, in addition to the legacy YUI and jQuery events.
|
||||
|
||||
=== 3.11 ===
|
||||
* PHPUnit has been upgraded to 9.5 (see MDL-71036 for details).
|
||||
|
||||
Reference in New Issue
Block a user