Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/4.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
dew326 committed Dec 6, 2024
2 parents f43a1a4 + f63ea6c commit 514e945
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/bundle/Resources/encore/ibexa.js.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const layout = [
path.resolve(__dirname, '../public/js/scripts/core/date.time.picker.js'),
path.resolve(__dirname, '../public/js/scripts/core/taggify.js'),
path.resolve(__dirname, '../public/js/scripts/core/suggestion.taggify.js'),
path.resolve(__dirname, '../public/js/scripts/core/storage.js'),
path.resolve(__dirname, '../public/js/scripts/adaptive.filters.js'),
path.resolve(__dirname, '../public/js/scripts/admin.notifications.js'),
path.resolve(__dirname, '../public/js/scripts/button.trigger.js'),
Expand Down
45 changes: 45 additions & 0 deletions src/bundle/Resources/public/js/scripts/core/storage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
(function (global, doc, ibexa) {
class IbexaStorage {
constructor(config) {
const keySuffix = config.isUserAware ? `:${ibexa.helpers.user.getId()}` : '';

this.key = `${config.key}${keySuffix}`;
this.eventName = config.eventName;
}

setItem(data) {
const stringifiedData = JSON.stringify(data);

global.localStorage.setItem(this.key, stringifiedData);

this.fireStorageChangeEvent(stringifiedData);
}

getItem() {
return JSON.parse(global.localStorage.getItem(this.key));
}

fireStorageChangeEvent(data) {
if (this.eventName) {
const storageChangeEvent = new CustomEvent(this.eventName, {
cancelable: true,
detail: { content: JSON.parse(data) },
});

doc.body.dispatchEvent(storageChangeEvent);
}
}

init() {
if (this.eventName) {
global.addEventListener('storage', (event) => {
if (event.key === this.key) {
this.fireStorageChangeEvent(event.newValue);
}
});
}
}
}

ibexa.addConfig('core.Storage', IbexaStorage);
})(window, window.document, window.ibexa);

0 comments on commit 514e945

Please sign in to comment.