Skip to content

Commit

Permalink
MDL-56683 theme_boost: Popovers on dynamic content
Browse files Browse the repository at this point in the history
  • Loading branch information
Damyon Wiese committed Nov 22, 2016
1 parent cd4a6b8 commit 52a5151
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/amd/build/event.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion lib/amd/src/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion theme/boost/amd/build/loader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion theme/boost/amd/src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {};
});

0 comments on commit 52a5151

Please sign in to comment.