admin-portal/tech/tabs/01-deploy/07_javascript.js
Frederico Falcao f2a6525224 init
2025-05-30 10:46:17 +01:00

47 lines
1.8 KiB
JavaScript

//
// FILE: 07_javascript.js
// Description: the javascript code that will be added to the website
document.addEventListener('DOMContentLoaded', function() {
var commitInfoModal = document.getElementById('commitInfoModal');
if (commitInfoModal) {
commitInfoModal.addEventListener('show.bs.modal', function (event) {
var button = event.relatedTarget;
var hash = button.getAttribute('data-commit-hash');
var modalBody = document.getElementById('commitModalBody');
modalBody.innerHTML = `<div class="text-center text-muted p-5">
<div class="spinner-border"></div>
<div>Loading…</div>
</div>`;
fetch('get_commit_info.php?hash=' + encodeURIComponent(hash))
.then(resp => resp.text())
.then(html => { modalBody.innerHTML = html; })
.catch(() => {
modalBody.innerHTML = '<div class="alert alert-danger">Failed to load commit info.</div>';
});
});
}
});
document.addEventListener('DOMContentLoaded', function () {
const usernameInput = document.querySelector('input[name="username"]');
const repoInput = document.querySelector('input[name="repo"]');
const hashInput = document.querySelector('input[name="hash"]');
const urlPreview = document.getElementById('github_url_zip');
function updateUrl() {
const username = usernameInput.value.trim() || 'USERNAME';
const repo = repoInput.value.trim() || 'REPO';
const hash = hashInput.value.trim() || 'HASH';
const url = `https://github.com/${username}/${repo}/archive/${hash}.zip`;
urlPreview.innerHTML = `<a href="${url}" target="_blank"><code>${url}</code></a>`;
}
[usernameInput, repoInput, hashInput].forEach(input => {
input.addEventListener('input', updateUrl);
});
updateUrl(); // Run once on load
});