diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2013-01-18 16:46:04 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2013-01-18 16:46:04 +0100 |
commit | 63601400e476c6cf43d985f3e7b9864681695ed4 (patch) | |
tree | f7846203a952e38aaf66989d0a4702779f549962 /resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js | |
parent | 8ff01378c9e0207f9169b81966a51def645b6a51 (diff) |
Update to MediaWiki 1.20.2
this update includes:
* adjusted Arch Linux skin
* updated FluxBBAuthPlugin
* patch for https://bugzilla.wikimedia.org/show_bug.cgi?id=44024
Diffstat (limited to 'resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js')
-rw-r--r-- | resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js b/resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js index caf9a9f2..d02d4327 100644 --- a/resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js +++ b/resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js @@ -1,24 +1,30 @@ /* - * JavaScript to enable right click edit functionality + * JavaScript to enable right click edit functionality. + * When the user right-clicks in a heading, it will open the + * edit screen. */ -jQuery( function( $ ) { +jQuery( function ( $ ) { // Select all h1-h6 elements that contain editsection links - $( 'h1:has(.editsection a), ' + - 'h2:has(.editsection a), ' + - 'h3:has(.editsection a), ' + - 'h4:has(.editsection a), ' + - 'h5:has(.editsection a), ' + - 'h6:has(.editsection a)' - ).live( 'contextmenu', function( e ) { - // Get href of the [edit] link - var href = $(this).find( '.editsection a' ).attr( 'href' ); - // Check if target is the anchor link itself. If so, don't suppress the context menu; this - // way the reader can still do things like copy URL, open in new tab etc. - var $target = $( e.target ); - if ( !$target.is( 'a' ) && !$target.parent().is( '.editsection' ) ){ + // Don't use the ":has:(.editsection a)" selector because it performs very bad. + // http://jsperf.com/jq-1-7-2-vs-jq-1-8-1-performance-of-mw-has/2 + $( document ).on( 'contextmenu', 'h1, h2, h3, h4, h5, h6', function ( e ) { + var $edit, href; + + $edit = $( this ).find( '.editsection a' ); + if ( !$edit.length ) { + return; + } + + // Get href of the editsection link + href = $edit.prop( 'href' ); + + // Headings can contain rich text. + // Make sure to not block contextmenu events on (other) anchor tags + // inside the heading (e.g. to do things like copy URL, open in new tab, ..). + // e.target can be the heading, but it can also be anything inside the heading. + if ( href && e.target.nodeName.toLowerCase() !== 'a' ) { window.location = href; e.preventDefault(); - return false; } } ); } ); |