Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed JS: fix incompatibilities with sphinx 6.x (jquery removal) #9359

Merged
merged 7 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions readthedocs/core/static-src/core/js/doc-embed/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ function attach_elastic_search_query_sphinx(data) {
/**
* Build a section with its matching results.
*
* A section has the form:
*
* <div>
* <a href={link}>{title}<a>
* </div>
* <div>
* {contents[0]}
* </div>
* <div>
* {contents[1]}
* </div>
*
* ...
*
* @param {String} title.
* @param {String} link.
* @param {Array} contents.
Expand All @@ -61,6 +75,14 @@ function attach_elastic_search_query_sphinx(data) {

/**
* Build a domain section.
* A domain section has the form:
*
* <div>
* <a href={link}>{title}<a>
* </div>
* <div>
* {content}
* </div>
*
* @param {String} title.
* @param {String} link.
Expand Down
31 changes: 18 additions & 13 deletions readthedocs/core/static-src/core/js/readthedocs-doc-embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ var sphinx = require('./doc-embed/sphinx');
var search = require('./doc-embed/search');


// While much of this script relies on jQuery (which Sphinx relies on),
// we purposefully do not use it before DOMContentLoaded in case scripts are loaded out of order
// Parts of this script rely on jQuery,
// since Sphinx no longer includes it,
// we must inject it if isn't found before executing our script.
(function () {
function domReady(fn) {
// If the DOM is already done parsing
Expand All @@ -26,15 +27,19 @@ var search = require('./doc-embed/search');
sponsorship.init();
}

// Inject JQuery if isn't present already.
if (!window.jQuery) {
console.log("JQuery not found. Injecting.");
var script = document.createElement("script");
script.type = 'text/javascript';
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js";
script.onload = function () { domReady(init); };
document.head.appendChild(script);
} else {
domReady(init);
}
domReady(function () {
// Inject JQuery if isn't present already.
if (!window.jQuery) {
console.log("JQuery not found. Injecting.");
stsewd marked this conversation as resolved.
Show resolved Hide resolved
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://code.jquery.com/jquery-3.6.0.min.js";
script.integrity = "sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==";
script.crossOrigin = "anonymous";
script.onload = init;
document.head.appendChild(script);
} else {
init();
}
});
}());
Loading