2018-04-29 00:06:46 +00:00
|
|
|
/**
|
|
|
|
* Initialise changelog
|
|
|
|
*/
|
|
|
|
import initChangelog from './changelog.vue.js';
|
|
|
|
|
|
|
|
{
|
|
|
|
const selector = '[data-vue="changelog"]';
|
|
|
|
if (window.Vue && document.querySelector(selector)) {
|
|
|
|
initChangelog(selector, 'explosion/spacy');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialise models
|
|
|
|
*/
|
|
|
|
import initModels from './models.vue.js';
|
|
|
|
|
|
|
|
{
|
|
|
|
if (window.Vue && document.querySelector('[data-model]')) {
|
|
|
|
initModels('explosion/spacy-models')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialise Universe
|
|
|
|
*/
|
|
|
|
import initUniverse from './universe.vue.js';
|
|
|
|
|
|
|
|
{
|
|
|
|
const selector = '[data-vue="universe"]';
|
|
|
|
if (window.Vue && document.querySelector(selector)) {
|
|
|
|
initUniverse(selector, '/universe/universe.json');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialise Quickstart
|
|
|
|
*/
|
2018-04-30 16:48:35 +00:00
|
|
|
{
|
|
|
|
if (document.querySelector('#qs') && window.Quickstart) {
|
|
|
|
new Quickstart('#qs');
|
|
|
|
}
|
2018-04-29 00:06:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-04-30 16:48:35 +00:00
|
|
|
* Initialise Juniper
|
2018-04-29 00:06:46 +00:00
|
|
|
*/
|
2018-04-30 16:48:35 +00:00
|
|
|
{
|
|
|
|
if (window.Juniper) {
|
2018-06-28 09:48:17 +00:00
|
|
|
new Juniper({
|
|
|
|
repo: 'ines/spacy-io-binder',
|
2018-08-15 13:28:48 +00:00
|
|
|
branch: 'live',
|
2018-06-28 09:48:17 +00:00
|
|
|
storageExpire: 60
|
|
|
|
});
|
2018-04-30 16:48:35 +00:00
|
|
|
}
|
2018-04-29 00:06:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Highlight section in viewport in sidebar, using in-view library
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
const sectionAttr = 'data-section';
|
|
|
|
const navAttr = 'data-nav';
|
|
|
|
const activeClass = 'is-active';
|
2018-06-11 15:47:46 +00:00
|
|
|
const sidebarAttr = 'data-sidebar-active';
|
2018-04-29 00:06:46 +00:00
|
|
|
const sections = [...document.querySelectorAll(`[${navAttr}]`)];
|
2018-06-11 15:47:46 +00:00
|
|
|
const currentItem = document.querySelector(`[${sidebarAttr}]`);
|
2018-04-29 00:06:46 +00:00
|
|
|
if (window.inView) {
|
2018-06-12 08:58:50 +00:00
|
|
|
if (currentItem && Element.prototype.scrollIntoView && !inView.is(currentItem)) {
|
|
|
|
currentItem.scrollIntoView();
|
|
|
|
}
|
2018-04-29 00:06:46 +00:00
|
|
|
if (sections.length) { // highlight first item regardless
|
|
|
|
sections[0].classList.add(activeClass);
|
|
|
|
}
|
|
|
|
inView(`[${sectionAttr}]`).on('enter', section => {
|
|
|
|
const id = section.getAttribute(sectionAttr);
|
|
|
|
const el = document.querySelector(`[${navAttr}="${id}"]`);
|
|
|
|
if (el) {
|
|
|
|
sections.forEach(el => el.classList.remove(activeClass));
|
|
|
|
el.classList.add(activeClass);
|
2018-06-12 08:58:50 +00:00
|
|
|
if (Element.prototype.scrollIntoView && !inView.is(el)) {
|
2018-06-11 15:47:46 +00:00
|
|
|
el.scrollIntoView();
|
|
|
|
}
|
2018-04-29 00:06:46 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Simple, collapsible accordion sections.
|
|
|
|
* Inspired by: https://inclusive-components.design/collapsible-sections/
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
const elements = [...document.querySelectorAll('.js-accordion')];
|
|
|
|
elements.forEach(el => el.addEventListener('click', ({ target }) => {
|
|
|
|
const exp = target.getAttribute('aria-expanded') === 'true' || false;
|
|
|
|
target.setAttribute('aria-expanded', !exp);
|
|
|
|
target.parentElement.nextElementSibling.hidden = exp;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reading indicator as progress bar
|
|
|
|
* @param {string} selector - Selector of <progress> element.
|
|
|
|
*/
|
|
|
|
class ProgressBar {
|
|
|
|
constructor(selector) {
|
|
|
|
this.scrollY = 0;
|
|
|
|
this.sizes = this.updateSizes();
|
|
|
|
this.el = document.querySelector(selector);
|
|
|
|
this.el.setAttribute('max', 100);
|
|
|
|
window.addEventListener('scroll', ev => {
|
|
|
|
this.scrollY = (window.pageYOffset || document.scrollTop) - (document.clientTop || 0);
|
|
|
|
requestAnimationFrame(this.update.bind(this));
|
|
|
|
});
|
|
|
|
window.addEventListener('resize', ev => {
|
|
|
|
this.sizes = this.updateSizes();
|
|
|
|
requestAnimationFrame(this.update.bind(this));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
update() {
|
|
|
|
const offset = 100 - ((this.sizes.height - this.scrollY - this.sizes.vh) / this.sizes.height * 100);
|
|
|
|
this.el.setAttribute('value', (this.scrollY == 0) ? 0 : offset || 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateSizes() {
|
|
|
|
return {
|
|
|
|
height: Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight),
|
|
|
|
vh: Math.max(document.documentElement.clientHeight, window.innerHeight || 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
new ProgressBar('.js-progress');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Embed code from GitHub repositories, similar to Gist embeds. Fetches the
|
|
|
|
* raw text and places it inside element.
|
|
|
|
* Usage: <pre><code data-gh-embed="spacy/master/examples/x.py"></code><pre>
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
const attr = 'data-gh-embed';
|
|
|
|
const url = 'https://raw.githubusercontent.com/explosion';
|
|
|
|
const elements = [...document.querySelectorAll(`[${attr}]`)];
|
|
|
|
elements.forEach(el => {
|
|
|
|
el.parentElement.setAttribute('data-loading', '');
|
|
|
|
fetch(`${url}/${el.getAttribute(attr)}`)
|
|
|
|
.then(res => res.text().then(text => ({ text, ok: res.ok })))
|
|
|
|
.then(({ text, ok }) => {
|
|
|
|
if (ok) {
|
|
|
|
el.textContent = text;
|
|
|
|
if (window.Prism) Prism.highlightElement(el);
|
|
|
|
}
|
|
|
|
el.parentElement.removeAttribute('data-loading');
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|