Skip to content

Commit 60aadf0

Browse files
committed
fix warning box positioning (again)
I noticed that the code to position warning boxes was using the document's width to work out if warning boxes should be pushed left, but now that the <main> element has overflow-x: hidden, it should be using the width of the question element. This changes the positioning code to do that, and I think it resolves some errors in positioning warnings for gaps, so they shouldn't ever overlap the input box now.
1 parent e2097fc commit 60aadf0

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

themes/default/files/resources/exam.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ select.multiplechoice {
11301130
margin-top: 2em;
11311131
}
11321132

1133-
.gap .warnings {
1133+
.gap .warnings:not(.shifted-down) {
11341134
margin-top: -0.5em;
11351135
}
11361136
.warnings.stick-right {

themes/default/files/scripts/part-display.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,10 @@ Numbas.queueScript('part-display',['display-util', 'display-base','util','jme'],
196196
if(!pd.html || !pd.warningsShown.peek()) {
197197
return;
198198
}
199-
var warnings_box = pd.html.querySelector('.warnings');
200-
var answer = pd.html.querySelector('.student-answer');
199+
var margin = 10;
200+
201+
var warnings_box = pd.html.querySelector(':scope > .student-answer .warnings');
202+
var answer = pd.html.querySelector(':scope > .student-answer');
201203
var offsetTop = 0;
202204
var offsetLeft = 0;
203205
var el = answer;
@@ -210,19 +212,22 @@ Numbas.queueScript('part-display',['display-util', 'display-base','util','jme'],
210212
var answer_width = answer.getBoundingClientRect().width;
211213

212214
var wtop = offsetTop + (p.isGap ? 0 : answer_height);
213-
var wleft = (offsetLeft + (p.isGap ? answer_width : 0));
215+
var wleft = (offsetLeft + (p.isGap ? margin + answer_width : 0));
214216

215217
warnings_box.style.top = wtop + 'px';
216218
warnings_box.style.left = wleft + 'px';
217219

218220
var box = warnings_box.getBoundingClientRect();
219-
var docWidth = document.documentElement.clientWidth;
220-
var margin = 10;
221-
var dr = box.right - docWidth + document.documentElement.clientLeft + margin;
221+
const question_html = pd.part.question.display.html;
222+
var question_box = question_html.getBoundingClientRect();
223+
var docWidth = question_box.width;
224+
var dr = box.right - question_box.left - docWidth + margin;
225+
warnings_box.classList.remove('shifted-down');
222226
if(dr > 0) {
223227
wleft -= dr;
224228
if(p.isGap) {
225229
wtop += answer_height;
230+
warnings_box.classList.add('shifted-down');
226231
}
227232
warnings_box.style.left = wleft + 'px';
228233
warnings_box.style.top = wtop + 'px';

0 commit comments

Comments
 (0)