Change javascript event handlers to use event.target.matches instead of walking the dom to install event handlers
This commit is contained in:
parent
1cb75f4ae5
commit
51373885b4
|
@ -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() {
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue