Skip to content

Commit 6107cbe

Browse files
committed
Add new option to suppress loading all the JS files
1 parent 69d603a commit 6107cbe

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

jupyterquiz/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
All files in the package are distributed under the MIT License
1212
'''
1313

14-
__version__ = '2.9.3'
14+
__version__ = '2.9.4'
1515
from .dynamic import display_quiz, capture_responses

jupyterquiz/dynamic/display.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
def display_quiz(ref, num=1_000_000, shuffle_questions=False,
1212
shuffle_answers=True, preserve_responses=False,
1313
border_radius=10, question_alignment="left",
14-
max_width=600, colors=None):
14+
max_width=600, colors=None, load_js=True):
1515
"""
1616
Display an interactive quiz in a Jupyter notebook.
1717
@@ -75,8 +75,8 @@ def display_quiz(ref, num=1_000_000, shuffle_questions=False,
7575
styles = build_styles(div_id, color_dict)
7676

7777
# Combine all JavaScript
78-
javascript = build_script(prefix_script, static, url, div_id)
78+
javascript = build_script(prefix_script, static, url, div_id, load_js)
7979

8080
# Display in notebook
8181
display(HTML(mydiv + styles))
82-
display(Javascript(javascript))
82+
display(Javascript(javascript))

jupyterquiz/dynamic/renderer.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def build_styles(div_id, color_dict):
3939
styles += '</style>'
4040
return styles
4141

42-
def build_script(prefix_script, static, url, div_id):
42+
def build_script(prefix_script, static, url, div_id, load_js):
4343
"""
4444
Combine the loading prefix, static JS files, and suffix template into a single script.
4545
"""
@@ -48,10 +48,11 @@ def build_script(prefix_script, static, url, div_id):
4848
script = prefix_script
4949

5050
# Load all static JS modules
51-
js_dir = importlib.resources.files(package).joinpath('js')
52-
for js_file in sorted(js_dir.iterdir(), key=lambda x: x.name):
53-
if js_file.name.endswith('.js'):
54-
script += js_file.read_bytes().decode('utf-8')
51+
if load_js:
52+
js_dir = importlib.resources.files(package).joinpath('js')
53+
for js_file in sorted(js_dir.iterdir(), key=lambda x: x.name):
54+
if js_file.name.endswith('.js'):
55+
script += js_file.read_bytes().decode('utf-8')
5556

5657
# Append appropriate suffix behavior
5758
if static:
@@ -63,4 +64,4 @@ def build_script(prefix_script, static, url, div_id):
6364
tpl = tpl_path.read_text()
6465
script += Template(tpl).substitute(url=url, div_id=div_id)
6566

66-
return script
67+
return script

0 commit comments

Comments
 (0)