Skip to content

Commit 9201c9d

Browse files
committed
Merge pull request #1545 from rtfd/fix-rtd-theme-override-in-embed-js
Fix sphinx_rtd_theme theme override in embed js
2 parents 418a2fe + 13c53c4 commit 9201c9d

File tree

5 files changed

+44
-603
lines changed

5 files changed

+44
-603
lines changed

readthedocs/core/static-src/core/js/doc-embed/build.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

readthedocs/core/static-src/core/js/doc-embed/footer.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
var Build = require('./build').Build;
21
var rtddata = require('./rtd-data');
32
var versionCompare = require('./version-compare');
43

@@ -10,7 +9,7 @@ function init() {
109
project: rtd['project'],
1110
version: rtd['version'],
1211
page: rtd['page'],
13-
theme: rtd['theme'],
12+
theme: rtd.get_theme_name(),
1413
format: "jsonp",
1514
};
1615

@@ -50,11 +49,11 @@ function init() {
5049

5150

5251
function injectFooter(data) {
53-
var build = new Build(rtddata.get());
52+
var config = rtddata.get();
5453

5554
// If the theme looks like ours, update the existing badge
5655
// otherwise throw a a full one into the page.
57-
if (build.is_rtd_theme()) {
56+
if (config.is_rtd_theme()) {
5857
$("div.rst-other-versions").html(data['html']);
5958
} else {
6059
$("body").append(data['html']);
@@ -67,7 +66,7 @@ function injectFooter(data) {
6766
}
6867

6968
// Show promo selectively
70-
if (data.promo && build.show_promo()) {
69+
if (data.promo && config.show_promo()) {
7170
var promo = new sponsorship.Promo(
7271
data.promo_data.id,
7372
data.promo_data.text,

readthedocs/core/static-src/core/js/doc-embed/rtd-data.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,50 @@
55
*/
66

77

8+
var configMethods = {
9+
is_rtd_theme: function () {
10+
return this.get_theme_name() === 'sphinx_rtd_theme';
11+
},
12+
13+
is_sphinx_builder: function () {
14+
return (!('builder' in this) || this.builder != 'mkdocs');
15+
},
16+
17+
get_theme_name: function () {
18+
// Crappy heuristic, but people change the theme name on us. So we have to
19+
// do some duck typing.
20+
if (this.theme !== 'sphinx_rtd_theme') {
21+
if ($('div.rst-other-versions').length === 1) {
22+
return 'sphinx_rtd_theme';
23+
}
24+
}
25+
return this.theme;
26+
},
27+
28+
show_promo: function () {
29+
return (
30+
this.api_host !== 'https://readthedocs.com' &&
31+
this.is_sphinx_builder() &&
32+
this.is_rtd_theme());
33+
}
34+
};
35+
36+
837
/*
938
* Access READTHEDOCS_DATA on call, not on module load. The reason is that the
1039
* READTHEDOCS_DATA might not be available during script load time.
1140
*/
1241
function get() {
13-
return $.extend({
42+
// Make `methods` the prototype.
43+
var config = Object.create(configMethods);
44+
45+
var defaults = {
1446
api_host: 'https://readthedocs.org'
15-
}, window.READTHEDOCS_DATA);
47+
};
48+
49+
$.extend(config, defaults, window.READTHEDOCS_DATA);
50+
51+
return config;
1652
}
1753

1854

readthedocs/core/static/core/js/autocomplete.js

Lines changed: 1 addition & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)