Pre-generate copyright information.
parent
ba862f0078
commit
5568a59854
75
js/h5p.js
75
js/h5p.js
|
@ -152,13 +152,18 @@ H5P.init = function (target) {
|
||||||
window.location.href = contentData.exportUrl;
|
window.location.href = contentData.exportUrl;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!(contentData.disable & H5P.DISABLE_COPYRIGHT) &&
|
if (!(contentData.disable & H5P.DISABLE_COPYRIGHT)) {
|
||||||
((instance.getCopyrights !== undefined) || H5P.hasCopyrights(library.params, contentId))) {
|
var copyright = H5P.getCopyrights(instance, library.params, contentId);
|
||||||
// Add copyrights button
|
|
||||||
|
if (copyright) {
|
||||||
|
// Add copyright dialog button
|
||||||
H5P.jQuery('<li class="h5p-button h5p-copyrights" role="button" tabindex="1" title="' + H5P.t('copyrightsDescription') + '">' + H5P.t('copyrights') + '</li>').appendTo($actions).click(function () {
|
H5P.jQuery('<li class="h5p-button h5p-copyrights" role="button" tabindex="1" title="' + H5P.t('copyrightsDescription') + '">' + H5P.t('copyrights') + '</li>').appendTo($actions).click(function () {
|
||||||
H5P.openCopyrightsDialog($actions, instance, library.params, contentId);
|
// Open dialog with copyright information
|
||||||
|
var dialog = new H5P.Dialog('copyrights', H5P.t('copyrightInformation'), copyright, $element);
|
||||||
|
dialog.open();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!(contentData.disable & H5P.DISABLE_EMBED)) {
|
if (!(contentData.disable & H5P.DISABLE_EMBED)) {
|
||||||
// Add embed button
|
// Add embed button
|
||||||
H5P.jQuery('<li class="h5p-button h5p-embed" role="button" tabindex="1" title="' + H5P.t('embedDescription') + '">' + H5P.t('embed') + '</li>').appendTo($actions).click(function () {
|
H5P.jQuery('<li class="h5p-button h5p-embed" role="button" tabindex="1" title="' + H5P.t('embedDescription') + '">' + H5P.t('embed') + '</li>').appendTo($actions).click(function () {
|
||||||
|
@ -864,19 +869,17 @@ H5P.Dialog = function (name, title, content, $element) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gather copyright information and display in a dialog over the content.
|
* Gather copyright information for the given content.
|
||||||
*
|
*
|
||||||
* @param {H5P.jQuery} $element
|
|
||||||
* DOM Element to insert dialog after.
|
|
||||||
* @param {Object} instance
|
* @param {Object} instance
|
||||||
* H5P instance to get copyright information for.
|
* H5P instance to get copyright information for.
|
||||||
* @param {Object} parameters
|
* @param {Object} parameters
|
||||||
* Parameters of the content instance.
|
* Parameters of the content instance.
|
||||||
* @param {number} contentId
|
* @param {number} contentId
|
||||||
* Identifies the H5P content
|
* Identifies the H5P content
|
||||||
|
* @returns {string} Copyright information.
|
||||||
*/
|
*/
|
||||||
H5P.openCopyrightsDialog = function ($element, instance, parameters, contentId) {
|
H5P.getCopyrights = function (instance, parameters, contentId) {
|
||||||
var copyrights;
|
|
||||||
if (instance.getCopyrights !== undefined) {
|
if (instance.getCopyrights !== undefined) {
|
||||||
// Use the instance's own copyright generator
|
// Use the instance's own copyright generator
|
||||||
copyrights = instance.getCopyrights();
|
copyrights = instance.getCopyrights();
|
||||||
|
@ -891,14 +894,7 @@ H5P.openCopyrightsDialog = function ($element, instance, parameters, contentId)
|
||||||
// Convert to string
|
// Convert to string
|
||||||
copyrights = copyrights.toString();
|
copyrights = copyrights.toString();
|
||||||
}
|
}
|
||||||
if (copyrights === undefined || copyrights === '') {
|
return 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();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -947,51 +943,6 @@ H5P.findCopyrights = function (info, parameters, contentId) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Recursive function for checking if content has copyrights
|
|
||||||
*
|
|
||||||
* @param {(Object|Array)} 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.
|
* Display a dialog containing the embed code.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue