2 * JavaScript to enable right click edit functionality.
3 * When the user right-clicks in a heading, it will open the
7 // Trigger this when a contextmenu click on the page targets an h1-h6 element.
8 // This uses a delegate handler which 1) starts immediately instead of blocking
9 // response on dom-ready, and 2) selects and binds once instead of N times.
10 $( document
).on( 'contextmenu', 'h1, h2, h3, h4, h5, h6', function ( e
) {
11 // Don't use ":has:(.mw-editsection a)" in the selector because it's slow.
12 var $edit
= $( this ).find( '.mw-editsection a' );
13 if ( !$edit
.length
) {
17 // Headings can contain rich text.
18 // Make sure to not block contextmenu events on (other) anchor tags
19 // inside the heading (e.g. to do things like copy URL, open in new tab, ..).
20 // e.target can be the heading, but it can also be anything inside the heading.
21 if ( e
.target
.nodeName
.toLowerCase() !== 'a' ) {
22 // Trigger native HTMLElement click instead of opening URL (T45052)
24 $edit
.get( 0 ).click();