From 7c29cdb9ac5a5ee1cd19fee30450c275365ff385 Mon Sep 17 00:00:00 2001 From: Trevor Parscal Date: Thu, 18 Nov 2010 22:03:57 +0000 Subject: [PATCH] Cleaned up the code a bit, and added a return false to prevent other bindings from being fired. --- .../mediawiki.action.view.rightClickEdit.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js diff --git a/resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js b/resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js new file mode 100644 index 0000000000..11254174fd --- /dev/null +++ b/resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js @@ -0,0 +1,24 @@ +/* + * JavaScript to enable right click edit functionality + */ +$( 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. + $target = $( e.target ); + if ( !$target.is( 'a' ) && !$target.parent().is( '.editsection' ) ){ + window.location = href; + e.preventDefault(); + return false; + } + } ); +} ); -- 2.20.1