Skip to content

Commit

Permalink
Version warning banner: inject on role="main" or main tag (#8079)
Browse files Browse the repository at this point in the history
  • Loading branch information
stsewd authored Apr 8, 2021
1 parent feb2040 commit 8009046
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
18 changes: 17 additions & 1 deletion docs/versions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,23 @@ you can enable it in the admin section of your docs (:guilabel:`Admin` > :guilab

.. note::

This feature is available only for :doc:`Sphinx projects </intro/getting-started-with-sphinx>`.
The banner will be injected in an HTML element with the ``main`` role or in the ``main`` tag.
For example:

.. code-block:: html

<div role="main">
<!-- The banner would be injected here -->
...
</div>

.. code-block:: html

<main>
<!-- The banner would be injected here -->
...
</main>


Redirects on root URLs
----------------------
Expand Down
11 changes: 7 additions & 4 deletions readthedocs/core/static-src/core/js/doc-embed/version-compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ function init(data) {
.attr('href', currentURL)
.text(data.slug);

var body = $("div.body");
if (!body.length) {
body = $("div.document");
var selectors = ['[role=main]', 'main', 'div.body', 'div.document'];
for (var i = 0; i < selectors.length; i += 1) {
var body = $(selectors[i]);
if (body.length) {
body.prepend(warning);
break;
}
}
body.prepend(warning);
}


Expand Down
Loading

0 comments on commit 8009046

Please sign in to comment.