summaryrefslogtreecommitdiff
path: root/resources/src/mediawiki.action/mediawiki.action.view.rightClickEdit.js
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2014-12-27 15:41:37 +0100
committerPierre Schmitz <pierre@archlinux.de>2014-12-31 11:43:28 +0100
commitc1f9b1f7b1b77776192048005dcc66dcf3df2bfb (patch)
tree2b38796e738dd74cb42ecd9bfd151803108386bc /resources/src/mediawiki.action/mediawiki.action.view.rightClickEdit.js
parentb88ab0086858470dd1f644e64cb4e4f62bb2be9b (diff)
Update to MediaWiki 1.24.1
Diffstat (limited to 'resources/src/mediawiki.action/mediawiki.action.view.rightClickEdit.js')
-rw-r--r--resources/src/mediawiki.action/mediawiki.action.view.rightClickEdit.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/resources/src/mediawiki.action/mediawiki.action.view.rightClickEdit.js b/resources/src/mediawiki.action/mediawiki.action.view.rightClickEdit.js
new file mode 100644
index 00000000..ada101eb
--- /dev/null
+++ b/resources/src/mediawiki.action/mediawiki.action.view.rightClickEdit.js
@@ -0,0 +1,26 @@
+/*!
+ * JavaScript to enable right click edit functionality.
+ * When the user right-clicks in a heading, it will open the
+ * edit screen.
+ */
+jQuery( function ( $ ) {
+ // Select all h1-h6 elements that contain editsection links
+ // Don't use the ":has:(.mw-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 = $( this ).find( '.mw-editsection a' );
+ if ( !$edit.length ) {
+ return;
+ }
+
+ // 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 ( e.target.nodeName.toLowerCase() !== 'a' ) {
+ // Trigger native HTMLElement click instead of opening URL (bug 43052)
+ e.preventDefault();
+ $edit.get( 0 ).click();
+ }
+ } );
+} );