Add site specific prefix to localStorage item identifier
Required for multisite instances on the same domainpull/81/head
parent
a2849c8367
commit
4153b4cae3
19
js/h5p.js
19
js/h5p.js
|
@ -2398,7 +2398,7 @@ H5P.createTitle = function (rawTitle, maxLength) {
|
||||||
*/
|
*/
|
||||||
if (preloadedData && preloadedData[subContentId] && preloadedData[subContentId][dataId] === '{}') {
|
if (preloadedData && preloadedData[subContentId] && preloadedData[subContentId][dataId] === '{}') {
|
||||||
if (H5PIntegration.saveContentStorages && H5PIntegration.saveContentStorages.localStorage && H5P.localStorageSupported) {
|
if (H5PIntegration.saveContentStorages && H5PIntegration.saveContentStorages.localStorage && H5P.localStorageSupported) {
|
||||||
const localStorageData = window.localStorage.getItem('H5P-cid-' + contentId + '-sid-' + subContentId);
|
const localStorageData = window.localStorage.getItem(H5P.getLocalStoragePrefix() + 'H5P-cid-' + contentId + '-sid-' + subContentId);
|
||||||
if (localStorageData) {
|
if (localStorageData) {
|
||||||
let data = {};
|
let data = {};
|
||||||
|
|
||||||
|
@ -2541,7 +2541,7 @@ H5P.createTitle = function (rawTitle, maxLength) {
|
||||||
) {
|
) {
|
||||||
// Add checksum of params to detect changes for resetting localStorage
|
// Add checksum of params to detect changes for resetting localStorage
|
||||||
window.localStorage.setItem(
|
window.localStorage.setItem(
|
||||||
'H5P-cid-' + contentId + '-sid-' + options.subContentId,
|
H5P.getLocalStoragePrefix() + 'H5P-cid-' + contentId + '-sid-' + options.subContentId,
|
||||||
'{"checksum":' + H5P.getNumericalHash(content.jsonContent) + ',"state":' + data + '}'
|
'{"checksum":' + H5P.getNumericalHash(content.jsonContent) + ',"state":' + data + '}'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -2573,7 +2573,7 @@ H5P.createTitle = function (rawTitle, maxLength) {
|
||||||
contentUserDataAjax(contentId, dataId, subContentId, function (error) {
|
contentUserDataAjax(contentId, dataId, subContentId, function (error) {
|
||||||
// When done deleting user data in DB, delete in localStorage
|
// When done deleting user data in DB, delete in localStorage
|
||||||
if ((!error || error === 'Not signed in.') && H5P.localStorageSupported) {
|
if ((!error || error === 'Not signed in.') && H5P.localStorageSupported) {
|
||||||
window.localStorage.removeItem('H5P-cid-' + contentId + '-sid-' + subContentId);
|
window.localStorage.removeItem(H5P.getLocalStoragePrefix() + 'H5P-cid-' + contentId + '-sid-' + subContentId);
|
||||||
}
|
}
|
||||||
}, null);
|
}, null);
|
||||||
};
|
};
|
||||||
|
@ -2695,6 +2695,19 @@ H5P.createTitle = function (rawTitle, maxLength) {
|
||||||
}, 0);
|
}, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get prefix for localStorage. Relevant for multiple instances on same domain.
|
||||||
|
*
|
||||||
|
* @return {string} Prefix for localStorage.
|
||||||
|
*/
|
||||||
|
H5P.getLocalStoragePrefix = function () {
|
||||||
|
if (!H5PIntegration.saveContentStorages || !H5PIntegration.saveContentStorages.localStorage || typeof(H5PIntegration.saveContentStorages.localStorage) !== 'string') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return H5PIntegration.saveContentStorages.localStorage;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get config for a library
|
* Get config for a library
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue