Skip to content

Commit a42c4d7

Browse files
authored
Move javascript back to head (#545)
* Move javascript back to head * Move jQuery function back to bottom * Do not change white space * Update comment + whitespace cleanup * Address review points * Fix code comments
1 parent 7e4592f commit a42c4d7

File tree

1 file changed

+34
-42
lines changed

1 file changed

+34
-42
lines changed

sphinx_rtd_theme/layout.html

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,42 @@
2828
<link rel="canonical" href="{{ theme_canonical_url }}{{ pagename }}.html"/>
2929
{% endif %}
3030

31-
{# CSS #}
32-
33-
{# OPENSEARCH #}
34-
{% if not embedded %}
35-
{% if use_opensearch %}
36-
<link rel="search" type="application/opensearchdescription+xml"
37-
title="{% trans docstitle=docstitle|e %}Search within {{ docstitle }}{% endtrans %}"
38-
href="{{ pathto('_static/opensearch.xml', 1) }}"/>
31+
{# JAVASCRIPTS #}
32+
<script type="text/javascript" src="{{ pathto('_static/js/modernizr.min.js', 1) }}"></script>
33+
{%- if not embedded %}
34+
{# XXX Sphinx 1.8.0 made this an external js-file, quick fix until we refactor the template to inherert more blocks directly from sphinx #}
35+
{% if sphinx_version >= "1.8.0" %}
36+
<script type="text/javascript" id="documentation_options" data-url_root="{{ pathto('', 1) }}" src="{{ pathto('_static/documentation_options.js', 1) }}"></script>
37+
{%- for scriptfile in script_files %}
38+
{{ js_tag(scriptfile) }}
39+
{%- endfor %}
40+
{% else %}
41+
<script type="text/javascript">
42+
var DOCUMENTATION_OPTIONS = {
43+
URL_ROOT:'{{ url_root }}',
44+
VERSION:'{{ release|e }}',
45+
LANGUAGE:'{{ language }}',
46+
COLLAPSE_INDEX:false,
47+
FILE_SUFFIX:'{{ '' if no_search_suffix else file_suffix }}',
48+
HAS_SOURCE: {{ has_source|lower }},
49+
SOURCELINK_SUFFIX: '{{ sourcelink_suffix }}'
50+
};
51+
</script>
52+
{%- for scriptfile in script_files %}
53+
<script type="text/javascript" src="{{ pathto(scriptfile, 1) }}"></script>
54+
{%- endfor %}
3955
{% endif %}
56+
<script type="text/javascript" src="{{ pathto('_static/js/theme.js', 1) }}"></script>
4057

41-
{% endif %}
58+
{# OPENSEARCH #}
59+
{%- if use_opensearch %}
60+
<link rel="search" type="application/opensearchdescription+xml"
61+
title="{% trans docstitle=docstitle|e %}Search within {{ docstitle }}{% endtrans %}"
62+
href="{{ pathto('_static/opensearch.xml', 1) }}"/>
63+
{%- endif %}
64+
{%- endif %}
4265

66+
{# CSS #}
4367
<link rel="stylesheet" href="{{ pathto('_static/' + style, 1) }}" type="text/css" />
4468
<link rel="stylesheet" href="{{ pathto('_static/pygments.css', 1) }}" type="text/css" />
4569
{%- for css in css_files %}
@@ -49,6 +73,7 @@
4973
<link rel="stylesheet" href="{{ pathto(css, 1) }}" type="text/css" />
5074
{%- endif %}
5175
{%- endfor %}
76+
5277
{%- for cssfile in extra_css_files %}
5378
<link rel="stylesheet" href="{{ pathto(cssfile, 1) }}" type="text/css" />
5479
{%- endfor %}
@@ -74,10 +99,6 @@
7499
{%- endif %}
75100
{%- endblock %}
76101
{%- block extrahead %} {% endblock %}
77-
78-
{# Keep modernizr in head - http://modernizr.com/docs/#installing #}
79-
<script src="{{ pathto('_static/js/modernizr.min.js', 1) }}"></script>
80-
81102
</head>
82103

83104
<body class="wy-body-for-nav">
@@ -186,35 +207,6 @@
186207
</div>
187208
{% include "versions.html" %}
188209

189-
{% if not embedded %}
190-
191-
{# XXX Sphinx 1.8.0 made this an external js-file, quick fix until we refactor the template to inherert more blocks directly from sphinx #}
192-
{% if sphinx_version >= "1.8.0" %}
193-
<script type="text/javascript" id="documentation_options" data-url_root="{{ pathto('', 1) }}" src="{{ pathto('_static/documentation_options.js', 1) }}"></script>
194-
{%- for scriptfile in script_files %}
195-
{{ js_tag(scriptfile) }}
196-
{%- endfor %}
197-
{% else %}
198-
<script type="text/javascript">
199-
var DOCUMENTATION_OPTIONS = {
200-
URL_ROOT:'{{ url_root }}',
201-
VERSION:'{{ release|e }}',
202-
LANGUAGE:'{{ language }}',
203-
COLLAPSE_INDEX:false,
204-
FILE_SUFFIX:'{{ '' if no_search_suffix else file_suffix }}',
205-
HAS_SOURCE: {{ has_source|lower }},
206-
SOURCELINK_SUFFIX: '{{ sourcelink_suffix }}'
207-
};
208-
</script>
209-
{%- for scriptfile in script_files %}
210-
<script type="text/javascript" src="{{ pathto(scriptfile, 1) }}"></script>
211-
{%- endfor %}
212-
{% endif %}
213-
214-
{% endif %}
215-
216-
<script type="text/javascript" src="{{ pathto('_static/js/theme.js', 1) }}"></script>
217-
218210
<script type="text/javascript">
219211
jQuery(function () {
220212
SphinxRtdTheme.Navigation.enable({{ 'true' if theme_sticky_navigation|tobool else 'false' }});

0 commit comments

Comments
 (0)