-
-
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.
- Loading branch information
Showing
49 changed files
with
4,389 additions
and
2,498 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
(() => { | ||
const initializeFeedback = (feedbackBtn) => { | ||
if (feedbackBtn.dataset.popoverInitialized) return; | ||
feedbackBtn.dataset.popoverInitialized = 'true'; | ||
|
||
new bootstrap.Popover(feedbackBtn, { sanitize: false, container: feedbackBtn.parentElement }); | ||
|
||
// Render MathJax previews. | ||
if (window.MathJax) { | ||
feedbackBtn.addEventListener('show.bs.popover', () => { | ||
MathJax.startup.promise = MathJax.startup.promise.then(() => MathJax.typesetPromise(['.popover-body'])); | ||
}); | ||
} | ||
|
||
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()); | ||
}); | ||
}; | ||
|
||
// Setup feedback popovers already on the page. | ||
document.querySelectorAll('.ww-feedback-btn').forEach(initializeFeedback); | ||
|
||
// Deal with feedback popovers that are added to the page later. | ||
const observer = new MutationObserver((mutationsList) => { | ||
mutationsList.forEach((mutation) => { | ||
mutation.addedNodes.forEach((node) => { | ||
if (node instanceof Element) { | ||
if (node.classList.contains('ww-feedback-btn')) initializeFeedback(node.firstElementChild); | ||
else node.querySelectorAll('.ww-feedback-btn').forEach(initializeFeedback); | ||
} | ||
}); | ||
}); | ||
}); | ||
observer.observe(document.body, { childList: true, subtree: true }); | ||
|
||
// Stop the mutation observer when the window is closed. | ||
window.addEventListener('unload', () => observer.disconnect()); | ||
})(); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.