Skip to content

Commit

Permalink
after hiding the lightbox, focus the original image's magnify button
Browse files Browse the repository at this point in the history
Otherwise, the focus was reset, which would mean you'd have to navigate
all the way back to the image from the start.
  • Loading branch information
christianp committed Apr 26, 2024
1 parent eec9b6e commit 70a4431
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions themes/default/files/scripts/display-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,13 @@ var display = Numbas.display = /** @lends Numbas.display */ {
style_options_localstorage_key: 'numbas-style-options',

/** Show the lightbox.
*
* @param {Element} original - The original image element which is going to be copied into the lightbox.
*/
show_lightbox: function() {
show_lightbox: function(original) {
lightbox.classList.add('shown');
lightbox.focus();
display.lightbox_original_element = original;
},

/** Hide the lightbox.
Expand All @@ -150,6 +153,9 @@ var display = Numbas.display = /** @lends Numbas.display */ {
lightbox.classList.remove('shown');
lightbox.innerHTML = '';
display.lightbox_pressing_state = 'none';
if(display.lightbox_original_element) {
display.lightbox_original_element.querySelector('button').focus();
}
},

setExam: function(exam) {
Expand Down Expand Up @@ -253,7 +259,7 @@ var display = Numbas.display = /** @lends Numbas.display */ {
function activate() {
lightbox.innerHTML = '';
lightbox.appendChild(elem);
Numbas.display.show_lightbox();
Numbas.display.show_lightbox(wrapper);
}

button.addEventListener('click', function(e) {
Expand Down

0 comments on commit 70a4431

Please sign in to comment.