Skip to content

Commit

Permalink
Embed js: use fetch API for footer (#9551)
Browse files Browse the repository at this point in the history
  • Loading branch information
stsewd authored Aug 30, 2022
1 parent 8f38a84 commit 7d91b7c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
34 changes: 15 additions & 19 deletions readthedocs/core/static-src/core/js/doc-embed/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ function init() {
version: rtd['version'],
page: rtd['page'],
theme: rtd.get_theme_name(),
format: "jsonp",
};

// Crappy heuristic, but people change the theme name on us.
Expand All @@ -61,25 +60,22 @@ function init() {
}

// Get footer HTML from API and inject it into the page.
$.ajax({
url: rtd.proxied_api_host + "/api/v2/footer_html/",
crossDomain: true,
xhrFields: {
withCredentials: true,
},
dataType: "jsonp",
data: get_data,
cache: true,
jsonpCallback: "callback",
success: function (data) {
if (data.show_version_warning) {
versionCompare.init(data.version_compare);
}
injectFooter(data);
},
error: function () {
console.error('Error loading Read the Docs footer');
let footer_api_url = rtd.proxied_api_host + "/api/v2/footer_html/?" + new URLSearchParams(get_data).toString();
fetch(footer_api_url, {method: 'GET'})
.then(response => {
if (!response.ok) {
throw new Error();
}
return response.json();
})
.then(data => {
if (data.show_version_warning) {
versionCompare.init(data.version_compare);
}
injectFooter(data);
})
.catch(error => {
console.error('Error loading Read the Docs footer');
});

// Register page view.
Expand Down
Loading

0 comments on commit 7d91b7c

Please sign in to comment.