Skip to content

Commit e638deb

Browse files
committed
js
1 parent e6e21b0 commit e638deb

File tree

2 files changed

+194
-1
lines changed

2 files changed

+194
-1
lines changed

config/page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<link rel="stylesheet" href="/skupper-docs/main.css"/>
1111
<link rel="icon" type="image/png" sizes="32x32" href="/images/skupper-icon-32.png"/>
1212
<link rel="icon" type="image/png" sizes="256x256" href="/images/skupper-icon-256.png"/>
13-
<script type="text/javascript" src="/main.js" defer="defer"></script>
13+
<script type="text/javascript" src="/skupper-docs/main.js" defer="defer"></script>
1414

1515
{{page.extra_headers}}
1616

input/main.js

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
const $ = document.querySelector.bind(document);
19+
const $$ = document.querySelectorAll.bind(document);
20+
21+
Element.prototype.$ = function () {
22+
return this.querySelector.apply(this, arguments);
23+
};
24+
25+
Element.prototype.$$ = function () {
26+
return this.querySelectorAll.apply(this, arguments);
27+
};
28+
29+
// window.addEventListener("load", () => {
30+
// const oldToc = $("#-toc");
31+
32+
// if (!oldToc) {
33+
// return;
34+
// }
35+
36+
// const headings = $$("h2");
37+
38+
// if (headings.length == 0) {
39+
// oldToc.remove();
40+
// return;
41+
// }
42+
43+
// const newToc = document.createElement("section");
44+
// const newTocHeading = document.createElement("h4");
45+
// const newTocHeadingText = document.createTextNode("Contents");
46+
47+
// newTocHeading.appendChild(newTocHeadingText);
48+
// newToc.appendChild(newTocHeading);
49+
// newToc.setAttribute("id", "-toc");
50+
51+
// const newTocLinks = document.createElement("nav");
52+
53+
// const topLink = document.createElement("a");
54+
// const topText = document.createTextNode("Top");
55+
56+
// topLink.setAttribute("href", "#");
57+
// topLink.appendChild(topText);
58+
59+
// newTocLinks.appendChild(topLink);
60+
61+
// for (const heading of headings) {
62+
// const link = document.createElement("a");
63+
// const text = document.createTextNode(heading.textContent);
64+
65+
// link.setAttribute("href", `#${heading.id}`);
66+
// link.appendChild(text);
67+
68+
// newTocLinks.appendChild(link);
69+
70+
// const subheadings = heading.parentElement.$$("h3");
71+
72+
// if (subheadings.length == 0) {
73+
// continue;
74+
// }
75+
76+
// const sublinks = document.createElement("nav");
77+
78+
// for (const subheading of subheadings) {
79+
// const sublink = document.createElement("a");
80+
// const subtext = document.createTextNode(subheading.textContent);
81+
82+
// sublink.setAttribute("href", `#${subheading.id}`);
83+
// sublink.appendChild(subtext);
84+
85+
// sublinks.appendChild(sublink);
86+
// }
87+
88+
// newTocLinks.appendChild(sublinks);
89+
// }
90+
91+
// newToc.appendChild(newTocLinks);
92+
// oldToc.replaceWith(newToc);
93+
// });
94+
95+
window.addEventListener("load", () => {
96+
const tocLinks = $("#-toc nav");
97+
98+
if (!tocLinks) {
99+
return;
100+
}
101+
102+
const updateHeadingSelection = () => {
103+
const currHash = window.location.hash;
104+
105+
for (const element of $$(".selected")) {
106+
element.classList.remove("selected");
107+
}
108+
109+
if (currHash) {
110+
for (const link of tocLinks.$$("a")) {
111+
const linkHash = new URL(link.href).hash;
112+
113+
if (linkHash === currHash) {
114+
link.classList.add("selected");
115+
break;
116+
}
117+
}
118+
119+
$(currHash).parentElement.parentElement.classList.add("selected");
120+
} else {
121+
const link = tocLinks.$("a");
122+
123+
link.classList.add("selected");
124+
}
125+
}
126+
127+
updateHeadingSelection();
128+
129+
window.addEventListener("hashchange", updateHeadingSelection);
130+
});
131+
132+
window.addEventListener("load", () => {
133+
for (const block of $$("pre > code.language-console")) {
134+
const lines = block.innerHTML.split("\n");
135+
136+
block.innerHTML = lines.map(line => {
137+
switch (line[0]) {
138+
case "#":
139+
return `<span class="shell-comment">${line}</span>`;
140+
case "$":
141+
return `<span class="shell-command">${line}</span>`;
142+
default:
143+
return `<span class="shell-output">${line}</span>`;
144+
}
145+
}).join("\n");
146+
}
147+
});
148+
149+
window.addEventListener("load", () => {
150+
for (const element of $$("div.attribute > div.attribute-heading")) {
151+
element.addEventListener("click", () => {
152+
element.parentElement.classList.toggle("collapsed");
153+
});
154+
}
155+
});
156+
157+
window.addEventListener("load", () => {
158+
if ($("a#expand-all")) {
159+
$("a#expand-all").addEventListener("click", () => {
160+
for (const element of $$("div.attribute.collapsed")) {
161+
element.classList.remove("collapsed");
162+
}
163+
});
164+
}
165+
166+
if ($("a#collapse-all")) {
167+
$("a#collapse-all").addEventListener("click", () => {
168+
for (const element of $$("div.attribute")) {
169+
element.classList.add("collapsed");
170+
}
171+
});
172+
}
173+
});
174+
175+
176+
// Function to open an image in fullscreen
177+
function openFullscreen(element) {
178+
if (element.requestFullscreen) {
179+
element.requestFullscreen();
180+
} else if (element.mozRequestFullScreen) { // Firefox
181+
element.mozRequestFullScreen();
182+
} else if (element.webkitRequestFullscreen) { // Chrome, Safari, and Opera
183+
element.webkitRequestFullscreen();
184+
} else if (element.msRequestFullscreen) { // IE/Edge
185+
element.msRequestFullscreen();
186+
}
187+
}
188+
// Attach click event listeners to all img elements
189+
document.querySelectorAll('img').forEach(img => {
190+
img.addEventListener('click', () => {
191+
openFullscreen(img);
192+
});
193+
});

0 commit comments

Comments
 (0)