HFP-1905 Include metadata in findCopyrights
parent
972c7a13f6
commit
14bcb913b7
51
js/h5p.js
51
js/h5p.js
|
@ -976,10 +976,10 @@ H5P.Dialog = function (name, title, content, $element) {
|
||||||
* 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 {Object} metadata
|
|
||||||
* Metadata of the content instance.
|
|
||||||
* @param {number} contentId
|
* @param {number} contentId
|
||||||
* Identifies the H5P content
|
* Identifies the H5P content
|
||||||
|
* @param {Object} metadata
|
||||||
|
* Metadata of the content instance.
|
||||||
* @returns {string} Copyright information.
|
* @returns {string} Copyright information.
|
||||||
*/
|
*/
|
||||||
H5P.getCopyrights = function (instance, parameters, contentId, metadata) {
|
H5P.getCopyrights = function (instance, parameters, contentId, metadata) {
|
||||||
|
@ -1022,8 +1022,18 @@ H5P.getCopyrights = function (instance, parameters, contentId, metadata) {
|
||||||
* To search for file objects in.
|
* To search for file objects in.
|
||||||
* @param {number} contentId
|
* @param {number} contentId
|
||||||
* Used to insert thumbnails for images.
|
* Used to insert thumbnails for images.
|
||||||
|
* @param {Object} extras - Extras.
|
||||||
|
* @param {object} extras.metadata - Metadata
|
||||||
|
* @param {object} extras.machineName - Library name of some kind.
|
||||||
|
* Metadata of the content instance.
|
||||||
*/
|
*/
|
||||||
H5P.findCopyrights = function (info, parameters, contentId) {
|
H5P.findCopyrights = function (info, parameters, contentId, extras) {
|
||||||
|
// If extras are
|
||||||
|
if (extras) {
|
||||||
|
extras.params = parameters;
|
||||||
|
buildFromMetadata(extras, extras.machineName, contentId);
|
||||||
|
}
|
||||||
|
|
||||||
var lastContentTypeName;
|
var lastContentTypeName;
|
||||||
// Cycle through parameters
|
// Cycle through parameters
|
||||||
for (var field in parameters) {
|
for (var field in parameters) {
|
||||||
|
@ -1057,18 +1067,7 @@ H5P.findCopyrights = function (info, parameters, contentId) {
|
||||||
H5P.findCopyrights(info, value, contentId);
|
H5P.findCopyrights(info, value, contentId);
|
||||||
}
|
}
|
||||||
else if (value instanceof Object) {
|
else if (value instanceof Object) {
|
||||||
if (value.metadata) {
|
buildFromMetadata(value, lastContentTypeName, contentId);
|
||||||
var metadataCopyrights = H5P.buildMetadataCopyrights(value.metadata, lastContentTypeName);
|
|
||||||
if (metadataCopyrights !== undefined) {
|
|
||||||
if (value.params && value.params.contentName === 'Image' && value.params.file) {
|
|
||||||
var path = value.params.file.path;
|
|
||||||
var width = value.params.file.width;
|
|
||||||
var height = value.params.file.height;
|
|
||||||
metadataCopyrights.setThumbnail(new H5P.Thumbnail(H5P.getPath(path, contentId), width, height));
|
|
||||||
}
|
|
||||||
info.addMedia(metadataCopyrights);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if object is a file with copyrights (old core)
|
// Check if object is a file with copyrights (old core)
|
||||||
if (value.copyright === undefined ||
|
if (value.copyright === undefined ||
|
||||||
|
@ -1089,6 +1088,21 @@ H5P.findCopyrights = function (info, parameters, contentId) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildFromMetadata (data, name, contentId) {
|
||||||
|
if (data.metadata) {
|
||||||
|
const metadataCopyrights = H5P.buildMetadataCopyrights(data.metadata, name);
|
||||||
|
if (metadataCopyrights !== undefined) {
|
||||||
|
if (data.params && data.params.contentName === 'Image' && data.params.file) {
|
||||||
|
const path = data.params.file.path;
|
||||||
|
const width = data.params.file.width;
|
||||||
|
const height = data.params.file.height;
|
||||||
|
metadataCopyrights.setThumbnail(new H5P.Thumbnail(H5P.getPath(path, contentId), width, height));
|
||||||
|
}
|
||||||
|
info.addMedia(metadataCopyrights);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
H5P.buildMetadataCopyrights = function (metadata, contentTypeName) {
|
H5P.buildMetadataCopyrights = function (metadata, contentTypeName) {
|
||||||
|
@ -1108,8 +1122,11 @@ H5P.buildMetadataCopyrights = function (metadata, contentTypeName) {
|
||||||
}).join(' / ') : undefined
|
}).join(' / ') : undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
if (contentTypeName && contentTypeName.indexOf('H5P.') === 0) {
|
if (contentTypeName) {
|
||||||
contentTypeName = contentTypeName.substr(4);
|
contentTypeName = contentTypeName
|
||||||
|
.split(' ')[0]
|
||||||
|
.replace(/^H5P\./, '')
|
||||||
|
.replace(/([a-z])([A-Z])/, '$1' + ' ' + '$2');
|
||||||
}
|
}
|
||||||
|
|
||||||
return new H5P.MediaCopyright(
|
return new H5P.MediaCopyright(
|
||||||
|
|
Loading…
Reference in New Issue