Skip to content

Commit

Permalink
better approach to fixing jquery issue
Browse files Browse the repository at this point in the history
  • Loading branch information
emmachughes committed Jun 18, 2024
1 parent 64055cb commit 4e1d933
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 deletions.
1 change: 0 additions & 1 deletion sourcecode/apis/contentauthor/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Homestead.json
!/public/js/videos/brightcove.js
!/public/js/videos/streamps.js
!/public/js/h5p/ndlah5p-youtube.js
!public/js/h5p/core-override
!/public/js/h5p/h5peditor-pre-save.js
!public/css
/public/css/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import jQuery from 'jquery';

window.H5P = window.H5P || {};
window.H5P.jQuery = jQuery;

// do not replace these with imports
require('../../../vendor/h5p/h5p-core/js/h5p.js');
require('../../../vendor/h5p/h5p-core/js/h5p-event-dispatcher.js');
require('../../../vendor/h5p/h5p-core/js/h5p-x-api-event.js');
require('../../../vendor/h5p/h5p-core/js/h5p-x-api.js');
require('../../../public/js/h5p/core-override/h5p-content-type.js'); //TODO Replaced to support patch-version in library folder name. Used by libraries to loads assets that is not js or css
require('../../../vendor/h5p/h5p-core/js/h5p-confirmation-dialog.js');
require('../../../vendor/h5p/h5p-core/js/h5p-action-bar.js');
require('../../../public/js/h5p/core-override/request-queue.js'); //TODO Change to vanilla H5P when they fix https://github.com/h5p/h5p-php-library/pull/66
require('../../../vendor/h5p/h5p-core/js/h5p-tooltip.js');
import '../js/core-override/h5p-jquery.js';
import '../../../vendor/h5p/h5p-core/js/h5p.js';
import '../../../vendor/h5p/h5p-core/js/h5p.js';
import '../../../vendor/h5p/h5p-core/js/h5p-event-dispatcher.js';
import '../../../vendor/h5p/h5p-core/js/h5p-x-api-event.js';
import '../../../vendor/h5p/h5p-core/js/h5p-x-api.js';
import '../js/core-override/h5p-content-type.js'; //TODO Replaced to support patch-version in library folder name. Used by libraries to loads assets that is not js or css
import '../../../vendor/h5p/h5p-core/js/h5p-confirmation-dialog.js';
import '../../../vendor/h5p/h5p-core/js/h5p-action-bar.js';
import '../js/core-override/request-queue.js'; //TODO Change to vanilla H5P when they fix https://github.com/h5p/h5p-php-library/pull/66
import '../../../vendor/h5p/h5p-core/js/h5p-tooltip.js';
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const H5P = window.H5P = window.H5P || {};

/**
* H5P.ContentType is a base class for all content types. Used by newRunnable()
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import jQuery from "jquery";

const H5P = window.H5P = window.H5P || {};
H5P.jQuery = jQuery;

const originalLoad = jQuery.fn.load;

// Copied from h5p-php-library
H5P.jQuery.fn.load = function (url, params, callback) {
/**
* NOTE:
* This is needed in order to support old libraries that uses the .load() function
* for elements in the deprecated jQuery way (elem.load(fn)), the correct way to do this
* now is elem.on('load', fn)
*/
if (typeof url === "function") {
console.warn('You are using a deprecated H5P library. Please upgrade!');
let args = Array.prototype.slice.call(arguments);
args.unshift('load');
return window.H5P.jQuery.fn.on.apply(this, args);
}

return originalLoad.apply(this, arguments);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const H5P = window.H5P = window.H5P || {};

/**
* Queue requests and handle them at your convenience
*
Expand Down

0 comments on commit 4e1d933

Please sign in to comment.