Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit d80d825

Browse files
authored
Merge branch 'master' into wavedrom
2 parents 889645d + 7eca4ae commit d80d825

29 files changed

Lines changed: 270 additions & 115 deletions

File tree

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Declare files that must always have LF line endings on checkout so docker compose works on Windows
2+
* eol=lf

conf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,12 @@
319319
# This is the file name suffix for HTML files (e.g. ".xhtml").
320320
# html_file_suffix = None
321321

322+
# It True, sets js files from Sphinx & Runestone to be loaded with defer attr
323+
# substantially speeding up page rendering. May cause issues with books that
324+
# have custom directives or raw html that assume jquery or another library
325+
# is loaded before body is parsed.
326+
html_defer_js = True
327+
322328
# Output file base name for HTML help builder.
323329
htmlhelp_basename = "PythonCoursewareProjectdoc"
324330

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
crossorigin="anonymous"
4444
/>
4545

46-
<script type="text/javascript">
46+
<script>
4747
eBookConfig = {};
4848

4949
eBookConfig.useRunestoneServices = false;

runestone/__init__.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import os, socket, pkg_resources
3131
import CodeChat.CodeToRest
3232
from sphinx.errors import ExtensionError
33+
from sphinx.builders.html import JavaScript
3334

3435

3536
# TODO: clean up - many of the folders are not needed as the files are imported by webpack
@@ -75,6 +76,26 @@ def runestone_extensions():
7576
modules.insert(0, modules.pop(modules.index("runestone.common")))
7677
return modules
7778

79+
# setup_js_defer(app, pagename, templatexname, context, doctree)
80+
# -----------------------
81+
# Used to inspect js right before it is rendered to page so that
82+
# we can forcibly defer js files or prevent same
83+
def setup_js_defer(app, pagename, templatexname, context, doctree):
84+
def js_defer(script_files):
85+
for js in sorted(script_files):
86+
if app.config.html_defer_js:
87+
# Files added from Runestone should already have defer set - so just add it to sphinx based ones
88+
to_defer = ["_static/jquery.js", "_static/underscore.js","_static/doctools.js"]
89+
if isinstance(js, JavaScript) and js in to_defer:
90+
js.attributes["defer"] = ""
91+
else:
92+
#config flag not set, prevent all deferrals
93+
if isinstance(js, JavaScript):
94+
js.attributes.pop("defer", None)
95+
return ''
96+
97+
context['js_defer'] = js_defer
98+
7899

79100
# setup(app)
80101
# ----------
@@ -94,16 +115,18 @@ def setup(app):
94115

95116
for jsfile in script_files:
96117
try:
97-
app.add_autoversioned_javascript(jsfile)
118+
app.add_autoversioned_javascript(jsfile, defer="")
98119
except ExtensionError:
99-
app.add_js_file(jsfile)
120+
app.add_js_file(jsfile, defer="")
100121
for cssfile in _css_files:
101122
try:
102123
app.add_autoversioned_stylesheet(cssfile)
103124
except ExtensionError:
104125
app.add_css_file(cssfile)
105126

106127
app.config.html_static_path.append("dist/")
128+
app.add_config_value("html_defer_js", False, 'env')
129+
app.connect('html-page-context', setup_js_defer)
107130

108131

109132
def get_master_url():

runestone/animation/animation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
def setup(app):
2727
app.add_directive("animation", Animation)
28-
app.add_autoversioned_javascript("animationbase.js")
28+
app.add_autoversioned_javascript("animationbase.js", defer="")
2929

3030

3131
SRC = """
@@ -40,7 +40,7 @@ def setup(app):
4040
<button onclick="%(divid)s_anim.backward()">Step Backward</button>
4141
<button onclick="%(divid)s_anim.end()">End</button>
4242
43-
<script type="text/javascript">
43+
<script>
4444
%(divid)s_init = function(divid)
4545
{
4646
var a = new Animator(new %(model)s(), new %(viewer)s(), divid)
@@ -52,7 +52,7 @@ def setup(app):
5252
</div>
5353
"""
5454

55-
SCRIPTTAG = """<script type="text/javascript" src="../_static/%s"></script>\n"""
55+
SCRIPTTAG = """<script src="../_static/%s"></script>\n"""
5656

5757

5858
class Animation(RunestoneIdDirective):

runestone/animation/animationrefactor.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22

33
<head>
4-
<script type "text/javascript" src="animationrefactor.js"></script>
4+
<script src="animationrefactor.js"></script>
55

