|
1 | | -// tmp fix for read-the-docs embeded versions injection |
| 1 | +// tmp fix for read-the-docs embedded versions injection |
2 | 2 | let jquery = jQuery; |
3 | 3 |
|
4 | 4 | $(document).ready(function() { |
@@ -35,36 +35,38 @@ $(document).ready(function() { |
35 | 35 |
|
36 | 36 | // remove elements, leave only 'versions' |
37 | 37 | var update = setInterval(function() { |
38 | | - if ($('.injected .rst-versions').length) { |
| 38 | + let ready = false, version = ''; |
| 39 | + if ($('readthedocs-flyout').length) { |
| 40 | + $('dl.versions', $('readthedocs-flyout').prop('shadowRoot')).appendTo('.version-switcher .switcher__list'); |
| 41 | + $('readthedocs-flyout').remove(); |
| 42 | + version = $('.switcher__list dl.versions dd strong a').text(); |
| 43 | + ready = true; |
| 44 | + } |
| 45 | + if (ready) { |
39 | 46 | clearInterval(update); |
40 | | - var version = $('.rst-other-versions dd.rtd-current-item a').text(); |
41 | | - $('.rst-current-version span:first').html(' ' + (version != '' ? version : 'Change version')); |
42 | | - $('.rst-other-versions').html($('.injected dl:first').clone()); |
43 | | - $('.injected').remove(); |
44 | | - |
45 | | - //replace url in version switcher |
46 | | - var currentVersion = $('.rst-other-versions dd.rtd-current-item a').attr('href'), |
47 | | - resourceUrl = document.location.href.replace(currentVersion, ''); |
48 | | - |
49 | | - $('.rst-other-versions dd a').each(function() { |
50 | | - $(this).attr('href', $(this).attr('href') + resourceUrl); |
51 | | - }); |
52 | | - |
53 | | - if ($('.version-warning').length) { |
54 | | - var url, |
55 | | - version = $('.version-warning .version').html(), |
56 | | - parts = $('.rst-other-versions dd a') |
57 | | - .first() |
58 | | - .attr('href') |
59 | | - .split('/'); |
60 | 47 |
|
61 | | - parts[4] = version; |
62 | | - url = parts.join('/'); |
| 48 | + if (!$('.rst-versions.switcher__selected-item').length) { |
| 49 | + // add rst-current-version back (what removed it??) |
| 50 | + $('.switcher.version-switcher').prepend(` |
| 51 | + <div class="rst-versions switcher__selected-item" data-toggle="rst-versions" role="note" aria-label="versions"> |
| 52 | + <div class="rst-current-version switcher__label" data-toggle="rst-current-version"> |
| 53 | + Version |
| 54 | + </div> |
| 55 | + </div> |
| 56 | + `); |
| 57 | + } |
| 58 | + $('.rst-current-version.switcher__label').html(version.length ? version : 'Change version'); |
| 59 | + $('.rst-other-versions.switcher__list dl.versions dd strong').parent().addClass('rtd-current-item'); |
63 | 60 |
|
64 | | - $('.version-warning .version').html($('<a href ="' + url + '" class="external">' + version + '</a>')); |
| 61 | + if ('master' !== (vl = $('.rst-other-versions.switcher__list dl.versions')).find('dd:first').text()) { |
| 62 | + vl.find('dd').each(function() {$(this).detach().prependTo(vl)}); |
65 | 63 | } |
66 | 64 | } |
67 | 65 | }, 300); |
| 66 | + setTimeout(function() { |
| 67 | + clearInterval(update); |
| 68 | + setSwitcherEvents(); |
| 69 | + }, 1200); |
68 | 70 |
|
69 | 71 | $('img').each(function() { |
70 | 72 | if ($(this).attr('title')) { |
|
0 commit comments