From efd79c9e796724ce259a6857e10d41b9b53a2262 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Tue, 10 Mar 2015 10:09:31 +0100 Subject: [PATCH] Support init target. --- js/h5p.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/js/h5p.js b/js/h5p.js index 9a08a7a..4223230 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -39,13 +39,15 @@ H5P.canHasFullScreen = (H5P.isFramed && H5P.externalEmbed !== false) ? (document * Initialize H5P content. * Scans for ".h5p-content" in the document and initializes H5P instances where found. */ -H5P.init = function () { +H5P.init = function (target) { // Useful jQuery object. - H5P.$body = H5P.jQuery(document.body); + if (H5P.$body === undefined) { + H5P.$body = H5P.jQuery(document.body); + } // H5Ps added in normal DIV. - var $containers = H5P.jQuery(".h5p-content").each(function () { - var $element = H5P.jQuery(this); + var $containers = H5P.jQuery('.h5p-content:not(.h5p-initialized)', target).each(function () { + var $element = H5P.jQuery(this).addClass('h5p-initialized'); var $container = H5P.jQuery('
').appendTo($element); var contentId = $element.data('content-id'); var contentData = H5PIntegration.contents['cid-' + contentId]; @@ -213,8 +215,8 @@ H5P.init = function () { }); // Insert H5Ps that should be in iframes. - H5P.jQuery("iframe.h5p-iframe").each(function () { - var contentId = H5P.jQuery(this).data('content-id'); + H5P.jQuery('iframe.h5p-iframe:not(.h5p-initialized)', target).each(function () { + var contentId = H5P.jQuery(this).addClass('h5p-initialized').data('content-id'); this.contentDocument.open(); this.contentDocument.write('' + H5P.getHeadTags(contentId) + '
'); this.contentDocument.close(); @@ -1390,6 +1392,6 @@ H5P.on = function(instance, eventType, handler) { H5P.jQuery(document).ready(function () { if (!H5P.preventInit) { // Start script need to be an external resource to load in correct order for IE9. - H5P.init(); + H5P.init(document.body); } });