forked from CenterForDigitalHumanities/rerum-playground
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from oss-slu/rerum-js-files
Issue #35 - Consolidate JS
- Loading branch information
Showing
6 changed files
with
157 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Import the function for storing manifest links | ||
import { storeManifestLink } from './manifestStorage.js'; | ||
|
||
// Wait until the DOM is fully loaded | ||
document.addEventListener('DOMContentLoaded', function() { | ||
const manifestUrl = document.getElementById('manifestUrl'); | ||
const loadManifest = document.getElementById('loadManifest'); | ||
const manifestMessage = document.getElementById('manifestMessage'); | ||
const loadMessage = document.getElementById("loadMessage"); | ||
const manifestLabelField = document.getElementById("manifestLabelField"); | ||
const loadingOverlay = document.querySelector('.loading-overlay'); | ||
|
||
// Function to show loading overlay | ||
function showLoading() { | ||
loadingOverlay.style.display = 'flex'; | ||
manifestMessage.textContent = ''; | ||
} | ||
|
||
// Function to hide loading overlay | ||
function hideLoading() { | ||
loadingOverlay.style.display = 'none'; | ||
} | ||
|
||
// Event listener for loading manifest | ||
loadManifest.addEventListener('click', async function() { | ||
const url = manifestUrl.value.trim(); | ||
if (!url) { | ||
manifestMessage.textContent = 'Please enter a URL.'; | ||
manifestMessage.style.color = 'red'; | ||
return; | ||
} | ||
|
||
showLoading(); | ||
|
||
try { | ||
const response = await fetch(url); | ||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`); | ||
} | ||
const data = await response.json(); | ||
|
||
hideLoading(); | ||
manifestMessage.textContent = 'Manifest loaded successfully!'; | ||
manifestMessage.style.color = 'green'; | ||
|
||
storeManifestLink(url); | ||
|
||
try { | ||
let manifestLabel = `Name: ${data.label.en[0]}`; | ||
let manifestType = `Type: ${data.type}`; | ||
let manifestItemCount = `Number of Items: ${data.items.length}`; | ||
|
||
loadMessage.innerHTML = "<u>Current Object:</u>"; | ||
manifestLabelField.innerHTML = `${manifestLabel} ${manifestType} ${manifestItemCount}`; | ||
} catch (metadataError) { | ||
loadMessage.innerHTML = "No metadata available!"; | ||
manifestLabelField.innerHTML = ""; | ||
} | ||
} catch (error) { | ||
hideLoading(); | ||
manifestMessage.textContent = 'Failed to load manifest. Please check the URL and try again.'; | ||
manifestMessage.style.color = 'red'; | ||
console.error('Error:', error); | ||
} | ||
}); | ||
}); | ||
|
||
// Toggle dropdown function, defined outside of DOMContentLoaded to ensure it's globally accessible | ||
function toggleDropdown() { | ||
const manifestContainer = document.getElementById('stored_manifest_links'); | ||
const dropdownArrow = document.getElementById('dropdownArrow'); | ||
|
||
if (manifestContainer.style.display === 'none' || manifestContainer.style.display === '') { | ||
manifestContainer.style.display = 'block'; | ||
dropdownArrow.textContent = '▲'; | ||
} else { | ||
manifestContainer.style.display = 'none'; | ||
dropdownArrow.textContent = '▼'; | ||
} | ||
} | ||
|
||
document.getElementById('dropdownLabel').addEventListener('click', toggleDropdown); | ||
document.getElementById('dropdownArrow').addEventListener('click', toggleDropdown); | ||
|
||
function renderStoredManifests() { | ||
const manifestContainer = document.getElementById('stored_manifest_links'); | ||
const storedManifests = getStoredManifestLinks(); | ||
|
||
if (!manifestContainer) { | ||
console.error("Manifest container not found."); | ||
return; | ||
} | ||
|
||
manifestContainer.innerHTML = ''; | ||
|
||
if (storedManifests.length === 0) { | ||
manifestContainer.innerHTML = '<p>No stored manifest links.</p>'; | ||
return; | ||
} | ||
|
||
storedManifests.forEach(manifestLink => { | ||
const manifestHTML = ` | ||
<a href="${manifestLink}" target="_blank" class="manifestLink"> | ||
<p>${manifestLink}</p> | ||
</a> | ||
`; | ||
manifestContainer.innerHTML += manifestHTML; | ||
}); | ||
} | ||
|
||
window.onload = function() { | ||
renderStoredManifests(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<div id="toolBar" class="sidebar"> | ||
<a href="index.html">Home</a> | ||
<a href="about.html">About</a> | ||
<a href="#">Contribute</a> | ||
<a href="#">Contact</a> | ||
<a href="tools.html">Tools</a> | ||
</div> |
Oops, something went wrong.