From 72eada0a4ed125ee75b10c67fdbc831677a63f3a Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Tue, 1 Oct 2024 23:07:00 -0500 Subject: [PATCH] Fix pagedown bugs --- resources/common.js | 28 +++++++++++++++++++++++++--- resources/darkmode-svg.css | 3 +++ templates/course/edit_lesson.html | 5 ----- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/resources/common.js b/resources/common.js index 703c737..2cf67b9 100644 --- a/resources/common.js +++ b/resources/common.js @@ -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) { if (url === '#') return; @@ -484,9 +508,7 @@ function navigateTo(url, reload_container, force_new_page=false) { $(document).prop('title', $(data).filter('title').text()); renderKatex($(reload_container)[0]); - if ('DjangoPagedown' in window) { - DjangoPagedown.init(); - } + initPagedown(); onWindowReady(); registerNavList(); $('.xdsoft_datetimepicker').hide(); diff --git a/resources/darkmode-svg.css b/resources/darkmode-svg.css index 7e8f329..7a01444 100644 --- a/resources/darkmode-svg.css +++ b/resources/darkmode-svg.css @@ -19,4 +19,7 @@ } .wmd-redo-button { background-image: url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/PjxzdmcgaGVpZ2h0PSI0OHB4IiBpZD0ic3ZnMTEzMDAiIHdpZHRoPSI0OHB4IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOmNjPSJodHRwOi8vY3JlYXRpdmVjb21tb25zLm9yZy9ucyMiIHhtbG5zOmRjPSJ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MzItNS40MDNjMC40ODMtMi45NTYsMC43MjktNS43MSwwLjcyOS04LjI4YzAtNy4zOTQtNC4xNjItMTIuMTQ4LTEyLjQ2MS0xNC4yNzIKICAgICAgYy0xMS44MDYtMi42MzgtMTkuODk2LTUuOTQyLTI0LjI2Ni05LjkwMWMtNC4zNzYtMy45Ni01LjY4Ni0xMS4yMjUtMy45MzUtMjEuNzk0TDMzMi40MTgsNjIuMDUKICAgICAgYzEuNzM4LTEwLjU2Myw1LjEyOS0xOC4yMjUsMTAuMTY1LTIyLjk4YzUuMDE5LTQuNzU1LDEzLjY2LTguMTgyLDI1LjkwNi0xMC4zMDZjNi4xMi0xLjA1MywxMC4xNzItMi42MzgsMTIuMTMtNC43NTUKICAgICAgYzEuOTcxLTIuMTA1LDIuOTUtNS4yNzUsMi45NS05LjUxMWMwLTIuNjkzLTAuMjY0LTUuNzEtMC44MDItOS4wNTFDMzgyLjI0MSwyLjExMSwzNzguODk0LTAuMTg0LDM3NS41NCwwLjI0NHoiLz4KICA8L2c+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPC9zdmc+"); } \ No newline at end of file diff --git a/templates/course/edit_lesson.html b/templates/course/edit_lesson.html index c160be4..f84adff 100644 --- a/templates/course/edit_lesson.html +++ b/templates/course/edit_lesson.html @@ -23,11 +23,6 @@ $(this).val(selectedValues); }); - setTimeout(function() { - if ('DjangoPagedown' in window) { - DjangoPagedown.init(); - } - }, 2000); }); {% endblock %}