Load Javascript after the preloadedJs
Submitted by frischi on Tue, 05/15/2018 - 08:19
Forums:
Hello,
Iḿ trying to develope a h5p content, but I need to add javascript after the dom has loaded because the js is a complete react app and needs the div container created from the "preloadedJs"
.
I tried to load the js with jquery getscript in the "C.prototype.attach" method with a relativ path. A "test.js" file in the same folder that contains the file with the "C.prototype.attach" function is cannot be found.
Does anybody know here, how I can load custom javascript after the dom load has finished?
This is my questionnaire.js file:
varH5P=H5P|| {};H5P.Questionnaire= (function ($) {/** * Constructor function. */functionC(options, id) {// Extend defaults with provided optionsthis.options=$.extend(true, {}, {language:'en' }, options);// Keep provided id.this.id=id; };
/** * Attach function called by H5P framework to insert H5P content into * page * * @param{jQuery}$container */C.prototype.attach=function ($container) { // Set class on container to identify it as a greeting card// container. Allows for styling later.$container.addClass("h5p-questionnaire");// Add image if provided.// if (this.options.image && this.options.image.path) {// $container.append('<img class="greeting-image" src="' + H5P.getPath(this.options.image.path, this.id) + '">');// }// Add greeting text.$container.append('<div class="questionnaire" id="learningstyle"></div>');$(document).ready(function () {$.getScript("test.js") .done(function (script, textStatus) {console.log(textStatus); }) .fail(function (jqxhr, settings, exception) {console.log('getscript failed');console.log('jqxhr');console.log(jqxhr);console.log('settings');console.log(settings);console.log('exception');console.log(exception); }); }); };
returnC;})(H5P.jQuery);
Thanx very much.
frischi
BV52
Wed, 05/16/2018 - 04:13
Permalink
Hi frischi,Please see answer
Hi frischi,
Please see answer here.
-BV52