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.
pull/52/head
Oliver Tacke 2018-07-18 10:45:14 +02:00
parent a295d7d434
commit 9ee5fb9907
1 changed files with 18 additions and 10 deletions

View File

@ -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.