66
<html>
77
<body onload="">
@@ -17,7 +17,7 @@
1717
<button onclick="ancan_anim.backward()">Step Backward</button>
1818
<button onclick="ancan_anim.end()">End</button>
1919
</div>
20-
<script type="text/javascript">
20+
<script>
2121
init1 = function(divid)
2222
{
2323
var a = new Animator(new SortModel(), new BarViewer(), divid)

runestone/animation/chart.html

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
<html>
22
<head>
33
<title>charts</title>
4-
<!-- <script type="text/javascript" src="https://www.google.com/jsapi"></script> -->
5-
<!-- <script type="text/javascript" src="chart.js"></script> -->
4+
<!-- <script src="https://www.google.com/jsapi"></script> -->
5+
<!-- <script src="chart.js"></script> -->
66

7-
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
8-
<script type="text/javascript" src="jqchart/jquery.gchart.js"></script>
9-
<script type="text/javascript" src="jqchart/jquery.gchart.graphviz.js"></script>
7+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
8+
<script src="jqchart/jquery.gchart.js"></script>
9+
<script src="jqchart/jquery.gchart.graphviz.js"></script>
1010
<style>
1111
#visualization { width: 800px; height: 400px; }
1212
</style>
1313

1414
</head>
1515
<body>
1616
<div id="visualization"></div>
17-
<script type="text/javascript">
17+
<script>
1818
// $("#visualization").gchart({type: 'graphviz', series: [$.gchart.series([20, 50, 30])]});
1919
// label: '<f0> left | <f1> middle | <f2> right'
2020

21-
$('#visualization').gchart($.gchart.graphviz(true,
21+
document.addEventListener('load', (event) => {
22+
$('#visualization').gchart($.gchart.graphviz(true,
2223
{
2324
struct1: {label: '<f0> left |<f1> middle |<f2> right'},
2425
struct2: {label: '<f0> one|<f1> two'},
@@ -32,6 +33,7 @@
3233
node: {shape: 'record'}
3334
}
3435
));
36+
});
3537

3638

3739
// $('#visualization').gchart($.gchart.graphviz(true,

runestone/animation/jqchart/gChartBasic.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
<style type="text/css">
77
#basicGChart { width: 450px; height: 300px }
88
</style>
9-
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
10-
<script type="text/javascript" src="jquery.gchart.js"></script>
11-
<script type="text/javascript">
9+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
10+
<script src="jquery.gchart.js"></script>
11+
<script>
12+
document.addEventListener('load', (event) => {
1213
$(function () {
1314
$('#basicGChart').gchart({type: 'line', maxValue: 40,
1415
title: 'Weather for|Brisbane, Australia', titleColor: 'green',
@@ -27,6 +28,7 @@
2728
$.gchart.axis('right', ['mm'], [50], 'blue', 'left')],
2829
legend: 'right'});
2930
});
31+
});
3032
</script>
3133
</head>
3234
<body>

runestone/animation/simpletree.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
<html>
33

44
<head>
5-
<script type="text/javascript" src="animationrefactor.js"></script>
6-
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
7-
<script type="text/javascript" src="jqchart/jquery.gchart.js"></script>
8-
<script type="text/javascript" src="jqchart/jquery.gchart.graphviz.js"></script>
9-
<script type="text/javascript" src="animationrefactor.js"></script>
10-
<script type="text/javascript" src="simpletree.js"></script>
5+
<script src="animationrefactor.js"></script>
6+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
7+
<script src="jqchart/jquery.gchart.js"></script>
8+
<script src="jqchart/jquery.gchart.graphviz.js"></script>
9+
<script src="animationrefactor.js"></script>
10+
<script src="simpletree.js"></script>
1111
</head>
1212

1313

@@ -29,7 +29,7 @@
2929
<button onclick="ancan_anim.backward()">Step Backward</button>
3030
<button onclick="ancan_anim.end()">End</button>
3131
</div>
32-
<script type="text/javascript">
32+
<script>
3333
init1 = function(divid)
3434
{
3535
var a = new Animator(new SimpleTreeModel(), new TreeViewer(), divid)

runestone/animation/sortingbase.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<!DOCTYPE html>
22

33
<head>
4-
<script type="text/javascript" src="sortmodels.js"></script>
5-
<script type="text/javascript" src="sortviewers.js"></script>
6-
<script type="text/javascript" src="animationbase.js"></script>
4+
<script src="sortmodels.js"></script>
5+
<script src="sortviewers.js"></script>
6+
<script src="animationbase.js"></script>
77

88

99
<html>

0 commit comments

Comments
 (0)