mirror of
https://github.com/tuna/mirror-web.git
synced 2025-12-25 20:32:46 +00:00
optimize z-help
Signed-off-by: Miao Wang <shankerwangmiao@gmail.com>
This commit is contained in:
parent
9e4b60a0a5
commit
9fdd14242f
|
|
@ -56,12 +56,6 @@ plugins:
|
|||
|
||||
babel_js_extensions: 'es6'
|
||||
|
||||
jekyll-minifier:
|
||||
# remove_spaces_inside_tags: false
|
||||
remove_multi_spaces: false
|
||||
# preserve_patterns:
|
||||
# - /<tmpl[\s\S]*?>[\s\S]*?<\/tmpl>/m
|
||||
|
||||
exclude: [Gemfile, Gemfile.lock, README.md, gen_robot.sh, vendor, geninfo/, gen_robot.sh, gen_desc.py, Dockerfile*]
|
||||
|
||||
sponsors:
|
||||
|
|
|
|||
|
|
@ -16,6 +16,11 @@
|
|||
<script>
|
||||
window.mirrorId = "{{page.mirrorid}}";
|
||||
</script>
|
||||
<style>
|
||||
.z-help pre.z-tmpl {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
{% assign help_pages = site.categories["help"] | sort: 'mirrorid' %}
|
||||
<div id="help-page">
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 5d50d50256629e6dfca83300e3a843392b5a8d69
|
||||
Subproject commit c7768b7c49e7a561a5f703115777970c0b4c1c88
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
---
|
||||
---
|
||||
|
||||
window.addEventListener('DOMContentLoaded', function () {
|
||||
|
||||
function generateFormConfig(form) {
|
||||
const formData = Object.fromEntries(new FormData(form).entries());
|
||||
Array.from( // FormData ignores unchecked checkboxes, workaround
|
||||
|
|
@ -54,7 +56,6 @@ function renderCode(tmpl) {
|
|||
let rendered = globalThis.Mustache.render(
|
||||
tmpl.textContent.trim(), conf, {}, { escape: x => x }
|
||||
)
|
||||
console.log(rendered);
|
||||
try {
|
||||
const lang = tmpl.attributes.getNamedItem('z-lang');
|
||||
if (lang && hljs.getLanguage(lang.value)) {
|
||||
|
|
@ -68,26 +69,33 @@ function renderCode(tmpl) {
|
|||
|
||||
function renderForm(event) {
|
||||
if (!event || event.currentTarget.classList.contains('z-global')) {
|
||||
Array.from(document.querySelectorAll('.z-help tmpl')).forEach(renderCode);
|
||||
Array.from(document.querySelectorAll('.z-help pre.z-tmpl')).forEach(renderCode);
|
||||
}
|
||||
else {
|
||||
renderCode(event.currentTarget.parentElement.nextElementSibling);
|
||||
}
|
||||
}
|
||||
|
||||
const form_update = renderForm;
|
||||
|
||||
// Load project config
|
||||
const GLOBAL_CONFIG = JSON.parse(atob(document.getElementById('z-config').textContent));
|
||||
|
||||
// Adjust <h1> and top <form> postion
|
||||
const h1 = document.getElementsByTagName('h1')[0];
|
||||
h1.parentElement.parentElement.insertBefore(h1, h1.parentElement.previousElementSibling);
|
||||
|
||||
// Hide HTTPS selector if filtered
|
||||
if (GLOBAL_CONFIG.filter && GLOBAL_CONFIG.filter.scheme) {
|
||||
document.querySelector('input[name="_scheme"]').parentElement.style.display = 'none';
|
||||
}
|
||||
|
||||
// Render code
|
||||
window.addEventListener('DOMContentLoaded', () => { renderForm(null); });
|
||||
renderForm(null);
|
||||
|
||||
const ignoreEventHandler = (event) => event.preventDefault();
|
||||
|
||||
for(const form of document.querySelectorAll('form.z-form')) {
|
||||
form.addEventListener('submit', ignoreEventHandler);
|
||||
if(form.classList.contains('z-global')) {
|
||||
form.addEventListener('change', ()=>renderForm(null));
|
||||
}else{
|
||||
form.addEventListener('change', renderForm);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue