2 * JavaScript to enable right click edit functionality.
3 * When the user right-clicks in a heading, it will open the
6 jQuery( function ( $ ) {
7 // Select all h1-h6 elements that contain editsection links
8 // Don't use the ":has:(.editsection a)" selector because it performs very bad.
9 // http://jsperf.com/jq-1-7-2-vs-jq-1-8-1-performance-of-mw-has/2
10 $( document
).on( 'contextmenu', 'h1, h2, h3, h4, h5, h6', function ( e
) {
13 $edit
= $( this ).find( '.editsection a' );
14 if ( !$edit
.length
) {
18 // Get href of the editsection link
19 href
= $edit
.prop( 'href' );
21 // Headings can contain rich text.
22 // Make sure to not block contextmenu events on (other) anchor tags
23 // inside the heading (e.g. to do things like copy URL, open in new tab, ..).
24 // e.target can be the heading, but it can also be anything inside the heading.
25 if ( href
&& e
.target
.nodeName
.toLowerCase() !== 'a' ) {
26 window
.location
= href
;