From 23c10834f6f9b189deea9c5d2464aa2d3ffd439b Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Fri, 19 Apr 2024 16:22:23 +0200 Subject: [PATCH] Fix version switcher (#291) --- docs/js/custom.js | 52 +++++++++++++++++++++------------------- docs/js/docs.switcher.js | 8 +++---- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/docs/js/custom.js b/docs/js/custom.js index 69faa931..96c528c5 100644 --- a/docs/js/custom.js +++ b/docs/js/custom.js @@ -1,4 +1,4 @@ -// tmp fix for read-the-docs embeded versions injection +// tmp fix for read-the-docs embedded versions injection let jquery = jQuery; $(document).ready(function() { @@ -35,36 +35,38 @@ $(document).ready(function() { // remove elements, leave only 'versions' var update = setInterval(function() { - if ($('.injected .rst-versions').length) { + let ready = false, version = ''; + if ($('readthedocs-flyout').length) { + $('dl.versions', $('readthedocs-flyout').prop('shadowRoot')).appendTo('.version-switcher .switcher__list'); + $('readthedocs-flyout').remove(); + version = $('.switcher__list dl.versions dd strong a').text(); + ready = true; + } + if (ready) { clearInterval(update); - var version = $('.rst-other-versions dd.rtd-current-item a').text(); - $('.rst-current-version span:first').html(' ' + (version != '' ? version : 'Change version')); - $('.rst-other-versions').html($('.injected dl:first').clone()); - $('.injected').remove(); - - //replace url in version switcher - var currentVersion = $('.rst-other-versions dd.rtd-current-item a').attr('href'), - resourceUrl = document.location.href.replace(currentVersion, ''); - - $('.rst-other-versions dd a').each(function() { - $(this).attr('href', $(this).attr('href') + resourceUrl); - }); - - if ($('.version-warning').length) { - var url, - version = $('.version-warning .version').html(), - parts = $('.rst-other-versions dd a') - .first() - .attr('href') - .split('/'); - parts[4] = version; - url = parts.join('/'); + if (!$('.rst-versions.switcher__selected-item').length) { + // add rst-current-version back (what removed it??) + $('.switcher.version-switcher').prepend(` +