Skip to content

Commit 97c2908

Browse files
committed
Auto focus on next element when solving multiple numerical or string problems
1 parent 2bd7a0d commit 97c2908

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
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.6'
14+
__version__ = '2.9.6.1'
1515
from .dynamic import display_quiz, capture_responses

jupyterquiz/js/numeric.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,22 @@ function check_numeric(ths, event) {
128128
} else {
129129
console.log('MathJax not detected');
130130
}
131+
// After correct answer, if next JupyterQuiz question exists and has a text input, scroll by current question height
132+
if (correct) {
133+
// find the current question wrapper
134+
var wrapper = ths.closest('.Quiz');
135+
if (wrapper) {
136+
var nextWrapper = wrapper.nextElementSibling;
137+
if (nextWrapper && nextWrapper.classList.contains('Quiz')) {
138+
var nextInput = nextWrapper.querySelector('input.Input-text');
139+
if (nextInput) {
140+
var height = wrapper.getBoundingClientRect().height;
141+
console.log(height);
142+
nextInput.focus();
143+
}
144+
}
145+
}
146+
}
131147
return false;
132148
}
133149

jupyterquiz/js/string.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,20 @@ function check_string(ths, event) {
148148
} else {
149149
console.log('MathJax not detected');
150150
}
151+
// After correct answer, if next JupyterQuiz question exists and has a text input, scroll by current question height
152+
if (correct) {
153+
var wrapper = ths.closest('.Quiz');
154+
if (wrapper) {
155+
var nextWrapper = wrapper.nextElementSibling;
156+
if (nextWrapper && nextWrapper.classList.contains('Quiz')) {
157+
var nextInput = nextWrapper.querySelector('input.Input-text');
158+
if (nextInput) {
159+
var height = wrapper.getBoundingClientRect().height;
160+
nextInput.focus();
161+
}
162+
}
163+
}
164+
}
151165
return false;
152166
}
153167
}

0 commit comments

Comments
 (0)