Skip to content

Fix sphinx_rtd_theme theme override in embed js #1545

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

Merged
merged 1 commit into from
Aug 6, 2015
Merged
Show file tree
Hide file tree
Changes from all 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
36 changes: 0 additions & 36 deletions readthedocs/core/static-src/core/js/doc-embed/build.js

This file was deleted.

9 changes: 4 additions & 5 deletions readthedocs/core/static-src/core/js/doc-embed/footer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var Build = require('./build').Build;
var rtddata = require('./rtd-data');
var versionCompare = require('./version-compare');

Expand All @@ -10,7 +9,7 @@ function init() {
project: rtd['project'],
version: rtd['version'],
page: rtd['page'],
theme: rtd['theme'],
theme: rtd.get_theme_name(),
format: "jsonp",
};

Expand Down Expand Up @@ -50,11 +49,11 @@ function init() {


function injectFooter(data) {
var build = new Build(rtddata.get());
var config = rtddata.get();

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

// Show promo selectively
if (data.promo && build.show_promo()) {
if (data.promo && config.show_promo()) {
var promo = new sponsorship.Promo(
data.promo_data.id,
data.promo_data.text,
Expand Down
40 changes: 38 additions & 2 deletions readthedocs/core/static-src/core/js/doc-embed/rtd-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,50 @@
*/


var configMethods = {
is_rtd_theme: function () {
return this.get_theme_name() === 'sphinx_rtd_theme';
},

is_sphinx_builder: function () {
return (!('builder' in this) || this.builder != 'mkdocs');
},

get_theme_name: function () {
// Crappy heuristic, but people change the theme name on us. So we have to
// do some duck typing.
if (this.theme !== 'sphinx_rtd_theme') {
if ($('div.rst-other-versions').length === 1) {
return 'sphinx_rtd_theme';
}
}
return this.theme;
},

show_promo: function () {
return (
this.api_host !== 'https://readthedocs.com' &&
this.is_sphinx_builder() &&
this.is_rtd_theme());
}
};


/*
* Access READTHEDOCS_DATA on call, not on module load. The reason is that the
* READTHEDOCS_DATA might not be available during script load time.
*/
function get() {
return $.extend({
// Make `methods` the prototype.
var config = Object.create(configMethods);

var defaults = {
api_host: 'https://readthedocs.org'
}, window.READTHEDOCS_DATA);
};

$.extend(config, defaults, window.READTHEDOCS_DATA);

return config;
}


Expand Down
15 changes: 1 addition & 14 deletions readthedocs/core/static/core/js/autocomplete.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading