|
1 |
| -!function(){"use strict";function u(e){return function(e){if(Array.isArray(e))return r(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||s(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e,t){if(e){if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function f(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=s(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,l=!0,a=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,i=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw i}}}}anchors.options.placement="left",anchors.add("h3").remove(".no-anchor");var d=document.querySelector("#toc").querySelectorAll("li");document.querySelector("#filter-input").addEventListener("keyup",function(e){if("Enter"===e.key){var t,n=f(d);try{for(n.s();!(t=n.n()).done;){var r=t.value;if(!r.classList.contains("display-none"))return location.replace(r.firstChild.href),e.preventDefault()}}catch(e){n.e(e)}finally{n.f()}}var o=function(){return!0},i=document.querySelector("#filter-input").value.toLowerCase();i.match(/^\s*$/)||(o=function(e){return e.firstChild.innerHTML&&e.firstChild.innerHTML.toLowerCase().includes(i)});var l,a=f(d);try{for(a.s();!(l=a.n()).done;){var s=l.value,c=u(s.querySelectorAll("li"));o(s)||c.some(function(e){return o(e)})?s.classList.remove("display-none"):s.classList.add("display-none")}}catch(e){a.e(e)}finally{a.f()}});var e,t=f(document.querySelectorAll(".toggle-sibling"));try{for(t.s();!(e=t.n()).done;){e.value.addEventListener("click",n)}}catch(e){t.e(e)}finally{t.f()}function n(){var e=this.parentNode.querySelectorAll(".toggle-target")[0],t=this.querySelectorAll(".icon")[0],n="display-none";e.classList.contains(n)?(e.classList.remove(n),t.innerHTML="▾"):(e.classList.add(n),t.innerHTML="▸")}function o(e){var t=document.getElementById(e);t&&0===t.offsetHeight&&t.parentNode.parentNode.classList.contains("display-none")&&t.parentNode.parentNode.classList.remove("display-none")}window.addEventListener("hashchange",function(){o(location.hash.slice(1))}),o(location.hash.slice(1));var i,l=f(document.querySelectorAll(".pre-open"));try{for(l.s();!(i=l.n()).done;){i.value.addEventListener("mousedown",a,!1)}}catch(e){l.e(e)}finally{l.f()}function a(){o(this.hash.slice(1))}var c=document.querySelector("#split-left"),y=document.querySelector("#split-right");function p(){history.replaceState({leftTop:c.scrollTop,rightTop:y.scrollTop},document.title)}function h(e){e&&history.replaceState(e.state,document.title),history.state&&(c.scrollTop=history.state.leftTop,y.scrollTop=history.state.rightTop)}c.style.overflow="hidden",c.style.overflow="",Split(["#split-left","#split-right"],{elementStyle:function(e,t,n){return{"flex-basis":"calc("+t+"% - "+n+"px)"}},gutterStyle:function(e,t){return{"flex-basis":t+"px"}},gutterSize:20,sizes:[20,80]}),window.addEventListener("load",function(){setTimeout(function(){h(),p(),c.addEventListener("scroll",p),y.addEventListener("scroll",p)},1)}),window.addEventListener("popstate",h)}(); |
| 1 | +(function () { |
| 2 | + 'use strict'; |
| 3 | + |
| 4 | + /* eslint-env browser */ |
| 5 | + /* eslint new-cap:0,no-undef:0,unicorn/prefer-query-selector:0 */ |
| 6 | + /* global anchors */ |
| 7 | + |
| 8 | + // add anchor links to headers |
| 9 | + anchors.options.placement = 'left'; |
| 10 | + anchors.add('h3').remove('.no-anchor'); |
| 11 | + |
| 12 | + // Filter UI |
| 13 | + const tocElements = document.querySelector('#toc').querySelectorAll('li'); |
| 14 | + |
| 15 | + document.querySelector('#filter-input').addEventListener('keyup', event_ => { |
| 16 | + // Enter key |
| 17 | + if (event_.key === 'Enter') { |
| 18 | + // Go to the first displayed item in the toc |
| 19 | + for (const element of tocElements) { |
| 20 | + if (!element.classList.contains('display-none')) { |
| 21 | + location.replace(element.firstChild.href); |
| 22 | + return event_.preventDefault() |
| 23 | + } |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + let match = () => true; |
| 28 | + |
| 29 | + const value = document.querySelector('#filter-input').value.toLowerCase(); |
| 30 | + |
| 31 | + if (!/^\s*$/.test(value)) { |
| 32 | + match = element => |
| 33 | + element.firstChild.innerHTML |
| 34 | + && element.firstChild.innerHTML.toLowerCase().includes(value); |
| 35 | + } |
| 36 | + |
| 37 | + for (const element of tocElements) { |
| 38 | + const children = [...element.querySelectorAll('li')]; |
| 39 | + if (match(element) || children.some(child => match(child))) { |
| 40 | + element.classList.remove('display-none'); |
| 41 | + } else { |
| 42 | + element.classList.add('display-none'); |
| 43 | + } |
| 44 | + } |
| 45 | + }); |
| 46 | + |
| 47 | + const toggles = document.querySelectorAll('.toggle-sibling'); |
| 48 | + |
| 49 | + for (const toggle of toggles) { |
| 50 | + toggle.addEventListener('click', toggleSibling); |
| 51 | + } |
| 52 | + |
| 53 | + function toggleSibling() { |
| 54 | + const stepSibling = this.parentNode.querySelectorAll('.toggle-target')[0]; |
| 55 | + const icon = this.querySelectorAll('.icon')[0]; |
| 56 | + const klass = 'display-none'; |
| 57 | + if (stepSibling.classList.contains(klass)) { |
| 58 | + stepSibling.classList.remove(klass); |
| 59 | + icon.innerHTML = '▾'; |
| 60 | + } else { |
| 61 | + stepSibling.classList.add(klass); |
| 62 | + icon.innerHTML = '▸'; |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + function showHashTarget(targetId) { |
| 67 | + const hashTarget = document.getElementById(targetId); |
| 68 | + // New target is hidden |
| 69 | + if (hashTarget && hashTarget.offsetHeight === 0 |
| 70 | + && hashTarget.parentNode.parentNode.classList.contains('display-none')) { |
| 71 | + hashTarget.parentNode.parentNode.classList.remove('display-none'); |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + window.addEventListener('hashchange', () => { |
| 76 | + showHashTarget(location.hash.slice(1)); |
| 77 | + }); |
| 78 | + |
| 79 | + showHashTarget(location.hash.slice(1)); |
| 80 | + |
| 81 | + const toclinks = document.querySelectorAll('.pre-open'); |
| 82 | + |
| 83 | + for (const toclink of toclinks) { |
| 84 | + toclink.addEventListener('mousedown', preOpen, false); |
| 85 | + } |
| 86 | + |
| 87 | + function preOpen() { |
| 88 | + showHashTarget(this.hash.slice(1)); |
| 89 | + } |
| 90 | + |
| 91 | + const splitLeft = document.querySelector('#split-left'); |
| 92 | + const splitRight = document.querySelector('#split-right'); |
| 93 | + // TODO const splitParent = splitLeft.parentNode |
| 94 | + // TODO const cwWithSb = splitLeft.clientWidth |
| 95 | + splitLeft.style.overflow = 'hidden'; |
| 96 | + // TODO const cwWithoutSb = splitLeft.clientWidth |
| 97 | + splitLeft.style.overflow = ''; |
| 98 | + |
| 99 | + Split(['#split-left', '#split-right'], { |
| 100 | + elementStyle(dimension, size, gutterSize) { |
| 101 | + return { |
| 102 | + 'flex-basis': 'calc(' + size + '% - ' + gutterSize + 'px)', |
| 103 | + } |
| 104 | + }, |
| 105 | + gutterStyle(dimension, gutterSize) { |
| 106 | + return { |
| 107 | + 'flex-basis': gutterSize + 'px', |
| 108 | + } |
| 109 | + }, |
| 110 | + gutterSize: 20, |
| 111 | + sizes: [20, 80], |
| 112 | + }); |
| 113 | + |
| 114 | + // Chrome doesn't remember scroll position properly so do it ourselves. |
| 115 | + // Also works on Firefox and Edge. |
| 116 | + |
| 117 | + function updateState() { |
| 118 | + history.replaceState( |
| 119 | + { |
| 120 | + leftTop: splitLeft.scrollTop, |
| 121 | + rightTop: splitRight.scrollTop, |
| 122 | + }, |
| 123 | + document.title, |
| 124 | + ); |
| 125 | + } |
| 126 | + |
| 127 | + function loadState(ev) { |
| 128 | + if (ev) { |
| 129 | + // Edge doesn't replace change history.state on popstate. |
| 130 | + history.replaceState(ev.state, document.title); |
| 131 | + } |
| 132 | + |
| 133 | + if (history.state) { |
| 134 | + splitLeft.scrollTop = history.state.leftTop; |
| 135 | + splitRight.scrollTop = history.state.rightTop; |
| 136 | + } |
| 137 | + } |
| 138 | + |
| 139 | + window.addEventListener('load', () => { |
| 140 | + // Restore after Firefox scrolls to hash. |
| 141 | + setTimeout(() => { |
| 142 | + loadState(); |
| 143 | + // Update with initial scroll position. |
| 144 | + updateState(); |
| 145 | + // Update scroll positions only after we've loaded because Firefox |
| 146 | + // emits an initial scroll event with 0. |
| 147 | + splitLeft.addEventListener('scroll', updateState); |
| 148 | + splitRight.addEventListener('scroll', updateState); |
| 149 | + }, 1); |
| 150 | + }); |
| 151 | + |
| 152 | + window.addEventListener('popstate', loadState); |
| 153 | + |
| 154 | +})(); |
0 commit comments