Script cleanup (#3372)

This commit is contained in:
Martin Taillefer 2019-02-25 07:19:06 -08:00 committed by GitHub
parent ccd58553f8
commit 5ce2285a01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 247 additions and 290 deletions

View File

@ -1,4 +1,4 @@
<svg class="hero-logo" version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 160 240">
<svg id="hero-logo" viewBox="0 0 160 240">
<polygon points="0,210 160,210 60,240"/>
<polygon points="0,200 60,190 60,80"/>
<polygon points="70,190 160,200 70,0"/>

Before

Width:  |  Height:  |  Size: 228 B

After

Width:  |  Height:  |  Size: 176 B

View File

@ -1,4 +1,4 @@
<svg class="landing-image" data-name="expanded art" viewBox="0 0 1200 900">
<svg class="landing-image" viewBox="0 0 1200 900">
<defs>
<style>
.p-1 {
@ -22,23 +22,15 @@
<path class="p-1" d="M380,580c-110,0-180,220-280,220"/>
<polygon points="1070 480 1100 450 1070 420 1070 480"/>
<line class="p-1" x1="790" y1="450" x2="1060" y2="450"/>
<g>
<line class="p-1" x1="790" y1="320" x2="1060" y2="320"/>
<line class="p-1" x1="790" y1="580" x2="1060" y2="580"/>
</g>
<line class="p-1" x1="790" y1="320" x2="1060" y2="320"/>
<line class="p-1" x1="790" y1="580" x2="1060" y2="580"/>
<polygon points="1069 610 1099 580 1069 550 1069 610"/>
<g>
<polygon points="390 610 420 580 390 550 390 610"/>
<polygon points="390 350 420 320 390 290 390 350"/>
</g>
<polygon points="390 610 420 580 390 550 390 610"/>
<polygon points="390 350 420 320 390 290 390 350"/>
<path class="p-1" d="M380,320c-110,0-180-219.46-280-219.46"/>
<polygon points="1069.5 350 1099.5 320 1069.5 290 1069.5 350"/>
<g>
<path d="M455.37,455v72.52c0,85.52,114.17,133,139.63,142.57V455Z"/>
<path class="p-2" d="M595,445V202.77L455.37,280V445Z"/>
</g>
<g>
<path d="M744.6,445c0-82.16-.1-165.19-.1-165.19L605,202.76V445Z"/>
<path class="p-3" d="M605,455V670.09c25.46-9.53,139.63-57.05,139.63-142.57v-.26c0-22,0-46.94,0-72.26Z"/>
</g>
<path d="M455.37,455v72.52c0,85.52,114.17,133,139.63,142.57V455Z"/>
<path class="p-2" d="M595,445V202.77L455.37,280V445Z"/>
<path d="M744.6,445c0-82.16-.1-165.19-.1-165.19L605,202.76V445Z"/>
<path class="p-3" d="M605,455V670.09c25.46-9.53,139.63-57.05,139.63-142.57v-.26c0-22,0-46.94,0-72.26Z"/>
</svg>

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -1,4 +1,4 @@
<svg class="landing-image" data-name="expanded art" viewBox="0 0 1200 900">
<svg class="landing-image" viewBox="0 0 1200 900">
<defs>
<style>
.r-1, .r-3, .r-4 {
@ -24,42 +24,24 @@
}
</style>
</defs>
<g>
<g>
<polygon points="100 277.57 100 320 142.43 320 100 277.57"/>
<polygon points="210 587.57 210 630 252.43 630 210 587.57"/>
<polygon points="890.5 329.07 890.5 371.5 932.93 371.5 890.5 329.07"/>
</g>
<path d="M100,795c84.32-10.77,165-40.47,241.15-77.37C476.51,652,603.47,561.86,751.25,525.42c117.73-29,287.93-22.63,349.46,102,2.07,4.19,3.6,8.49,5.42,12.77l-6.64,3.86c-36.75-34.34-82.24-55.82-131.45-65.17-53.63-10.2-108.94-7-162.24,3.64-50.57,10.12-99.64,26.81-147.29,46.36C574.75,663.27,494.88,706.24,411.75,742c-82,35.28-168.81,63.89-258.89,65.28A468,468,0,0,1,95,804.45v-8.86C96.67,795.4,98.33,795.19,100,795Z"/>
</g>
<g>
<path class="r-1" d="M100,650s57.21,62.93,150,93.6"/>
<g>
<line class="r-1" x1="129.95" y1="290.92" x2="320.87" y2="100"/>
<line class="r-1" x1="700" y1="141.13" x2="741.13" y2="100"/>
<line class="r-1" x1="240" y1="600" x2="590" y2="251.1"/>
<line class="r-1" x1="920" y1="340.13" x2="1100" y2="159.13"/>
</g>
</g>
<g>
<g>
<polygon class="r-2" points="560.21 510.56 682.41 461.91 630.82 237.77 560.21 510.56"/>
<polygon class="r-2" points="692.15 459.66 872.05 438.78 604.68 79.6 692.15 459.66"/>
<path class="r-2" d="M714.75,524.54c16.31-5,32.76-9.5,49.56-13.38l110-62.63L562.45,520.3l97,23.49C677.6,536.77,696,530.3,714.75,524.54Z"/>
</g>
<g>
<polygon class="r-2" points="296 282.57 296 325 338.43 325 296 282.57"/>
<polygon class="r-2" points="450.5 557.07 450.5 599.5 492.93 599.5 450.5 557.07"/>
</g>
</g>
<g>
<path class="r-3" d="M477,800c100-30,211-101.14,330-124,250-48,293,102,293,102"/>
<g>
<line class="r-3" x1="100.43" y1="520.43" x2="240.87" y2="380"/>
<line class="r-4" x1="325.5" y1="294.5" x2="520" y2="100"/>
<line class="r-3" x1="800.13" y1="249.13" x2="950.02" y2="100"/>
<line class="r-4" x1="481" y1="569" x2="520.33" y2="530.33"/>
<line class="r-4" x1="1004.63" y1="474.63" x2="1099.51" y2="379.51"/>
</g>
</g>
<polygon points="100 277.57 100 320 142.43 320 100 277.57"/>
<polygon points="210 587.57 210 630 252.43 630 210 587.57"/>
<polygon points="890.5 329.07 890.5 371.5 932.93 371.5 890.5 329.07"/>
<path d="M100,795c84.32-10.77,165-40.47,241.15-77.37C476.51,652,603.47,561.86,751.25,525.42c117.73-29,287.93-22.63,349.46,102,2.07,4.19,3.6,8.49,5.42,12.77l-6.64,3.86c-36.75-34.34-82.24-55.82-131.45-65.17-53.63-10.2-108.94-7-162.24,3.64-50.57,10.12-99.64,26.81-147.29,46.36C574.75,663.27,494.88,706.24,411.75,742c-82,35.28-168.81,63.89-258.89,65.28A468,468,0,0,1,95,804.45v-8.86C96.67,795.4,98.33,795.19,100,795Z"/>
<path class="r-1" d="M100,650s57.21,62.93,150,93.6"/>
<line class="r-1" x1="129.95" y1="290.92" x2="320.87" y2="100"/>
<line class="r-1" x1="700" y1="141.13" x2="741.13" y2="100"/>
<line class="r-1" x1="240" y1="600" x2="590" y2="251.1"/>
<line class="r-1" x1="920" y1="340.13" x2="1100" y2="159.13"/>
<polygon class="r-2" points="560.21 510.56 682.41 461.91 630.82 237.77 560.21 510.56"/>
<polygon class="r-2" points="692.15 459.66 872.05 438.78 604.68 79.6 692.15 459.66"/>
<path class="r-2" d="M714.75,524.54c16.31-5,32.76-9.5,49.56-13.38l110-62.63L562.45,520.3l97,23.49C677.6,536.77,696,530.3,714.75,524.54Z"/>
<polygon class="r-2" points="296 282.57 296 325 338.43 325 296 282.57"/>
<polygon class="r-2" points="450.5 557.07 450.5 599.5 492.93 599.5 450.5 557.07"/>
<path class="r-3" d="M477,800c100-30,211-101.14,330-124,250-48,293,102,293,102"/>
<line class="r-3" x1="100.43" y1="520.43" x2="240.87" y2="380"/>
<line class="r-4" x1="325.5" y1="294.5" x2="520" y2="100"/>
<line class="r-3" x1="800.13" y1="249.13" x2="950.02" y2="100"/>
<line class="r-4" x1="481" y1="569" x2="520.33" y2="530.33"/>
<line class="r-4" x1="1004.63" y1="474.63" x2="1099.51" y2="379.51"/>
</svg>

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -1,4 +1,4 @@
<svg class="landing-image" data-name="expanded art" viewBox="0 0 1200 900">
<svg class="landing-image" viewBox="0 0 1200 900">
<defs>
<style>
.cls-1, .cls-2, .cls-3, .cls-4 {
@ -15,7 +15,6 @@
}
.cls-2 {
// stroke: #fff;
stroke-width: 30px;
}
@ -36,42 +35,26 @@
}
</style>
</defs>
<g>
<g>
<circle cx="149.5" cy="149.5" r="50"/>
<circle cx="149.5" cy="750.5" r="50"/>
<polygon points="240 120 210 150 240 180 240 120"/>
<polygon points="240 720 210 750 240 780 240 720"/>
</g>
<g>
<path class="cls-1" d="M250,150c200,0,500,300,700,300"/>
<path class="cls-1" d="M250,750c200,0,499-300,700-300"/>
<line class="cls-1" x1="250" y1="750" x2="950" y2="750"/>
<line class="cls-1" x1="250" y1="150" x2="950" y2="150"/>
</g>
</g>
<g>
<g>
<g>
<path class="cls-2" d="M950,150c-200,0-500,300-700,300"/>
<path class="cls-2" d="M950,750c-200,0-499-300-700-300"/>
<line class="cls-2" x1="250" y1="450" x2="950" y2="450"/>
</g>
<g>
<line class="cls-3" x1="340" y1="450" x2="950" y2="450"/>
<path class="cls-4" d="M950,150c-200,0-500,300-700,300"/>
<path class="cls-4" d="M950,750c-200,0-499-300-700-300"/>
</g>
</g>
<g>
<circle class="cls-5" cx="149.5" cy="449.5" r="50"/>
<circle class="cls-5" cx="1050.5" cy="149.5" r="50"/>
<circle class="cls-5" cx="1050.5" cy="750.5" r="50"/>
<circle class="cls-6" cx="1050.5" cy="449.5" r="50"/>
<polygon class="cls-5" points="240 420 210 450 240 480 240 420"/>
<polygon class="cls-6" points="960 480 990 450 960 420 960 480"/>
<polygon class="cls-5" points="960 180 990 150 960 120 960 180"/>
<polygon class="cls-5" points="960 780 990 750 960 720 960 780"/>
</g>
</g>
<circle cx="149.5" cy="149.5" r="50"/>
<circle cx="149.5" cy="750.5" r="50"/>
<polygon points="240 120 210 150 240 180 240 120"/>
<polygon points="240 720 210 750 240 780 240 720"/>
<path class="cls-1" d="M250,150c200,0,500,300,700,300"/>
<path class="cls-1" d="M250,750c200,0,499-300,700-300"/>
<line class="cls-1" x1="250" y1="750" x2="950" y2="750"/>
<line class="cls-1" x1="250" y1="150" x2="950" y2="150"/>
<path class="cls-2" d="M950,150c-200,0-500,300-700,300"/>
<path class="cls-2" d="M950,750c-200,0-499-300-700-300"/>
<line class="cls-2" x1="250" y1="450" x2="950" y2="450"/>
<line class="cls-3" x1="340" y1="450" x2="950" y2="450"/>
<path class="cls-4" d="M950,150c-200,0-500,300-700,300"/>
<path class="cls-4" d="M950,750c-200,0-499-300-700-300"/>
<circle class="cls-5" cx="149.5" cy="449.5" r="50"/>
<circle class="cls-5" cx="1050.5" cy="149.5" r="50"/>
<circle class="cls-5" cx="1050.5" cy="750.5" r="50"/>
<circle class="cls-6" cx="1050.5" cy="449.5" r="50"/>
<polygon class="cls-5" points="240 420 210 450 240 480 240 420"/>
<polygon class="cls-6" points="960 480 990 450 960 420 960 480"/>
<polygon class="cls-5" points="960 180 990 150 960 120 960 180"/>
<polygon class="cls-5" points="960 780 990 750 960 720 960 780"/>
</svg>

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@ -1,4 +1,4 @@
<svg class="landing-image" id="expanded_art" data-name="expanded art" viewBox="0 0 1200 900">
<svg class="landing-image" viewBox="0 0 1200 900">
<defs>
<style>
.m-1 {
@ -41,34 +41,18 @@
<path class="m-2" d="M250.49,743.49C216.2,777.16,172.84,800,100,800"/>
<path class="m-2" d="M100,800c137,0,390-104,570-284s430-77,430-77"/>
<path class="m-2" d="M474.34,668.6C695.34,535.6,817,439,1100,439"/>
<g>
<line class="m-3" x1="830" y1="100" x2="830" y2="800"/>
<line class="m-4" x1="830" y1="100" x2="830" y2="800"/>
</g>
<g>
<g>
<ellipse cx="150" cy="148.55" rx="50" ry="50.47"/>
<polygon points="391.65 171.25 355.69 193.98 378.21 230.28 391.65 171.25"/>
<polygon points="215.97 289.64 179.56 267.66 157.79 304.41 215.97 289.64"/>
</g>
<g>
<circle class="m-5" cx="220" cy="430" r="50"/>
<circle class="m-1" cx="635" cy="256" r="50"/>
<polygon class="m-1" points="424.37 376.1 441.35 337.22 402.47 320.24 424.37 376.1"/>
</g>
<g>
<line class="m-6" x1="404.19" y1="352.78" x2="276.07" y2="406.49"/>
<line class="m-6" x1="578.89" y1="279.53" x2="448.03" y2="334.39"/>
</g>
<g>
<g>
<line class="m-2" x1="177.73" y1="260.9" x2="164.55" y2="208.2"/>
<line class="m-2" x1="205.37" y1="371.49" x2="189.22" y2="306.86"/>
</g>
<g>
<line class="m-2" x1="394.71" y1="203.48" x2="576.12" y2="243.13"/>
<line class="m-2" x1="208.7" y1="162.83" x2="347.94" y2="193.26"/>
</g>
</g>
</g>
<line class="m-3" x1="830" y1="100" x2="830" y2="800"/>
<line class="m-4" x1="830" y1="100" x2="830" y2="800"/>
<ellipse cx="150" cy="148.55" rx="50" ry="50.47"/>
<polygon points="391.65 171.25 355.69 193.98 378.21 230.28 391.65 171.25"/>
<polygon points="215.97 289.64 179.56 267.66 157.79 304.41 215.97 289.64"/>
<circle class="m-5" cx="220" cy="430" r="50"/>
<circle class="m-1" cx="635" cy="256" r="50"/>
<polygon class="m-1" points="424.37 376.1 441.35 337.22 402.47 320.24 424.37 376.1"/>
<line class="m-6" x1="404.19" y1="352.78" x2="276.07" y2="406.49"/>
<line class="m-6" x1="578.89" y1="279.53" x2="448.03" y2="334.39"/>
<line class="m-2" x1="177.73" y1="260.9" x2="164.55" y2="208.2"/>
<line class="m-2" x1="205.37" y1="371.49" x2="189.22" y2="306.86"/>
<line class="m-2" x1="394.71" y1="203.48" x2="576.12" y2="243.13"/>
<line class="m-2" x1="208.7" y1="162.83" x2="347.94" y2="193.26"/>
</svg>

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -59,15 +59,15 @@ title: Istio
</script>
<main class="landing">
<div class="banner">
<div id="banner">
{{< inline_image "landing/istio-logo.svg" >}}
<div class="hero-text">
<h1 class="hero-label">Istio</h1>
<h1 class="hero-lead">Connect, secure, control, and observe services.
<div id="hero-text">
<h1 id="hero-label">Istio</h1>
<h1 id="hero-lead">Connect, secure, control, and observe services.
</div>
</div>
<div class="panels">
<div id="panels">
<div id="panel1" class="panel">
<a href="/docs/concepts/traffic-management/">
<div class="panel-img-top">

View File

@ -59,15 +59,15 @@ title: Istio
</script>
<main class="landing">
<div class="banner">
<div id="banner">
{{< inline_image "landing/istio-logo.svg" >}}
<div class="hero-text">
<h1 class="hero-label">Istio</h1>
<h1 class=“hero-lead”>用于连接、保护、控制和观测服务。
<div id="hero-text">
<h1 id="hero-label">Istio</h1>
<h1 id="hero-lead">用于连接、保护、控制和观测服务。
</div>
</div>
<div class="panels">
<div id="panels">
<div id="panel1" class="panel">
<a href="/zh/docs/concepts/traffic-management/">
<div class="panel-img-top">

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,5 @@
"use strict";function applyStyleSheet(a){"Dark Theme"===a?document.body.classList.add("dark-theme"):document.body.classList.remove("dark-theme");let b=document.getElementById("light-theme-item");null!==b&&("Light Theme"===a?b.classList.add("active"):b.classList.remove("active")),b=document.getElementById("dark-theme-item"),null!==b&&("Dark Theme"===a?b.classList.add("active"):b.classList.remove("active"))}function createCookie(a,b,c){let d="";if(c){const a=new Date;a.setTime(a.getTime()+1e3*(60*(60*(24*c)))),d="; expires="+a.toGMTString()}document.cookie=a+"="+b+d+"; path=/"}function readCookie(a){const b=a+"=",d=document.cookie.split(";");for(let e,c=0;c<d.length;c++){for(e=d[c];" "===e.charAt(0);)e=e.substring(1,e.length);if(0===e.indexOf(b)){let a=e.substring(b.length,e.length);return"light"===a?a="Light Theme":"dark"==a&&(a="Dark Theme"),a}}return null}function setActiveStyleSheet(a){applyStyleSheet(a),createCookie("style",a)}function loadActiveStyleSheet(){let a=readCookie("style");null!==a&&applyStyleSheet(a)}loadActiveStyleSheet(),document.addEventListener("DOMContentLoaded",()=>{loadActiveStyleSheet()});
const click="click",mouseenter="mouseenter",mouseleave="mouseleave",active="active";
"use strict";const escapeChars={"¢":"cent","£":"pound","¥":"yen","€":"euro","©":"copy","®":"reg","<":"lt",">":"gt",'"':"quot","&":"amp","'":"#39"},regex=/[¢£¥€©®<>"&']/g;function escapeHTML(a){return a.replace(regex,function(a){return"&"+escapeChars[a]+";"})}function saveFile(a,b){const c=document.createElement("a");c.setAttribute("href","data:text/text;charset=utf-8,"+encodeURI(b)),c.setAttribute("download",a),c.click()}function printText(a){const b=window.open("","","left=0,top=0,width=100,height=100,toolbar=0,scrollbars=0,status=0,location=0,menubar=0",!1);b.document.write("<html><body><pre><code>"+a+"</code></pre></html>"),b.document.close(),b.focus(),b.print(),b.close()}function navigateToUrlOrRoot(a){const b=new XMLHttpRequest;b.open("GET",a,!0),b.onreadystatechange=()=>{if(4===b.readyState&&404===b.status){const b=new URL(a);b.pathname="",a=b.toString()}window.location.href=a},b.send()}function onDOMLoaded(a){listen(document,"DOMContentLoaded",a)}function getById(a){return document.getElementById(a)}function query(a,b){return a.querySelector(b)}function queryAll(a,b){return a.querySelectorAll(b)}function listen(a,b,c){a.addEventListener(b,c)}
"use strict";const darkThemeClass="dark-theme",darkTheme="Dark Theme",darkThemeItem="dark-theme-item",lightTheme="Light Theme",lightThemeItem="light-theme-item",styleCookie="style";function applyStyleSheet(a){a===darkTheme?document.body.classList.add(darkThemeClass):document.body.classList.remove(darkThemeClass);let b=getById(lightThemeItem);b&&(a===lightTheme?b.classList.add(active):b.classList.remove(active)),b=getById(darkThemeItem),b&&(a===darkTheme?b.classList.add(active):b.classList.remove(active))}function createCookie(a,b,c){let d="";if(c){const a=new Date;a.setTime(a.getTime()+1e3*(60*(60*(24*c)))),d="; expires="+a.toGMTString()}document.cookie=a+"="+b+d+"; path=/"}function readCookie(a){const b=a+"=",d=document.cookie.split(";");for(let e,c=0;c<d.length;c++){for(e=d[c];" "===e.charAt(0);)e=e.substring(1,e.length);if(0===e.indexOf(b)){let a=e.substring(b.length,e.length);return"light"===a?a=lightTheme:"dark"===a&&(a=darkTheme),a}}return null}function loadActiveStyleSheet(){let a=readCookie(styleCookie);null!==a&&applyStyleSheet(a)}loadActiveStyleSheet(),onDOMLoaded(()=>{function a(a){applyStyleSheet(a),createCookie(styleCookie,a)}loadActiveStyleSheet(),listen(getById(lightThemeItem),click,()=>(a(lightTheme),!1)),listen(getById(darkThemeItem),click,()=>(a(darkTheme),!1))});
//# sourceMappingURL=styleSwitcher.min.js.map

File diff suppressed because one or more lines are too long

View File

@ -129,7 +129,7 @@
{{ partial "footer.html" . }}
<div id="scroll-to-top-container">
<button id="scroll-to-top" aria-hidden="true" onclick="scrollToTop()" title='{{ i18n "button_top"}}'>
<button id="scroll-to-top" aria-hidden="true" title='{{ i18n "button_top"}}'>
{{ partial "icon.html" "top" }}
</button>
</div>

View File

@ -47,8 +47,8 @@
<div></div>
<a class="active" id="light-theme-item" href="" onclick="setActiveStyleSheet('Light Theme');return false;">{{ i18n "light_theme" }}</a>
<a id="dark-theme-item" href="" onclick="setActiveStyleSheet('Dark Theme');return false;">{{ i18n "dark_theme" }}</a>
<a class="active" id="light-theme-item">{{ i18n "light_theme" }}</a>
<a id="dark-theme-item">{{ i18n "dark_theme" }}</a>
{{ if not .Site.Data.args.archive }}
<div></div>

View File

@ -26,7 +26,7 @@
{{ if not .Site.Data.args.archive }}
{{ if strings.HasSuffix $section.Dir "blog/" }}
<div class="subscribe" >
<div id="subscribe" >
<a href="/feed.xml" target="_blank">
{{ partial "large_icon.html" "rss" }}{{ i18n "subscribe" }}
</a>

View File

@ -5,6 +5,6 @@ mkdir -p generated/css generated/js generated/img
npx sass src/sass/_all.scss all.css -s compressed
mv all.css* generated/css
npx babel src/js/menu.js src/js/header.js src/js/sidebar.js src/js/tabs.js src/js/prism.js src/js/utils.js src/js/codeBlocks.js src/js/links.js src/js/scroll.js src/js/overlays.js src/js/clipboard.js --out-file generated/js/all.min.js --source-maps --minified --no-comments --presets minify
npx babel src/js/styleSwitcher.js --out-file generated/js/styleSwitcher.min.js --source-maps --minified --no-comments --presets minify
npx babel src/js/menu.js src/js/header.js src/js/sidebar.js src/js/tabs.js src/js/prism.js src/js/codeBlocks.js src/js/links.js src/js/scroll.js src/js/overlays.js src/js/clipboard.js --out-file generated/js/all.min.js --source-maps --minified --no-comments --presets minify
npx babel src/js/constants.js src/js/utils.js src/js/styleSwitcher.js --out-file generated/js/styleSwitcher.min.js --source-maps --minified --no-comments --presets minify
npx svgstore -o generated/img/icons.svg src/icons/**/*.svg

View File

@ -1,7 +1,7 @@
"use strict";
// All the voodoo needed to support our fsancy code blocks
document.addEventListener('DOMContentLoaded', () => {
// All the voodoo needed to support our fancy code blocks
onDOMLoaded(() => {
// Add a toolbar to all PRE blocks
function attachToolbar(pre) {
@ -10,18 +10,18 @@ document.addEventListener('DOMContentLoaded', () => {
copyButton.className = "copy";
copyButton.innerHTML = "<svg><use xlink:href='" + iconFile + "#copy'/></svg>";
copyButton.setAttribute("aria-label", buttonCopy);
copyButton.addEventListener("mouseenter", e => e.currentTarget.classList.add("toolbar-show"));
copyButton.addEventListener("mouseleave", e => e.currentTarget.classList.remove("toolbar-show"));
listen(copyButton, mouseenter, e => e.currentTarget.classList.add("toolbar-show"));
listen(copyButton, mouseleave, e => e.currentTarget.classList.remove("toolbar-show"));
const downloadButton = document.createElement('button');
downloadButton.title = buttonDownload;
downloadButton.className = "download";
downloadButton.innerHTML = "<svg><use xlink:href='" + iconFile + "#download'/></svg>";
downloadButton.setAttribute("aria-label", buttonDownload);
downloadButton.addEventListener("mouseenter", e => e.currentTarget.classList.add("toolbar-show"));
downloadButton.addEventListener("mouseleave", e => e.currentTarget.classList.remove("toolbar-show"));
listen(downloadButton, mouseenter, e => e.currentTarget.classList.add("toolbar-show"));
listen(downloadButton, mouseleave, e => e.currentTarget.classList.remove("toolbar-show"));
downloadButton.addEventListener("click", e => {
listen(downloadButton, click, e => {
const div = e.currentTarget.parentElement;
const codes = div.getElementsByTagName("CODE");
if ((codes !== null) && (codes.length > 0)) {
@ -57,10 +57,10 @@ document.addEventListener('DOMContentLoaded', () => {
printButton.className = "print";
printButton.innerHTML = "<svg><use xlink:href='" + iconFile + "#printer'/></svg>";
printButton.setAttribute("aria-label", buttonPrint);
printButton.addEventListener("mouseenter", e => e.currentTarget.classList.add("toolbar-show"));
printButton.addEventListener("mouseleave", e => e.currentTarget.classList.remove("toolbar-show"));
listen(printButton, mouseenter, e => e.currentTarget.classList.add("toolbar-show"));
listen(printButton, mouseleave, e => e.currentTarget.classList.remove("toolbar-show"));
printButton.addEventListener("click", e => {
listen(printButton, click, e => {
const div = e.currentTarget.parentElement;
const text = getToolbarDivText(div);
printText(text);
@ -76,13 +76,13 @@ document.addEventListener('DOMContentLoaded', () => {
div.appendChild(downloadButton);
div.appendChild(copyButton);
pre.addEventListener("mouseenter", e => {
listen(pre, mouseenter, e => {
e.currentTarget.nextSibling.classList.add("toolbar-show");
e.currentTarget.nextSibling.nextSibling.classList.add("toolbar-show");
e.currentTarget.nextSibling.nextSibling.nextSibling.classList.add("toolbar-show");
});
pre.addEventListener("mouseleave", e => {
listen(pre, mouseleave, e => {
e.currentTarget.nextSibling.classList.remove("toolbar-show");
e.currentTarget.nextSibling.nextSibling.classList.remove("toolbar-show");
e.currentTarget.nextSibling.nextSibling.nextSibling.classList.remove("toolbar-show");
@ -225,7 +225,7 @@ document.addEventListener('DOMContentLoaded', () => {
}
}
document.querySelectorAll('pre').forEach(pre => {
queryAll(document, 'pre').forEach(pre => {
attachToolbar(pre);
applySyntaxColoring(pre);
loadExternal(pre);

4
src/js/constants.js Normal file
View File

@ -0,0 +1,4 @@
const click = 'click';
const mouseenter = 'mouseenter';
const mouseleave = 'mouseleave';
const active = 'active';

View File

@ -1,60 +1,66 @@
"use strict";
// Attach the event handlers to support the search box and hamburger
document.addEventListener('DOMContentLoaded', () => {
onDOMLoaded(() => {
const searchForm = 'search-form';
const headerLinks = 'header-links';
const searchTextbox = 'search-textbox';
const showSearch = 'show-search';
const openHamburger = 'open-hamburger';
// Show the header links, hide the search box
function showNavBarLinks() {
document.getElementById('search-form').classList.remove('show-search');
document.getElementById('header-links').classList.remove('show-search');
document.getElementById('search-textbox').value = '';
getById(searchForm).classList.remove(showSearch);
getById(headerLinks).classList.remove(showSearch);
getById(searchTextbox).value = '';
}
// Show the header search box, hide the links
function showSearchBox() {
document.getElementById('search-form').classList.add('show-search');
document.getElementById('header-links').classList.add('show-search');
document.getElementById('search-textbox').focus();
getById(searchForm).classList.add(showSearch);
getById(headerLinks).classList.add(showSearch);
getById(searchTextbox).focus();
}
// Hide the search box when the user hits the ESC key
document.body.addEventListener("keyup", e => {
listen(document.body, "keyup", e => {
if (e.which === 27) {
showNavBarLinks();
}
});
// Show the search box
document.getElementById('search-show').addEventListener("click", e => {
listen(getById('search-show'), click, e => {
e.preventDefault();
showSearchBox();
});
// Hide the search box
document.getElementById('search-close').addEventListener("click", e => {
listen(getById('search-close'), click, e => {
e.preventDefault();
showNavBarLinks();
});
// When the user submits the search form, initiate a search
document.getElementById('search-form').addEventListener("submit", e => {
listen(getById(searchForm), "submit", e => {
e.preventDefault();
const textbox = document.getElementById('search-textbox');
const searchPageUrl = document.getElementById('search-page-url');
const textbox = getById(searchTextbox);
const searchPageUrl = getById('search-page-url');
const url = searchPageUrl.value + '?q=' + textbox.value;
showNavBarLinks();
window.location.assign(url);
});
document.getElementById('hamburger').addEventListener("click", () => {
document.getElementById('brand').classList.toggle('open-hamburger');
document.getElementById('header-links').classList.toggle('open-hamburger');
document.getElementById('search-form').classList.toggle('open-hamburger');
document.getElementById('search-textbox').focus();
listen(getById('hamburger'), click, () => {
getById('brand').classList.toggle(openHamburger);
getById(headerLinks).classList.toggle(openHamburger);
getById(searchForm).classList.toggle(openHamburger);
getById(searchTextbox).focus();
});
window.addEventListener("resize", () => {
document.getElementById('brand').classList.remove('open-hamburger');
document.getElementById('header-links').classList.remove('open-hamburger');
document.getElementById('search-form').classList.remove('open-hamburger');
listen(window, "resize", () => {
getById('brand').classList.remove(openHamburger);
getById(headerLinks).classList.remove(openHamburger);
getById(searchForm).classList.remove(openHamburger);
});
});

View File

@ -1,6 +1,6 @@
"use strict";
document.addEventListener('DOMContentLoaded', () => {
onDOMLoaded(() => {
function attachLink(node) {
const anchor = document.createElement("a");
@ -15,7 +15,7 @@ document.addEventListener('DOMContentLoaded', () => {
// Add a link icon next to each header so people can easily get bookmarks to headers
function attachLinksToHeaders() {
for (let level = 2; level <= 6; level++) {
document.querySelectorAll("h" + level.toString()).forEach(hdr => {
queryAll(document, "h" + level.toString()).forEach(hdr => {
if (hdr.id !== "") {
attachLink(hdr);
}
@ -25,7 +25,7 @@ document.addEventListener('DOMContentLoaded', () => {
// Add a link icon next to each defined term so people can easily get bookmarks to them in the glossary
function attachLinksToDefinedTerms() {
document.querySelectorAll('dt').forEach(dt => {
queryAll(document, 'dt').forEach(dt => {
if (dt.id !== "") {
attachLink(dt);
}
@ -34,7 +34,7 @@ document.addEventListener('DOMContentLoaded', () => {
// Make it so each link outside of the current domain opens up in a different window
function makeOutsideLinksOpenInTabs() {
document.querySelectorAll('a').forEach(link => {
queryAll(document, 'a').forEach(link => {
if (link.hostname && link.hostname !== location.hostname) {
link.setAttribute("target", "_blank");
link.setAttribute("rel", "noopener");
@ -44,7 +44,7 @@ document.addEventListener('DOMContentLoaded', () => {
// Create the set of endnotes that expand URLs when printing
function createEndnotes() {
const notes = document.getElementById("endnotes");
const notes = getById("endnotes");
if (notes === null) {
return;
}
@ -53,7 +53,7 @@ document.addEventListener('DOMContentLoaded', () => {
const main = document.getElementsByTagName("main")[0];
const map = new Map(null);
let numLinks = 0;
main.querySelectorAll('a').forEach(link => {
queryAll(main, 'a').forEach(link => {
if (link.pathname === location.pathname) {
// skip links pointing to the current page
return;
@ -92,7 +92,7 @@ document.addEventListener('DOMContentLoaded', () => {
if (numLinks > 0) {
// only show the section if there are links
document.getElementById("endnotes-container").classList.add('show');
getById("endnotes-container").classList.add('show');
}
}

View File

@ -1,9 +1,9 @@
"use strict";
// Attach the event handlers to support menus
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('.menu').forEach(menu => {
menu.querySelector(".menu-trigger").addEventListener("click", e => {
onDOMLoaded(() => {
queryAll(document, '.menu').forEach(menu => {
listen(query(menu, ".menu-trigger"), click, e => {
e.cancelBubble = true;
toggleOverlay(menu);
});

View File

@ -30,7 +30,7 @@ function closeActiveOverlay() {
}
}
document.addEventListener("DOMContentLoaded", () => {
onDOMLoaded(() => {
// Attach a popper to the given anchor
function attachPopper(anchor, element) {
if (popper !== null) {
@ -54,7 +54,7 @@ document.addEventListener("DOMContentLoaded", () => {
}
// Expand spans that define terms into appropriate popup markup
document.querySelectorAll('.term').forEach(term => {
queryAll(document, '.term').forEach(term => {
const i = document.createElement('i');
i.innerHTML = "<svg class='icon'><use xlink:href='" + iconFile + "#glossary'/></svg>";
@ -80,14 +80,14 @@ document.addEventListener("DOMContentLoaded", () => {
div.appendChild(body);
div.appendChild(arrow);
div.setAttribute("aria-hidden", "true");
div.addEventListener('click', e => {
listen(div, click, e => {
e.cancelBubble = true;
});
term.parentNode.insertBefore(div, term.nextSibling);
term.removeAttribute('data-title');
term.removeAttribute('data-body');
term.addEventListener('click', e => {
listen(term, click, e => {
e.cancelBubble = true;
toggleOverlay(div);
attachPopper(term, div);
@ -95,5 +95,5 @@ document.addEventListener("DOMContentLoaded", () => {
});
});
window.addEventListener("click", closeActiveOverlay);
window.addEventListener("resize", closeActiveOverlay);
listen(window, click, closeActiveOverlay);
listen(window, "resize", closeActiveOverlay);

View File

@ -6,19 +6,24 @@ let tocLinks;
let tocHeadings;
// what we do when the user scrolls the page
window.addEventListener("scroll", handlePageScroll);
listen(window, "scroll", handlePageScroll);
// discover a few DOM elements up front so we don't need to do it a zillion times for the life of the page
document.addEventListener('DOMContentLoaded', () => {
scrollToTopButton = document.getElementById('scroll-to-top');
onDOMLoaded(() => {
scrollToTopButton = getById('scroll-to-top');
listen(scrollToTopButton, click, () => {
// scroll the document to the top
document.body.scrollTop = 0; // for Safari
document.documentElement.scrollTop = 0; // for Chrome, Firefox, IE and Opera
});
const toc = document.getElementById('toc');
const toc = getById('toc');
if (toc) {
tocLinks = toc.getElementsByTagName('a');
tocHeadings = new Array(tocLinks.length);
for (let i = 0; i < tocLinks.length; i++) {
tocHeadings[i] = document.getElementById(tocLinks[i].hash.substring(1));
tocHeadings[i] = getById(tocLinks[i].hash.substring(1));
}
}
@ -90,7 +95,7 @@ function handlePageScroll() {
// Note that this only works once for a given target row per page load. If the user is clicking
// around within a page, the second click to the same deep link will not trigger this hack and
// the user will be left with the row under the page header.
const target = document.querySelector(":target");
const target = query(document, ":target");
if (target && target.tagName === 'TR' && !target.dataset.scrolled) {
document.documentElement.scrollTop -= 55; // where 55 is the approximate header height
target.dataset.scrolled = 'true';

View File

@ -1,16 +1,16 @@
"use strict";
// Attach the event handlers to support the sidebar
document.addEventListener('DOMContentLoaded', () => {
const sidebar = document.getElementById('sidebar');
onDOMLoaded(() => {
const sidebar = getById('sidebar');
if (sidebar == null) {
return;
}
// toggle subtree in sidebar
sidebar.querySelectorAll('.tree-toggle').forEach(o => {
o.addEventListener("click", () => {
o.querySelectorAll('i.chevron').forEach(chevron => {
queryAll(sidebar, '.tree-toggle').forEach(o => {
listen(o, click, () => {
queryAll(o, 'i.chevron').forEach(chevron => {
chevron.classList.toggle('show');
});
@ -27,8 +27,8 @@ document.addEventListener('DOMContentLoaded', () => {
});
// expand/collapse cards
sidebar.querySelectorAll('.header').forEach(header => {
header.addEventListener("click", () => {
queryAll(sidebar, '.header').forEach(header => {
listen(header, click, () => {
const body = header.nextElementSibling;
body.classList.toggle('show');
@ -43,7 +43,7 @@ document.addEventListener('DOMContentLoaded', () => {
});
// force expand the default cards
sidebar.querySelectorAll('.body').forEach(body => {
queryAll(sidebar, '.body').forEach(body => {
if (body.classList.contains("default")) {
body.style.maxHeight = body.scrollHeight + "px";
body.classList.toggle("default");
@ -52,11 +52,11 @@ document.addEventListener('DOMContentLoaded', () => {
});
// toggle sidebar on/off
const toggler = document.getElementById('sidebar-toggler');
const toggler = getById('sidebar-toggler');
if (toggler) {
toggler.addEventListener("click", e => {
document.getElementById("sidebar-container").classList.toggle('active');
e.currentTarget.querySelector('svg.icon').classList.toggle('flipped');
listen(toggler, click, e => {
getById("sidebar-container").classList.toggle(active);
query(e.currentTarget, 'svg.icon').classList.toggle('flipped');
});
}
});

View File

@ -1 +1 @@
"use strict"; function applyStyleSheet(title) { if (title === "Dark Theme") { document.body.classList.add("dark-theme"); } else { document.body.classList.remove("dark-theme"); } // set the active theme menu item function applyStyleSheet(title) { function applyStyleSheet(title) { function applyStyleSheet(title) { function applyStyleSheet(title) { if (title === "Dark Theme") { function applyStyleSheet(title) { document.body.classList.add("dark-theme"); function applyStyleSheet(title) { } else { function applyStyleSheet(title) { document.body.classList.remove("dark-theme"); } } item = document.getElementById("dark-theme-item"); if (item !== null) { if (title === "Dark Theme") { item.classList.add("active"); } else { item.classList.remove("active"); } } } function createCookie(name, value, days) { let expires = ""; if (days) { const date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toGMTString(); } document.cookie = name + "=" + value + expires + "; path=/"; } function readCookie(name) { const nameEQ = name + "="; const ca = document.cookie.split(';'); for (let i = 0; i < ca.length; i++) { let c = ca[i]; while (c.charAt(0) === ' ') { c = c.substring(1, c.length); } if (c.indexOf(nameEQ) === 0) { let result = c.substring(nameEQ.length, c.length); // convert legacy cookie values if (result === "light") { result = "Light Theme"; } else if (result === "dark") { result = "Dark Theme"; } return result; } } return null; } } else { } else { } else { document.body.classList.remove("dark-theme"); } else { } } } else { } else { // set the active theme menu item if (cookie !== null) { document.body.classList.remove("dark-theme"); } function applyStyleSheet(title) { document.body.classList.remove("dark-theme"); function applyStyleSheet(title) { document.body.classList.remove("dark-theme"); if (title === "Dark Theme") { document.body.classList.remove("dark-theme"); document.body.classList.add("dark-theme"); ); });
"use strict"; document.body.classList.remove("dark-theme"); } else { document.body.classList.remove("dark-theme"); document.body.classList.remove("dark-theme"); document.body.classList.remove("dark-theme"); } document.body.classList.remove("dark-theme"); document.body.classList.remove("dark-theme"); // set the active theme menu item document.body.classList.remove("dark-theme"); function applyStyleSheet(title) { } } function applyStyleSheet(title) { } else { } if (title === "Dark Theme") { } // set the active theme menu item } document.body.classList.add("dark-theme"); } } else { } document.body.classList.remove("dark-theme"); item.classList.add(active); } else { item.classList.remove(active); } } item = getById(darkThemeItem); if (item) { if (title === darkTheme) { item.classList.add(active); } else { item.classList.remove(active); } } } function createCookie(name, value, days) { let expires = ""; if (days) { const date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toGMTString(); } document.cookie = name + "=" + value + expires + "; path=/"; } function readCookie(name) { const nameEQ = name + "="; const ca = document.cookie.split(';'); for (let i = 0; i < ca.length; i++) { let c = ca[i]; while (c.charAt(0) === ' ') { c = c.substring(1, c.length); } if (c.indexOf(nameEQ) === 0) { let result = c.substring(nameEQ.length, c.length); // convert legacy cookie values if (result === "light") { result = lightTheme; } else if (result === "dark") { result = darkTheme; } return result; } } return null; } } else { let cookie = readCookie(styleCookie); } else { document.body.classList.remove("dark-theme"); } } loadActiveStyleSheet(); onDOMLoaded(() => { } else { document.body.classList.remove("dark-theme"); } createCookie(styleCookie, title); } listen(getById(lightThemeItem), click, () => { return false; // set the active theme menu item function applyStyleSheet(title) { // set the active theme menu item if (title === "Dark Theme") { // set the active theme menu item document.body.classList.add("dark-theme"); return false; }); });

View File

@ -1,54 +1,42 @@
"use strict";
document.addEventListener('DOMContentLoaded', () => {
onDOMLoaded(() => {
// Select the active tabs on the page per cookie values
function selectActiveTabs() {
document.querySelectorAll(".tabset").forEach(tabset => {
tabset.querySelectorAll(".tab-strip").forEach(strip => {
const cookieName = strip.dataset.cookieName;
if (cookieName) {
const cookieValue = readCookie(cookieName);
if (cookieValue) {
strip.querySelectorAll("a").forEach(anchor => {
if (anchor.dataset.cookieValue == cookieValue) {
anchor.classList.add("active");
document.getElementById(anchor.dataset.tab).classList.add('active');
} else {
anchor.classList.remove("active");
document.getElementById(anchor.dataset.tab).classList.remove('active');
}
});
}
}
});
});
}
queryAll(document, ".tabset").forEach(tabset => {
queryAll(tabset, ".tab-strip").forEach(strip => {
const cookieName = strip.dataset.cookieName;
// Attach the event handlers to support tab sets
function attachTabHandlers() {
document.querySelectorAll(".tabset").forEach(tabset => {
tabset.querySelectorAll(".tab-strip").forEach(strip => {
const cookieName = strip.dataset.cookieName;
strip.querySelectorAll("a").forEach(anchor => {
const cookieValue = anchor.dataset.cookieValue;
anchor.addEventListener("click", () => {
strip.querySelectorAll("a").forEach(anchor2 => {
anchor2.classList.remove('active');
document.getElementById(anchor2.dataset.tab).classList.remove('active');
});
anchor.classList.add("active");
document.getElementById(anchor.dataset.tab).classList.add('active');
if (cookieName !== null) {
createCookie(cookieName, cookieValue);
// select the active tabs on the page per cookie values
if (cookieName) {
const cookieValue = readCookie(cookieName);
if (cookieValue) {
queryAll(strip, "a").forEach(anchor => {
if (anchor.dataset.cookieValue === cookieValue) {
anchor.classList.add(active);
getById(anchor.dataset.tab).classList.add(active);
} else {
anchor.classList.remove(active);
getById(anchor.dataset.tab).classList.remove(active);
}
});
}
}
// attach the event handlers to support tab sets
queryAll(strip, "a").forEach(anchor => {
listen(anchor, click, () => {
queryAll(strip, "a").forEach(anchor2 => {
anchor2.classList.remove(active);
getById(anchor2.dataset.tab).classList.remove(active);
});
anchor.classList.add(active);
getById(anchor.dataset.tab).classList.add(active);
if (cookieName !== null) {
createCookie(cookieName, anchor.dataset.cookieValue);
}
});
});
});
}
selectActiveTabs();
attachTabHandlers();
});
});

View File

@ -1,11 +1,5 @@
"use strict";
// Scroll the document to the top
function scrollToTop() {
document.body.scrollTop = 0; // for Safari
document.documentElement.scrollTop = 0; // for Chrome, Firefox, IE and Opera
}
const escapeChars = {
'¢': 'cent',
'£': 'pound',
@ -59,8 +53,6 @@ function navigateToUrlOrRoot(url) {
const u = new URL(url);
u.pathname = '';
url = u.toString();
} else {
console.log("OK");
}
// go!
@ -69,3 +61,23 @@ function navigateToUrlOrRoot(url) {
request.send();
}
function onDOMLoaded(cb) {
listen(document, "DOMContentLoaded", cb);
}
function getById(id) {
return document.getElementById(id);
}
function query(o, s) {
return o.querySelector(s);
}
function queryAll(o, s) {
return o.querySelectorAll(s);
}
function listen(o, e, f) {
o.addEventListener(e, f);
}

View File

@ -1,4 +1,4 @@
.subscribe {
#subscribe {
padding: 1em;
font-size: 1.2em;
background-color: $backgroundColor;

View File

@ -1,11 +1,11 @@
.landing {
.banner {
#banner {
display: flex;
justify-content: center;
padding-top: 1rem;
padding-bottom: 1rem;
.hero-label {
#hero-label {
margin: 0 0 0 0;
padding: 30px 0 0 0;
font-size: 4rem;
@ -13,7 +13,7 @@
text-align: center;
}
.hero-lead {
#hero-lead {
display: block;
font-size: 1rem;
font-weight: $heroLeadWeight;
@ -22,36 +22,36 @@
padding: 0;
}
.hero-logo {
#hero-logo {
width: 0;
fill: $heroLogoColor;
}
.hero-text {
#hero-text {
width: 20rem;
margin-left: 0;
}
@media (min-width: $bp-sm) {
.hero-logo {
#hero-logo {
width: 7rem;
}
.hero-label {
#hero-label {
text-align: left;
}
.hero-lead {
#hero-lead {
text-align: left;
}
.hero-text {
#hero-text {
margin-left: 3rem;
}
}
}
.panels {
#panels {
display: grid;
grid-template-columns: [panel] auto;
padding-top: 30px;