Efficiently reset null user tokens
[mediawiki.git] / resources / mediawiki.action / mediawiki.action.view.rightClickEdit.js
blob93befe3a44cbd1b8b5ab6143ddf2a9ac4ab4e724
1 /**
2  * JavaScript to enable right click edit functionality.
3  * When the user right-clicks in a heading, it will open the
4  * edit screen.
5  */
6 jQuery( function ( $ ) {
7         // Select all h1-h6 elements that contain editsection links
8         // Don't use the ":has:(.mw-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' );
12                 if ( !$edit.length ) {
13                         return;
14                 }
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)
22                         e.preventDefault();
23                         $edit.get( 0 ).click();
24                 }
25         } );
26 } );