mirror of
https://github.com/readthedocs/sphinx_rtd_theme.git
synced 2025-02-25 18:55:21 -06:00
Use the prettier to lint the file
This commit is contained in:
parent
2fc2aaa002
commit
26cdafa32e
@ -1,22 +1,29 @@
|
||||
{%- if theme_flyout_display == "attached" %}
|
||||
function renderLanguages(config) {
|
||||
if (!config.projects.translations.length) {
|
||||
return "";
|
||||
}
|
||||
const themeFlyoutDisplay = "{{ theme_flyout_display }}";
|
||||
const themeVersionSelector = "{{ theme_version_selector }}";
|
||||
const themeLanguageSelector = "{{ theme_language_selector }}";
|
||||
|
||||
const languagesHTML = `
|
||||
<dl>
|
||||
<dt>{{ _('Languages') }}</dt>
|
||||
${ config.projects.translations.map(
|
||||
(translation) => `
|
||||
<dd ${ translation.slug == config.projects.current.slug ? 'class="rtd-current-item"' : '' }>
|
||||
<a href="${ translation.urls.documentation }">${ translation.language.code }</a>
|
||||
</dd>
|
||||
`).join("\n")}
|
||||
</dl>
|
||||
`;
|
||||
return languagesHTML;
|
||||
}
|
||||
if (themeFlyoutDisplay === "attached") {
|
||||
function renderLanguages(config) {
|
||||
if (!config.projects.translations.length) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const languagesHTML = `
|
||||
<dl>
|
||||
<dt>{{ _('Languages') }}</dt>
|
||||
${config.projects.translations
|
||||
.map(
|
||||
(translation) => `
|
||||
<dd ${translation.slug == config.projects.current.slug ? 'class="rtd-current-item"' : ""}>
|
||||
<a href="${translation.urls.documentation}">${translation.language.code}</a>
|
||||
</dd>
|
||||
`,
|
||||
)
|
||||
.join("\n")}
|
||||
</dl>
|
||||
`;
|
||||
return languagesHTML;
|
||||
}
|
||||
|
||||
function renderVersions(config) {
|
||||
if (!config.versions.active.length) {
|
||||
@ -25,12 +32,15 @@ function renderLanguages(config) {
|
||||
const versionsHTML = `
|
||||
<dl>
|
||||
<dt>{{ _('Versions') }}</dt>
|
||||
${ config.versions.active.map(
|
||||
(version) => `
|
||||
<dd ${ version.slug === config.versions.current.slug ? 'class="rtd-current-item"' : '' }>
|
||||
<a href="${ version.urls.documentation }">${ version.slug }</a>
|
||||
${config.versions.active
|
||||
.map(
|
||||
(version) => `
|
||||
<dd ${version.slug === config.versions.current.slug ? 'class="rtd-current-item"' : ""}>
|
||||
<a href="${version.urls.documentation}">${version.slug}</a>
|
||||
</dd>
|
||||
`).join("\n")}
|
||||
`,
|
||||
)
|
||||
.join("\n")}
|
||||
</dl>
|
||||
`;
|
||||
return versionsHTML;
|
||||
@ -49,42 +59,45 @@ function renderLanguages(config) {
|
||||
const downloadsHTML = `
|
||||
<dl>
|
||||
<dt>{{ _('Downloads') }}</dt>
|
||||
${ Object.entries(config.versions.current.downloads).map(
|
||||
([name, url]) => `
|
||||
${Object.entries(config.versions.current.downloads)
|
||||
.map(
|
||||
([name, url]) => `
|
||||
<dd>
|
||||
<a href="${ url }">${ downloadsNameDisplay[name] }</a>
|
||||
<a href="${url}">${downloadsNameDisplay[name]}</a>
|
||||
</dd>
|
||||
`).join("\n")}
|
||||
`,
|
||||
)
|
||||
.join("\n")}
|
||||
</dl>
|
||||
`;
|
||||
return downloadsHTML;
|
||||
}
|
||||
|
||||
document.addEventListener("readthedocs-addons-data-ready", function(event) {
|
||||
document.addEventListener("readthedocs-addons-data-ready", function (event) {
|
||||
const config = event.detail.data();
|
||||
|
||||
const flyout = `
|
||||
<div class="rst-versions" data-toggle="rst-versions" role="note">
|
||||
<span class="rst-current-version" data-toggle="rst-current-version">
|
||||
<span class="fa fa-book"> Read the Docs</span>
|
||||
v: ${ config.versions.current.slug }
|
||||
v: ${config.versions.current.slug}
|
||||
<span class="fa fa-caret-down"></span>
|
||||
</span>
|
||||
<div class="rst-other-versions">
|
||||
<div class="injected">
|
||||
${ renderLanguages(config) }
|
||||
${ renderVersions(config) }
|
||||
${ renderDownloads(config) }
|
||||
${renderLanguages(config)}
|
||||
${renderVersions(config)}
|
||||
${renderDownloads(config)}
|
||||
<dl>
|
||||
<dt>{{ _('On Read the Docs') }}</dt>
|
||||
<dd>
|
||||
<a href="${ config.projects.current.urls.home }">{{ _('Project Home') }}</a>
|
||||
<a href="${config.projects.current.urls.home}">{{ _('Project Home') }}</a>
|
||||
</dd>
|
||||
<dd>
|
||||
<a href="${ config.projects.current.urls.builds }">{{ _('Builds') }}</a>
|
||||
<a href="${config.projects.current.urls.builds}">{{ _('Builds') }}</a>
|
||||
</dd>
|
||||
<dd>
|
||||
<a href="${ config.projects.current.urls.downloads }">{{ _('Downloads') }}</a>
|
||||
<a href="${config.projects.current.urls.downloads}">{{ _('Downloads') }}</a>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl>
|
||||
@ -113,82 +126,96 @@ function renderLanguages(config) {
|
||||
document.body.insertAdjacentHTML("beforeend", flyout);
|
||||
|
||||
// Trigger the Read the Docs Addons Search modal when clicking on the "Search docs" input from inside the flyout.
|
||||
document.querySelector("#flyout-search-form").addEventListener("focusin", () => {
|
||||
const event = new CustomEvent("readthedocs-search-show");
|
||||
document.dispatchEvent(event);
|
||||
});
|
||||
document
|
||||
.querySelector("#flyout-search-form")
|
||||
.addEventListener("focusin", () => {
|
||||
const event = new CustomEvent("readthedocs-search-show");
|
||||
document.dispatchEvent(event);
|
||||
});
|
||||
|
||||
// Trigger the Read the Docs Addons Search modal when clicking on "Search docs" input from the topnav.
|
||||
document.querySelector("[role='search'] input").addEventListener("focusin", () => {
|
||||
const event = new CustomEvent("readthedocs-search-show");
|
||||
document.dispatchEvent(event);
|
||||
});
|
||||
});
|
||||
{%- endif %}
|
||||
document
|
||||
.querySelector("[role='search'] input")
|
||||
.addEventListener("focusin", () => {
|
||||
const event = new CustomEvent("readthedocs-search-show");
|
||||
document.dispatchEvent(event);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
{%- if theme_version_selector or theme_language_selector %}
|
||||
function onSelectorSwitch(event) {
|
||||
const option = event.target.selectedIndex;
|
||||
const item = event.target.options[option];
|
||||
window.location.href = item.dataset.url;
|
||||
}
|
||||
|
||||
document.addEventListener("readthedocs-addons-data-ready", function(event) {
|
||||
const config = event.detail.data();
|
||||
|
||||
const versionSwitch = document.querySelector("div.switch-menus > div.version-switch");
|
||||
const languageSwitch = document.querySelector("div.switch-menus > div.language-switch");
|
||||
|
||||
const dropdownSelectors = document.querySelector("div.dropdown-selectors");
|
||||
|
||||
{%- if theme_version_selector %}
|
||||
let versions = config.versions.active;
|
||||
if (config.versions.current.type === "external") {
|
||||
versions.unshift(config.versions.current);
|
||||
if (themeLanguageSelector || themeVersionSelector) {
|
||||
function onSelectorSwitch(event) {
|
||||
const option = event.target.selectedIndex;
|
||||
const item = event.target.options[option];
|
||||
window.location.href = item.dataset.url;
|
||||
}
|
||||
const versionSelect = `
|
||||
|
||||
document.addEventListener("readthedocs-addons-data-ready", function (event) {
|
||||
const config = event.detail.data();
|
||||
|
||||
const versionSwitch = document.querySelector(
|
||||
"div.switch-menus > div.version-switch",
|
||||
);
|
||||
const languageSwitch = document.querySelector(
|
||||
"div.switch-menus > div.language-switch",
|
||||
);
|
||||
|
||||
const dropdownSelectors = document.querySelector("div.dropdown-selectors");
|
||||
|
||||
if (themeVersionSelector) {
|
||||
let versions = config.versions.active;
|
||||
if (config.versions.current.type === "external") {
|
||||
versions.unshift(config.versions.current);
|
||||
}
|
||||
const versionSelect = `
|
||||
<select>
|
||||
${ versions.map(
|
||||
${versions
|
||||
.map(
|
||||
(version) => `
|
||||
<option
|
||||
value="${ version.slug }"
|
||||
${ config.versions.current.slug === version.slug ? 'selected="selected"' : '' }
|
||||
data-url="${ version.urls.documentation }">
|
||||
${ version.slug }
|
||||
</option>`
|
||||
).join("\n") }
|
||||
value="${version.slug}"
|
||||
${config.versions.current.slug === version.slug ? 'selected="selected"' : ""}
|
||||
data-url="${version.urls.documentation}">
|
||||
${version.slug}
|
||||
</option>`,
|
||||
)
|
||||
.join("\n")}
|
||||
</select>
|
||||
`;
|
||||
|
||||
versionSwitch.innerHTML = versionSelect;
|
||||
versionSwitch.firstChild.addEventListener("change", onSelectorSwitch);
|
||||
{%- endif %}
|
||||
versionSwitch.innerHTML = versionSelect;
|
||||
versionSwitch.firstChild.addEventListener("change", onSelectorSwitch);
|
||||
}
|
||||
|
||||
if (themeLanguageSelector) {
|
||||
if (config.projects.translations.length) {
|
||||
// Add the current language to the options on the selector
|
||||
let languages = config.projects.translations.concat(
|
||||
config.projects.current,
|
||||
);
|
||||
languages = languages.sort((a, b) =>
|
||||
a.language.name.localeCompare(b.language.name),
|
||||
);
|
||||
|
||||
{%- if theme_language_selector %}
|
||||
if (config.projects.translations.length) {
|
||||
// Add the current language to the options on the selector
|
||||
let languages = config.projects.translations.concat(config.projects.current);
|
||||
languages = languages.sort((a, b) => a.language.name.localeCompare(b.language.name));
|
||||
|
||||
const languageSelect= `
|
||||
const languageSelect = `
|
||||
<select>
|
||||
${ languages.map(
|
||||
(language) => `
|
||||
${languages
|
||||
.map(
|
||||
(language) => `
|
||||
<option
|
||||
value="${ language.language.code }"
|
||||
${ config.projects.current.slug === language.slug ? 'selected="selected"' : '' }
|
||||
data-url="${ language.urls.documentation }">
|
||||
${ language.language.name }
|
||||
</option>`
|
||||
).join("\n") }
|
||||
value="${language.language.code}"
|
||||
${config.projects.current.slug === language.slug ? 'selected="selected"' : ""}
|
||||
data-url="${language.urls.documentation}">
|
||||
${language.language.name}
|
||||
</option>`,
|
||||
)
|
||||
.join("\n")}
|
||||
</select>
|
||||
`;
|
||||
|
||||
languageSwitch.innerHTML = languageSelect;
|
||||
languageSwitch.firstChild.addEventListener("change", onSelectorSwitch);
|
||||
}
|
||||
{%- endif %}
|
||||
});
|
||||
{%- endif %}
|
||||
languageSwitch.innerHTML = languageSelect;
|
||||
languageSwitch.firstChild.addEventListener("change", onSelectorSwitch);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user