-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1159 from drgrice1/html-dropdown
Add an HTML/JavaScript drop down menu option to parserPopUp.pl.
- Loading branch information
Showing
4 changed files
with
221 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
(() => { | ||
const setupDropdown = (dropdown) => { | ||
const input = dropdown?.querySelector(`input[name="${dropdown.dataset.feedbackInsertElement}"]`); | ||
const dropdownBtn = dropdown?.querySelector('button.dropdown-toggle'); | ||
if (!dropdown || !input || !dropdownBtn) return; | ||
|
||
// Give the dropdown button the correct/incorrect colors. | ||
if (input.classList.contains('correct')) dropdownBtn.classList.add('correct'); | ||
if (input.classList.contains('incorrect')) dropdownBtn.classList.add('incorrect'); | ||
if (input.classList.contains('partially-correct')) dropdownBtn.classList.add('partially-correct'); | ||
|
||
const options = Array.from(dropdown.querySelectorAll('.dropdown-item:not(.disabled)')); | ||
|
||
dropdown.addEventListener('shown.bs.dropdown', () => { | ||
for (const option of options) { | ||
if (option.classList.contains('active')) { | ||
option.focus(); | ||
break; | ||
} | ||
} | ||
}); | ||
|
||
for (const option of options) { | ||
option.addEventListener('click', () => { | ||
options.forEach((o) => o.classList.remove('active')); | ||
option.classList.add('active'); | ||
input.value = option.dataset.value; | ||
dropdownBtn.textContent = option.dataset.content; | ||
dropdownBtn.focus(); | ||
|
||
if (window.MathJax) | ||
MathJax.startup.promise = MathJax.startup.promise.then(() => MathJax.typesetPromise([dropdownBtn])); | ||
|
||
// If any feedback popovers are open, then update their positions. | ||
for (const popover of document.querySelectorAll('.ww-feedback-btn')) { | ||
bootstrap.Popover.getInstance(popover)?.update(); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
// Set up dropdowns that are already in the page. | ||
document.querySelectorAll('.pg-dropdown').forEach(setupDropdown); | ||
|
||
// Observer that sets up MathQuill inputs. | ||
const observer = new MutationObserver((mutationsList) => { | ||
for (const mutation of mutationsList) { | ||
for (const node of mutation.addedNodes) { | ||
if (node instanceof Element) { | ||
if (node.classList.contains('pg-dropdown')) { | ||
setupDropdown(node); | ||
} else { | ||
node.querySelectorAll('.pg-dropdown').forEach(setupDropdown); | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
observer.observe(document.body, { childList: true, subtree: true }); | ||
|
||
// Stop the mutation observer when the window is closed. | ||
window.addEventListener('unload', () => observer.disconnect()); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
.pg-dropdown { | ||
.btn.dropdown-toggle { | ||
--bs-btn-color: #555; | ||
--bs-btn-bg: white; | ||
--bs-btn-padding-y: 0.2rem; | ||
--bs-btn-padding-x: 0.45rem; | ||
--bs-btn-font-size: 0.85rem; | ||
--bs-btn-border-radius: 4px; | ||
--bs-btn-border-color: #ccc; | ||
--bs-btn-hover-color: #000; | ||
--bs-btn-hover-bg: #d3d4d5; | ||
--bs-btn-hover-border-color: #ccc; | ||
--bs-btn-focus-shadow-rgb: 33, 37, 41; | ||
--bs-btn-active-color: #000; | ||
--bs-btn-active-bg: #d3d4d5; | ||
--bs-btn-active-border-color: #ccc; | ||
--bs-btn-active-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125); | ||
|
||
&.show { | ||
border-color: rgba(112, 154, 192, 0.8); | ||
outline: 0; | ||
box-shadow: | ||
inset 0 1px 1px rgba(0, 0, 0, 0.25), | ||
0 0 0 0.2rem rgba(136, 187, 221, 0.8); | ||
} | ||
|
||
&::after { | ||
margin-left: 0.9em; | ||
} | ||
} | ||
|
||
.dropdown-menu { | ||
--bs-dropdown-min-width: 100%; | ||
} | ||
|
||
.dropdown-item { | ||
--bs-dropdown-link-active-color: black; | ||
--bs-dropdown-link-active-bg: lightgray; | ||
--bs-dropdown-link-hover-bg: #d3d3d387; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters