From 9c0fb69e27431ad86a2cea773b204617aea769be Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 26 Apr 2013 17:27:35 +0200 Subject: [PATCH] Improved boardgame flexibility. --- js/h5p.js | 126 ++++++------------------------------------------------ 1 file changed, 12 insertions(+), 114 deletions(-) diff --git a/js/h5p.js b/js/h5p.js index 8466055..d02b5ce 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -10,7 +10,7 @@ H5P.init = function () { if (H5P.$body === undefined) { H5P.$body = H5P.jQuery('body'); } - + if (H5P.fullScreenBrowserPrefix === undefined) { if (document.cancelFullScreen) { H5P.fullScreenBrowserPrefix = ''; @@ -25,13 +25,13 @@ H5P.init = function () { H5P.fullScreenBrowserPrefix = 'ms'; } } - + H5P.jQuery(".h5p-content").each(function (idx, el) { var $el = H5P.jQuery(el); var contentId = $el.data('content-id'); var obj = new (H5P.classFromName($el.data('class')))(H5P.jQuery.parseJSON(H5PIntegration.getJsonContent(contentId)), contentId); obj.attach($el); - + if (H5PIntegration.getFullscreen(contentId)) { H5P.jQuery('
' + H5PIntegration.fullscreenText + '
').insertBefore($el).children().click(function () { H5P.fullScreen($el, obj); @@ -43,7 +43,7 @@ H5P.init = function () { /** * Enable full screen for the given h5p. - * + * * @param {jQuery} $el Container * @param {object} obj H5P * @returns {undefined} @@ -57,11 +57,11 @@ H5P.fullScreen = function ($el, obj) { $el.add(H5P.$body).removeClass('h5p-semi-fullscreen'); $disable.remove(); H5P.$body.unbind('keyup', keyup); - + if (obj.resize !== undefined) { obj.resize(false); } - + return false; }; keyup = function (event) { @@ -82,17 +82,17 @@ H5P.fullScreen = function ($el, obj) { $el.add(H5P.$body).removeClass('h5p-fullscreen'); document.removeEventListener(eventName, arguments.callee, false); }); - + if (H5P.fullScreenBrowserPrefix === '') { $el[0].requestFullScreen(); } else { $el[0][H5P.fullScreenBrowserPrefix + 'RequestFullScreen'](); } - + $el.add(H5P.$body).addClass('h5p-fullscreen'); } - + if (obj.resize !== undefined) { obj.resize(true); } @@ -165,119 +165,17 @@ H5P.libraryFromString = function (library) { return false; } }; -// Play a video. $target is jQuery object to attach video to. (Appended). -// Params are video-params from content. cp is content path. onEnded is -// function to call when finished. -// -// TODO: Try to get rid of content path. -H5P.playVideo = function ($target, params, skipButtonText, cp, onEnded) { - var $ = H5P.jQuery; - - var width = 635, // TODO: These should come from some dimension setting. - height = 500; - - var $container = $('
').css({ - position: "absolute", - top: "0px", - left: "0px", - "z-index": "500", - width: width, - height: height - }); - - var sources = ''; - var willWork = false; // Used for testing if video tag is supported, AND for testing if we can play back our given formats - - var video = document.createElement('video'); - video.autoplay = true; - video.width = width; - video.height = height; - - if (video.canPlayType !== undefined) { - for (var i = 0; i < params.length; i++) { - var file = params[i]; - // TODO: The files should probably be in their own group. - if (file.mime.indexOf('video') === 0) { - if (video.canPlayType(file.mime)) { - var source = document.createElement('source'); - source.src = cp + file.path; - source.type = file.mime; - video.appendChild(source); - willWork = willWork || true; - } - } - } - - if (willWork) { - $container.append(video); - $(video).on('ended', function() { - onEnded(); - }); - } - } - - var fplayer = undefined; - if (!willWork) { - // use flowplayer fallback - var fp_container = document.createElement("div"); - fp_container.width = "100%"; - fp_container.height = "100%"; - fplayer = flowplayer(fp_container, { - src: "http://releases.flowplayer.org/swf/flowplayer-3.2.16.swf", - wmode: "opaque", - width: width, - height: height - }, { - buffering: true, - clip: { - url: window.location.protocol + '//' + window.location.host + cp + params[0].path, - autoPlay: true, - autoBuffering: true, - onFinish: function () { - onEnded(); - }, - onError: function () { - onEnded(); - } - } - }); - - willWork = true; - $container.append(fp_container); - } - - if (!willWork) { - // Video tag is not supported and flash player failed too. - onEnded(); - return; - } - - if (skipButtonText) { - var $skipButton = $('').click(function (ev) { - if (fplayer !== undefined) { - // Must stop this first. Errorama if we don't - fplayer.stop().close().unload(); - } - $container.hide(); - onEnded(); - }); - $container.append($skipButton); - } - - // Finally, append to target. - $target.append($container); -}; /** * Recursivly clone the given object. - * + * * @param {object} object Object to clone. * @param {type} recursive * @returns {object} A clone of object. */ H5P.cloneObject = function (object, recursive, array) { var clone = array !== undefined && array ? [] : {}; - + for (var i in object) { if (object.hasOwnProperty(i)) { if (recursive !== undefined && recursive && typeof object[i] === 'object') { @@ -288,7 +186,7 @@ H5P.cloneObject = function (object, recursive, array) { } } } - + return clone; };