HFP-2508 Fix reset of all subContentIds on Copy/Paste
parent
4a9c3c7881
commit
f19ca76461
19
js/h5p.js
19
js/h5p.js
|
@ -2256,7 +2256,6 @@ H5P.createTitle = function (rawTitle, maxLength) {
|
|||
* Get item from the H5P Clipboard.
|
||||
*
|
||||
* @private
|
||||
* @param {boolean} [skipUpdateFileUrls]
|
||||
* @return {Object}
|
||||
*/
|
||||
var parseClipboard = function () {
|
||||
|
@ -2274,8 +2273,8 @@ H5P.createTitle = function (rawTitle, maxLength) {
|
|||
return;
|
||||
}
|
||||
|
||||
// Update file URLs
|
||||
updateFileUrls(clipboardData.specific, function (path) {
|
||||
// Update file URLs and reset content Ids
|
||||
recursiveUpdate(clipboardData.specific, function (path) {
|
||||
var isTmpFile = (path.substr(-4, 4) === '#tmp');
|
||||
if (!isTmpFile && clipboardData.contentId) {
|
||||
// Comes from existing content
|
||||
|
@ -2296,22 +2295,20 @@ H5P.createTitle = function (rawTitle, maxLength) {
|
|||
if (clipboardData.generic) {
|
||||
// Use reference instead of key
|
||||
clipboardData.generic = clipboardData.specific[clipboardData.generic];
|
||||
|
||||
// Avoid multiple content with same ID
|
||||
delete clipboardData.generic.subContentId;
|
||||
}
|
||||
|
||||
return clipboardData;
|
||||
};
|
||||
|
||||
/**
|
||||
* Update file URLs. Useful when copying content.
|
||||
* Update file URLs and reset content IDs.
|
||||
* Useful when copying content.
|
||||
*
|
||||
* @private
|
||||
* @param {object} params Reference
|
||||
* @param {function} handler Modifies the path to work when pasted
|
||||
*/
|
||||
var updateFileUrls = function (params, handler) {
|
||||
var recursiveUpdate = function (params, handler) {
|
||||
for (var prop in params) {
|
||||
if (params.hasOwnProperty(prop) && params[prop] instanceof Object) {
|
||||
var obj = params[prop];
|
||||
|
@ -2319,7 +2316,11 @@ H5P.createTitle = function (rawTitle, maxLength) {
|
|||
obj.path = handler(obj.path);
|
||||
}
|
||||
else {
|
||||
updateFileUrls(obj, handler);
|
||||
if (obj.library !== undefined && obj.subContentId !== undefined) {
|
||||
// Avoid multiple content with same ID
|
||||
delete obj.subContentId;
|
||||
}
|
||||
recursiveUpdate(obj, handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue