Polished function comments to keep a constant style, added sanity check in shuffleArray

namespaces
Frank Ronny Larsen 2013-11-26 14:54:29 +01:00
parent 47dcb931e9
commit c87b233482
1 changed files with 49 additions and 17 deletions

View File

@ -3,8 +3,10 @@ var H5P = H5P || {};
// This needs to be determined before init is run. // This needs to be determined before init is run.
H5P.isFramed = (window.self !== window.top); // (window.parent !== window); H5P.isFramed = (window.self !== window.top); // (window.parent !== window);
// Initialize H5P content /**
// Scans for ".h5p-content" * Initialize H5P content.
* Scans for ".h5p-content" in the document and initializes H5P instances where found.
*/
H5P.init = function () { H5P.init = function () {
if (H5P.$window === undefined) { if (H5P.$window === undefined) {
H5P.$window = H5P.jQuery(window); H5P.$window = H5P.jQuery(window);
@ -94,10 +96,25 @@ H5P.init = function () {
} }
}; };
/**
* Fullscreen iframe container
*
* @param {string} contentId Content id of H5P in iframe
* @param {object} obj H5P object
* @param {function} exitCallback Callback function called when user exits fullscreen.
* @returns {undefined}
*/
H5P.fullScreenIframe = function (contentId, obj, exitCallback) { H5P.fullScreenIframe = function (contentId, obj, exitCallback) {
H5P.fullScreen(H5P.jQuery('#iframe-wrapper-' + contentId), obj, exitCallback); H5P.fullScreen(H5P.jQuery('#iframe-wrapper-' + contentId), obj, exitCallback);
}; };
/**
* Resize iframe height.
*
* @param {string} contentId Content id of H5P in iframe
* @param {integer} height New height in pixels.
* @returns {undefined}
*/
H5P.resizeIframe = function (contentId, height) { H5P.resizeIframe = function (contentId, height) {
var iframe = document.getElementById('iframe-' + contentId); var iframe = document.getElementById('iframe-' + contentId);
// Don't allow iFrame to grow beyond window height; // Don't allow iFrame to grow beyond window height;
@ -112,6 +129,7 @@ H5P.resizeIframe = function (contentId, height) {
* *
* @param {jQuery} $el Container * @param {jQuery} $el Container
* @param {object} obj H5P * @param {object} obj H5P
* @param {function} exitCallback Callback function called when user exits fullscreen.
* @returns {undefined} * @returns {undefined}
*/ */
H5P.fullScreen = function ($el, obj, exitCallback) { H5P.fullScreen = function ($el, obj, exitCallback) {
@ -238,18 +256,21 @@ H5P.getContentPath = function (contentId) {
return H5PIntegration.getContentPath(contentId); return H5PIntegration.getContentPath(contentId);
}; };
/**
// * Get library class constructor from H5P by classname.
// Used from libraries to construct instances of other libraries' objects by *
// name. * Used from libraries to construct instances of other libraries' objects by name.
// *
H5P.classFromName = function(name) { * @param {string} name Name of library
* @returns Class constructor
*/
H5P.classFromName = function (name) {
var arr = name.split("."); var arr = name.split(".");
return this[arr[arr.length-1]]; return this[arr[arr.length-1]];
}; };
// Helper object for keeping coordinates in the same format all over. // Helper object for keeping coordinates in the same format all over.
H5P.Coords = function(x, y, w, h) { H5P.Coords = function (x, y, w, h) {
if ( !(this instanceof H5P.Coords) ) if ( !(this instanceof H5P.Coords) )
return new H5P.Coords(x, y, w, h); return new H5P.Coords(x, y, w, h);
@ -281,8 +302,10 @@ H5P.Coords = function(x, y, w, h) {
}; };
/** /**
*@param {string} library * Parse library string into values.
* library in the format machineName majorVersion.minorVersion *
* @param {string} library
* library in the format "machineName majorVersion.minorVersion"
* @returns * @returns
* library as an object with machineName, majorVersion and minorVersion properties * library as an object with machineName, majorVersion and minorVersion properties
* return false if the library parameter is invalid * return false if the library parameter is invalid
@ -305,11 +328,12 @@ H5P.libraryFromString = function (library) {
/** /**
* Get the path to the library * Get the path to the library
* *
* @param {string} machineName The machine name of the library * @param {string} library
* The library identifier in the format "machineName-majorVersion.minorVersion"
* @returns {string} The full path to the library * @returns {string} The full path to the library
*/ */
H5P.getLibraryPath = function(machineName) { H5P.getLibraryPath = function (library) {
return H5PIntegration.getLibraryPath(machineName); return H5PIntegration.getLibraryPath(library);
}; };
/** /**
@ -378,9 +402,17 @@ H5P.cssLoaded = function (path) {
return false; return false;
}; };
// We have several situations where we want to shuffle an array, extend array /**
// to do so. * Shuffle an array in place.
H5P.shuffleArray = function(array) { *
* @param {array} array Array to shuffle
* @returns {array} The passed array is returned for chaining.
*/
H5P.shuffleArray = function (array) {
if (! array instanceof Array) {
return;
}
var i = array.length, j, tempi, tempj; var i = array.length, j, tempi, tempj;
if ( i === 0 ) return false; if ( i === 0 ) return false;
while ( --i ) { while ( --i ) {