diff --git a/demo/index.html b/demo/index.html index 9e794c26..a8cce79a 100644 --- a/demo/index.html +++ b/demo/index.html @@ -2,13 +2,13 @@ - + ';return t};return t(H5PIntegration.core.styles)+t(H5PIntegration.contents["cid-"+e].styles)+n(H5PIntegration.core.scripts)+n(H5PIntegration.contents["cid-"+e].scripts)+""},H5P.communicator=function(){function e(){var e=this,t={};window.addEventListener("message",function(e){window.parent===e.source&&"h5p"===e.data.context&&void 0!==t[e.data.action]&&t[e.data.action](e.data)},!1),e.on=function(e,n){t[e]=n},e.send=function(e,t){void 0===t&&(t={}),t.context="h5p",t.action=e,window.parent.postMessage(t,"*")}}return window.postMessage&&window.addEventListener?new e:void 0}(),H5P.fullScreen=function(e,t,n,r){if(void 0===H5P.exitFullScreen){if(H5P.isFramed&&H5P.externalEmbed===!1)return window.parent.H5P.fullScreen(e,t,n,H5P.$body.get()),H5P.isFullscreen=!0,H5P.exitFullScreen=function(){window.parent.H5P.exitFullScreen()},void H5P.on(t,"exitFullScreen",function(){H5P.isFullscreen=!1,H5P.exitFullScreen=void 0});var i,o,a=e;if(void 0===r)$body=H5P.$body;else{$body=H5P.jQuery(r),i=$body.add(e.get());var s="#h5p-iframe-"+e.parent().data("content-id");o=H5P.jQuery(s),e=o.parent()}i=e.add(H5P.$body).add(i);var u=function(e){i.addClass(e),void 0!==o&&o.css("height","")},c=function(){H5P.trigger(t,"resize"),H5P.trigger(t,"focus"),H5P.trigger(t,"enterFullScreen")},l=function(e){H5P.isFullscreen=!1,i.removeClass(e),H5P.trigger(t,"resize"),H5P.trigger(t,"focus"),H5P.exitFullScreen=void 0,void 0!==n&&n(),H5P.trigger(t,"exitFullScreen")};if(H5P.isFullscreen=!0,void 0===H5P.fullScreenBrowserPrefix){if(H5P.isFramed)return;u("h5p-semi-fullscreen");var d,f=H5P.jQuery('
').appendTo(a.find(".h5p-content-controls")),p=H5P.exitFullScreen=function(){h?g[v].content=h:m.removeChild(metaTag),f.remove(),$body.unbind("keyup",d),l("h5p-semi-fullscreen")};d=function(e){27===e.keyCode&&p()},f.click(p),$body.keyup(d);for(var h,g=document.getElementsByTagName("meta"),v=0;v-1?new c(e.params,t):new c(e.params,t,i),void 0===f.$&&(f.$=H5P.jQuery(f)),void 0===f.contentId&&(f.contentId=t),void 0===f.subContentId&&e.subContentId&&(f.subContentId=e.subContentId),void 0===f.parent&&i&&i.parent&&(f.parent=i.parent),void 0===f.libraryInfo&&(f.libraryInfo={versionedName:e.library,versionedNameNoSpaces:s+"-"+a[0]+"."+a[1],machineName:s,majorVersion:a[0],minorVersion:a[1]}),void 0!==n&&(n.toggleClass("h5p-standalone",d),f.attach(n),H5P.trigger(f,"domChanged",{$target:n,library:s,key:"newLibrary"},{bubbles:!0,external:!0}),void 0!==r&&r||H5P.trigger(f,"resize")),f},H5P.error=function(e){void 0!==window.console&&void 0!==console.error&&console.error(e.stack?e.stack:e)},H5P.t=function(e,t,n){if(void 0===n&&(n="H5P"),void 0===H5PIntegration.l10n[n])return'[Missing translation namespace "'+n+'"]';if(void 0===H5PIntegration.l10n[n][e])return'[Missing translation "'+e+'" in "'+n+'"]';var r=H5PIntegration.l10n[n][e];if(void 0!==t)for(var i in t)r=r.replace(i,t[i]);return r},H5P.Dialog=function(e,t,n,r){var i=this,o=H5P.jQuery('

'+t+'

'+n+'
').insertAfter(r).click(function(){i.close()}).children(".h5p-inner").click(function(){return!1}).find(".h5p-close").click(function(){i.close()}).end().end();this.open=function(){setTimeout(function(){o.addClass("h5p-open"),H5P.jQuery(i).trigger("dialog-opened",[o])},1)},this.close=function(){o.removeClass("h5p-open"),setTimeout(function(){o.remove()},200)}},H5P.getCopyrights=function(e,t,n){var r;if(void 0!==e.getCopyrights)try{r=e.getCopyrights()}catch(i){}return void 0===r&&(r=new H5P.ContentCopyrights,H5P.findCopyrights(r,t,n)),void 0!==r&&(r=r.toString()),r},H5P.findCopyrights=function(e,t,n){for(var r in t)if(t.hasOwnProperty(r)){var i=t[r];if(i instanceof Array)H5P.findCopyrights(e,i,n);else if(i instanceof Object)if(void 0===i.copyright||void 0===i.copyright.license||void 0===i.path||void 0===i.mime)H5P.findCopyrights(e,i,n);else{var o=new H5P.MediaCopyright(i.copyright);void 0!==i.width&&void 0!==i.height&&o.setThumbnail(new H5P.Thumbnail(H5P.getPath(i.path,n),i.width,i.height)),e.addMedia(o)}}},H5P.openEmbedDialog=function(e,t,n,r){var i=t+n,o=new H5P.Dialog("embed",H5P.t("embed"),''+H5P.t("size")+': × px
'+H5P.t("showAdvanced")+'

'+H5P.t("advancedHelp")+'

