From ad03edf6620d8d55204b1ac8d4e70e080cd79cda Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Thu, 30 Oct 2014 15:51:20 +0100 Subject: [PATCH 1/2] Added generic fallback for libraries that hasn't implemented getCopyrights. --- js/h5p.js | 73 +++++++++++++++++++++++++++++++++++++++++++++----- styles/h5p.css | 4 ++- 2 files changed, 69 insertions(+), 8 deletions(-) diff --git a/js/h5p.js b/js/h5p.js index 9cea78d..65bf07e 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -70,11 +70,12 @@ H5P.init = function () { window.location.href = contentData.exportUrl; }); } - if (instance.getCopyrights !== undefined) { - // Display copyrights button - H5P.jQuery('
  • ' + H5P.t('copyrights') + '
  • ').appendTo($actions).click(function () { - H5P.openCopyrightsDialog($actions, instance); - }); + + // Display copyrights button + H5P.jQuery('
  • ' + H5P.t('copyrights') + '
  • ').appendTo($actions).click(function () { + H5P.openCopyrightsDialog($actions, instance, library.params, contentId); + }); + } if (contentData.embedCode !== undefined) { // Display embed button @@ -482,19 +483,77 @@ H5P.Dialog = function (name, title, content, $element) { * @param {object} instance to get copyright information from. * @returns {undefined} */ -H5P.openCopyrightsDialog = function ($element, instance) { - var copyrights = instance.getCopyrights(); +H5P.openCopyrightsDialog = function ($element, instance, parameters, contentId) { + var copyrights; + if (instance.getCopyrights !== undefined) { + // Use the instance's own copyright generator + copyrights = instance.getCopyrights(); + } + else { + // Create a generic flat copyright list + copyrights = new H5P.ContentCopyrights(); + H5P.findCopyrights(copyrights, parameters, contentId); + } + if (copyrights !== undefined) { + // Convert to string copyrights = copyrights.toString(); } if (copyrights === undefined || copyrights === '') { + // Use no copyrights default text copyrights = H5P.t('noCopyrights'); } + // Open dialog with copyright information var dialog = new H5P.Dialog('copyrights', H5P.t('copyrightInformation'), copyrights, $element); dialog.open(); }; +/** + * Gather a flat list of copyright information from the given parameters. + * + * @param {H5P.ContentCopyrights} info Used to collect all information in. + * @param {(Object|Arrray)} parameters To search for file objects in. + * @param {Number} contentId Used to insert thumbnails for images. + * @returns {undefined} + */ +H5P.findCopyrights = function (info, parameters, contentId) { + // Cycle through parameters + for (var field in parameters) { + if (!parameters.hasOwnProperty(field)) { + continue; // Do not check + } + var value = parameters[field]; + + if (value instanceof Array) { + // Cycle through array + H5P.findCopyrights(info, value, contentId); + } + else if (value instanceof Object) { + // Check if object is a file with copyrights + if (value.copyright === undefined || + value.copyright.license === undefined || + value.path === undefined || + value.mime === undefined) { + + // Nope, cycle throught object + H5P.findCopyrights(info, value, contentId); + } + else { + // Found file, add copyrights + var copyrights = new H5P.MediaCopyright(value.copyright); + if (value.width !== undefined && value.height !== undefined) { + copyrights.setThumbnail(new H5P.Thumbnail(H5P.getPath(value.path, contentId), value.width, value.height)); + } + info.addMedia(copyrights); + } + } + else { + } + } +}; + + /** * Display a dialog containing the embed code. * diff --git a/styles/h5p.css b/styles/h5p.css index c9099c6..3ceb8e8 100644 --- a/styles/h5p.css +++ b/styles/h5p.css @@ -234,6 +234,8 @@ div.h5p-fullscreen { font-size: 1.5em; margin: 0.25em 0; position: absolute; + line-height: 1.25em; + padding: 0; } .h5p-embed-dialog .h5p-inner { width: 50%; @@ -322,4 +324,4 @@ div.h5p-fullscreen { padding-left: 38px; min-height: 30px; line-height: 30px; -} \ No newline at end of file +} From dd83933a0a82797345b0650e434d7fa7f7149f2b Mon Sep 17 00:00:00 2001 From: Svein-Tore Griff With Date: Sat, 1 Nov 2014 13:47:24 +0100 Subject: [PATCH 2/2] Remove } --- js/h5p.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/h5p.js b/js/h5p.js index 65bf07e..9ae10ea 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -76,7 +76,6 @@ H5P.init = function () { H5P.openCopyrightsDialog($actions, instance, library.params, contentId); }); - } if (contentData.embedCode !== undefined) { // Display embed button H5P.jQuery('
  • ' + H5P.t('embed') + '
  • ').appendTo($actions).click(function () {