https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112930

Revision: 112930
Author:   krinkle
Date:     2012-03-03 00:50:35 +0000 (Sat, 03 Mar 2012)
Log Message:
-----------
[CentralAuth] Refactor JS
* Prefix variable definitions with 'var'. Previously `methodHint` was occupying 
the global namespace ("ack" search reveals no usage of this stuff in 
./trunk/phase3 or ./trunk/extensions other than this dir)
* Remove wg prefix of the variable to avoid confusion with wiki globals
* Binding hideMethodHint directly to methodHint.onclick. No need to set an 
attribute and let eval()-behavior on a javascript string
* Using ResourceLoader module messages (and client side: mw.msg and 
mw.message), instead of exposing a global in javascript with pre-processed raw 
html (wfMsgWikiHtml).
* Remove redundant hideMethodHint
* Fix onclick="showMethodHint('{$method}')" by using a data attribute and 
binding a delegated event handler on the container and showing the method hint 
that way
* Hiding the (?) with CSS if javascript isn't running
* Clean up JS to use mw and jQuery, adding nice little fadeIn/Out to the hint 
bubble, and re-using the same hint element instead of re-creating it
* Other mis

* Fixes:
-- Bug 34915 - Uncaught ReferenceError: showMethodHint is not defined
-- Bug 34916 - Port CentralAuth to use ResourceLoader
* Pokes: r112925, r112926

Modified Paths:
--------------
    trunk/extensions/CentralAuth/CentralAuth.php
    trunk/extensions/CentralAuth/modules/ext.centralauth.css
    trunk/extensions/CentralAuth/modules/ext.centralauth.js
    trunk/extensions/CentralAuth/specials/SpecialCentralAuth.php

