Change javascript event handlers to use event.target.matches instead of walking the dom to install event handlers

This commit is contained in:
Maurice Parker 2019-10-15 09:04:21 -05:00
parent 1cb75f4ae5
commit 51373885b4
2 changed files with 15 additions and 15 deletions

View File

@ -1,17 +1,15 @@
// These mouse functions are used by NetNewsWire for Mac to display link previews
function mouseDidEnterLink(anchor) {
window.webkit.messageHandlers.mouseDidEnter.postMessage(anchor.href);
}
function mouseDidExitLink(anchor) {
window.webkit.messageHandlers.mouseDidExit.postMessage(anchor.href);
}
// Add the mouse listeners for the above functions
function linkHover() {
document.querySelectorAll("a").forEach(element => {
element.addEventListener("mouseenter", function() { mouseDidEnterLink(this) });
element.addEventListener("mouseleave", function() { mouseDidExitLink(this) });
});
window.onmouseover = function(event) {
if (event.target.matches('a')) {
window.webkit.messageHandlers.mouseDidEnter.postMessage(event.target.href);
}
}
window.onmouseout = function(event) {
if (event.target.matches('a')) {
window.webkit.messageHandlers.mouseDidExit.postMessage(event.target.href);
}
}
}
function postRenderProcessing() {

View File

@ -33,9 +33,11 @@ async function imageWasClicked(img) {
// Add the click listeners for images
function imageClicks() {
document.querySelectorAll("img").forEach(element => {
element.addEventListener("click", function() { imageWasClicked(this) });
});
window.onclick = function(event) {
if (event.target.matches('img')) {
imageWasClicked(event.target);
}
}
}
// Add the playsinline attribute to any HTML5 videos that don't have it.