From f19ca764619f8e27f44844bbf5cca0db5cc79602 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Thu, 3 Jan 2019 12:46:16 +0100 Subject: [PATCH] HFP-2508 Fix reset of all subContentIds on Copy/Paste --- js/h5p.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/js/h5p.js b/js/h5p.js index eb685c5..bbca97f 100644 --- a/js/h5p.js +++ b/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); } } }