1
0
mirror of https://github.com/moodle/moodle.git synced 2025-04-23 09:23:09 +02:00

MDL-56683 theme_boost: Popovers on dynamic content

This commit is contained in:
Damyon Wiese 2016-11-03 11:24:51 +08:00
parent cd4a6b8b0b
commit 52a51514f6
4 changed files with 30 additions and 4 deletions
lib/amd
theme/boost/amd

@ -1 +1 @@
define(["jquery","core/yui"],function(a,b){return{Events:{FORM_FIELD_VALIDATION:"core_form-field-validation"},notifyFilterContentUpdated:function(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})})},notifyEditorContentRestored:function(){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(["jquery","core/yui"],function(a,b){return{Events:{FORM_FIELD_VALIDATION:"core_form-field-validation"},getLegacyEvents:function(){var c=a.Deferred();return b.use("event","moodle-core-event",function(){c.resolve(window.M.core.event)}),c.promise()},notifyFilterContentUpdated:function(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})})},notifyEditorContentRestored:function(){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)})}}});

@ -35,6 +35,20 @@ define(['jquery', 'core/yui'],
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}
*/
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
*
@ -45,7 +59,7 @@ define(['jquery', 'core/yui'],
nodes = $(nodes);
Y.use('event', 'moodle-core-event', function(Y) {
// Trigger it the JQuery way.
$(document).trigger(M.core.event.FILTER_CONTENT_UPDATED, nodes);
$(document).trigger(M.core.event.FILTER_CONTENT_UPDATED, [nodes]);
// Create a YUI NodeList from our JQuery Object.
var yuiNodes = new Y.NodeList(nodes.get());

@ -1 +1 @@
define(["jquery","./tether"],function(a,b){return window.jQuery=a,window.Tether=b,require(["theme_boost/util","theme_boost/alert","theme_boost/button","theme_boost/carousel","theme_boost/collapse","theme_boost/dropdown","theme_boost/modal","theme_boost/scrollspy","theme_boost/tab","theme_boost/tooltip","theme_boost/popover"],function(){a("body").popover({selector:'[data-toggle="popover"]',trigger:"focus"})}),{}});
define(["jquery","./tether","core/event"],function(a,b,c){return window.jQuery=a,window.Tether=b,require(["theme_boost/util","theme_boost/alert","theme_boost/button","theme_boost/carousel","theme_boost/collapse","theme_boost/dropdown","theme_boost/modal","theme_boost/scrollspy","theme_boost/tab","theme_boost/tooltip","theme_boost/popover"],function(){a("body").popover({selector:'[data-toggle="popover"]',trigger:"focus"}),c.getLegacyEvents().done(function(b){a(document).on(b.FILTER_CONTENT_UPDATED,function(){a("body").popover({selector:'[data-toggle="popover"]',trigger:"focus"})})})}),{}});

@ -23,7 +23,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since 2.9
*/
define(['jquery', './tether'], function(jQuery, Tether) {
define(['jquery', './tether', 'core/event'], function(jQuery, Tether, Event) {
window.jQuery = jQuery;
window.Tether = Tether;
@ -40,11 +40,23 @@ define(['jquery', './tether'], function(jQuery, Tether) {
'theme_boost/tooltip',
'theme_boost/popover'],
function() {
jQuery('body').popover({
selector: '[data-toggle="popover"]',
trigger: 'focus'
});
// We need to call popover automatically if nodes are added to the page later.
Event.getLegacyEvents().done(function(events) {
jQuery(document).on(events.FILTER_CONTENT_UPDATED, function() {
jQuery('body').popover({
selector: '[data-toggle="popover"]',
trigger: 'focus'
});
});
});
});
return {};
});