ebd1ebccdf2dcebefec9cc864a4cf55f8fe602fb
[lhc/web/wiklou.git] / resources / src / mediawiki.action / mediawiki.action.view.rightClickEdit.js
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 }
15
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 (T45052)
22 e.preventDefault();
23 $edit.get( 0 ).click();
24 }
25 } );
26 } );