r75762 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75761‎ | r75762 | r75763 >
Date:23:42, 31 October 2010
Author:krinkle
Status:resolved (Comments)
Tags:
Comment:
Adding mediawiki.advanced.rightclickedit.js
* Removing loadhook from legacy rightclickedit.js
* Replacing module adder in OutputPage
* Define mediawiki.advanced.rightclickedit module
Modified paths:
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/resources/Resources.php (modified) (history)
  • /trunk/phase3/resources/mediawiki.advanced (added) (history)
  • /trunk/phase3/resources/mediawiki.advanced/mediawiki.advanced.rightclickedit.js (added) (history)
  • /trunk/phase3/skins/common/rightclickedit.js (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/rightclickedit.js
@@ -43,6 +43,4 @@
4444 }
4545 }
4646 }
47 -}
48 -
49 -hookEvent("load", setupRightClickEdit);
 47+}
\ No newline at end of file
Index: trunk/phase3/includes/OutputPage.php
@@ -1641,7 +1641,7 @@
16421642 }
16431643
16441644 if( $wgUser->getBoolOption( 'editsectiononrightclick' ) ) {
1645 - $this->addModules( 'mediawiki.legacy.rightclickedit' );
 1645+ $this->addModules( 'mediawiki.advanced.rightclickedit' );
16461646 }
16471647
16481648 if( $wgUniversalEditButton ) {
Index: trunk/phase3/resources/Resources.php
@@ -319,6 +319,9 @@
320320 'debugScripts' => 'resources/mediawiki/mediawiki.log.js',
321321 'debugRaw' => false
322322 ) ),
 323+ 'mediawiki.advanced.rightclickedit' => new ResourceLoaderFileModule( array(
 324+ 'scripts' => 'resources/mediawiki.advanced/mediawiki.advanced.rightclickedit.js',
 325+ ) ),
323326 'mediawiki.specials.preferences' => new ResourceLoaderFileModule( array(
324327 'scripts' => 'resources/mediawiki.specials/mediawiki.specials.preferences.js',
325328 'styles' => 'resources/mediawiki.specials/mediawiki.specials.preferences.css',
Index: trunk/phase3/resources/mediawiki.advanced/mediawiki.advanced.rightclickedit.js
@@ -0,0 +1,19 @@
 2+/*
 3+ * JavaScript to enable right click edit functionality
 4+ */
 5+
 6+// Select all h1-h6 elements that contain editsection links
 7+$('h1, h2, h3, h4, h5, h6').filter( ':has(.editsection a)' ).bind( 'contextmenu', function( e ) {
 8+
 9+ // Get href of the [edit] link
 10+ var href = $(this).find( '.editsection a' ).attr( 'href' );
 11+
 12+ // Check if target is the anchor link itself. If so, dont supress the contextmenu
 13+ // So that the reader can still do things like copy url, open in new tab etc.
 14+ $target = $( e.target );
 15+ if( !$target.is( 'a' ) && !$target.parent().is( '.editsection' ) ){
 16+ window.location = href;
 17+ e.preventDefault();
 18+ }
 19+
 20+});
\ No newline at end of file
Property changes on: trunk/phase3/resources/mediawiki.advanced/mediawiki.advanced.rightclickedit.js
___________________________________________________________________
Added: svn:eol-style
121 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r75795Follow-up r75762krinkle15:32, 1 November 2010
r75797Follow-up r75762; deleted rightclickedit.js...krinkle15:53, 1 November 2010

Comments

#Comment by Catrope (talk | contribs)   13:12, 1 November 2010
-}
-
-hookEvent("load", setupRightClickEdit);
+}

? Why not just remove the file if it's obsolete?

The right click edit JS should be wrapped in a document ready block.

#Comment by Krinkle (talk | contribs)   14:27, 1 November 2010

I left the file itself for legacy. Just making sure it wont load twice. if it's not supposed to be used by third parties, no problem with removing it. But I thought an gadget or extension could dynamically add headers and call this function on the head-elements to make it work there too.

But then again, the file is no longer being loaded so, if this is a usecase, I'll bind 'live' instead of normal bind so that re-binding isn't needed. What do you think ?

#Comment by Catrope (talk | contribs)   14:37, 1 November 2010

Grepping /trunk/extensions for "rightclickedit" found nothing, so removing it should be safe.

Live binding sounds good, although I don't think that'll work with .filter(), so you'd have to move the :has() condition into the main selector.

Status & tagging log