Did some optimization, moved more func to core and added some comments.

namespaces
Frode Petterson 2014-06-19 16:09:23 +02:00
parent 0bcfa16861
commit 41f7039cbf
1 changed files with 22 additions and 19 deletions

View File

@ -1,3 +1,4 @@
// TODO: Should we split up the generic parts needed by the editor(and others), and the parts needed to "run" H5Ps?
var H5P = H5P || {};
// Determine if we're inside an iframe.
@ -34,7 +35,7 @@ else if (document.documentElement.msRequestFullscreen) {
*/
H5P.init = function () {
// Useful jQuery object.
H5P.$body = H5P.jQuery('body');
H5P.$body = H5P.jQuery(document.body);
// Prepare internal resizer for content.
var $window = H5P.jQuery(window.top);
@ -282,7 +283,17 @@ H5P.getPath = function (path, contentId) {
return path;
}
return H5PIntegration.getContentPath(contentId) + path;
if (contentId !== undefined) {
prefix = H5PIntegration.getContentPath(contentId);
}
else if (window['H5PEditor'] !== undefined) {
prefix = H5PEditor.filesPath;
}
else {
return;
}
return window.parent.location.protocol + "//" + window.parent.location.host + prefix + '/' + path;
};
/**
@ -886,6 +897,8 @@ H5P.cloneObject = function (object, recursive) {
/**
* Remove all empty spaces before and after the value.
* TODO: Only include this or String.trim(). What is best?
* I'm leaning towards implementing the missing ones: http://kangax.github.io/compat-table/es5/
* So should we make this function deprecated?
*
* @param {String} value
* @returns {@exp;value@call;replace}
@ -901,13 +914,8 @@ H5P.trim = function (value) {
* @returns {Boolean}
*/
H5P.jsLoaded = function (path) {
for (var i = 0; i < H5P.loadedJs.length; i++) {
if (H5P.loadedJs[i] === path) {
return true;
}
}
return false;
H5P.loadedJs = H5P.loadedJs || [];
return H5P.jQuery.inArray(path, H5P.loadedJs) !== -1;
};
/**
@ -917,13 +925,8 @@ H5P.jsLoaded = function (path) {
* @returns {Boolean}
*/
H5P.cssLoaded = function (path) {
for (var i = 0; i < H5P.loadedCss.length; i++) {
if (H5P.loadedCss[i] === path) {
return true;
}
}
return false;
H5P.loadedCss = H5P.loadedCss || [];
return H5P.jQuery.inArray(path, H5P.loadedCss) !== -1;
};
/**
@ -984,8 +987,8 @@ if (String.prototype.trim === undefined) {
};
}
// Finally, we want to run init when document is ready. But not if we're
// in an iFrame. Then we wait for parent to start init().
// Finally, we want to run init when document is ready.
// TODO: Move to integration. Systems like Moodle using YUI cannot get its translations set before this starts!
if (H5P.jQuery) {
H5P.jQuery(document).ready(function () {
if (!H5P.initialized) {