aboutsummaryrefslogtreecommitdiffstats
path: root/resources/src/mediawiki.misc-authed-pref
diff options
context:
space:
mode:
authorTimo Tijhof <krinklemail@gmail.com>2019-11-05 16:22:13 -0500
committerTimo Tijhof <krinklemail@gmail.com>2019-11-05 16:34:59 -0500
commitc6569804984521066762b0139ee2a82f8d5dd24c (patch)
tree9da61cb1167b776e30d1b7743cfb0f46c798291d /resources/src/mediawiki.misc-authed-pref
parent187668016734600689d80eaaad2409ebbfc7f181 (diff)
downloadmediawikicore-c6569804984521066762b0139ee2a82f8d5dd24c.tar.gz
mediawikicore-c6569804984521066762b0139ee2a82f8d5dd24c.zip
resources: Merge dblClickEdit and rightClickEdit JS code
Both are rare preferences that are off by default and have no active steward. They are small enough that it isn't worth creating and registering public bundle for on all page views for all users. Instead, combine them into a single module. Bug: T233676 Change-Id: I21a492ad8b6005c1bd9257599cd19b594fc3d263
Diffstat (limited to 'resources/src/mediawiki.misc-authed-pref')
-rw-r--r--resources/src/mediawiki.misc-authed-pref/dblClickEdit.js19
-rw-r--r--resources/src/mediawiki.misc-authed-pref/rightClickEdit.js32
2 files changed, 51 insertions, 0 deletions
diff --git a/resources/src/mediawiki.misc-authed-pref/dblClickEdit.js b/resources/src/mediawiki.misc-authed-pref/dblClickEdit.js
new file mode 100644
index 000000000000..6815433af689
--- /dev/null
+++ b/resources/src/mediawiki.misc-authed-pref/dblClickEdit.js
@@ -0,0 +1,19 @@
+/*!
+ * Enable double-click-to-edit functionality.
+ */
+( function () {
+ if ( !parseInt( mw.user.options.get( 'editondblclick' ), 10 ) ) {
+ return;
+ }
+ $( function () {
+ $( '#mw-content-text' ).on( 'dblclick', function ( e ) {
+ // Trigger native HTMLElement click instead of opening URL (T45052)
+ var $a = $( '#ca-edit a' );
+ // Not every page has an edit link (T59713)
+ if ( $a.length ) {
+ e.preventDefault();
+ $a.get( 0 ).click();
+ }
+ } );
+ } );
+}() );
diff --git a/resources/src/mediawiki.misc-authed-pref/rightClickEdit.js b/resources/src/mediawiki.misc-authed-pref/rightClickEdit.js
new file mode 100644
index 000000000000..8c936eb39cd6
--- /dev/null
+++ b/resources/src/mediawiki.misc-authed-pref/rightClickEdit.js
@@ -0,0 +1,32 @@
+/*!
+ * Enable right-click-to-edit functionality.
+ *
+ * When the user right-clicks in a content heading, it will open the
+ * edit section link.
+ */
+( function () {
+ if ( !parseInt( mw.user.options.get( 'editsectiononrightclick' ), 10 ) ) {
+ return;
+ }
+
+ // Trigger this when a contextmenu click on the page targets an h1-h6 element.
+ // This uses a delegate handler which 1) starts immediately instead of blocking
+ // response on dom-ready, and 2) selects and binds once instead of N times.
+ $( document ).on( 'contextmenu', 'h1, h2, h3, h4, h5, h6', function ( e ) {
+ // Don't use ":has:(.mw-editsection a)" in the selector because it's slow.
+ 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 (T45052)
+ e.preventDefault();
+ $edit.get( 0 ).click();
+ }
+ } );
+}() );