123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- var closure = window.closure || {};
- closure.docs = closure.docs || {};
- closure.docs.LOCATION = String(window.location);
- closure.docs.get = function(param) {
- var data = window['_JEKYLL_DATA'];
- return data && data[param];
- };
- closure.docs.forEachElement = function(selector, func) {
- var elements = document.querySelectorAll(selector);
- for (var i = 0, length = elements.length; i < length; i++) {
- func(elements[i]);
- }
- };
- closure.docs.forEachHeading = function(func) {
- closure.docs.forEachElement(
- 'article > h1, article > h2, article > h3, ' +
- 'article > h4, article > h5, article > h6',
- function(heading) {
- var match = /^h(\d)$/i.exec(heading.tagName);
- func(heading, Number(match[1]));
- });
- };
- closure.docs.addScrollListener = function() {
-
- var last = void 0;
-
- var threshold = 140;
- document.addEventListener('scroll', function() {
- var top = document.body.scrollTop;
- document.body.classList.toggle('scrolled', top > threshold);
- document.body.classList.toggle('down', top > last);
- last = top;
- });
- };
- closure.docs.interceptLinkClicks = function() {
-
- function scrollToHash() {
- var hash = window.location.hash.substring(1);
- if (hash) {
- var el = document.getElementById(hash);
- var delta = document.body.classList.contains('scrolled') ? 72 : 128;
- document.body.scrollTop = el.offsetTop - delta;
- }
- }
- document.addEventListener('click', function(e) {
- if (!e.target || e.target.tagName != 'A') return;
- var href = e.target.getAttribute('href');
- if (href && href[0] == '#') {
- window.location.hash = href;
- requestAnimationFrame(scrollToHash);
- e.preventDefault();
- }
- });
-
- requestAnimationFrame(scrollToHash);
- };
- closure.docs.findTitle = function() {
-
- var h1 = document.querySelectorAll('article > h1')[1];
- if (h1) {
- var pageTitle = h1.textContent;
- h1.remove();
- var title = document.querySelector('title');
- if (!title.textContent) title.textContent = pageTitle;
- var heading = document.querySelector('h1#top_of_page');
- if (heading && !heading.textContent) heading.textContent = pageTitle;
- }
- };
- closure.docs.autoNumber = function() {
- var min = Number(closure.docs.get('page.toc.min') || 2);
- var nums = [];
- var ids = {};
- closure.docs.forEachHeading(function(heading, level) {
- if (level < min) return;
-
-
- while (nums.length > level - min + 1) {
- nums.pop();
- }
- if (!/^\d/.test(heading.textContent)) return;
- while (nums.length < level - min + 1) {
- nums.push(0);
- }
- nums[nums.length - 1]++;
-
- if (!heading.id) {
- var base = '_' +
- heading.textContent.toLowerCase()
- .replace(/[^a-z]+/g, '-')
- .replace(/^-|-$/g, '');
- var suffix = '';
- while (base + suffix in ids) {
- suffix++;
- }
- heading.id = base + suffix;
- ids[base + suffix] = true;
- }
-
- heading.textContent =
- heading.textContent.replace(/^\d+(\.\d+)*/, nums.join('.'));
- });
- };
- closure.docs.fixLinkText = function() {
- closure.docs.forEachElement('a', function(link) {
- var href = link.getAttribute('href');
- if (!/^#/.test(href) || !/^\?\?+$/.test(link.textContent)) return;
- var heading = document.getElementById(href.substring(1));
- if (heading) link.textContent = heading.textContent;
-
- });
- };
- closure.docs.buildToc = function() {
-
- var min = Number(closure.docs.get('page.toc.min') || 2);
- var max = Number(closure.docs.get('page.toc.max') || 3);
-
- var stack = [];
- closure.docs.forEachHeading(function(heading, level) {
- if (level < min || level > max) return;
- var depth = level - min + 1;
- while (stack.length > depth) {
- stack.pop();
- }
- while (stack.length < depth) {
- var list = document.createElement('ul');
-
- var prev = stack[stack.length - 1];
- if (prev) {
- if (!prev.lastChild) prev.appendChild(document.createElement('li'));
- prev.lastChild.appendChild(list);
- }
- stack.push(list);
- }
- var item = document.createElement('li');
- stack[stack.length - 1].appendChild(item);
- var link = document.createElement('a');
- item.appendChild(link);
- link.href = '#' + heading.id;
- link.textContent = heading.textContent;
- });
-
- var toc = stack[0];
- closure.docs.forEachElement('nav.toc ul', function(ul) {
- if (toc && toc.innerHTML) {
- ul.innerHTML += toc.innerHTML;
- } else {
- ul.parentElement.remove();
- }
- });
- };
- closure.docs.fixSyntaxHighlighting = function() {
- closure.docs.forEachElement('.highlight .nx+.p', function(p) {
- if (p.textContent[0] == '(') p.previousElementSibling.className = 'nf';
- });
- };
- closure.docs.highlightCallouts = function() {
- closure.docs.forEachElement('p', function(p) {
- var match = /^([A-Za-z]+):/.exec(p.textContent);
- if (match) p.classList.add('callout-' + match[1].toLowerCase());
- });
- };
- closure.docs.setEditLink = function() {
- var link = document.querySelector('a.edit');
- var match =
- /\/\/([^.]+).github.io\/([^/]+)\/(.*)$/.exec(closure.docs.LOCATION);
- if (!match || !link) return;
- link.href = [
- 'https://github.com', match[1], match[2], 'edit/master/doc',
- match[3] + '.md'
- ].join('/');
- };
- closure.docs.markActiveNav = function() {
-
- var abs = (function() {
- var link = document.createElement('a');
- return function(rel) {
- link.href = rel;
- return link.href;
- };
- })();
-
- var suffix = function(prefix, string) {
- return string.substring(0, prefix.length) == prefix ?
- string.substring(prefix.length) :
- '';
- };
-
- var location = closure.docs.LOCATION;
- var page = location.replace(/\.(?:md|html)?/, '');
- var section = location.substring(0, location.lastIndexOf('/'));
-
- var sectionParameter = closure.docs.get('page.section');
- if (sectionParameter != null) {
- var root = closure.docs.get('site.baseurl;') || '/';
- if (root.length > 1 && root[root.length - 1] == '/') {
- root = root.substring(0, root.length - 1);
- }
- section = abs(root + '/' + sectionParameter.replace(/^\/|\/$/g, ''));
- }
-
- closure.docs.forEachElement('header nav a', function(a) {
- if (/^\/[^/]*$/.test(suffix(section, a.href))) {
- a.classList.add('active');
- }
- });
- closure.docs.forEachElement('nav.side a', function(a) {
- if (/^(\.html|\.md)?$/.test(suffix(page, a.href))) {
- a.classList.add('active');
- }
- });
- };
- closure.docs.startAnalytics = function() {
- var productKey = closure.docs.get('page.ga');
- if (!productKey) return;
- (function(i, s, o, g, r, a, m) {
- i['GoogleAnalyticsObject'] = r;
- i[r] = i[r] || function() {
- (i[r].q = i[r].q || []).push(arguments);
- }, i[r].l = 1 * new Date();
- a = s.createElement(o), m = s.getElementsByTagName(o)[0];
- a.async = 1;
- a.src = g;
- m.parentNode.insertBefore(a, m);
- })(window, document, 'script', '//www.google-analytics.com/analytics.js',
- 'ga');
- window['ga']('create', productKey, 'auto');
- window['ga']('send', 'pageview');
- };
- closure.docs.initialize = function() {
- closure.docs.findTitle();
- closure.docs.autoNumber();
- closure.docs.buildToc();
- closure.docs.fixLinkText();
- closure.docs.fixSyntaxHighlighting();
- closure.docs.highlightCallouts();
- closure.docs.markActiveNav();
- closure.docs.addScrollListener();
- closure.docs.interceptLinkClicks();
- closure.docs.setEditLink();
- closure.docs.startAnalytics();
- };
|