Skip to content

Commit

Permalink
Merge pull request #39 from oss-slu/rerum-js-files
Browse files Browse the repository at this point in the history
Issue #35 - Consolidate JS
  • Loading branch information
alar12 authored Nov 7, 2024
2 parents 3c6886d + eb32b75 commit eeea8bd
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 199 deletions.
29 changes: 3 additions & 26 deletions web/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<title>About | Rerum Playground</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="./js/playground.js" type="module"></script>
<script src="./js/about.js"></script>
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="https://unpkg.com/chota@latest">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
Expand Down Expand Up @@ -47,13 +49,7 @@
</head>

<body>
<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>
<div id="menu-placeholder"></div>

<header>
<div class="header">
Expand Down Expand Up @@ -114,24 +110,5 @@ <h2>What is a JSON Manifest?</h2>
</div>

<div id="footer-placeholder"></div>

<script src="./js/playground.js" type="module"></script>

<script>
function openCloseMenu() {
var toolBar = document.getElementById("toolBar");
var mainContent = document.querySelector(".content") || document.querySelector(".container") || document.querySelector("#tool_set");
toolBar.classList.toggle("sidebar-open");
if (mainContent) {
mainContent.classList.toggle("shift");
}
}
fetch('footer.html')
.then(response => response.text())
.then(data => {
document.getElementById('footer-placeholder').innerHTML = data;
})
.catch(error => console.error('Error loading footer:', error));
</script>
</body>
</html>
32 changes: 3 additions & 29 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<title>Rerum Playground</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="./js/index.js"></script>
<script src="./js/playground.js" type="module"></script>
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="https://unpkg.com/chota@latest">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
Expand Down Expand Up @@ -52,15 +54,7 @@
</head>

<body>
<!--Sidebar page links. Still needs styles above.-->
<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>

<div id="menu-placeholder"></div>
<header>
<div class = "header">
<div class = "row">
Expand All @@ -86,25 +80,5 @@ <h2>Welcome to the RERUM Playground</h2>
</div>

<div id="footer-placeholder"></div>

<script src="./js/playground.js" type="module"></script>

<!--Function to open and close sidebar menu by changing its width. Needs work.-->
<script>
function openCloseMenu() {
var toolBar = document.getElementById("toolBar");
var mainContent = document.querySelector(".content") || document.querySelector(".container") || document.querySelector("#tool_set");
toolBar.classList.toggle("sidebar-open");
if (mainContent) {
mainContent.classList.toggle("shift");
}
}
fetch('footer.html')
.then(response => response.text())
.then(data => {
document.getElementById('footer-placeholder').innerHTML = data;
})
.catch(error => console.error('Error loading footer:', error));
</script>
</body>
</html>
28 changes: 28 additions & 0 deletions web/js/playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,31 @@ document.addEventListener('DOMContentLoaded', () => {
console.error("Error initializing the playground: ", err);
}
});

//fetch footer
fetch('footer.html')
.then(response => response.text())
.then(data => {
document.getElementById('footer-placeholder').innerHTML = data;
})
.catch(error => console.error('Error loading footer:', error));

//fetch menu
fetch('menu.html')
.then(response => response.text())
.then(data => {
document.getElementById('menu-placeholder').innerHTML = data;
})
.catch(error => console.error('Error loading menu:', error));

//menubar js
function openCloseMenu() {
var toolBar = document.getElementById("toolBar");
var mainContent = document.querySelector(".content") || document.querySelector(".container") || document.querySelector("#tool_set");
toolBar.classList.toggle("sidebar-open");
if (mainContent) {
mainContent.classList.toggle("shift");
}
}

window.openCloseMenu = openCloseMenu;
113 changes: 113 additions & 0 deletions web/js/tool.js
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} &nbsp;&nbsp;&nbsp;&nbsp; ${manifestType} &nbsp;&nbsp;&nbsp;&nbsp; ${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();
};
7 changes: 7 additions & 0 deletions web/menu.html
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>
Loading

0 comments on commit eeea8bd

Please sign in to comment.