Skip to content

Commit c0ef72e

Browse files
committed
Fix clipboard for empty browser cache (artefactual#1783)
Set browser local storage values for clipboard if their corresponding variables are null on load, which happens if the browser storage is cleared.
1 parent 3b39ae1 commit c0ef72e

File tree

2 files changed

+11
-31
lines changed

2 files changed

+11
-31
lines changed

Diff for: js/clipboard.js

+3-14
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,8 @@
1212
this.storage = localStorage;
1313
this.types = ['informationObject', 'actor', 'repository'];
1414
this.initialItems = {'informationObject': [], 'actor': [], 'repository': []};
15-
this.items = JSON.parse(this.storage.getItem('clipboard'));
16-
this.exportTokens = JSON.parse(this.storage.getItem('exportTokens'));
17-
18-
if (!this.items)
19-
{
20-
this.items = this.initialItems;
21-
}
22-
23-
if (!this.exportTokens)
24-
{
25-
this.exportTokens = [];
26-
}
27-
15+
this.items = JSON.parse(this.storage.getItem('clipboard')) || this.initialItems;
16+
this.exportTokens = JSON.parse(this.storage.getItem('exportTokens')) || [];
2817
this.init();
2918
};
3019

@@ -344,7 +333,7 @@
344333

345334
// Load items from local storage in case activity
346335
// in another tab has changed the content
347-
this.items = JSON.parse(this.storage.getItem("clipboard"));
336+
this.items = JSON.parse(this.storage.getItem("clipboard")) || this.initialItems;
348337

349338
var type = $button.data('clipboard-type');
350339
var slug = $button.data('clipboard-slug');

Diff for: plugins/arDominionB5Plugin/js/clipboard.js

+8-17
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,11 @@ import Tooltip from "bootstrap/js/dist/tooltip";
1111

1212
this.storage = localStorage;
1313
this.types = ["informationObject", "actor", "repository"];
14-
this.initialItems = JSON.stringify({
15-
informationObject: [],
16-
actor: [],
17-
repository: [],
18-
});
19-
this.items = JSON.parse(this.storage.getItem("clipboard"));
20-
this.exportTokens = JSON.parse(this.storage.getItem("exportTokens"));
21-
22-
if (!this.items) {
23-
this.items = JSON.parse(this.initialItems);
24-
}
25-
26-
if (!this.exportTokens) {
27-
this.exportTokens = [];
28-
}
14+
this.initialItems = { informationObject: [], actor: [], repository: [] };
15+
this.items =
16+
JSON.parse(this.storage.getItem("clipboard")) || this.initialItems;
17+
this.exportTokens =
18+
JSON.parse(this.storage.getItem("exportTokens")) || [];
2919

3020
this.init();
3121
}
@@ -335,7 +325,8 @@ import Tooltip from "bootstrap/js/dist/tooltip";
335325

336326
// Load items from local storage in case activity
337327
// in another tab has changed the content
338-
this.items = JSON.parse(this.storage.getItem("clipboard"));
328+
this.items =
329+
JSON.parse(this.storage.getItem("clipboard")) || this.initialItems;
339330

340331
var $button = $(event.target).closest("button");
341332
var type = $button.data("clipboard-type");
@@ -375,7 +366,7 @@ import Tooltip from "bootstrap/js/dist/tooltip";
375366
if (type && this.types.includes(type)) {
376367
this.items[type] = [];
377368
} else {
378-
this.items = JSON.parse(this.initialItems);
369+
this.items = this.initialItems;
379370
}
380371

381372
this.storage.setItem("clipboard", JSON.stringify(this.items));

0 commit comments

Comments
 (0)