| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- ---
- import Layout from "../layouts/Layout.astro";
- import Taskbar from "../components/taskbar.astro";
- import App from "../components/app.astro";
- import Aboutme from "../components/aboutme.astro";
- import Redirect from "../components/redirect.astro";
- import Contact from "../components/contact.astro";
- import Projects from "../components/projects.astro";
- // Projects
- import Summize from "../components/projects/summize.astro";
- import Notion from "../components/projects/notion.astro";
- import "../styles/global.css";
- import me from "../assets/apps/me.png";
- import github from "../assets/apps/github.png";
- import pastwork from "../assets/apps/pastWork.png";
- import projects from "../assets/apps/projects.png";
- import blog from "../assets/apps/blog.png";
- import contact from "../assets/apps/contact.png";
- function dragElement(elmnt) {
- var pos1 = 0,
- pos2 = 0,
- pos3 = 0,
- pos4 = 0;
- if (document.getElementById(elmnt.id + "header")) {
- // If present, the header is where you move the DIV from:
- document.getElementById(elmnt.id + "header").onmousedown = dragMouseDown;
- document.getElementById(elmnt.id + "header").ontouchstart = dragMouseDown;
- } else {
- // Otherwise, move the DIV from anywhere inside the DIV:
- elmnt.onmousedown = dragMouseDown;
- elmnt.ontouchstart = dragMouseDown;
- }
- function dragMouseDown(e) {
- // e.preventDefault();
- raiseUpSpec(elmnt.id);
- // Get the initial touch point for touch events
- if (e.type == "touchstart") {
- pos3 = e.touches[0].clientX;
- pos4 = e.touches[0].clientY;
- } else {
- pos3 = e.clientX;
- pos4 = e.clientY;
- }
- document.onmouseup = closeDragElement;
- document.ontouchend = closeDragElement;
- document.onmousemove = elementDrag;
- document.ontouchmove = elementDrag;
- }
- function elementDrag(e) {
- // e.preventDefault();
- if (e.type == "touchmove") {
- // Calculate the new cursor position for touch
- pos1 = pos3 - e.touches[0].clientX;
- pos2 = pos4 - e.touches[0].clientY;
- pos3 = e.touches[0].clientX;
- pos4 = e.touches[0].clientY;
- } else {
- // Calculate the new cursor position for mouse
- pos1 = pos3 - e.clientX;
- pos2 = pos4 - e.clientY;
- pos3 = e.clientX;
- pos4 = e.clientY;
- }
- // Set the element's new position
- elmnt.style.top = elmnt.offsetTop - pos2 + "px";
- elmnt.style.left = elmnt.offsetLeft - pos1 + "px";
- }
- function closeDragElement() {
- // Stop moving when mouse button or touch is released
- document.onmouseup = null;
- document.ontouchend = null;
- document.onmousemove = null;
- document.ontouchmove = null;
- }
- }
- /** Raise up window with given ID */
- function raiseUpSpec(id: string) {
- console.log("raising ", id);
- let els = document.getElementsByClassName("window");
- let elArray = Array.from(els as HTMLCollectionOf<HTMLElement>);
- // find the highest z-index
- let highestIndex = 0;
- for (let element in elArray) {
- let zindex = parseInt(elArray[element].style.zIndex);
- if (zindex > highestIndex) {
- highestIndex = zindex;
- }
- }
- // set the highest z-index plus one
- document.getElementById(id).style.zIndex = (highestIndex + 1).toString();
- }
- function updateRedirectMessage() {
- const redirectElement = document.getElementById("redirect");
- const redirectUrl = redirectElement.dataset.redirecturl; // Access the data attribute
- const messageElement = redirectElement.querySelector("h2");
- messageElement.innerHTML = `You are about to be redirected to <a class="redirUrl" style=" cursor: pointer;
- color: blue;
- text-decoration: underline; " href="${redirectUrl}"">${redirectUrl.replace("https://", "")}</a>`;
- const buttonElement = redirectElement.querySelector("#okButton");
- // open redirect url
- buttonElement.setAttribute(
- "onclick",
- `window.location.href = "${redirectUrl}"`
- );
- }
- let apps: app[] = [
- {
- name: "About Me",
- logo: me.src,
- onclick: () => {
- raiseUpSpec("aboutme");
- document.getElementById("aboutme").style.display = "block";
- },
- row: 1,
- },
- {
- name: "Blog",
- logo: blog.src,
- onclick: () => {
- raiseUpSpec("redirect");
- document.getElementById("redirect").style.display = "block";
- document.getElementById("redirect").dataset.redirecturl =
- "https://blog.simo.ng/";
- updateRedirectMessage();
- },
- row: 1,
- },
- {
- name: "Projects",
- logo: projects.src,
- onclick: () => {
- raiseUpSpec("projects");
- document.getElementById("projects").style.display = "block";
- },
- row: 1,
- },
- {
- name: "Past Work",
- logo: pastwork.src,
- row: 1,
- },
- {
- name: "Github",
- logo: github.src,
- onclick: () => {
- // ignore
- raiseUpSpec("redirect");
- document.getElementById("redirect").style.display = "block";
- document.getElementById("redirect").dataset.redirecturl =
- "https://github.com/s1monlol/";
- updateRedirectMessage();
- },
- row: 2,
- },
- {
- name: "Contact",
- logo: contact.src,
- row: 2,
- onclick: () => {
- raiseUpSpec("contact");
- document.getElementById("contact").style.display = "block";
- },
- },
- ];
- let projectsArr: project[] = [
- {
- title: "Summize",
- id: "summize",
- },
- {
- title: "Notion Canvas",
- id: "notion",
- },
- {
- title: "PGPCord",
- id: "pgpcord",
- },
- ];
- const row1Items = apps.filter((item) => item.row === 1);
- const row2Items = apps.filter((item) => item.row === 2);
- let clientFunctions: Function[] | String[] = [
- raiseUpSpec,
- updateRedirectMessage,
- dragElement,
- updateRedirectMessage,
- ];
- clientFunctions = clientFunctions.map((item) => String(item));
- apps = apps.map((item) => {
- item.onclick = String(item.onclick);
- return item;
- });
- ---
- <Layout title="Simo">
- <div class="flex">
- <div class="h-80 flex flex-col items-start">
- {row1Items.map((item) => <App {item} />)}
- </div>
- <div class="h-80 flex flex-col items-start">
- {row2Items.map((item) => <App {item} />)}
- </div>
- </div>
- </Layout>
- <Aboutme />
- <Redirect />
- <Contact />
- <Taskbar />
- <Projects projects={projectsArr} />
- <!-- Projects -->
- <Summize />
- <Notion />
- <script define:vars={{ apps, projectsArr, clientFunctions }}>
- for (func in clientFunctions) {
- eval(clientFunctions[func]);
- }
- Array.from(document.getElementsByClassName("project")).forEach((project) => {
- console.log(projectsArr[0].id + "item");
- let id = projectsArr.find((i) => i.id + "item" == project.id).id;
- console.log(id);
- if (id == "pgpcord") {
- project.onclick = () => {
- setTimeout(() => {
- raiseUpSpec("redirect");
- document.getElementById("redirect").style.display = "block";
- document.getElementById("redirect").dataset.redirecturl =
- "https://blog.simo.ng/articles/WIP/pgpcord";
- updateRedirectMessage();
- }, 1);
- };
- return;
- }
- project.onclick = () => {
- setTimeout(() => {
- document.getElementById(id).style.display = "block";
- raiseUpSpec(id);
- console.log("test");
- }, 1);
- };
- });
- Array.from(document.getElementsByClassName("window")).forEach((window) => {
- dragElement(window);
- window.addEventListener("click", () => {
- raiseUpSpec(window.id);
- });
- Array.from(document.querySelectorAll(".projectwindow a")).forEach(
- (link) => {
- link.addEventListener("click", (e) => {
- document.getElementById("redirect").style.display = "block";
- document.getElementById("redirect").dataset.redirecturl = link.href;
- updateRedirectMessage();
- e.preventDefault();
- setTimeout(() => {
- raiseUpSpec("redirect");
- }, 1);
- return false;
- });
- }
- );
- Array.from(window.getElementsByClassName("close")).forEach((button) => {
- button.addEventListener("click", () => {
- window.style.display = "none";
- });
- });
- });
- apps.forEach((app) => {
- let itemName = app.name.replace(" ", "");
- // console.info(document.getElementById(app.name));
- if (app.onclick == "undefined") {
- return;
- }
- document.getElementById(itemName).addEventListener("click", () => {
- const appFunc = eval(app.onclick);
- appFunc();
- });
- });
- </script>
|