Hi,
We are using javascript (jQuery) in page summary content, like screenshot below.
Our current version is 3.3, but after upgrading to 3.6, the above js code does not work, because external jQuery conflicts with Moodle's jQuery and all the initializations on our jQuery does not execute at all. We have tons of pages to update and a huge production userbase so we are hesitating to make any change this big. Is there any way to make it work with some quick changes in Moodle's functionality?
We have tried the following code and it works, but like I said this will be a really huge change.
function initScript(libraries = [], callback, requireJQuery = true){
if (!callback)
callback = function () {};
var jRef;
var oldJquery = false;
if(requireJQuery){
if($ !== undefined)
oldJquery = true;
else
includeJquery();
}
for (i=0; i<libraries.length; i++) {
includeJS(libraries[i]);
}
if(requireJQuery){
if(!oldJquery)
jRef = $.noConflict(true);
else
jRef = $;
callback(jRef);
} else {
callback(null);
}
}
This code works fine by calling via summary content like this
var urls = ['/local/3rdMil/javascript/LoadingOverlay.js'];
initScript(urls, function (_$) {
_$.LoadingOverlay('show');
_$(document).ready(function () {
.
.
.
A quick help will be very much appreciated.