Skip to content

Commit

Permalink
add eslint
Browse files Browse the repository at this point in the history
- relates to #170
  • Loading branch information
LB Johnston committed May 28, 2022
1 parent 0a9dcb8 commit 3955d03
Show file tree
Hide file tree
Showing 7 changed files with 2,981 additions and 221 deletions.
8 changes: 8 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
*.min.js
**/lib/
public/
coverage/
**/vendor/
docs/_build
sphinx_wagtail_theme/static
14 changes: 14 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"root": true,
"extends": ["@wagtail/eslint-config-wagtail"],
"env": { "browser": true },
"globals": {
"DOCUMENTATION_OPTIONS": "readonly",
"Search": "readonly"
},
"rules": {
"no-plusplus": "off",
"no-underscore-dangle": ["error", { "allow": ["_index"] }],
"vars-on-top": "off"
}
}
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ jobs:
- uses: actions/setup-python@v2
with:
python-version: 3.7
- run: make setup
- run: make setup
- run: make install-for-development
- run: make lint-minimal
- run: npm run lint:css
- run: npm run lint
- run: make test

visual-regression-tests:
Expand Down
86 changes: 47 additions & 39 deletions js/theme.js
Original file line number Diff line number Diff line change
@@ -1,118 +1,126 @@
// T3Docs
import '../sass/theme.scss';
import autocomplete from 'autocompleter'
import 'bootstrap';
import "../sass/theme.scss";
import autocomplete from "autocompleter";
import "bootstrap";

// Ensure our own namespace
if (typeof window.T3Docs === 'undefined') {
if (typeof window.T3Docs === "undefined") {
window.T3Docs = {};
}


// Inject collapsible menu
function toggleCurrent(event) {
event.preventDefault();
var link = event.currentTarget.parentElement;
var element = link.parentElement;
var siblings = element.parentElement.parentElement.querySelectorAll('li.current');
var siblings =
element.parentElement.parentElement.querySelectorAll("li.current");
for (var i = 0; i < siblings.length; i++) {
if (siblings[i] !== element) {
siblings[i].classList.remove('current');
siblings[i].classList.remove("current");
}
}
element.classList.toggle('current');
element.classList.toggle("current");
}

function makeMenuExpandable() {
var toc = document.querySelector('.toc');
var links = toc.getElementsByTagName('a');
var toc = document.querySelector(".toc");
var links = toc.getElementsByTagName("a");
for (var i = 0; i < links.length; i++) {
if (links[i].nextSibling) {
var expand = document.createElement('span');
expand.classList.add('toctree-expand');
expand.addEventListener('click', toggleCurrent, true);
var expand = document.createElement("span");
expand.classList.add("toctree-expand");
expand.addEventListener("click", toggleCurrent, true);
links[i].prepend(expand);
}
}
}
makeMenuExpandable();

makeMenuExpandable();

// Wrap tables to make them responsive
function makeTablesResponsive() {
var tables = document.querySelectorAll('.rst-content table.docutils');
var tables = document.querySelectorAll(".rst-content table.docutils");
for (var i = 0; i < tables.length; i++) {
wrapper = document.createElement('div');
wrapper.classList.add('table-responsive');
const wrapper = document.createElement("div");
wrapper.classList.add("table-responsive");
tables[i].parentNode.insertBefore(wrapper, tables[i]);
wrapper.appendChild(tables[i]);
}
}
makeTablesResponsive();

makeTablesResponsive();

// Search
document.addEventListener('DOMContentLoaded', function () {
document.addEventListener("DOMContentLoaded", () => {
var searchform = document.getElementById("search-form");
var searchinput = document.getElementById("searchinput");
if (searchform && searchinput) {
autocomplete({
input: searchinput,
fetch: function (text, update) {
fetch: (text, update) => {
// Populate autocomplete suggestions from the Sphinx `Search` object.
if (typeof window.T3Docs.autocomplete === 'undefined') {
window.T3Docs.autocomplete = new Array();
if (typeof window.T3Docs.autocomplete === "undefined") {
window.T3Docs.autocomplete = [];
// Add page titles first.
Object.keys(Search._index.titles).forEach(function (item) {
Object.keys(Search._index.titles).forEach((item) => {
window.T3Docs.autocomplete.push({
label: Search._index.titles[item],
docname: Search._index.docnames[item],
group: "Pages",
});
});
// Add autodoc/code terms second.
Object.keys(Search._index.objects).forEach(function (item) {
Object.keys(Search._index.objects[item]).forEach(function (subitem) {
Object.keys(Search._index.objects).forEach((item) => {
Object.keys(Search._index.objects[item]).forEach((subitem) => {
window.T3Docs.autocomplete.push({
label: `${item}.${subitem}`,
group: "Code reference"
group: "Code reference",
});
});
});
}
var suggestions = window.T3Docs.autocomplete.filter(function (entry) {
return entry.label.toLowerCase().includes(text.toLowerCase());
});
var suggestions = window.T3Docs.autocomplete.filter((entry) =>
entry.label.toLowerCase().includes(text.toLowerCase())
);
update(suggestions);
},
minLength: 3,
render: function (item) {
render: (item) => {
var div = document.createElement("div");
div.textContent = item.label;
return div;
},
customize: function(input, inputRect, container, maxHeight) {
customize: (input, inputRect, container) => {
// Do not force same width as input box - allow it to go wider.
// eslint-disable-next-line no-param-reassign
container.style.minWidth = inputRect.width + "px";
// eslint-disable-next-line no-param-reassign
container.style.width = "auto";
},
onSelect: function (item) {
onSelect: (item) => {
// If they selected a page, disable search form and go straight to it.
if(item.docname !== undefined) {
searchform.onsubmit = function(){ return false };
if (item.docname !== undefined) {
searchform.onsubmit = function onsubmit() {
return false;
};
// Figure out the URL from the docname.
// Mostly taken from Sphinx's searchtools.js
var linkUrl;
if (DOCUMENTATION_OPTIONS.BUILDER === "dirhtml") {
var dirname = item.docname + "/";
if (dirname.match(/\/index\/$/)) {
dirname = dirname.substring(0, dirname.length-6);
} else if (dirname == 'index/') {
dirname = '';
dirname = dirname.substring(0, dirname.length - 6);
} else if (dirname === "index/") {
dirname = "";
}
linkUrl = DOCUMENTATION_OPTIONS.URL_ROOT + dirname;
} else {
// normal html builders
linkUrl = DOCUMENTATION_OPTIONS.URL_ROOT + item.docname + DOCUMENTATION_OPTIONS.FILE_SUFFIX;
linkUrl =
DOCUMENTATION_OPTIONS.URL_ROOT +
item.docname +
DOCUMENTATION_OPTIONS.FILE_SUFFIX;
}
// Go to the URL.
window.location.href = linkUrl;
Expand All @@ -122,7 +130,7 @@ document.addEventListener('DOMContentLoaded', function () {
searchinput.value = item.label;
searchform.submit();
}
}
},
});
}
});
Loading

0 comments on commit 3955d03

Please sign in to comment.