From 9ee8130aaef7981c234e1fb80189885a34bb88e3 Mon Sep 17 00:00:00 2001 From: Thomas Marstrander Date: Mon, 27 Apr 2015 13:21:31 +0200 Subject: [PATCH] Added copyrights fix. --- js/h5p.js | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/js/h5p.js b/js/h5p.js index 9b38d5e..b8a09e0 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -130,7 +130,8 @@ H5P.init = function (target) { window.location.href = contentData.exportUrl; }); } - if (!(contentData.disable & H5P.DISABLE_COPYRIGHT) && instance.getCopyrights !== undefined) { + if (!(contentData.disable & H5P.DISABLE_COPYRIGHT) && + ((instance.getCopyrights !== undefined) || H5P.hasCopyrights(library.params, contentId))) { // Add copyrights button H5P.jQuery('
  • ' + H5P.t('copyrights') + '
  • ').appendTo($actions).click(function () { H5P.openCopyrightsDialog($actions, instance, library.params, contentId); @@ -883,6 +884,47 @@ H5P.findCopyrights = function (info, parameters, contentId) { } }; +/** + * Recursive function for checking if content has copyrights + * + * @param {(Object|Arrray)} parameters To search for file objects in. + * @param {Number} contentId Used to insert thumbnails for images. + * @returns {boolean} Returns true if complete copyright information was found. + */ +H5P.hasCopyrights = function (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 + if (H5P.hasCopyrights(value, contentId)) { + return true; + } + } + 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 + if (H5P.hasCopyrights(value, contentId)) { + return true; + } + } + else { + // Found file, return true + return true; + } + } + } + return false; +}; /** * Display a dialog containing the embed code.