refactor: make styles, js common for posts
This commit is contained in:
parent
3865436f75
commit
2a8c3194d1
7 changed files with 143 additions and 87 deletions
30
scripts/common.js
Normal file
30
scripts/common.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
const TERMINAL_PROMPT = "barrett@ruth:~$ ";
|
||||
let clearing = false;
|
||||
|
||||
function clearPrompt(delay, callback) {
|
||||
if (clearing) return;
|
||||
clearing = true;
|
||||
|
||||
const terminalPrompt = document.querySelector(".terminal-prompt");
|
||||
const topicLength = terminalPrompt.innerHTML.length - TERMINAL_PROMPT.length;
|
||||
let i = 0;
|
||||
|
||||
function removeChar() {
|
||||
if (i++ < topicLength) {
|
||||
terminalPrompt.textContent = terminalPrompt.textContent.slice(0, -1);
|
||||
setTimeout(removeChar, delay / topicLength);
|
||||
} else {
|
||||
i = 0;
|
||||
clearing = false;
|
||||
callback && callback();
|
||||
}
|
||||
}
|
||||
|
||||
removeChar();
|
||||
}
|
||||
|
||||
function goHome(e) {
|
||||
e.preventDefault();
|
||||
|
||||
clearPrompt(500, () => (window.location.href = "/"));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue