-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e5fe84
commit 6662305
Showing
3 changed files
with
175 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,65 @@ | ||
addButtonListeners(); | ||
{ | ||
const faqLastUpdatedElement = document.getElementById('last-updated'); | ||
if(faqLastUpdatedElement !== undefined) { | ||
// fetch github api to get date of last edit of FAQ | ||
fetch('https://api.github.com/repos/techmino-hub/techmino-hub.github.io/commits?path=faq.html') | ||
.then(response => response.json()) | ||
.then(json => { | ||
const lastUpdated = new Date(json[0].commit.committer.date); | ||
const currentDate = new Date(); | ||
const timeDifference = currentDate - lastUpdated; | ||
let formattedDate; | ||
|
||
const faqLastUpdatedElement = document.getElementById('last-updated'); | ||
if(faqLastUpdatedElement !== undefined) { | ||
// fetch github api to get date of last edit of FAQ | ||
fetch('https://api.github.com/repos/techmino-hub/techmino-hub.github.io/commits?path=faq.html') | ||
.then(response => response.json()) | ||
.then(json => { | ||
const lastUpdated = new Date(json[0].commit.committer.date); | ||
const currentDate = new Date(); | ||
const timeDifference = currentDate - lastUpdated; | ||
let formattedDate; | ||
if (timeDifference < 60 * 60 * 1000) { | ||
const minutes = Math.floor(timeDifference / (60 * 1000)); | ||
formattedDate = `${minutes} minutes ago`; | ||
} else if (timeDifference < 24 * 60 * 60 * 1000) { | ||
const hours = Math.floor(timeDifference / (60 * 60 * 1000)); | ||
formattedDate = `${hours} hours ago`; | ||
} else { | ||
formattedDate = lastUpdated.toLocaleDateString('en-US', { | ||
year: "numeric", | ||
month: "long", | ||
day: "numeric" | ||
}) | ||
} | ||
|
||
if (timeDifference < 60 * 60 * 1000) { | ||
const minutes = Math.floor(timeDifference / (60 * 1000)); | ||
formattedDate = `${minutes} minutes ago`; | ||
} else if (timeDifference < 24 * 60 * 60 * 1000) { | ||
const hours = Math.floor(timeDifference / (60 * 60 * 1000)); | ||
formattedDate = `${hours} hours ago`; | ||
} else { | ||
formattedDate = lastUpdated.toLocaleDateString('en-US', { | ||
year: "numeric", | ||
month: "long", | ||
day: "numeric" | ||
}) | ||
} | ||
|
||
faqLastUpdatedElement.innerText = "Last updated: " + formattedDate; | ||
}); | ||
} | ||
|
||
function addFAQEntries(faqObject) { | ||
faqObject.forEach(entry => { | ||
faqSection.innerHTML += faqHTML(entry); | ||
}); | ||
|
||
addButtonListeners(); | ||
} | ||
faqLastUpdatedElement.innerText = "Last updated: " + formattedDate; | ||
}); | ||
} | ||
|
||
function addButtonListeners() { | ||
// Add button listeners | ||
const questionHeaders = document.getElementsByClassName('question-header'); | ||
for(let i = 0; i < questionHeaders.length; i++) { | ||
questionHeaders[i].addEventListener('click', () => { | ||
questionHeaders[i].parentElement.classList.toggle('expanded'); | ||
}); | ||
} | ||
} | ||
|
||
function faqHTML(entry) { | ||
return `<div class="question"> | ||
<button class="question-header"> | ||
<div class="question-icon-container"> | ||
<svg class="question-icon" viewBox="0 0 24 24"> | ||
<path fill="currentColor" d="M7 14l5-5 5 5z"></path> | ||
</svg> | ||
</div> | ||
<h2 class="question-title">${entry.question}</h2> | ||
</button> | ||
<div class="answer"> | ||
${entry.answerHTML} | ||
<div class="answer-source">— ${entry.author}</div> | ||
</div> | ||
</div>`; | ||
// Add radio listeners | ||
for(const radioElement of document.getElementsByClassName('tag-filter')[0].getElementsByTagName('input')) { | ||
radioElement.addEventListener('change', () => { | ||
handleFilterUpdate(radioElement.name, radioElement.value); | ||
}); | ||
} | ||
|
||
function handleFilterUpdate(tag, mode) { | ||
tag = tag.trim().toLowerCase(); | ||
mode = mode.trim().toLowerCase(); | ||
|
||
const faqElement = document.getElementsByClassName('faq')[0]; | ||
|
||
if(mode === "all") { | ||
faqElement.classList.remove(`show-${tag}`); | ||
faqElement.classList.remove(`hide-${tag}`); | ||
} else if(mode === "include") { | ||
faqElement.classList.remove(`hide-${tag}`); | ||
faqElement.classList.add(`show-${tag}`); | ||
} else if(mode === "exclude") { | ||
faqElement.classList.remove(`show-${tag}`); | ||
faqElement.classList.add(`hide-${tag}`); | ||
} else { | ||
console.error(`Invalid filter mode: ${mode}`); | ||
} | ||
} | ||
} |
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