Skip to content

Commit

Permalink
Tweaks to style and popover DOM placement.
Browse files Browse the repository at this point in the history
Reduce the padding on the card headers in the results popover.

Make the popover container the parent element of the feedback button.
In most cases this will result in the popover being in the DOM
immediately after the feedback button, and thus also immediately after
the button in the tab order.

Make clicking on the popover header close it.  Note that this does not
have interactive semantics other than a pointer cursor when the mouse is
over it, and is not focusable.  That is probably okay since this would
be an annoying tab stop for keyboard users, and keyboard users can
already open and close the popover with the button.
  • Loading branch information
drgrice1 committed Oct 29, 2023
1 parent 4839f01 commit 8b76324
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions htdocs/js/Feedback/feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
if (feedbackBtn.dataset.popoverInitialized) return;
feedbackBtn.dataset.popoverInitialized = 'true';

new bootstrap.Popover(feedbackBtn, { sanitize: false });
new bootstrap.Popover(feedbackBtn, { sanitize: false, container: feedbackBtn.parentElement });

// Render MathJax previews.
if (window.MathJax) {
Expand All @@ -12,15 +12,19 @@
});
}

// Execute javascript in the answer preview.
feedbackBtn.addEventListener('shown.bs.popover', () => {
const bsPopover = bootstrap.Popover.getInstance(feedbackBtn);

// Execute javascript in the answer preview.
bsPopover.tip?.querySelectorAll('script').forEach((origScript) => {
const newScript = document.createElement('script');
Array.from(origScript.attributes).forEach((attr) => newScript.setAttribute(attr.name, attr.value));
newScript.appendChild(document.createTextNode(origScript.innerHTML));
origScript.parentNode.replaceChild(newScript, origScript);
});

// Make a click on the popover header close the popover.
bsPopover.tip?.querySelector('.popover-header')?.addEventListener('click', () => bsPopover?.hide());
});
};

Expand Down
1 change: 1 addition & 0 deletions htdocs/js/Problem/problem.scss
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@
.popover-header {
--bs-popover-header-bg: var(--bs-success);
--bs-popover-header-color: white;
cursor: pointer;
}
}

Expand Down
2 changes: 1 addition & 1 deletion macros/PG.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ sub ENDDOCUMENT {
return '' unless defined $line && $line =~ /\S/;
return Mojo::DOM->new_tag(
'div',
class => 'card-header text-center',
class => 'card-header text-center p-1',
sub { Mojo::DOM->new_tag('h4', class => 'card-title fs-6 m-0', $title); }
) . Mojo::DOM->new_tag('div', class => "card-body text-center $class", sub {$line});
}
Expand Down

0 comments on commit 8b76324

Please sign in to comment.