Skip to content
Myr

custom.js

This file

Path

docs/js/custom.js

105 lines · 3.8 KiB · JavaScript

Last changed by

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

History of this file

Take it

The walk stopped after 200 commits: lines older than 46984fc point at it.

:bookmark: Release version 0.1.0Sebastián Ramírezbefore adoption46984fc

lines 1–14why, one step back
1document.querySelectorAll(".use-termynal").forEach(node => {
2 node.style.display = "block";3 new Termynal(node, {4 lineDelay: 5005 });6});7const progressLiteralStart = "---> 100%";8const promptLiteralStart = "$ ";9const customPromptLiteralStart = "# ";10const termynalActivateClass = "termy";11let termynals = [];1213function createTermynals() {14 document

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

line 15why, one step back
15 .querySelectorAll(`.${termynalActivateClass} .highlight`)

:bookmark: Release version 0.1.0Sebastián Ramírezbefore adoption46984fc

lines 16–105why, one step back
16 .forEach(node => {
17 const text = node.textContent;18 const lines = text.split("\n");19 const useLines = [];20 let buffer = [];21 function saveBuffer() {22 if (buffer.length) {23 let isBlankSpace = true;24 buffer.forEach(line => {25 if (line) {26 isBlankSpace = false;27 }28 });29 dataValue = {};30 if (isBlankSpace) {31 dataValue["delay"] = 0;32 }33 if (buffer[buffer.length - 1] === "") {34 // A last single <br> won't have effect35 // so put an additional one36 buffer.push("");37 }38 const bufferValue = buffer.join("<br>");39 dataValue["value"] = bufferValue;40 useLines.push(dataValue);41 buffer = [];42 }43 }44 for (let line of lines) {45 if (line === progressLiteralStart) {46 saveBuffer();47 useLines.push({48 type: "progress"49 });50 } else if (line.startsWith(promptLiteralStart)) {51 saveBuffer();52 const value = line.replace(promptLiteralStart, "").trimEnd();53 useLines.push({54 type: "input",55 value: value56 });57 } else if (line.startsWith("// ")) {58 saveBuffer();59 const value = "💬 " + line.replace("// ", "").trimEnd();60 useLines.push({61 value: value,62 class: "termynal-comment",63 delay: 064 });65 } else if (line.startsWith(customPromptLiteralStart)) {66 saveBuffer();67 const promptStart = line.indexOf(promptLiteralStart);68 if (promptStart === -1) {69 console.error("Custom prompt found but no end delimiter", line)70 }71 const prompt = line.slice(0, promptStart).replace(customPromptLiteralStart, "")72 let value = line.slice(promptStart + promptLiteralStart.length);73 useLines.push({74 type: "input",75 value: value,76 prompt: prompt77 });78 } else {79 buffer.push(line);80 }81 }82 saveBuffer();83 const div = document.createElement("div");84 node.replaceWith(div);85 const termynal = new Termynal(div, {86 lineData: useLines,87 noInit: true,88 lineDelay: 50089 });90 termynals.push(termynal);91 });92}9394function loadVisibleTermynals() {95 termynals = termynals.filter(termynal => {96 if (termynal.container.getBoundingClientRect().top - innerHeight <= 0) {97 termynal.init();98 return false;99 }100 return true;101 });102}103window.addEventListener("scroll", loadVisibleTermynals);104createTermynals();105loadVisibleTermynals();