Skip to content

Commit cb3eea7

Browse files
committed
New example: Multicol module
1 parent 2f4519c commit cb3eea7

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

modules/multicol.html

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,80 @@ <h1>A Lament for Confederation</h1>
204204
</div>
205205
</fieldset>
206206
</body>
207+
<script>
208+
const article = document.querySelector("article");
209+
const title = document.querySelector(".title");
210+
const options = document.querySelector("#options");
211+
const legend = document.querySelector("#options > legend");
212+
const blockquote = document.getElementsByTagName("blockquote")[0];
213+
214+
const colCount = document.getElementById("colCount");
215+
const colWidth = document.getElementById("colWidth");
216+
const gapSize = document.getElementById("gapSize");
217+
const colSpan = document.getElementById("colSpan");
218+
const blockSpan = document.getElementById("blockSpan");
219+
const colFill = document.getElementById("colFill");
220+
const breakP = document.getElementById("break");
221+
222+
// make options visible if js is enabled
223+
options.style.display = "revert";
224+
225+
legend.addEventListener("click", () => {
226+
showAndHideMenu();
227+
});
228+
229+
colCount.addEventListener("change", () => {
230+
article.style.columnCount = colCount.value;
231+
});
232+
233+
colWidth.addEventListener("change", () => {
234+
article.style.columnWidth = `${colWidth.value}em`;
235+
});
236+
237+
gapSize.addEventListener("change", () => {
238+
article.style.gap = `${gapSize.value}em`;
239+
});
240+
241+
colSpan.addEventListener("change", () => {
242+
setColSpan(colSpan, title);
243+
});
244+
245+
blockSpan.addEventListener("change", () => {
246+
setColSpan(blockSpan, blockquote);
247+
});
248+
249+
colFill.addEventListener("change", () => {
250+
if (colFill.checked) {
251+
article.style.columnFill = "balance";
252+
} else {
253+
article.style.columnFill = "auto";
254+
}
255+
});
256+
257+
breakP.addEventListener("change", () => {
258+
if (breakP.checked) {
259+
article.classList.add("breakInside");
260+
} else {
261+
article.classList.remove("breakInside");
262+
}
263+
});
264+
265+
function showAndHideMenu() {
266+
if (legend.getAttribute("aria-expanded") === "true") {
267+
// close it
268+
legend.setAttribute("aria-expanded", "false");
269+
} else {
270+
// open it
271+
legend.setAttribute("aria-expanded", "true");
272+
}
273+
}
274+
275+
function setColSpan(control, element) {
276+
if (control.checked) {
277+
element.style.columnSpan = "all";
278+
} else {
279+
element.style.columnSpan = "none";
280+
}
281+
}
282+
</script>
207283
</html>

0 commit comments

Comments
 (0)