Modified: trunk/extensions/CentralAuth/CentralAuth.php
===================================================================
--- trunk/extensions/CentralAuth/CentralAuth.php        2012-03-03 00:17:15 UTC 
(rev 112929)
+++ trunk/extensions/CentralAuth/CentralAuth.php        2012-03-03 00:50:35 UTC 
(rev 112930)
@@ -260,6 +260,22 @@
 $wgResourceModules['ext.centralauth'] = array(
        'scripts' => 'ext.centralauth.js',
        'styles' => 'ext.centralauth.css',
+       'messages' => array(
+               'centralauth-merge-method-primary',
+               'centralauth-merge-method-primary-desc',
+               'centralauth-merge-method-new',
+               'centralauth-merge-method-new-desc',
+               'centralauth-merge-method-empty',
+               'centralauth-merge-method-empty-desc',
+               'centralauth-merge-method-password',
+               'centralauth-merge-method-password-desc',
+               'centralauth-merge-method-mail',
+               'centralauth-merge-method-mail-desc',
+               'centralauth-merge-method-admin',
+               'centralauth-merge-method-admin-desc',
+               'centralauth-merge-method-login',
+               'centralauth-merge-method-login-desc',
+       ),
 ) + $commonModuleInfo;
 
 $wgResourceModules['ext.centralauth.noflash'] = array(

Modified: trunk/extensions/CentralAuth/modules/ext.centralauth.css
===================================================================
--- trunk/extensions/CentralAuth/modules/ext.centralauth.css    2012-03-03 
00:17:15 UTC (rev 112929)
+++ trunk/extensions/CentralAuth/modules/ext.centralauth.css    2012-03-03 
00:50:35 UTC (rev 112930)
@@ -12,3 +12,8 @@
 .merge-method-help-name {
        font-weight: bold;
 }
+
+/* Hide them when javascript fails or isn't enabled */
+.client-nojs .mw-centralauth-wikislist .merge-method-help {
+       display: none;
+}

Modified: trunk/extensions/CentralAuth/modules/ext.centralauth.js
===================================================================
--- trunk/extensions/CentralAuth/modules/ext.centralauth.js     2012-03-03 
00:17:15 UTC (rev 112929)
+++ trunk/extensions/CentralAuth/modules/ext.centralauth.js     2012-03-03 
00:50:35 UTC (rev 112930)
@@ -1,34 +1,57 @@
-wgCursorPosition = { x : 0, y : 0 };
-function updateCursorPosition( e ) {
-       e = e || window.event;
-       wgCursorPosition.x = e.clientX + ( document.documentElement.scrollLeft 
|| document.body.scrollLeft )
-               - document.documentElement.clientLeft;
-       wgCursorPosition.y = e.clientY + ( document.documentElement.scrollTop 
|| document.body.scrollTop )
-               - document.documentElement.clientTop;
-}
-document.onmousemove = updateCursorPosition;
+( function ( mw, $, undefined ) {
+       var cursorPosition, $methodHint;
 
-methodHint = null;
-function showMethodHint( methodName ) {
-       hideMethodHint();
+       cursorPosition = {
+               x : 0,
+               y : 0
+       };
 
-       method = wgMergeMethodDescriptions[methodName];
-       helpHtml = "<p class='merge-method-help-name'>" + method.short + "</p>" 
+ method.desc;
+       $(document).on( 'mousemove', function updateCursorPosition( e ) {
+               cursorPosition.x = 
+                       e.clientX
+                       + ( document.documentElement.scrollLeft || 
document.body.scrollLeft )
+                       - document.documentElement.clientLeft;
 
-       methodHint = document.createElement( 'div' );
-       methodHint.innerHTML = helpHtml;
-       methodHint.setAttribute( 'class', 'merge-method-help-div' );
-       methodHint.style.left = wgCursorPosition.x + 'px';
-       methodHint.style.top = wgCursorPosition.y + 'px';
-       methodHint.setAttribute( 'onclick', 'hideMethodHint()' );
+               cursorPosition.y =
+                       e.clientY
+                       + ( document.documentElement.scrollTop || 
document.body.scrollTop )
+                       - document.documentElement.clientTop;
+       } );
 
-       var content = document.getElementById('content') || 
document.getElementById('mw_content') || document.body;
-       content.appendChild( methodHint );
-}
+       function showMethodHint( methodName ) {
+               var content, hintHtml;
 
-function hideMethodHint() {
-       if( methodHint ) {
-               methodHint.parentNode.removeChild( methodHint );
-               methodHint = null;
+               if ( !$methodHint ) {
+                       $methodHint = $( '<div>' )
+                               .addClass( 'merge-method-help-div' )
+                               .hide()
+                               .click( function () {
+                                       $(this).fadeOut();
+                               } );
+
+                       content = document.getElementById( 'content' ) || 
document.getElementById( 'mw_content' ) || document.body;
+                       $(content).append( $methodHint );
+               }
+       
+               hintHtml = mw.html.element( 'p', {
+                       'class': 'merge-method-help-name'
+               }, mw.msg( 'centralauth-merge-method-' + methodName ) ) + 
mw.message( 'centralauth-merge-method-' + methodName + '-desc' ).escaped();
+       
+               $methodHint
+                       .html( hintHtml )
+                       .css({
+                               left: cursorPosition.x + 'px',
+                               top: cursorPosition.y + 'px'
+                       });
+
+               $methodHint.fadeIn();
        }
-}
+
+       $( document ).ready( function () {
+               // Bind an event listener to the common parent of all (?) 
elements
+               $( '.mw-centralauth-wikislist' ).on( 'click', 
'.merge-method-help', function () {
+                       showMethodHint( $(this).data( 'centralauth-mergemethod' 
) );
+               } );
+       } );
+
+}( mediaWiki, jQuery ) );

Modified: trunk/extensions/CentralAuth/specials/SpecialCentralAuth.php
===================================================================
--- trunk/extensions/CentralAuth/specials/SpecialCentralAuth.php        
2012-03-03 00:17:15 UTC (rev 112929)
+++ trunk/extensions/CentralAuth/specials/SpecialCentralAuth.php        
2012-03-03 00:50:35 UTC (rev 112930)
@@ -416,11 +416,26 @@
         */
        function formatMergeMethod( $method ) {
                global $wgExtensionAssetsPath;
+               
+               $brief = wfMessage( 'centralauth-merge-method-{$method}' 
)->text();
+               $html = 
+                       Html::element(
+                               'img', array(
+                                       'src' => 
"{$wgExtensionAssetsPath}/CentralAuth/icons/merged-{$method}.png",
+                                       'alt' => $brief,
+                                       'title' => $brief,
+                               )
+                       )
+                       . Html::element(
+                               'span', array(
+                                       'class' => 'merge-method-help',
+                                       'title' => $brief,
+                                       'data-centralauth-mergemethod' => 
$method
+                               ),
+                               '(?)'
+                       );
 
-               $img = htmlspecialchars( 
"{$wgExtensionAssetsPath}/CentralAuth/icons/merged-{$method}.png" );
-               $brief = wfMsgHtml( "centralauth-merge-method-{$method}" );
-               return "<img src=\"{$img}\" alt=\"{$brief}\" 
title=\"{$brief}\"/>" .
-                       "<span class=\"merge-method-help\" title=\"{$brief}\" 
onclick=\"showMethodHint('{$method}')\">(?)</span>";
+               return $html;
        }
 
        /**


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to