From 9ee5fb99078b3beb1cc98cf291c3569df9ec5caf Mon Sep 17 00:00:00 2001 From: Oliver Tacke Date: Wed, 18 Jul 2018 10:45:14 +0200 Subject: [PATCH] HFP-2110 Refactor to have a plain setClipboard function Custom editors handled storing data to the clipboard on their own, so the datainclipboard trigger was missing for some functionality. H5P.clipboardify() however doesn't cope with additional information that the custom editors can deal with. Custom editors that prepare their own clipboard data can now use H5P.setClipboard() directly and set their data while other elements will be informed about the clipboard change. Also relevant for HFP-2111 and HFP-2112. --- js/h5p.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/js/h5p.js b/js/h5p.js index 1c73e70..a5bc3c5 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -2166,7 +2166,7 @@ H5P.createTitle = function (rawTitle, maxLength) { self.width = 20; // % self.height = (params.params.file.height / params.params.file.width) * self.width; - } + }; if (!genericProperty) { genericProperty = 'action'; @@ -2202,14 +2202,7 @@ H5P.createTitle = function (rawTitle, maxLength) { if (!(clipboardItem instanceof H5P.ClipboardItem)) { clipboardItem = new H5P.ClipboardItem(clipboardItem); } - - localStorage.setItem('h5pClipboard', JSON.stringify(clipboardItem)); - - // Clear cache - parsedClipboard = null; - - // Trigger an event so all 'Paste' buttons may be enabled. - H5P.externalDispatcher.trigger('datainclipboard', {reset: false}); + H5P.setClipboard(clipboardItem); }; /** @@ -2229,7 +2222,22 @@ H5P.createTitle = function (rawTitle, maxLength) { } return parsedClipboard; - } + }; + + /** + * Set item in the H5P Clipboard. + * + * @param {H5P.ClipboardItem|object} clipboardItem - Data to be set. + */ + H5P.setClipboard = function (clipboardItem) { + localStorage.setItem('h5pClipboard', JSON.stringify(clipboardItem)); + + // Clear cache + parsedClipboard = null; + + // Trigger an event so all 'Paste' buttons may be enabled. + H5P.externalDispatcher.trigger('datainclipboard', {reset: false}); + }; /** * Get item from the H5P Clipboard.