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 ) {
11 var $edit = $( this ).find( '.mw-editsection a, .editsection a' );
12 if ( !$edit.length ) {
16 // Headings can contain rich text.
17 // Make sure to not block contextmenu events on (other) anchor tags
18 // inside the heading (e.g. to do things like copy URL, open in new tab, ..).
19 // e.target can be the heading, but it can also be anything inside the heading.
20 if ( e.target.nodeName.toLowerCase() !== 'a' ) {
21 // Trigger native HTMLElement click instead of opening URL (bug 43052)
23 $edit.get( 0 ).click();