Skip to content

Commit

Permalink
chore: Add support for collections for start:dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Conrad Chan committed Jun 3, 2021
1 parent cad6bee commit dc86eff
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@
<button onClick="setProperty('fileid')" data-testid="fileid-set">Set new file ID</button>
</div>

<div class="container" id="collection">
<div>Collection: <span id="collection-display"></span></div>
<input id="collection-set" data-testid="collection" placeholder="Enter list of file ids" />
<button onClick="setProperty('collection')" data-testid="collection-set">Set new collection</button>
<button onClick="clearProperty('collection')" data-testid="collection-clear">Clear</button>
<div>Enter 2+ comma separated list of file ids</div>
</div>

<div class="container" id="load">
<button onClick="loadPreview()" data-testid="load-preview">Load Preview</button>
</div>
Expand All @@ -67,6 +75,14 @@
/* global Box */
preview = new Box.Preview();

function clearProperty(selector) {
var inputEl = document.getElementById(selector + '-set');
var displayEl = document.getElementById(selector + '-display');
inputEl.value = '';
displayEl.textContent = '';
localStorage.setItem(selector, '');
}

function setProperty(selector) {
// Get new value, fallback to local storage
var inputValue = document.querySelector('#' + selector + '-set');
Expand All @@ -87,12 +103,20 @@
function loadPreview(options) {
var token = localStorage.getItem('token');
var fileid = localStorage.getItem('fileid');
var fileidList = localStorage.getItem('collection') || '';

if (!token || !fileid) {
return;
}

var collection =
fileidList &&
fileidList.split(',').map(function(fileid) {
return fileid.trim();
});

var previewOptions = options || {
collection,
enableThumbnailsSidebar: true,
showAnnotations: true,
showDownload: true,
Expand All @@ -105,6 +129,7 @@
// Try to load all properties from storage on page load
setProperty('token');
setProperty('fileid');
setProperty('collection');
loadPreview();
</script>
</body>
Expand Down

0 comments on commit dc86eff

Please sign in to comment.