",e);H5P.jQuery(o).on("dialog-opened",function(e,t){var n=t.find(".h5p-inner"),o=n.find(".h5p-scroll-content"),a=o.outerHeight()-o.innerHeight(),s=function(){var e=n.height();o[0].scrollHeight+a>e?n.css("height",""):(n.css("height","auto"),e=n.height()),n.css("marginTop","-"+e/2+"px")},u=t.find(".h5p-embed-size:eq(0)"),c=t.find(".h5p-embed-size:eq(1)"),l=function(e,t){var n=parseFloat(e.val());return isNaN(n)?t:Math.ceil(n)},d=function(){t.find(".h5p-embed-code-container:first").val(i.replace(":w",l(u,r.width)).replace(":h",l(c,r.height)))};u.change(d),c.change(d),d(),t.find(".h5p-embed-code-container").each(function(e,t){H5P.jQuery(this).css("height",this.scrollHeight+"px").focus(function(){H5P.jQuery(this).select()})}),t.find(".h5p-embed-code-container").eq(0).select(),s();var f=function(){var e=H5P.jQuery(this),n=e.next();n.is(":visible")?(e.removeClass("h5p-open").text(H5P.t("showAdvanced")),n.hide()):(e.addClass("h5p-open").text(H5P.t("hideAdvanced")),n.show()),t.find(".h5p-embed-code-container").each(function(e,t){H5P.jQuery(this).css("height",this.scrollHeight+"px")}),s()};t.find(".h5p-expander").click(f).keypress(function(e){32===e.keyCode&&f.apply(this)})}),o.open()},H5P.ContentCopyrights=function(){var e,t=[],n=[];this.setLabel=function(t){e=t},this.addMedia=function(e){void 0!==e&&t.push(e)},this.addContent=function(e){void 0!==e&&n.push(e)},this.toString=function(){for(var r="",i=0;i"+e+""+r),r='
'+r+"
"),r}},H5P.MediaCopyright=function(e,t,n,r){var i,o=new H5P.DefinitionList,a=function(e){return void 0===t||void 0===t[e]?H5P.t(e):t[e]},s=function(e,t){return"license"===e?H5P.copyrightLicenses[t]:t};if(void 0!==e){for(var u in r)r.hasOwnProperty(u)&&(e[u]=r[u]);void 0===n&&(n=["title","author","year","source","license"]);for(var c=0;c'+e+"
"),e)}},H5P.copyrightLicenses={U:"Undisclosed","CC BY":"Attribution","CC BY-SA":"Attribution-ShareAlike","CC BY-ND":"Attribution-NoDerivs","CC BY-NC":"Attribution-NonCommercial","CC BY-NC-SA":"Attribution-NonCommercial-ShareAlike","CC BY-NC-ND":"Attribution-NonCommercial-NoDerivs","GNU GPL":"General Public License",PD:"Public Domain","ODC PDDL":"Public Domain Dedication and Licence","CC PDM":"Public Domain Mark",C:"Copyright"},H5P.Thumbnail=function(e,t,n){var r,i=100;void 0!==t&&(r=Math.round(i*(t/n))),this.toString=function(){return''+H5P.t("}},H5P.Field=function(e,t){this.getLabel=function(){return e},this.getValue=function(){return t}},H5P.DefinitionList=function(){var e=[];this.add=function(t){e.push(t)},this.size=function(){return e.length},this.get=function(t){return e[t]},this.toString=function(){for(var t="",n=0;n"+r.getLabel()+"
"+r.getValue()+"
"}return""===t?t:'
'+t+"
"}},H5P.Coords=function(e,t,n,r){return this instanceof H5P.Coords?(this.x=0,this.y=0,this.w=1,this.h=1,"object"==typeof e?(this.x=e.x,this.y=e.y,this.w=e.w,this.h=e.h):(void 0!==e&&(this.x=e),void 0!==t&&(this.y=t),void 0!==n&&(this.w=n),void 0!==r&&(this.h=r)),this):new H5P.Coords(e,t,n,r)},H5P.libraryFromString=function(e){var t=/(.+)\s(\d)+\.(\d)$/g,n=t.exec(e);return null!==n?{machineName:n[1],majorVersion:n[2],minorVersion:n[3]}:!1},H5P.getLibraryPath=function(e){return H5PIntegration.url+"/libraries/"+e},H5P.cloneObject=function(e,t){var n=e instanceof Array?[]:{};for(var r in e)e.hasOwnProperty(r)&&(void 0!==t&&t&&"object"==typeof e[r]?n[r]=H5P.cloneObject(e[r],t):n[r]=e[r]);return n},H5P.trim=function(e){return e.replace(/^\s+|\s+$/g,"")},H5P.jsLoaded=function(e){return H5PIntegration.loadedJs=H5PIntegration.loadedJs||[],-1!==H5P.jQuery.inArray(e,H5PIntegration.loadedJs)},H5P.cssLoaded=function(e){return H5PIntegration.loadedCss=H5PIntegration.loadedCss||[],-1!==H5P.jQuery.inArray(e,H5PIntegration.loadedCss)},H5P.shuffleArray=function(e){if(e instanceof Array){var t,n,r,i=e.length;if(0===i)return!1;for(;--i;)t=Math.floor(Math.random()*(i+1)),n=e[i],r=e[t],e[i]=r,e[t]=n;return e}},H5P.setFinished=function(e,t,n,r){if(H5PIntegration.postUserStatistics===!0){var i=function(e){return Math.round(e.getTime()/1e3)};H5P.jQuery.post(H5PIntegration.ajaxPath+"setFinished",{contentId:e,score:t,maxScore:n,opened:i(H5P.opened[e]),finished:i(new Date),time:r})}},Array.prototype.indexOf||(Array.prototype.indexOf=function(e){for(var t=0;t").text(e.replace(/(<([^>]+)>)/gi,"")).text();return n.length>t&&(n=n.substr(0,t-3)+"..."),n},function(e){function t(t,n,r,i,o,a,s,u){if(void 0===H5PIntegration.user)return void i("Not signed in.");var c={url:H5PIntegration.ajax.contentUserData.replace(":contentId",t).replace(":dataType",n).replace(":subContentId",r?r:0),dataType:"json",async:void 0===u?!0:u};void 0!==o?(c.type="POST",c.data={data:null===o?0:o,preload:a?1:0,invalidate:s?1:0}):c.type="GET",void 0!==i&&(c.error=function(e,t){i(t)},c.success=function(e){return e.success?e.data===!1||void 0===e.data?void i():void i(void 0,e.data):void i(e.error)}),e.ajax(c)}H5P.getUserData=function(e,n,r,i){i||(i=0);var o=H5PIntegration.contents["cid-"+e],a=o.contentUserData;if(a&&a[i]&&a[i][n]){if("RESET"===a[i][n])return void r(void 0,null);try{r(void 0,JSON.parse(a[i][n]))}catch(s){r(s)}}else t(e,n,i,function(e,t){if(e||void 0===t)return void r(e,t);void 0===o.contentUserData&&(o.contentUserData=a={}),void 0===a[i]&&(a[i]={}),a[i][n]=t;try{r(void 0,JSON.parse(t))}catch(s){r(s)}})},H5P.setUserData=function(e,n,r,i){var o=H5P.jQuery.extend(!0,{},{subContentId:0,preloaded:!0,deleteOnChange:!1,async:!0},i);try{r=JSON.stringify(r)}catch(a){return void(o.errorCallback&&o.errorCallback(a))}var s=H5PIntegration.contents["cid-"+e];s.contentUserData||(s.contentUserData={});var u=s.contentUserData;void 0===u[o.subContentId]&&(u[o.subContentId]={}),r!==u[o.subContentId][n]&&(u[o.subContentId][n]=r,t(e,n,o.subContentId,function(e,t){o.errorCallback&&e&&o.errorCallback(e)},r,o.preloaded,o.deleteOnChange,o.async))},H5P.deleteUserData=function(e,n,r){r||(r=0);var i=H5PIntegration.contents["cid-"+e].contentUserData;i&&i[r]&&i[r][n]&&delete i[r][n],t(e,n,r,void 0,null)},e(document).ready(function(){H5P.preventInit||H5P.init(document.body),H5PIntegration.saveFreq!==!1&&H5P.$window.on("beforeunload",function(){for(var e=0;e0&&t-1 in e}function r(e,t,n){if(Z.isFunction(t))return Z.grep(e,function(e,r){return!!t.call(e,r,e)!==n});if(t.nodeType)return Z.grep(e,function(e){return e===t!==n});if("string"==typeof t){if(se.test(t))return Z.filter(t,e,n);t=Z.filter(t,e)}return Z.grep(e,function(e){return _.call(t,e)>=0!==n})}function i(e,t){for(;(e=e[t])&&1!==e.nodeType;);return e}function o(e){var t=he[e]={};return Z.each(e.match(pe)||[],function(e,n){t[n]=!0}),t}function a(){J.removeEventListener("DOMContentLoaded",a,!1),e.removeEventListener("load",a,!1),Z.ready()}function s(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=Z.expando+s.uid++}function c(e,t,n){var r;if(void 0===n&&1===e.nodeType)if(r="data-"+t.replace(xe,"-$1").toLowerCase(),n=e.getAttribute(r),"string"==typeof n){try{n="true"===n?!0:"false"===n?!1:"null"===n?null:+n+""===n?+n:be.test(n)?Z.parseJSON(n):n}catch(i){}ye.set(e,t,n)}else n=void 0;return n}function u(){return!0}function l(){return!1}function d(){try{return J.activeElement}catch(e){}}function f(e,t){return Z.nodeName(e,"table")&&Z.nodeName(11!==t.nodeType?t:t.firstChild,"tr")?e.getElementsByTagName("tbody")[0]||e.appendChild(e.ownerDocument.createElement("tbody")):e}function p(e){return e.type=(null!==e.getAttribute("type"))+"/"+e.type,e}function h(e){var t=qe.exec(e.type);return t?e.type=t[1]:e.removeAttribute("type"),e}function g(e,t){for(var n=0,r=e.length;r>n;n++)me.set(e[n],"globalEval",!t||me.get(t[n],"globalEval"))}function v(e,t){var n,r,i,o,a,s,c,u;if(1===t.nodeType){if(me.hasData(e)&&(o=me.access(e),a=me.set(t,o),u=o.events)){delete a.handle,a.events={};for(i in u)for(n=0,r=u[i].length;r>n;n++)Z.event.add(t,i,u[i][n])}ye.hasData(e)&&(s=ye.access(e),c=Z.extend({},s),ye.set(t,c))}}function m(e,t){var n=e.getElementsByTagName?e.getElementsByTagName(t||"*"):e.querySelectorAll?e.querySelectorAll(t||"*"):[];return void 0===t||t&&Z.nodeName(e,t)?Z.merge([e],n):n}function y(e,t){var n=t.nodeName.toLowerCase();"input"===n&&Ce.test(e.type)?t.checked=e.checked:("input"===n||"textarea"===n)&&(t.defaultValue=e.defaultValue)}function b(t,n){var r,i=Z(n.createElement(t)).appendTo(n.body),o=e.getDefaultComputedStyle&&(r=e.getDefaultComputedStyle(i[0]))?r.display:Z.css(i[0],"display");return i.detach(),o}function x(e){var t=J,n=Re[e];return n||(n=b(e,t),"none"!==n&&n||(Me=(Me||Z("\n '),e.frameJs=e.frameJs||"dist/h5p-standalone-frame.min.js",e.frameCss=e.frameCss||"dist/css/h5p.css",e.h5pContent=e.h5pContent||"workspace",H5PIntegration.core={styles:[e.frameCss],scripts:[e.frameJs]},H5PIntegration.init(e.id,e.h5pContent)}}(H5P.jQuery),H5P.ContentType=function(e,t){function n(){}return n.prototype=new H5P.EventDispatcher,n.prototype.isRoot=function(){return e},n.prototype.getLibraryFilePath=function(e){return H5P.getLibraryPath(this.libraryInfo.versionedNameNoSpaces)+"/"+e},n};var H5P=H5P||{};H5P.Event=function(e,t,n){this.type=e,this.data=t;var r=!1,i=!1,o=!1;void 0===n&&(n={}),n.bubbles===!0&&(r=!0),n.external===!0&&(i=!0),this.preventBubbling=function(){r=!1},this.getBubbles=function(){return r},this.scheduleForExternal=function(){return i&&!o?(o=!0,!0):!1}},H5P.EventDispatcher=function(){function e(){var e=this,t={};this.on=function(n,r,i){if("function"!=typeof r)throw TypeError("listener must be a function");e.trigger("newListener",{type:n,listener:r});var o={listener:r,thisArg:i};t[n]?t[n].push(o):t[n]=[o]},this.once=function(t,n,r){if(!(n instanceof Function))throw TypeError("listener must be a function");var i=function(t){e.off(t,i),n.apply(this,t)};e.on(t,i,r)},this.off=function(n,r){if(void 0!==r&&!(r instanceof Function))throw TypeError("listener must be a function");if(void 0!==t[n]){if(void 0===r)return delete t[n],void e.trigger("removeListener",n);for(var i=0;i0&&(this.data.statement.result.score.scaled=Math.round(e/t*1e4)/1e4),n&&n.activityStartTime){var r=Math.round((Date.now()-n.activityStartTime)/10)/100;this.data.statement.result.duration="PT"+r+"S"}},H5P.XAPIEvent.prototype.setVerb=function(e){-1!==H5P.jQuery.inArray(e,H5P.XAPIEvent.allowedXAPIVerbs)?this.data.statement.verb={id:"http://adlnet.gov/expapi/verbs/"+e,display:{"en-US":e}}:void 0!==e.id&&(this.data.statement.verb=e)},H5P.XAPIEvent.prototype.getVerb=function(e){var t=this.data.statement;return"verb"in t?e===!0?t.verb:t.verb.id.slice(31):null},H5P.XAPIEvent.prototype.setObject=function(e){e.contentId&&(this.data.statement.object={id:this.getContentXAPIId(e),objectType:"Activity",definition:{extensions:{"http://h5p.org/x-api/h5p-local-content-id":e.contentId}}},e.subContentId?(this.data.statement.object.definition.extensions["http://h5p.org/x-api/h5p-subContentId"]=e.subContentId,"function"==typeof e.getTitle&&(this.data.statement.object.definition.name={"en-US":e.getTitle()})):H5PIntegration&&H5PIntegration.contents&&H5PIntegration.contents["cid-"+e.contentId].title&&(this.data.statement.object.definition.name={"en-US":H5P.createTitle(H5PIntegration.contents["cid-"+e.contentId].title)}))},H5P.XAPIEvent.prototype.setContext=function(e){if(e.parent&&(e.parent.contentId||e.parent.subContentId)){void 0===e.parent.subContentId?e.parent.contentId:e.parent.subContentId;this.data.statement.context={contextActivities:{parent:[{id:this.getContentXAPIId(e.parent),objectType:"Activity"}]}}}e.libraryInfo&&(void 0===this.data.statement.context&&(this.data.statement.context={contextActivities:{}}),this.data.statement.context.contextActivities.category=[{id:"http://h5p.org/libraries/"+e.libraryInfo.versionedNameNoSpaces,objectType:"Activity"}])},H5P.XAPIEvent.prototype.setActor=function(){if(void 0!==H5PIntegration.user)this.data.statement.actor={name:H5PIntegration.user.name,mbox:"mailto:"+H5PIntegration.user.mail,objectType:"Agent"};else{var e;localStorage.H5PUserUUID?e=localStorage.H5PUserUUID:(e=H5P.createUUID(),localStorage.H5PUserUUID=e),this.data.statement.actor={account:{name:e,homePage:H5PIntegration.siteUrl},objectType:"Agent"}}},H5P.XAPIEvent.prototype.getMaxScore=function(){return this.getVerifiedStatementValue(["result","score","max"])},H5P.XAPIEvent.prototype.getScore=function(){return this.getVerifiedStatementValue(["result","score","raw"])},H5P.XAPIEvent.prototype.getContentXAPIId=function(e){var t;return e.contentId&&H5PIntegration&&H5PIntegration.contents&&(t=H5PIntegration.contents["cid-"+e.contentId].url,e.subContentId&&(t+="?subContentId="+e.subContentId)),t},H5P.XAPIEvent.prototype.getVerifiedStatementValue=function(e){for(var t=this.data.statement,n=0;n6)&&(H5P.fullScreenBrowserPrefix="webkit")):document.documentElement.mozRequestFullScreen?H5P.fullScreenBrowserPrefix="moz":document.documentElement.msRequestFullscreen&&(H5P.fullScreenBrowserPrefix="ms"),H5P.DISABLE_NONE=0,H5P.DISABLE_FRAME=1,H5P.DISABLE_DOWNLOAD=2,H5P.DISABLE_EMBED=4,H5P.DISABLE_COPYRIGHT=8,H5P.DISABLE_ABOUT=16,H5P.opened={},H5P.init=function(e){void 0===H5P.$body&&(H5P.$body=H5P.jQuery(document.body)),void 0===H5P.canHasFullScreen&&(H5P.canHasFullScreen=H5P.isFramed&&H5P.externalEmbed!==!1?document.fullscreenEnabled||document.webkitFullscreenEnabled||document.mozFullScreenEnabled?!0:!1:!0);H5P.jQuery(".h5p-content:not(.h5p-initialized)",e).each(function(){var e=H5P.jQuery(this).addClass("h5p-initialized"),t=H5P.jQuery('
').appendTo(e),n=e.data("content-id"),r=H5PIntegration.contents["cid-"+n];if(void 0===r)return H5P.error("No data for content id "+n+". Perhaps the library is gone?");var i={library:r.library,params:JSON.parse(r.jsonContent)};H5P.getUserData(n,"state",function(e,n){if(n)i.userDatas={state:n};else if(null===n&&H5PIntegration.saveFreq){delete r.contentUserData;var o=new H5P.Dialog("content-user-data-reset","Data Reset","

"+H5P.t("contentChanged")+"

"+H5P.t("startingOver")+'

OK
',t);H5P.jQuery(o).on("dialog-opened",function(e,t){t.find(".h5p-dialog-ok-button").click(function(){o.close()}).keypress(function(e){32===e.which&&o.close()})}),o.open()}});var o=H5P.newRunnable(i,n,t,!0,{standalone:!0});1==r.fullScreen&&H5P.canHasFullScreen&&H5P.jQuery('
').prependTo(t).children().click(function(){H5P.fullScreen(t,o)});var a=H5P.jQuery('
    ');if(r.disable&H5P.DISABLE_DOWNLOAD||H5P.jQuery('
  • '+H5P.t("download")+"
  • ").appendTo(a).click(function(){window.location.href=r.exportUrl}),!(r.disable&H5P.DISABLE_COPYRIGHT)){var s=H5P.getCopyrights(o,i.params,n);s&&H5P.jQuery('
  • '+H5P.t("copyrights")+"
  • ").appendTo(a).click(function(){var e=new H5P.Dialog("copyrights",H5P.t("copyrightInformation"),s,t);e.open()})}if(r.disable&H5P.DISABLE_EMBED||H5P.jQuery('
  • '+H5P.t("embed")+"
  • ").appendTo(a).click(function(){H5P.openEmbedDialog(a,r.embedCode,r.resizeCode,{width:e.width(),height:e.height()})}),r.disable&H5P.DISABLE_ABOUT||H5P.jQuery('
  • ').appendTo(a),r.disable&H5P.DISABLE_FRAME||!a.children().length?e.addClass("h5p-no-frame"):(a.insertAfter(t),e.addClass("h5p-frame")),H5P.opened[n]=new Date,H5P.on(o,"finish",function(e){void 0!==e.data&&H5P.setFinished(n,e.data.score,e.data.maxScore,e.data.time)}),H5P.on(o,"xAPI",H5P.xAPICompletedListener),H5PIntegration.saveFreq!==!1&&(o.getCurrentState instanceof Function||"function"==typeof o.getCurrentState)){var c,u=function(){var e=o.getCurrentState();void 0!==e&&H5P.setUserData(n,"state",e,{deleteOnChange:!0}),H5PIntegration.saveFreq&&(c=setTimeout(u,1e3*H5PIntegration.saveFreq))};H5PIntegration.saveFreq&&(c=setTimeout(u,1e3*H5PIntegration.saveFreq)),H5P.on(o,"xAPI",function(e){var t=e.getVerb();("completed"===t||"progressed"===t)&&(clearTimeout(c),c=setTimeout(u,3e3))})}if(H5P.isFramed){var l;if(H5P.externalEmbed===!1){var d=window.parent.document.getElementById("h5p-iframe-"+n),f=function(){if(!window.parent.H5P.isFullscreen){var e=d.parentElement.style.height;d.parentElement.style.height=d.parentElement.clientHeight+"px",d.style.height="1px",d.style.height=d.contentDocument.body.scrollHeight+"px",d.parentElement.style.height=e}};H5P.on(o,"resize",function(){clearTimeout(l),l=setTimeout(function(){f()},1)})}else if(H5P.communicator){var p=!1;H5P.communicator.on("ready",function(){H5P.communicator.send("hello")}),H5P.communicator.on("hello",function(){p=!0,document.body.style.overflow="hidden",H5P.trigger(o,"resize")}),H5P.communicator.on("resizePrepared",function(e){H5P.communicator.send("resize",{height:document.body.scrollHeight})}),H5P.communicator.on("resize",function(){H5P.trigger(o,"resize")}),H5P.on(o,"resize",function(){H5P.isFullscreen||(clearTimeout(l),l=setTimeout(function(){p?H5P.communicator.send("prepareResize"):H5P.communicator.send("hello")},0))})}}H5P.isFramed&&H5P.externalEmbed!==!1||H5P.jQuery(window.parent).resize(function(){window.parent.H5P.isFullscreen?H5P.trigger(o,"resize"):H5P.trigger(o,"resize")}),H5P.instances.push(o),H5P.trigger(o,"resize")});H5P.jQuery("iframe.h5p-iframe:not(.h5p-initialized)",e).each(function(){var e=H5P.jQuery(this).addClass("h5p-initialized").data("content-id");this.contentDocument.open(),this.contentDocument.write(''+H5P.getHeadTags(e)+'
    '),this.contentDocument.close()})},H5P.getHeadTags=function(e){var t=function(e){for(var t="",n=0;n';return t},n=function(e){for(var t="",n=0;n';return t};return t(H5PIntegration.core.styles)+t(H5PIntegration.contents["cid-"+e].styles)+n(H5PIntegration.core.scripts)+n(H5PIntegration.contents["cid-"+e].scripts)+""},H5P.communicator=function(){function e(){var e=this,t={};window.addEventListener("message",function(e){window.parent===e.source&&"h5p"===e.data.context&&void 0!==t[e.data.action]&&t[e.data.action](e.data)},!1),e.on=function(e,n){t[e]=n},e.send=function(e,t){void 0===t&&(t={}),t.context="h5p",t.action=e,window.parent.postMessage(t,"*")}}return window.postMessage&&window.addEventListener?new e:void 0}(),H5P.fullScreen=function(e,t,n,r){if(void 0===H5P.exitFullScreen){if(H5P.isFramed&&H5P.externalEmbed===!1)return window.parent.H5P.fullScreen(e,t,n,H5P.$body.get()),H5P.isFullscreen=!0,H5P.exitFullScreen=function(){window.parent.H5P.exitFullScreen()},void H5P.on(t,"exitFullScreen",function(){H5P.isFullscreen=!1,H5P.exitFullScreen=void 0});var i,o,a=e;if(void 0===r)$body=H5P.$body;else{$body=H5P.jQuery(r),i=$body.add(e.get());var s="#h5p-iframe-"+e.parent().data("content-id");o=H5P.jQuery(s),e=o.parent()}i=e.add(H5P.$body).add(i);var c=function(e){i.addClass(e),void 0!==o&&o.css("height","")},u=function(){H5P.trigger(t,"resize"),H5P.trigger(t,"focus"),H5P.trigger(t,"enterFullScreen")},l=function(e){H5P.isFullscreen=!1,i.removeClass(e),H5P.trigger(t,"resize"),H5P.trigger(t,"focus"),H5P.exitFullScreen=void 0,void 0!==n&&n(),H5P.trigger(t,"exitFullScreen")};if(H5P.isFullscreen=!0,void 0===H5P.fullScreenBrowserPrefix){if(H5P.isFramed)return;c("h5p-semi-fullscreen");var d,f=H5P.jQuery('
    ').appendTo(a.find(".h5p-content-controls")),p=H5P.exitFullScreen=function(){h?g[m].content=h:v.removeChild(metaTag),f.remove(),$body.unbind("keyup",d),l("h5p-semi-fullscreen")};d=function(e){27===e.keyCode&&p()},f.click(p),$body.keyup(d);for(var h,g=document.getElementsByTagName("meta"),m=0;m-1?new u(e.params,t):new u(e.params,t,i),void 0===f.$&&(f.$=H5P.jQuery(f)),void 0===f.contentId&&(f.contentId=t),void 0===f.subContentId&&e.subContentId&&(f.subContentId=e.subContentId),void 0===f.parent&&i&&i.parent&&(f.parent=i.parent),void 0===f.libraryInfo&&(f.libraryInfo={versionedName:e.library,versionedNameNoSpaces:s+"-"+a[0]+"."+a[1],machineName:s,majorVersion:a[0],minorVersion:a[1]}),void 0!==n&&(n.toggleClass("h5p-standalone",d),f.attach(n),H5P.trigger(f,"domChanged",{$target:n,library:s,key:"newLibrary"},{bubbles:!0,external:!0}),void 0!==r&&r||H5P.trigger(f,"resize")),f},H5P.error=function(e){void 0!==window.console&&void 0!==console.error&&console.error(e.stack?e.stack:e)},H5P.t=function(e,t,n){if(void 0===n&&(n="H5P"),void 0===H5PIntegration.l10n[n])return'[Missing translation namespace "'+n+'"]';if(void 0===H5PIntegration.l10n[n][e])return'[Missing translation "'+e+'" in "'+n+'"]';var r=H5PIntegration.l10n[n][e];if(void 0!==t)for(var i in t)r=r.replace(i,t[i]);return r},H5P.Dialog=function(e,t,n,r){var i=this,o=H5P.jQuery('

    '+t+'

    '+n+'
    ').insertAfter(r).click(function(){i.close()}).children(".h5p-inner").click(function(){return!1}).find(".h5p-close").click(function(){i.close()}).end().end();this.open=function(){setTimeout(function(){o.addClass("h5p-open"),H5P.jQuery(i).trigger("dialog-opened",[o])},1)},this.close=function(){o.removeClass("h5p-open"),setTimeout(function(){o.remove()},200)}},H5P.getCopyrights=function(e,t,n){var r;if(void 0!==e.getCopyrights)try{r=e.getCopyrights()}catch(i){}return void 0===r&&(r=new H5P.ContentCopyrights,H5P.findCopyrights(r,t,n)),void 0!==r&&(r=r.toString()),r},H5P.findCopyrights=function(e,t,n){for(var r in t)if(t.hasOwnProperty(r)){var i=t[r];if(i instanceof Array)H5P.findCopyrights(e,i,n);else if(i instanceof Object)if(void 0===i.copyright||void 0===i.copyright.license||void 0===i.path||void 0===i.mime)H5P.findCopyrights(e,i,n);else{var o=new H5P.MediaCopyright(i.copyright);void 0!==i.width&&void 0!==i.height&&o.setThumbnail(new H5P.Thumbnail(H5P.getPath(i.path,n),i.width,i.height)),e.addMedia(o)}}},H5P.openEmbedDialog=function(e,t,n,r){var i=t+n,o=new H5P.Dialog("embed",H5P.t("embed"),''+H5P.t("size")+': × px
    '+H5P.t("showAdvanced")+'

    '+H5P.t("advancedHelp")+'

    ",e);H5P.jQuery(o).on("dialog-opened",function(e,t){var n=t.find(".h5p-inner"),o=n.find(".h5p-scroll-content"),a=o.outerHeight()-o.innerHeight(),s=function(){var e=n.height();o[0].scrollHeight+a>e?n.css("height",""):(n.css("height","auto"),e=n.height()),n.css("marginTop","-"+e/2+"px")},c=t.find(".h5p-embed-size:eq(0)"),u=t.find(".h5p-embed-size:eq(1)"),l=function(e,t){var n=parseFloat(e.val());return isNaN(n)?t:Math.ceil(n)},d=function(){t.find(".h5p-embed-code-container:first").val(i.replace(":w",l(c,r.width)).replace(":h",l(u,r.height)))};c.change(d),u.change(d),d(),t.find(".h5p-embed-code-container").each(function(e,t){H5P.jQuery(this).css("height",this.scrollHeight+"px").focus(function(){H5P.jQuery(this).select()})}),t.find(".h5p-embed-code-container").eq(0).select(),s();var f=function(){var e=H5P.jQuery(this),n=e.next();n.is(":visible")?(e.removeClass("h5p-open").text(H5P.t("showAdvanced")),n.hide()):(e.addClass("h5p-open").text(H5P.t("hideAdvanced")),n.show()),t.find(".h5p-embed-code-container").each(function(e,t){H5P.jQuery(this).css("height",this.scrollHeight+"px")}),s()};t.find(".h5p-expander").click(f).keypress(function(e){32===e.keyCode&&f.apply(this)})}),o.open()},H5P.ContentCopyrights=function(){var e,t=[],n=[];this.setLabel=function(t){e=t},this.addMedia=function(e){void 0!==e&&t.push(e)},this.addContent=function(e){void 0!==e&&n.push(e)},this.toString=function(){for(var r="",i=0;i"+e+""+r),r='
    '+r+"
    "),r}},H5P.MediaCopyright=function(e,t,n,r){var i,o=new H5P.DefinitionList,a=function(e){return void 0===t||void 0===t[e]?H5P.t(e):t[e]},s=function(e,t){return"license"===e?H5P.copyrightLicenses[t]:t};if(void 0!==e){for(var c in r)r.hasOwnProperty(c)&&(e[c]=r[c]);void 0===n&&(n=["title","author","year","source","license"]);for(var u=0;u'+e+"
    "),e)}},H5P.copyrightLicenses={U:"Undisclosed","CC BY":"Attribution","CC BY-SA":"Attribution-ShareAlike","CC BY-ND":"Attribution-NoDerivs","CC BY-NC":"Attribution-NonCommercial","CC BY-NC-SA":"Attribution-NonCommercial-ShareAlike","CC BY-NC-ND":"Attribution-NonCommercial-NoDerivs","GNU GPL":"General Public License",PD:"Public Domain","ODC PDDL":"Public Domain Dedication and Licence","CC PDM":"Public Domain Mark",C:"Copyright"},H5P.Thumbnail=function(e,t,n){var r,i=100;void 0!==t&&(r=Math.round(i*(t/n))),this.toString=function(){return''+H5P.t("}},H5P.Field=function(e,t){this.getLabel=function(){return e},this.getValue=function(){return t}},H5P.DefinitionList=function(){var e=[];this.add=function(t){e.push(t)},this.size=function(){return e.length},this.get=function(t){return e[t]},this.toString=function(){for(var t="",n=0;n"+r.getLabel()+"
    "+r.getValue()+"
    "}return""===t?t:'
    '+t+"
    "}},H5P.Coords=function(e,t,n,r){return this instanceof H5P.Coords?(this.x=0,this.y=0,this.w=1,this.h=1,"object"==typeof e?(this.x=e.x,this.y=e.y,this.w=e.w,this.h=e.h):(void 0!==e&&(this.x=e),void 0!==t&&(this.y=t),void 0!==n&&(this.w=n),void 0!==r&&(this.h=r)),this):new H5P.Coords(e,t,n,r)},H5P.libraryFromString=function(e){var t=/(.+)\s(\d)+\.(\d)$/g,n=t.exec(e);return null!==n?{machineName:n[1],majorVersion:n[2],minorVersion:n[3]}:!1},H5P.getLibraryPath=function(e){return H5PIntegration.url+"/libraries/"+e},H5P.cloneObject=function(e,t){var n=e instanceof Array?[]:{};for(var r in e)e.hasOwnProperty(r)&&(void 0!==t&&t&&"object"==typeof e[r]?n[r]=H5P.cloneObject(e[r],t):n[r]=e[r]);return n},H5P.trim=function(e){return e.replace(/^\s+|\s+$/g,"")},H5P.jsLoaded=function(e){return H5PIntegration.loadedJs=H5PIntegration.loadedJs||[],-1!==H5P.jQuery.inArray(e,H5PIntegration.loadedJs)},H5P.cssLoaded=function(e){return H5PIntegration.loadedCss=H5PIntegration.loadedCss||[],-1!==H5P.jQuery.inArray(e,H5PIntegration.loadedCss)},H5P.shuffleArray=function(e){if(e instanceof Array){var t,n,r,i=e.length;if(0===i)return!1;for(;--i;)t=Math.floor(Math.random()*(i+1)),n=e[i],r=e[t],e[i]=r,e[t]=n;return e}},H5P.setFinished=function(e,t,n,r){if(H5PIntegration.postUserStatistics===!0){var i=function(e){return Math.round(e.getTime()/1e3)};H5P.jQuery.post(H5PIntegration.ajaxPath+"setFinished",{contentId:e,score:t,maxScore:n,opened:i(H5P.opened[e]),finished:i(new Date),time:r})}},Array.prototype.indexOf||(Array.prototype.indexOf=function(e){for(var t=0;t
    ").text(e.replace(/(<([^>]+)>)/gi,"")).text();return n.length>t&&(n=n.substr(0,t-3)+"..."),n},function(e){function t(t,n,r,i,o,a,s,c){if(void 0===H5PIntegration.user)return void i("Not signed in.");var u={url:H5PIntegration.ajax.contentUserData.replace(":contentId",t).replace(":dataType",n).replace(":subContentId",r?r:0),dataType:"json",async:void 0===c?!0:c};void 0!==o?(u.type="POST",u.data={data:null===o?0:o,preload:a?1:0,invalidate:s?1:0}):u.type="GET",void 0!==i&&(u.error=function(e,t){i(t)},u.success=function(e){return e.success?e.data===!1||void 0===e.data?void i():void i(void 0,e.data):void i(e.error)}),e.ajax(u)}H5P.getUserData=function(e,n,r,i){i||(i=0);var o=H5PIntegration.contents["cid-"+e],a=o.contentUserData;if(a&&a[i]&&a[i][n]){if("RESET"===a[i][n])return void r(void 0,null);try{r(void 0,JSON.parse(a[i][n]))}catch(s){r(s)}}else t(e,n,i,function(e,t){if(e||void 0===t)return void r(e,t);void 0===o.contentUserData&&(o.contentUserData=a={}),void 0===a[i]&&(a[i]={}),a[i][n]=t;try{r(void 0,JSON.parse(t))}catch(s){r(s)}})},H5P.setUserData=function(e,n,r,i){var o=H5P.jQuery.extend(!0,{},{subContentId:0,preloaded:!0,deleteOnChange:!1,async:!0},i);try{r=JSON.stringify(r)}catch(a){return void(o.errorCallback&&o.errorCallback(a))}var s=H5PIntegration.contents["cid-"+e];s.contentUserData||(s.contentUserData={});var c=s.contentUserData;void 0===c[o.subContentId]&&(c[o.subContentId]={}),r!==c[o.subContentId][n]&&(c[o.subContentId][n]=r,t(e,n,o.subContentId,function(e,t){o.errorCallback&&e&&o.errorCallback(e)},r,o.preloaded,o.deleteOnChange,o.async))},H5P.deleteUserData=function(e,n,r){r||(r=0);var i=H5PIntegration.contents["cid-"+e].contentUserData;i&&i[r]&&i[r][n]&&delete i[r][n],t(e,n,r,void 0,null)},e(document).ready(function(){H5P.preventInit||H5P.init(document.body),H5PIntegration.saveFreq!==!1&&H5P.$window.on("beforeunload",function(){for(var e=0;e0)for(var n=t,r=Array.isArray(n),i=0,n=r?n:n[Symbol.iterator]();;){var o;if(r){if(i>=n.length)break;o=n[i++]}else{if(i=n.next(),i.done)break;o=i.value}var a=o;if("string"!=typeof a||!a)throw new TypeError("Dependency name must be given as a not empty string");this.edges.push([e,a])}else this.edges.push([e]);return this},e.prototype.sort=function(){for(var e=this,t=[],n=this.edges,r=Array.isArray(n),i=0,n=r?n:n[Symbol.iterator]();;){var o;if(r){if(i>=n.length)break;o=n[i++]}else{if(i=n.next(),i.done)break;o=i.value}for(var a=o,s=a,c=Array.isArray(s),u=0,s=c?s:s[Symbol.iterator]();;){var l;if(c){if(u>=s.length)break;l=s[u++]}else{if(u=s.next(),u.done)break;l=u.value}var d=l;-1===t.indexOf(d)&&t.push(d)}}for(var f=t.length,p=new Array(t.length),h=function x(n,r){if(0!==r.length&&-1!==r.indexOf(n))throw new Error("Cyclic dependency found. "+n+" is dependent of itself.\nDependency chain: "+r.join(" -> ")+" => "+n);var i=t.indexOf(n);if(-1!==i){var o=!1;t[i]=!1;for(var a=e.edges,s=Array.isArray(a),c=0,a=s?a:a[Symbol.iterator]();;){var u;if(s){if(c>=a.length)break;u=a[c++]}else{if(c=a.next(),c.done)break;u=c.value}var l=u;l[0]===n&&(o=o||r.concat([n]),x(l[1],o))}p[--f]=n}},g=0;g=m.length)break;b=m[y++]}else{if(y=m.next(),y.done)break;b=y.value}var a=b;a[0]===d&&h(a[1],[d])}p[--f]=d}}return p},e.prototype.clear=function(){return this.edges=[],this},e}();t.exports=r}),function(e,t){"object"==typeof module&&"object"==typeof module.exports?module.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("jQuery requires a window with a document");return t(e)}:t(e)}("undefined"!=typeof window?window:this,function(e,t){function n(e){var t="length"in e&&e.length,n=Z.type(e);return"function"===n||Z.isWindow(e)?!1:1===e.nodeType&&t?!0:"array"===n||0===t||"number"==typeof t&&t>0&&t-1 in e}function r(e,t,n){if(Z.isFunction(t))return Z.grep(e,function(e,r){return!!t.call(e,r,e)!==n});if(t.nodeType)return Z.grep(e,function(e){return e===t!==n});if("string"==typeof t){if(se.test(t))return Z.filter(t,e,n);t=Z.filter(t,e)}return Z.grep(e,function(e){return _.call(t,e)>=0!==n})}function i(e,t){for(;(e=e[t])&&1!==e.nodeType;);return e}function o(e){var t=he[e]={};return Z.each(e.match(pe)||[],function(e,n){t[n]=!0}),t}function a(){G.removeEventListener("DOMContentLoaded",a,!1),e.removeEventListener("load",a,!1),Z.ready()}function s(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=Z.expando+s.uid++}function c(e,t,n){var r;if(void 0===n&&1===e.nodeType)if(r="data-"+t.replace(xe,"-$1").toLowerCase(),n=e.getAttribute(r),"string"==typeof n){try{n="true"===n?!0:"false"===n?!1:"null"===n?null:+n+""===n?+n:be.test(n)?Z.parseJSON(n):n}catch(i){}ye.set(e,t,n)}else n=void 0;return n}function u(){return!0}function l(){return!1}function d(){try{return G.activeElement}catch(e){}}function f(e,t){return Z.nodeName(e,"table")&&Z.nodeName(11!==t.nodeType?t:t.firstChild,"tr")?e.getElementsByTagName("tbody")[0]||e.appendChild(e.ownerDocument.createElement("tbody")):e}function p(e){return e.type=(null!==e.getAttribute("type"))+"/"+e.type,e}function h(e){var t=Oe.exec(e.type);return t?e.type=t[1]:e.removeAttribute("type"),e}function g(e,t){for(var n=0,r=e.length;r>n;n++)ve.set(e[n],"globalEval",!t||ve.get(t[n],"globalEval"))}function m(e,t){var n,r,i,o,a,s,c,u;if(1===t.nodeType){if(ve.hasData(e)&&(o=ve.access(e),a=ve.set(t,o),u=o.events)){delete a.handle,a.events={};for(i in u)for(n=0,r=u[i].length;r>n;n++)Z.event.add(t,i,u[i][n])}ye.hasData(e)&&(s=ye.access(e),c=Z.extend({},s),ye.set(t,c))}}function v(e,t){var n=e.getElementsByTagName?e.getElementsByTagName(t||"*"):e.querySelectorAll?e.querySelectorAll(t||"*"):[];return void 0===t||t&&Z.nodeName(e,t)?Z.merge([e],n):n}function y(e,t){var n=t.nodeName.toLowerCase();"input"===n&&Ce.test(e.type)?t.checked=e.checked:("input"===n||"textarea"===n)&&(t.defaultValue=e.defaultValue)}function b(t,n){var r,i=Z(n.createElement(t)).appendTo(n.body),o=e.getDefaultComputedStyle&&(r=e.getDefaultComputedStyle(i[0]))?r.display:Z.css(i[0],"display");return i.detach(),o}function x(e){var t=G,n=Re[e];return n||(n=b(e,t),"none"!==n&&n||(Me=(Me||Z("\n '),e.frameJs=e.frameJs||"dist/h5p-standalone-frame.min.js",e.frameCss=e.frameCss||"dist/css/h5p.css",e.h5pContent=e.h5pContent||"workspace",H5PIntegration.core={styles:[e.frameCss],scripts:[e.frameJs]},H5PIntegration.init(e.id,e.h5pContent)}}(H5P.jQuery),H5P.ContentType=function(e,t){function n(){}return n.prototype=new H5P.EventDispatcher,n.prototype.isRoot=function(){return e},n.prototype.getLibraryFilePath=function(e){return H5P.getLibraryPath(this.libraryInfo.versionedNameNoSpaces)+"/"+e},n};var H5P=H5P||{};H5P.Event=function(e,t,n){this.type=e,this.data=t;var r=!1,i=!1,o=!1;void 0===n&&(n={}),n.bubbles===!0&&(r=!0),n.external===!0&&(i=!0),this.preventBubbling=function(){r=!1},this.getBubbles=function(){return r},this.scheduleForExternal=function(){return i&&!o?(o=!0,!0):!1}},H5P.EventDispatcher=function(){function e(){var e=this,t={};this.on=function(n,r,i){if("function"!=typeof r)throw TypeError("listener must be a function");e.trigger("newListener",{type:n,listener:r});var o={listener:r,thisArg:i};t[n]?t[n].push(o):t[n]=[o]},this.once=function(t,n,r){if(!(n instanceof Function))throw TypeError("listener must be a function");var i=function(t){e.off(t.type,i),n.call(this,t)};e.on(t,i,r)},this.off=function(n,r){if(void 0!==r&&!(r instanceof Function))throw TypeError("listener must be a function");if(void 0!==t[n]){if(void 0===r)return delete t[n],void e.trigger("removeListener",n);for(var i=0;i0&&(this.data.statement.result.score.scaled=Math.round(e/t*1e4)/1e4))),"undefined"==typeof r?this.data.statement.result.completion="completed"===this.getVerb()||"answered"===this.getVerb():this.data.statement.result.completion=r,"undefined"!=typeof i&&(this.data.statement.result.success=i),n&&n.activityStartTime){var o=Math.round((Date.now()-n.activityStartTime)/10)/100;this.data.statement.result.duration="PT"+o+"S"}},H5P.XAPIEvent.prototype.setVerb=function(e){-1!==H5P.jQuery.inArray(e,H5P.XAPIEvent.allowedXAPIVerbs)?this.data.statement.verb={id:"http://adlnet.gov/expapi/verbs/"+e,display:{"en-US":e}}:void 0!==e.id&&(this.data.statement.verb=e)},H5P.XAPIEvent.prototype.getVerb=function(e){var t=this.data.statement;return"verb"in t?e===!0?t.verb:t.verb.id.slice(31):null},H5P.XAPIEvent.prototype.setObject=function(e){e.contentId&&(this.data.statement.object={id:this.getContentXAPIId(e),objectType:"Activity",definition:{extensions:{"http://h5p.org/x-api/h5p-local-content-id":e.contentId}}},e.subContentId?(this.data.statement.object.definition.extensions["http://h5p.org/x-api/h5p-subContentId"]=e.subContentId,"function"==typeof e.getTitle&&(this.data.statement.object.definition.name={"en-US":e.getTitle()})):H5PIntegration&&H5PIntegration.contents&&H5PIntegration.contents["cid-"+e.contentId].title&&(this.data.statement.object.definition.name={"en-US":H5P.createTitle(H5PIntegration.contents["cid-"+e.contentId].title)}))},H5P.XAPIEvent.prototype.setContext=function(e){if(e.parent&&(e.parent.contentId||e.parent.subContentId)){void 0===e.parent.subContentId?e.parent.contentId:e.parent.subContentId;this.data.statement.context={contextActivities:{parent:[{id:this.getContentXAPIId(e.parent),objectType:"Activity"}]}}}e.libraryInfo&&(void 0===this.data.statement.context&&(this.data.statement.context={contextActivities:{}}),this.data.statement.context.contextActivities.category=[{id:"http://h5p.org/libraries/"+e.libraryInfo.versionedNameNoSpaces,objectType:"Activity"}])},H5P.XAPIEvent.prototype.setActor=function(){if(void 0!==H5PIntegration.user)this.data.statement.actor={name:H5PIntegration.user.name,mbox:"mailto:"+H5PIntegration.user.mail,objectType:"Agent"};else{var e;try{localStorage.H5PUserUUID?e=localStorage.H5PUserUUID:(e=H5P.createUUID(),localStorage.H5PUserUUID=e)}catch(t){e="not-trackable-"+H5P.createUUID()}this.data.statement.actor={account:{name:e,homePage:H5PIntegration.siteUrl},objectType:"Agent"}}},H5P.XAPIEvent.prototype.getMaxScore=function(){return this.getVerifiedStatementValue(["result","score","max"])},H5P.XAPIEvent.prototype.getScore=function(){return this.getVerifiedStatementValue(["result","score","raw"])},H5P.XAPIEvent.prototype.getContentXAPIId=function(e){ +var t;return e.contentId&&H5PIntegration&&H5PIntegration.contents&&(t=H5PIntegration.contents["cid-"+e.contentId].url,e.subContentId&&(t+="?subContentId="+e.subContentId)),t},H5P.XAPIEvent.prototype.getVerifiedStatementValue=function(e){for(var t=this.data.statement,n=0;n6)&&(H5P.fullScreenBrowserPrefix="webkit")):document.documentElement.mozRequestFullScreen?H5P.fullScreenBrowserPrefix="moz":document.documentElement.msRequestFullscreen&&(H5P.fullScreenBrowserPrefix="ms"),H5P.DISABLE_NONE=0,H5P.DISABLE_FRAME=1,H5P.DISABLE_DOWNLOAD=2,H5P.DISABLE_EMBED=4,H5P.DISABLE_COPYRIGHT=8,H5P.DISABLE_ABOUT=16,H5P.opened={},H5P.init=function(e){void 0===H5P.$body&&(H5P.$body=H5P.jQuery(document.body)),void 0===H5P.canHasFullScreen&&(H5P.canHasFullScreen=H5P.isFramed&&H5P.externalEmbed!==!1?document.fullscreenEnabled||document.webkitFullscreenEnabled||document.mozFullScreenEnabled?!0:!1:!0);H5P.jQuery(".h5p-content:not(.h5p-initialized)",e).each(function(){var e=H5P.jQuery(this).addClass("h5p-initialized"),t=H5P.jQuery('
    ').appendTo(e),n=e.data("content-id"),r=H5PIntegration.contents["cid-"+n];if(void 0===r)return H5P.error("No data for content id "+n+". Perhaps the library is gone?");var i={library:r.library,params:JSON.parse(r.jsonContent)};H5P.getUserData(n,"state",function(e,o){if(o)i.userDatas={state:o};else if(null===o&&H5PIntegration.saveFreq){delete r.contentUserData;var a=new H5P.Dialog("content-user-data-reset","Data Reset","

    "+H5P.t("contentChanged")+"

    "+H5P.t("startingOver")+'

    OK
    ',t);H5P.jQuery(a).on("dialog-opened",function(e,t){var r=function(e){("click"===e.type||32===e.which)&&(a.close(),H5P.deleteUserData(n,"state",0))};t.find(".h5p-dialog-ok-button").click(r).keypress(r)}),a.open()}});var o=H5P.newRunnable(i,n,t,!0,{standalone:!0});1==r.fullScreen&&H5P.canHasFullScreen&&H5P.jQuery('
    ').prependTo(t).children().click(function(){H5P.fullScreen(t,o)});var a=H5P.jQuery('
      '),s=function(e,t,n){H5P.jQuery("
    • ",{"class":"h5p-button h5p-"+(n?n:e),role:"button",tabindex:0,title:H5P.t(e+"Description"),html:H5P.t(e),on:{click:t,keypress:function(e){32===e.which&&(t(),e.preventDefault())}},appendTo:a})};if(r.disable&H5P.DISABLE_DOWNLOAD||s("download",function(){window.location.href=r.exportUrl},"export"),!(r.disable&H5P.DISABLE_COPYRIGHT)){var c=H5P.getCopyrights(o,i.params,n);c&&s("copyrights",function(){var e=new H5P.Dialog("copyrights",H5P.t("copyrightInformation"),c,t);e.open()})}if(r.disable&H5P.DISABLE_EMBED||s("embed",function(){H5P.openEmbedDialog(a,r.embedCode,r.resizeCode,{width:e.width(),height:e.height()})}),r.disable&H5P.DISABLE_ABOUT||H5P.jQuery('
    • ').appendTo(a),r.disable&H5P.DISABLE_FRAME||!a.children().length?e.addClass("h5p-no-frame"):(a.insertAfter(t),e.addClass("h5p-frame")),H5P.opened[n]=new Date,H5P.on(o,"finish",function(e){void 0!==e.data&&H5P.setFinished(n,e.data.score,e.data.maxScore,e.data.time)}),H5P.on(o,"xAPI",H5P.xAPICompletedListener),H5PIntegration.saveFreq!==!1&&(o.getCurrentState instanceof Function||"function"==typeof o.getCurrentState)){var u,l=function(){var e=o.getCurrentState();void 0!==e&&H5P.setUserData(n,"state",e,{deleteOnChange:!0}),H5PIntegration.saveFreq&&(u=setTimeout(l,1e3*H5PIntegration.saveFreq))};H5PIntegration.saveFreq&&(u=setTimeout(l,1e3*H5PIntegration.saveFreq)),H5P.on(o,"xAPI",function(e){var t=e.getVerb();("completed"===t||"progressed"===t)&&(clearTimeout(u),u=setTimeout(l,3e3))})}if(H5P.isFramed){var d;if(H5P.externalEmbed===!1){var f=window.parent.document.getElementById("h5p-iframe-"+n),p=function(){if(!window.parent.H5P.isFullscreen){var e=f.parentElement.style.height;f.parentElement.style.height=f.parentElement.clientHeight+"px",f.style.height="1px",f.style.height=f.contentDocument.body.scrollHeight+"px",f.parentElement.style.height=e}};H5P.on(o,"resize",function(){clearTimeout(d),d=setTimeout(function(){p()},1)})}else if(H5P.communicator){var h=!1;H5P.communicator.on("ready",function(){H5P.communicator.send("hello")}),H5P.communicator.on("hello",function(){h=!0,document.body.style.height="auto",document.body.style.overflow="hidden",H5P.trigger(o,"resize")}),H5P.communicator.on("resizePrepared",function(e){H5P.communicator.send("resize",{scrollHeight:document.body.scrollHeight})}),H5P.communicator.on("resize",function(){H5P.trigger(o,"resize")}),H5P.on(o,"resize",function(){H5P.isFullscreen||(clearTimeout(d),d=setTimeout(function(){h?H5P.communicator.send("prepareResize",{scrollHeight:document.body.scrollHeight,clientHeight:document.body.clientHeight}):H5P.communicator.send("hello")},0))})}}H5P.isFramed&&H5P.externalEmbed!==!1||H5P.jQuery(window.parent).resize(function(){window.parent.H5P.isFullscreen?H5P.trigger(o,"resize"):H5P.trigger(o,"resize")}),H5P.instances.push(o),H5P.trigger(o,"resize")});H5P.jQuery("iframe.h5p-iframe:not(.h5p-initialized)",e).each(function(){var e=H5P.jQuery(this).addClass("h5p-initialized").data("content-id");this.contentDocument.open(),this.contentDocument.write(''+H5P.getHeadTags(e)+'
      '),this.contentDocument.close()})},H5P.getHeadTags=function(e){var t=function(e){for(var t="",n=0;n';return t},n=function(e){for(var t="",n=0;n';return t};return''+t(H5PIntegration.core.styles)+t(H5PIntegration.contents["cid-"+e].styles)+n(H5PIntegration.core.scripts)+n(H5PIntegration.contents["cid-"+e].scripts)+""},H5P.communicator=function(){function e(){var e=this,t={};window.addEventListener("message",function(e){window.parent===e.source&&"h5p"===e.data.context&&void 0!==t[e.data.action]&&t[e.data.action](e.data)},!1),e.on=function(e,n){t[e]=n},e.send=function(e,t){void 0===t&&(t={}),t.context="h5p",t.action=e,window.parent.postMessage(t,"*")}}return window.postMessage&&window.addEventListener?new e:void 0}(),H5P.semiFullScreen=function(e,t,n,r){H5P.fullScreen(e,t,n,r,!0)},H5P.fullScreen=function(e,t,n,r,i){if(void 0===H5P.exitFullScreen){if(H5P.isFramed&&H5P.externalEmbed===!1)return window.parent.H5P.fullScreen(e,t,n,H5P.$body.get(),i),H5P.isFullscreen=!0,H5P.exitFullScreen=function(){window.parent.H5P.exitFullScreen()},void H5P.on(t,"exitFullScreen",function(){H5P.isFullscreen=!1,H5P.exitFullScreen=void 0});var o,a,s=e;if(void 0===r)$body=H5P.$body;else{$body=H5P.jQuery(r),o=$body.add(e.get());var c="#h5p-iframe-"+e.parent().data("content-id");a=H5P.jQuery(c),e=a.parent()}o=e.add(H5P.$body).add(o);var u=function(e){o.addClass(e),void 0!==a&&a.css("height","")},l=function(){H5P.trigger(t,"resize"),H5P.trigger(t,"focus"),H5P.trigger(t,"enterFullScreen")},d=function(e){H5P.isFullscreen=!1,o.removeClass(e),H5P.trigger(t,"resize"),H5P.trigger(t,"focus"),H5P.exitFullScreen=void 0,void 0!==n&&n(),H5P.trigger(t,"exitFullScreen")};if(H5P.isFullscreen=!0,void 0===H5P.fullScreenBrowserPrefix||i===!0){if(H5P.isFramed)return;u("h5p-semi-fullscreen");var f,p=H5P.jQuery('
      ').appendTo(s.find(".h5p-content-controls")),h=H5P.exitFullScreen=function(){g?m.content=g:b.removeChild(m),p.remove(),$body.unbind("keyup",f),d("h5p-semi-fullscreen")};f=function(e){27===e.keyCode&&h()},p.click(h),$body.keyup(f);for(var g,m,v=document.getElementsByTagName("meta"),y=0;y-1?new u(e.params,t):new u(e.params,t,i),void 0===f.$&&(f.$=H5P.jQuery(f)),void 0===f.contentId&&(f.contentId=t),void 0===f.subContentId&&e.subContentId&&(f.subContentId=e.subContentId),void 0===f.parent&&i&&i.parent&&(f.parent=i.parent),void 0===f.libraryInfo&&(f.libraryInfo={versionedName:e.library,versionedNameNoSpaces:s+"-"+a[0]+"."+a[1],machineName:s,majorVersion:a[0],minorVersion:a[1]}),void 0!==n&&(n.toggleClass("h5p-standalone",d),f.attach(n),H5P.trigger(f,"domChanged",{$target:n,library:s,key:"newLibrary"},{bubbles:!0,external:!0}),void 0!==r&&r||H5P.trigger(f,"resize")),f},H5P.error=function(e){void 0!==window.console&&void 0!==console.error&&console.error(e.stack?e.stack:e)},H5P.t=function(e,t,n){if(void 0===n&&(n="H5P"),void 0===H5PIntegration.l10n[n])return'[Missing translation namespace "'+n+'"]';if(void 0===H5PIntegration.l10n[n][e])return'[Missing translation "'+e+'" in "'+n+'"]';var r=H5PIntegration.l10n[n][e];if(void 0!==t)for(var i in t)r=r.replace(i,t[i]);return r},H5P.Dialog=function(e,t,n,r){var i=this,o=H5P.jQuery('

      '+t+'

      '+n+'
      ').insertAfter(r).click(function(){i.close()}).children(".h5p-inner").click(function(){return!1}).find(".h5p-close").click(function(){i.close()}).end().find("a").click(function(e){e.stopPropagation()}).end().end();this.open=function(){setTimeout(function(){o.addClass("h5p-open"),H5P.jQuery(i).trigger("dialog-opened",[o])},1)},this.close=function(){o.removeClass("h5p-open"),setTimeout(function(){o.remove()},200)}},H5P.getCopyrights=function(e,t,n){var r;if(void 0!==e.getCopyrights)try{r=e.getCopyrights()}catch(i){}return void 0===r&&(r=new H5P.ContentCopyrights,H5P.findCopyrights(r,t,n)),void 0!==r&&(r=r.toString()),r},H5P.findCopyrights=function(e,t,n){for(var r in t)if(t.hasOwnProperty(r)){var i=t[r];if(i instanceof Array)H5P.findCopyrights(e,i,n);else if(i instanceof Object)if(void 0===i.copyright||void 0===i.copyright.license||void 0===i.path||void 0===i.mime)H5P.findCopyrights(e,i,n);else{var o=new H5P.MediaCopyright(i.copyright);void 0!==i.width&&void 0!==i.height&&o.setThumbnail(new H5P.Thumbnail(H5P.getPath(i.path,n),i.width,i.height)),e.addMedia(o)}}},H5P.openEmbedDialog=function(e,t,n,r){var i=t+n,o=new H5P.Dialog("embed",H5P.t("embed"),''+H5P.t("size")+': × px
      '+H5P.t("showAdvanced")+'

      '+H5P.t("advancedHelp")+'

      ",e);H5P.jQuery(o).on("dialog-opened",function(e,t){var n=t.find(".h5p-inner"),o=n.find(".h5p-scroll-content"),a=o.outerHeight()-o.innerHeight(),s=function(){var e=n.height();o[0].scrollHeight+a>e?n.css("height",""):(n.css("height","auto"),e=n.height()),n.css("marginTop","-"+e/2+"px")},c=t.find(".h5p-embed-size:eq(0)"),u=t.find(".h5p-embed-size:eq(1)"),l=function(e,t){var n=parseFloat(e.val());return isNaN(n)?t:Math.ceil(n)},d=function(){t.find(".h5p-embed-code-container:first").val(i.replace(":w",l(c,r.width)).replace(":h",l(u,r.height)))};c.change(d),u.change(d),d(),t.find(".h5p-embed-code-container").each(function(e,t){H5P.jQuery(this).css("height",this.scrollHeight+"px").focus(function(){H5P.jQuery(this).select()})}),t.find(".h5p-embed-code-container").eq(0).select(),s();var f=function(){var e=H5P.jQuery(this),n=e.next();n.is(":visible")?(e.removeClass("h5p-open").text(H5P.t("showAdvanced")),n.hide()):(e.addClass("h5p-open").text(H5P.t("hideAdvanced")),n.show()),t.find(".h5p-embed-code-container").each(function(e,t){H5P.jQuery(this).css("height",this.scrollHeight+"px")}),s()};t.find(".h5p-expander").click(f).keypress(function(e){32===e.keyCode&&f.apply(this)})}),o.open()},H5P.ContentCopyrights=function(){var e,t=[],n=[];this.setLabel=function(t){e=t},this.addMedia=function(e){void 0!==e&&t.push(e)},this.addContent=function(e){void 0!==e&&n.push(e)},this.toString=function(){for(var r="",i=0;i"+e+""+r),r='
      '+r+"
      "),r}},H5P.MediaCopyright=function(e,t,n,r){var i,o=new H5P.DefinitionList,a=function(e){return void 0===t||void 0===t[e]?H5P.t(e):t[e]},s=function(e,t){return"license"===e?H5P.copyrightLicenses[t]:t};if(void 0!==e){for(var c in r)r.hasOwnProperty(c)&&(e[c]=r[c]);void 0===n&&(n=["title","author","year","source","license"]);for(var u=0;u'+e+"
      "),e)}},H5P.copyrightLicenses={U:"Undisclosed","CC BY":'Attribution 4.0',"CC BY-SA":'Attribution-ShareAlike 4.0',"CC BY-ND":'Attribution-NoDerivs 4.0',"CC BY-NC":'Attribution-NonCommercial 4.0',"CC BY-NC-SA":'Attribution-NonCommercial-ShareAlike 4.0',"CC BY-NC-ND":'Attribution-NonCommercial-NoDerivs 4.0',"GNU GPL":'General Public License v3',PD:"Public Domain","ODC PDDL":'Public Domain Dedication and Licence',"CC PDM":"Public Domain Mark",C:"Copyright"},H5P.Thumbnail=function(e,t,n){var r,i=100;void 0!==t&&(r=Math.round(i*(t/n))),this.toString=function(){return''+H5P.t("}},H5P.Field=function(e,t){this.getLabel=function(){return e},this.getValue=function(){return t}},H5P.DefinitionList=function(){var e=[];this.add=function(t){e.push(t)},this.size=function(){return e.length},this.get=function(t){return e[t]},this.toString=function(){for(var t="",n=0;n"+r.getLabel()+"
      "+r.getValue()+"
      "}return""===t?t:'
      '+t+"
      "}},H5P.Coords=function(e,t,n,r){return this instanceof H5P.Coords?(this.x=0,this.y=0,this.w=1,this.h=1,"object"==typeof e?(this.x=e.x,this.y=e.y,this.w=e.w,this.h=e.h):(void 0!==e&&(this.x=e),void 0!==t&&(this.y=t),void 0!==n&&(this.w=n),void 0!==r&&(this.h=r)),this):new H5P.Coords(e,t,n,r)},H5P.libraryFromString=function(e){var t=/(.+)\s(\d+)\.(\d+)$/g,n=t.exec(e);return null!==n?{machineName:n[1],majorVersion:n[2],minorVersion:n[3]}:!1},H5P.getLibraryPath=function(e){return(void 0!==H5PIntegration.libraryUrl?H5PIntegration.libraryUrl+"/":H5PIntegration.url+"/libraries/")+e},H5P.cloneObject=function(e,t){var n=e instanceof Array?[]:{};for(var r in e)e.hasOwnProperty(r)&&(void 0!==t&&t&&"object"==typeof e[r]?n[r]=H5P.cloneObject(e[r],t):n[r]=e[r]);return n},H5P.trim=function(e){return e.replace(/^\s+|\s+$/g,"")},H5P.jsLoaded=function(e){return H5PIntegration.loadedJs=H5PIntegration.loadedJs||[],-1!==H5P.jQuery.inArray(e,H5PIntegration.loadedJs)},H5P.cssLoaded=function(e){return H5PIntegration.loadedCss=H5PIntegration.loadedCss||[],-1!==H5P.jQuery.inArray(e,H5PIntegration.loadedCss)},H5P.shuffleArray=function(e){if(e instanceof Array){var t,n,r,i=e.length;if(0===i)return!1;for(;--i;)t=Math.floor(Math.random()*(i+1)),n=e[i],r=e[t],e[i]=r,e[t]=n;return e}},H5P.setFinished=function(e,t,n,r){if("number"==typeof t&&H5PIntegration.postUserStatistics===!0){var i=function(e){return Math.round(e.getTime()/1e3)};H5P.jQuery.post(H5PIntegration.ajax.setFinished,{contentId:e,score:t,maxScore:n,opened:i(H5P.opened[e]),finished:i(new Date),time:r,token:H5PIntegration.tokens.result})}},Array.prototype.indexOf||(Array.prototype.indexOf=function(e){for(var t=0;t
      ").text(e.replace(/(<([^>]+)>)/gi,"")).text();return n.length>t&&(n=n.substr(0,t-3)+"..."),n},function(e){function t(t,n,r,i,o,a,s,c){if(void 0===H5PIntegration.user)return void i("Not signed in.");var u={url:H5PIntegration.ajax.contentUserData.replace(":contentId",t).replace(":dataType",n).replace(":subContentId",r?r:0),dataType:"json",async:void 0===c?!0:c};void 0!==o?(u.type="POST",u.data={data:null===o?0:o,preload:a?1:0,invalidate:s?1:0,token:H5PIntegration.tokens.contentUserData}):u.type="GET",void 0!==i&&(u.error=function(e,t){i(t)},u.success=function(e){return e.success?e.data===!1||void 0===e.data?void i():void i(void 0,e.data):void i(e.message)}),e.ajax(u)}H5P.getUserData=function(e,n,r,i){i||(i=0),H5PIntegration.contents=H5PIntegration.contents||{};var o=H5PIntegration.contents["cid-"+e]||{},a=o.contentUserData;if(a&&a[i]&&void 0!==a[i][n]){if("RESET"===a[i][n])return void r(void 0,null);try{r(void 0,JSON.parse(a[i][n]))}catch(s){r(s)}}else t(e,n,i,function(e,t){if(e||void 0===t)return void r(e,t);void 0===o.contentUserData&&(o.contentUserData=a={}),void 0===a[i]&&(a[i]={}),a[i][n]=t;try{r(void 0,JSON.parse(t))}catch(s){r(s)}})},H5P.setUserData=function(e,n,r,i){var o=H5P.jQuery.extend(!0,{},{subContentId:0,preloaded:!0,deleteOnChange:!1,async:!0},i);try{r=JSON.stringify(r)}catch(a){return void(o.errorCallback&&o.errorCallback(a))}var s=H5PIntegration.contents["cid-"+e];void 0===s&&(s=H5PIntegration.contents["cid-"+e]={}),s.contentUserData||(s.contentUserData={});var c=s.contentUserData;void 0===c[o.subContentId]&&(c[o.subContentId]={}),r!==c[o.subContentId][n]&&(c[o.subContentId][n]=r,t(e,n,o.subContentId,function(e,t){o.errorCallback&&e&&o.errorCallback(e)},r,o.preloaded,o.deleteOnChange,o.async))},H5P.deleteUserData=function(e,n,r){r||(r=0);var i=H5PIntegration.contents["cid-"+e].contentUserData;i&&i[r]&&i[r][n]&&delete i[r][n],t(e,n,r,void 0,null)},e(document).ready(function(){if(H5P.preventInit||H5P.init(document.body),H5PIntegration.saveFreq!==!1){var e=0,t=function(){var t=(new Date).getTime();if(t-e>250){e=t;for(var n=0;n { - let dependencies = h5p.preloadedDependencies; - let loadDependencies = dependencies.map(dependency => { - machinePath = dependency.machineName + (h5p.pathIncludesVersion ? "-" + dependency.majorVersion + "." + dependency.minorVersion : ''); - return getJSONPromise(`${pathToContent}/${machinePath}/library.json`).then(library => { - let styles = []; - let scripts = []; - let dependencies2 = []; - let libraryPath = library.machineName + (h5p.pathIncludesVersion ? "-" + library.majorVersion + "." + library.minorVersion : ''); - - if (library.preloadedCss) { - styles = library.preloadedCss.map(style => `${pathToContent}/${libraryPath}/${style.path}`); - } - - if (library.preloadedJs) { - scripts = library.preloadedJs.map(script => `${pathToContent}/${libraryPath}/${script.path}`); - } + let dependencyCSS = {}; + let dependencyJS = {}; + // let dependencyDepth = 0; + + let loadDependencies = function(toFind, alreadyFound, h5p) { + // console.log(`loading dependency level: ${dependencyDepth}`); + // dependencyDepth++; + let findDependencies = toFind.map((dependency) => { + return getJSONPromise(`${pathToContent}/${dependency}/library.json`).then(library => { + let styles = []; + let scripts = []; + let dependencies2 = []; + let libraryPath = library.machineName + (h5p.pathIncludesVersion ? "-" + library.majorVersion + "." + library.minorVersion : ''); + + if (library.preloadedCss) { + dependencyCSS[libraryPath] = dependencyCSS[libraryPath] ? dependencyCSS[libraryPath] : []; + styles = library.preloadedCss.forEach(style => { + dependencyCSS[libraryPath].push(`${pathToContent}/${libraryPath}/${style.path}`); + }); + } + + if (library.preloadedJs) { + dependencyJS[libraryPath] = dependencyJS[libraryPath] ? dependencyJS[libraryPath] : []; + scripts = library.preloadedJs.forEach(script => { + dependencyJS[libraryPath].push(`${pathToContent}/${libraryPath}/${script.path}`); + }); + } + + if (library.preloadedDependencies) { + dependencies2 = library.preloadedDependencies.map(dependency2 => dependency2.machineName + (h5p.pathIncludesVersion ? "-" + dependency2.majorVersion + "." + dependency2.minorVersion : '')); + } + + return Promise.resolve({libraryPath: libraryPath, dependencies: dependencies2}); + }); + }); - if (library.preloadedDependencies) { - dependencies2 = library.preloadedDependencies.map(dependency2 => dependency2.machineName); + let findNext = []; + return Promise.all(findDependencies).then((data) => { + // loop over newly found libraries + data.forEach((library) => { + // push into found list + alreadyFound.push(library); + // check if any dependencies haven't been found yet + library.dependencies.forEach((dependency) => { + if (!alreadyFound.find((foundLibrary) => foundLibrary.libraryPath === dependency) && !data.find((foundLibrary) => foundLibrary.libraryPath === dependency)) { + findNext.push(dependency); } - - return Promise.resolve({ name: dependency.machineName, styles: styles, scripts: scripts, dependencies: dependencies2 }); }); }); - return Promise.all(loadDependencies); - }); + + if(findNext.length > 0) { + return loadDependencies(findNext, alreadyFound, h5p); + } + return Promise.resolve(alreadyFound); + }); + } let getLibrary = checklibraryPath.then(function (h5p) { let mainLibrary = h5p.preloadedDependencies.find(dep => dep.machineName === h5p.mainLibrary); @@ -105,40 +134,69 @@ return getJSONPromise(`${pathToContent}/${mainLibraryPath}/library.json`); }); - Promise.all([getInfo, getContent, getLibrary, getDirectDependencies]).then(data => { - let [h5p, content, library, dependencies] = data; + Promise.all([getInfo, getContent, getLibrary]).then(data => { + let [h5p, content, library] = data; + let libraryPath = library.machineName + (h5p.pathIncludesVersion ? "-" + library.majorVersion + "." + library.minorVersion : ''); let styles = library.preloadedCss.map(style => `${pathToContent}/${libraryPath}/${style.path}`); let scripts = library.preloadedJs.map(script => `${pathToContent}/${libraryPath}/${script.path}`); + let directDependencyNames = h5p.preloadedDependencies.map(dependency2 => dependency2.machineName + (h5p.pathIncludesVersion ? "-" + dependency2.majorVersion + "." + dependency2.minorVersion : '')); - let dependencySorter = new Toposort(); + loadDependencies(directDependencyNames, [], h5p).then((results) => { + let dependencySorter = new Toposort(); - dependencies.forEach(dependency => dependencySorter.add(dependency.name, dependency.dependencies)); + results.forEach(dependency => dependencySorter.add(dependency.libraryPath, dependency.dependencies)); - dependencySorter.sort().reverse().forEach(function (dependencyName) { - let dependency = dependencies.find(function (dept) { - return dept.name === dependencyName; + dependencySorter.sort().reverse().forEach(function (dependencyName) { + Array.prototype.push.apply(styles, dependencyCSS[dependencyName]); + Array.prototype.push.apply(scripts, dependencyJS[dependencyName]); }); - if (typeof dependency === "undefined") { - console.warn("Skipping unmet dependency " + dependencyName); - return; - } - Array.prototype.push.apply(styles, dependency.styles); - Array.prototype.push.apply(scripts, dependency.scripts); - }); - H5PIntegration.contents = H5PIntegration.contents ? H5PIntegration.contents : {}; + H5PIntegration.contents = H5PIntegration.contents ? H5PIntegration.contents : {}; - H5PIntegration.contents[`cid-${id}`] = { - library: `${library.machineName} ${library.majorVersion}.${library.minorVersion}`, - jsonContent: JSON.stringify(content), - styles: styles, - scripts: scripts - }; + H5PIntegration.contents[`cid-${id}`] = { + library: `${library.machineName} ${library.majorVersion}.${library.minorVersion}`, + jsonContent: JSON.stringify(content), + styles: styles, + scripts: scripts + }; - H5P.init(); + H5P.init(); + }); + // let dependencySorter = new Toposort(); + + // dependencies.forEach(dependency => dependencySorter.add(dependency.name, dependency.dependencies)); + // otherDependencies.forEach(dependency => dependencySorter.add(dependency.name, dependency.dependencies)); + + // dependencySorter.sort().reverse().forEach(function (dependencyName) { + // let dependency = dependencies.find(function (dept) { + // return dept.name === dependencyName; + // }) || otherDependencies.find(function (dept) { + // return dept.name === dependencyName; + // }); + // console.log(dependencyName); + // if (!dependency) { + // console.warn(`${dependencyName} could not be found`); + // return; + // } + // Array.prototype.push.apply(styles, dependency.styles); + // Array.prototype.push.apply(scripts, dependency.scripts); + // }); + + // scripts.unshift('../workspace/Tether-1.0/scripts/tether.min.js'); + + // H5PIntegration.contents = H5PIntegration.contents ? H5PIntegration.contents : {}; + + // H5PIntegration.contents[`cid-${id}`] = { + // library: `${library.machineName} ${library.majorVersion}.${library.minorVersion}`, + // jsonContent: JSON.stringify(content), + // styles: styles, + // scripts: scripts + // }; + + // H5P.init(); }); }; diff --git a/src/js/h5pintegration.js b/src/js/h5pintegration.js index 97631e87..14be2a48 100644 --- a/src/js/h5pintegration.js +++ b/src/js/h5pintegration.js @@ -76,39 +76,68 @@ var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = }); }); - var getDirectDependencies = checklibraryPath.then(function (h5p) { - var dependencies = h5p.preloadedDependencies; - var loadDependencies = dependencies.map(function (dependency) { - machinePath = dependency.machineName + (h5p.pathIncludesVersion ? "-" + dependency.majorVersion + "." + dependency.minorVersion : ''); - return getJSONPromise(pathToContent + "/" + machinePath + "/library.json").then(function (library) { + var dependencyCSS = {}; + var dependencyJS = {}; + // let dependencyDepth = 0; + + var loadDependencies = function loadDependencies(toFind, alreadyFound, h5p) { + // console.log(`loading dependency level: ${dependencyDepth}`); + // dependencyDepth++; + var findDependencies = toFind.map(function (dependency) { + return getJSONPromise(pathToContent + "/" + dependency + "/library.json").then(function (library) { var styles = []; var scripts = []; var dependencies2 = []; var libraryPath = library.machineName + (h5p.pathIncludesVersion ? "-" + library.majorVersion + "." + library.minorVersion : ''); if (library.preloadedCss) { - styles = library.preloadedCss.map(function (style) { - return pathToContent + "/" + libraryPath + "/" + style.path; + dependencyCSS[libraryPath] = dependencyCSS[libraryPath] ? dependencyCSS[libraryPath] : []; + styles = library.preloadedCss.forEach(function (style) { + dependencyCSS[libraryPath].push(pathToContent + "/" + libraryPath + "/" + style.path); }); } if (library.preloadedJs) { - scripts = library.preloadedJs.map(function (script) { - return pathToContent + "/" + libraryPath + "/" + script.path; + dependencyJS[libraryPath] = dependencyJS[libraryPath] ? dependencyJS[libraryPath] : []; + scripts = library.preloadedJs.forEach(function (script) { + dependencyJS[libraryPath].push(pathToContent + "/" + libraryPath + "/" + script.path); }); } if (library.preloadedDependencies) { dependencies2 = library.preloadedDependencies.map(function (dependency2) { - return dependency2.machineName; + return dependency2.machineName + (h5p.pathIncludesVersion ? "-" + dependency2.majorVersion + "." + dependency2.minorVersion : ''); }); } - return Promise.resolve({ name: dependency.machineName, styles: styles, scripts: scripts, dependencies: dependencies2 }); + return Promise.resolve({ libraryPath: libraryPath, dependencies: dependencies2 }); }); }); - return Promise.all(loadDependencies); - }); + + var findNext = []; + return Promise.all(findDependencies).then(function (data) { + // loop over newly found libraries + data.forEach(function (library) { + // push into found list + alreadyFound.push(library); + // check if any dependencies haven't been found yet + library.dependencies.forEach(function (dependency) { + if (!alreadyFound.find(function (foundLibrary) { + return foundLibrary.libraryPath === dependency; + }) && !data.find(function (foundLibrary) { + return foundLibrary.libraryPath === dependency; + })) { + findNext.push(dependency); + } + }); + }); + + if (findNext.length > 0) { + return loadDependencies(findNext, alreadyFound, h5p); + } + return Promise.resolve(alreadyFound); + }); + }; var getLibrary = checklibraryPath.then(function (h5p) { var mainLibrary = h5p.preloadedDependencies.find(function (dep) { @@ -118,13 +147,12 @@ var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = return getJSONPromise(pathToContent + "/" + mainLibraryPath + "/library.json"); }); - Promise.all([getInfo, getContent, getLibrary, getDirectDependencies]).then(function (data) { - var _data = _slicedToArray(data, 4); + Promise.all([getInfo, getContent, getLibrary]).then(function (data) { + var _data = _slicedToArray(data, 3); var h5p = _data[0]; var content = _data[1]; var library = _data[2]; - var dependencies = _data[3]; var libraryPath = library.machineName + (h5p.pathIncludesVersion ? "-" + library.majorVersion + "." + library.minorVersion : ''); var styles = library.preloadedCss.map(function (style) { @@ -135,34 +163,65 @@ var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = return pathToContent + "/" + libraryPath + "/" + script.path; }); - var dependencySorter = new Toposort(); - - dependencies.forEach(function (dependency) { - return dependencySorter.add(dependency.name, dependency.dependencies); + var directDependencyNames = h5p.preloadedDependencies.map(function (dependency2) { + return dependency2.machineName + (h5p.pathIncludesVersion ? "-" + dependency2.majorVersion + "." + dependency2.minorVersion : ''); }); - dependencySorter.sort().reverse().forEach(function (dependencyName) { - var dependency = dependencies.find(function (dept) { - return dept.name === dependencyName; + loadDependencies(directDependencyNames, [], h5p).then(function (results) { + var dependencySorter = new Toposort(); + + results.forEach(function (dependency) { + return dependencySorter.add(dependency.libraryPath, dependency.dependencies); }); - if (typeof dependency === "undefined") { - console.warn("Skipping unmet dependency " + dependencyName); - return; - } - Array.prototype.push.apply(styles, dependency.styles); - Array.prototype.push.apply(scripts, dependency.scripts); - }); - H5PIntegration.contents = H5PIntegration.contents ? H5PIntegration.contents : {}; + dependencySorter.sort().reverse().forEach(function (dependencyName) { + Array.prototype.push.apply(styles, dependencyCSS[dependencyName]); + Array.prototype.push.apply(scripts, dependencyJS[dependencyName]); + }); + + H5PIntegration.contents = H5PIntegration.contents ? H5PIntegration.contents : {}; - H5PIntegration.contents["cid-" + id] = { - library: library.machineName + " " + library.majorVersion + "." + library.minorVersion, - jsonContent: JSON.stringify(content), - styles: styles, - scripts: scripts - }; + H5PIntegration.contents["cid-" + id] = { + library: library.machineName + " " + library.majorVersion + "." + library.minorVersion, + jsonContent: JSON.stringify(content), + styles: styles, + scripts: scripts + }; - H5P.init(); + H5P.init(); + }); + // let dependencySorter = new Toposort(); + + // dependencies.forEach(dependency => dependencySorter.add(dependency.name, dependency.dependencies)); + // otherDependencies.forEach(dependency => dependencySorter.add(dependency.name, dependency.dependencies)); + + // dependencySorter.sort().reverse().forEach(function (dependencyName) { + // let dependency = dependencies.find(function (dept) { + // return dept.name === dependencyName; + // }) || otherDependencies.find(function (dept) { + // return dept.name === dependencyName; + // }); + // console.log(dependencyName); + // if (!dependency) { + // console.warn(`${dependencyName} could not be found`); + // return; + // } + // Array.prototype.push.apply(styles, dependency.styles); + // Array.prototype.push.apply(scripts, dependency.scripts); + // }); + + // scripts.unshift('../workspace/Tether-1.0/scripts/tether.min.js'); + + // H5PIntegration.contents = H5PIntegration.contents ? H5PIntegration.contents : {}; + + // H5PIntegration.contents[`cid-${id}`] = { + // library: `${library.machineName} ${library.majorVersion}.${library.minorVersion}`, + // jsonContent: JSON.stringify(content), + // styles: styles, + // scripts: scripts + // }; + + // H5P.init(); }); };