mirror of
https://github.com/moodle/moodle.git
synced 2025-07-27 01:10:51 +02:00
MDL-51222 Javascript: Trigger events for filters on DOM insertion
When nodes are added to the dom, they may need to be re-processed by a JS based filter. To do this we need to trigger the legacy YUI event filter-content-updated. To make this easier I added some wrappers to template that will insert the node, run any JS and trigger the event. I also changed existing yui code to call the amd function to trigger the event. This way all jquery and yui listeners will always be notified.
This commit is contained in:
52
lib/amd/src/event.js
Normal file
52
lib/amd/src/event.js
Normal file
@@ -0,0 +1,52 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Global registry of core events that can be triggered/listened for.
|
||||
*
|
||||
* @module core/event
|
||||
* @package core
|
||||
* @class event
|
||||
* @copyright 2015 Damyon Wiese <damyon@moodle.com>
|
||||
* @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 */ {
|
||||
// Public variables and functions.
|
||||
/**
|
||||
* 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());
|
||||
|
||||
// And again for YUI.
|
||||
Y.fire(M.core.event.FILTER_CONTENT_UPDATED, { nodes: yuiNodes });
|
||||
});
|
||||
},
|
||||
|
||||
};
|
||||
});
|
Reference in New Issue
Block a user