diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Reformat the stylesheet and script to two spaces
Diffstat (limited to 'assets/cgit.js')
| -rw-r--r-- | assets/cgit.js | 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 file changed, 113 insertions, 113 deletions
diff --git a/assets/cgit.js b/assets/cgit.js index 0fed45a..34927d0 100644 --- a/assets/cgit.js +++ b/assets/cgit.js @@ -33,26 +33,26 @@ var age_limit = [ 2 * HOUR, 2 * DAY, 2 * WEEK, 2 * MONTH, 2 * YEAR, var update_delay = [ 10, 5 * MINUTE, 30 * MINUTE, DAY, DAY, DAY, DAY ]; function render_age(element, age) { - var text, bucket; + var text, bucket; - for (bucket = 0; bucket < age_classes.length; bucket++) - if (age < age_limit[bucket]) - break; + for (bucket = 0; bucket < age_classes.length; bucket++) + if (age < age_limit[bucket]) + break; - text = Math.round(age / age_unit[bucket]) + " " + age_suffix[bucket]; + text = Math.round(age / age_unit[bucket]) + " " + age_suffix[bucket]; - // Every age on the page is measured again on each pass, so most of - // them are already reading correctly and writing to them would cost a - // repaint for nothing. - if (element.textContent != text) { - element.textContent = text; - // An age past the last limit is still counted in years, but - // there is no class beyond age-years to put on it. - if (bucket == age_classes.length) - bucket--; - if (element.className != age_classes[bucket]) - element.className = age_classes[bucket]; - } + // Every age on the page is measured again on each pass, so most of + // them are already reading correctly and writing to them would cost a + // repaint for nothing. + if (element.textContent != text) { + element.textContent = text; + // An age past the last limit is still counted in years, but + // there is no class beyond age-years to put on it. + if (bucket == age_classes.length) + bucket--; + if (element.className != age_classes[bucket]) + element.className = age_classes[bucket]; + } } /* @@ -62,36 +62,36 @@ function render_age(element, age) { * one counted in years for a day. */ function refresh_ages() { - var bucket, elements, i, age; - var delay = 24 * 3600; - var now = Math.round(new Date().getTime() / 1000); + var bucket, elements, i, age; + var delay = 24 * 3600; + var now = Math.round(new Date().getTime() / 1000); - for (bucket = 0; bucket < age_classes.length; bucket++) { - elements = document.getElementsByClassName(age_classes[bucket]); + for (bucket = 0; bucket < age_classes.length; bucket++) { + elements = document.getElementsByClassName(age_classes[bucket]); - if (elements.length && update_delay[bucket] < delay) - delay = update_delay[bucket]; + if (elements.length && update_delay[bucket] < delay) + delay = update_delay[bucket]; - for (i = 0; i < elements.length; i++) { - age = now - elements[i].getAttribute("data-ut"); + for (i = 0; i < elements.length; i++) { + age = now - elements[i].getAttribute("data-ut"); - // A commit dated ahead of the viewer's clock would - // otherwise show a negative age, and ui-shared.c - // clamps it the same way. - if (age < 0) - age = 0; + // A commit dated ahead of the viewer's clock would + // otherwise show a negative age, and ui-shared.c + // clamps it the same way. + if (age < 0) + age = 0; - render_age(elements[i], age); - } - } + render_age(elements[i], age); + } + } - window.setTimeout(refresh_ages, delay * 1000); + window.setTimeout(refresh_ages, delay * 1000); } document.addEventListener("DOMContentLoaded", function () { - // Nothing here depends on layout, so the first pass can run as soon - // as the document is parsed. - refresh_ages(); + // Nothing here depends on layout, so the first pass can run as soon + // as the document is parsed. + refresh_ages(); }, false); })(); @@ -106,12 +106,12 @@ document.addEventListener("DOMContentLoaded", function () { (function () { document.addEventListener("DOMContentLoaded", function () { - var i, selects = document.querySelectorAll("select[data-autosubmit]"); + var i, selects = document.querySelectorAll("select[data-autosubmit]"); - for (i = 0; i < selects.length; i++) - selects[i].addEventListener("change", function () { - this.form.submit(); - }); + for (i = 0; i < selects.length; i++) + selects[i].addEventListener("change", function () { + this.form.submit(); + }); }, false); })(); @@ -129,38 +129,38 @@ document.addEventListener("DOMContentLoaded", function () { var bar = null; function place_bar() { - var match, first, last, table; - var table_box, first_box, last_box, top, bottom; + var match, first, last, table; + var table_box, first_box, last_box, top, bottom; - if (bar) { - bar.remove(); - bar = null; - } - match = /^#n(\d+)(?:-n?(\d+))?$/.exec(location.hash); - if (!match) - return; - first = document.getElementById("n" + match[1]); - if (!first) - return; - last = (match[2] && document.getElementById("n" + match[2])) || first; - table = first.closest("table"); - if (!table) - return; - table_box = table.getBoundingClientRect(); - first_box = first.getBoundingClientRect(); - last_box = last.getBoundingClientRect(); - top = Math.min(first_box.top, last_box.top) - table_box.top; - bottom = Math.max(first_box.bottom, last_box.bottom) - table_box.top; - bar = document.createElement("div"); - bar.className = "line-hl"; - bar.style.top = top + "px"; - bar.style.height = (bottom - top) + "px"; - table.appendChild(bar); + if (bar) { + bar.remove(); + bar = null; + } + match = /^#n(\d+)(?:-n?(\d+))?$/.exec(location.hash); + if (!match) + return; + first = document.getElementById("n" + match[1]); + if (!first) + return; + last = (match[2] && document.getElementById("n" + match[2])) || first; + table = first.closest("table"); + if (!table) + return; + table_box = table.getBoundingClientRect(); + first_box = first.getBoundingClientRect(); + last_box = last.getBoundingClientRect(); + top = Math.min(first_box.top, last_box.top) - table_box.top; + bottom = Math.max(first_box.bottom, last_box.bottom) - table_box.top; + bar = document.createElement("div"); + bar.className = "line-hl"; + bar.style.top = top + "px"; + bar.style.height = (bottom - top) + "px"; + table.appendChild(bar); - // A browser only scrolls to a fragment that names a real id, which a - // range never does, so bring the start of one into view here. - if (match[2]) - first.scrollIntoView({ block: "center" }); + // A browser only scrolls to a fragment that names a real id, which a + // range never does, so bring the start of one into view here. + if (match[2]) + first.scrollIntoView({ block: "center" }); } document.addEventListener("DOMContentLoaded", place_bar, false); @@ -179,9 +179,9 @@ window.addEventListener("hashchange", place_bar, false); var STORAGE_KEY = "cgit-theme"; var ORDER = [ "auto", "light", "dark" ]; var ICONS = { - auto: '<svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="9"/><path d="M12 3a9 9 0 0 0 0 18z" fill="currentColor" stroke="none"/></svg>', - light: '<svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="5"/><path d="M12 1v3M12 20v3M4.2 4.2l2.1 2.1M17.7 17.7l2.1 2.1M1 12h3M20 12h3M4.2 19.8l2.1-2.1M17.7 6.3l2.1-2.1"/></svg>', - dark: '<svg viewBox="0 0 24 24"><path d="M21 12.8A9 9 0 1 1 11.2 3 7 7 0 0 0 21 12.8z"/></svg>' + auto: '<svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="9"/><path d="M12 3a9 9 0 0 0 0 18z" fill="currentColor" stroke="none"/></svg>', + light: '<svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="5"/><path d="M12 1v3M12 20v3M4.2 4.2l2.1 2.1M17.7 17.7l2.1 2.1M1 12h3M20 12h3M4.2 19.8l2.1-2.1M17.7 6.3l2.1-2.1"/></svg>', + dark: '<svg viewBox="0 0 24 24"><path d="M21 12.8A9 9 0 1 1 11.2 3 7 7 0 0 0 21 12.8z"/></svg>' }; /* @@ -191,41 +191,41 @@ var ICONS = { * on the automatic theme. */ function saved() { - try { - return localStorage.getItem(STORAGE_KEY); - } catch (e) { - return null; - } + try { + return localStorage.getItem(STORAGE_KEY); + } catch (e) { + return null; + } } function persist(theme) { - try { - localStorage.setItem(STORAGE_KEY, theme); - } catch (e) { } + try { + localStorage.setItem(STORAGE_KEY, theme); + } catch (e) { } } function apply(theme, button) { - var html = document.documentElement; + var html = document.documentElement; - if (theme === "auto") - html.removeAttribute("data-theme"); - else - html.setAttribute("data-theme", theme); + if (theme === "auto") + html.removeAttribute("data-theme"); + else + html.setAttribute("data-theme", theme); - // The browser paints the page canvas and the scrollbars from - // color-scheme rather than from the stylesheet, so it has to be told - // the choice as well. - html.style.colorScheme = (theme === "auto") ? "" : theme; + // The browser paints the page canvas and the scrollbars from + // color-scheme rather than from the stylesheet, so it has to be told + // the choice as well. + html.style.colorScheme = (theme === "auto") ? "" : theme; - if (button) { - button.innerHTML = ICONS[theme]; - button.title = "Colour theme: " + theme; - } + if (button) { + button.innerHTML = ICONS[theme]; + button.title = "Colour theme: " + theme; + } } var theme = saved(); if (ORDER.indexOf(theme) < 0) - theme = "auto"; + theme = "auto"; // This runs while the file is being parsed rather than on DOMContentLoaded. // The script is fetched from the head and so runs before the body exists, @@ -238,22 +238,22 @@ apply(theme, null); document.documentElement.classList.add("cgit-js"); document.addEventListener("DOMContentLoaded", function () { - var root = document.getElementById("cgit"); - if (!root) - return; - var button = root.querySelector(".theme-toggle"); - if (!button) - return; + var root = document.getElementById("cgit"); + if (!root) + return; + var button = root.querySelector(".theme-toggle"); + if (!button) + return; - apply(theme, button); - // The button is served hidden so that a reader without scripting is - // never shown a control that cannot do anything. - button.hidden = false; - button.addEventListener("click", function () { - theme = ORDER[(ORDER.indexOf(theme) + 1) % ORDER.length]; - persist(theme); - apply(theme, button); - }); + apply(theme, button); + // The button is served hidden so that a reader without scripting is + // never shown a control that cannot do anything. + button.hidden = false; + button.addEventListener("click", function () { + theme = ORDER[(ORDER.indexOf(theme) + 1) % ORDER.length]; + persist(theme); + apply(theme, button); + }); }, false); })(); |
