-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
34 lines (29 loc) · 1.09 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
This is your site JavaScript code - you can add interactivity!
*/
// Print a message in the browser's dev tools console each time the page loads
// Use your menus or right-click / control-click and choose "Inspect" > "Console"
console.log("Hello 🌎");
/*
Make the "Click me!" button move when the visitor clicks it:
- First add the button to the page by following the steps in the TODO 🚧
*/
const btn = document.querySelector("button"); // Get the button from the page
if (btn) { // Detect clicks on the button
btn.onclick = function () {
// The 'dipped' class in style.css changes the appearance on click
btn.classList.toggle("dipped");
};
}
// ----- GLITCH STARTER PROJECT HELPER CODE -----
// Open file when the link in the preview is clicked
let goto = (file, line) => {
window.parent.postMessage(
{ type: "glitch/go-to-line", payload: { filePath: file, line: line } }, "*"
);
};
// Get the file opening button from its class name
const filer = document.querySelectorAll(".fileopener");
filer.forEach((f) => {
f.onclick = () => { goto(f.dataset.file, f.dataset.line); };
});