[wp-trac] [WordPress Trac] #46713: Comment reply link uses inconvenient eventlistener
WordPress Trac
noreply at wordpress.org
Sun Jun 2 10:49:20 UTC 2019
#46713: Comment reply link uses inconvenient eventlistener
--------------------------+------------------------------
Reporter: szandman | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Comments | Version: 5.1
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Comment (by janpaulkleijn):
Hi there,
During my efforts to make my website more accessible I was also pointed
out by Google LightHouse that the adding of the 'touchstart' event
listener in this file lacked the option **passive**.
This can be corrected by altering the file: ''wp-includes/js/comment-
reply.min.js''
First the availability of support for the option parameter in the User
Agent must be checked.
https://developer.mozilla.org/en-
US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
Check option support (minified)
{{{
var supportsPassive=false;try{var
opts=Object.defineProperty({},'passive',{get:function(){supportsPassive=true;}});window.addEventListener("testPassive",
null, opts);window.removeEventListener("testPassive", null, opts);} catch
(e) {}
}}}
So you insert this code in the ''comment-reply.min.js'' file, right above
the current code.
Then the option must be added to the call for the 'touchstart' event
listener in the code itself. Where you see:
{{{
addEventListener("touchstart",f)
}}}
you should replace it with:
{{{
addEventListener("touchstart",f,supportsPassive?{passive:true}:false)
}}}
At the moment this event listener is found only twice in the beginning
part of the code.
This will solve your issue.
A good and thorough explanation of passive event listeners:
https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
--
Ticket URL: <https://core.trac.wordpress.org/ticket/46713#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list