Fix pagedown bugs

This commit is contained in:
cuom1999 2024-10-01 23:07:00 -05:00
parent 9c01ec8a22
commit 72eada0a4e
3 changed files with 28 additions and 8 deletions

View file

@ -426,6 +426,30 @@ function submitFormWithParams($form, method) {
} }
} }
function initPagedown(maxRetries=5) {
// There's a race condition so we want to retry several times
let attempts = 0;
function tryInit() {
try {
// make sure pagedown_init.js was loaded
if ('DjangoPagedown' in window) {
DjangoPagedown.init();
} else if (attempts < maxRetries) {
attempts++;
setTimeout(tryInit, 1000);
}
} catch (error) {
// this may happen if Markdown.xyz.js was not loaded
if (attempts < maxRetries) {
attempts++;
setTimeout(tryInit, 1000);
}
}
}
setTimeout(tryInit, 100);
}
function navigateTo(url, reload_container, force_new_page=false) { function navigateTo(url, reload_container, force_new_page=false) {
if (url === '#') return; if (url === '#') return;
@ -484,9 +508,7 @@ function navigateTo(url, reload_container, force_new_page=false) {
$(document).prop('title', $(data).filter('title').text()); $(document).prop('title', $(data).filter('title').text());
renderKatex($(reload_container)[0]); renderKatex($(reload_container)[0]);
if ('DjangoPagedown' in window) { initPagedown();
DjangoPagedown.init();
}
onWindowReady(); onWindowReady();
registerNavList(); registerNavList();
$('.xdsoft_datetimepicker').hide(); $('.xdsoft_datetimepicker').hide();

File diff suppressed because one or more lines are too long

View file

@ -23,11 +23,6 @@
$(this).val(selectedValues); $(this).val(selectedValues);
}); });
setTimeout(function() {
if ('DjangoPagedown' in window) {
DjangoPagedown.init();
}
}, 2000);
}); });
</script> </script>
{% endblock %} {% endblock %}