Umherirrender has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/94412


Change subject: migrate redirectToFragment() from wikibits.js to own module
......................................................................

migrate redirectToFragment() from wikibits.js to own module

This patch creates the new top module
'mediawiki.action.view.redirectToFragment'.
This module contains the same code, but was migrated to use
jQuery.profile to detect the layout of the browser.

Other changes as written on bug 35858 should can be done in seperate
patch set(s). This is to have a start

Bug: 35858
Change-Id: Ic10c060c3a2cbab455348e57740fc8abdc66ff9a
---
M includes/Article.php
M resources/Resources.php
A resources/mediawiki.action/mediawiki.action.view.redirectToFragment.js
M skins/common/wikibits.js
4 files changed, 39 insertions(+), 34 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/12/94412/1

diff --git a/includes/Article.php b/includes/Article.php
index a6afd8e..387caca 100644
--- a/includes/Article.php
+++ b/includes/Article.php
@@ -989,9 +989,9 @@
 
                                // Set the fragment if one was specified in the 
redirect
                                if ( strval( $this->getTitle()->getFragment() ) 
!= '' ) {
-                                       $outputPage->addInlineScript( 
Xml::encodeJsCall(
-                                               'redirectToFragment', array( 
$this->getTitle()->getFragmentForURL() )
-                                       ) );
+                                       $outputPage->addJsConfigVars( 
'wgRedirectToFragment', $this->getTitle()->getFragmentForURL() );
+                                       wfDebug( "setting module 
mediawiki.action.view.redirectToFragmen" );
+                                       $outputPage->addModules( 
'mediawiki.action.view.redirectToFragment' );
                                }
 
                                // Add a <link rel="canonical"> tag
diff --git a/resources/Resources.php b/resources/Resources.php
index 9eb5227..b4e1d70 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -819,6 +819,13 @@
                        'postedit-confirmation',
                ),
        ),
+       'mediawiki.action.view.redirectToFragment' => array(
+               'scripts' => 
'resources/mediawiki.action/mediawiki.action.view.redirectToFragment.js',
+               'dependencies' => array(
+                       'jquery.client',
+               ),
+               'position' => 'top',
+       ),
        'mediawiki.action.view.rightClickEdit' => array(
                'scripts' => 
'resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js',
        ),
diff --git 
a/resources/mediawiki.action/mediawiki.action.view.redirectToFragment.js 
b/resources/mediawiki.action/mediawiki.action.view.redirectToFragment.js
new file mode 100644
index 0000000..a7da2cb
--- /dev/null
+++ b/resources/mediawiki.action/mediawiki.action.view.redirectToFragment.js
@@ -0,0 +1,29 @@
+/**
+ * JavaScript to scroll the page to a id, when a redirect with fragment is 
viewed.
+ */
+( function ( mw, $ ) {
+       var profile = $.client.profile(),
+               fragment = mw.config.get( 'wgRedirectToFragment' );
+       if ( profile.layout === 'webkit' && profile.layoutVersion < 420 ) {
+               // Released Safari w/ WebKit 418.9.1 messes up horribly
+               // Nightlies of 420+ are ok
+               return;
+       }
+       if ( !window.location.hash ) {
+               window.location.hash = fragment;
+
+               // Mozilla needs to wait until after load, otherwise the window 
doesn't
+               // scroll.  See 
<https://bugzilla.mozilla.org/show_bug.cgi?id=516293>.
+               // There's no obvious way to detect this programmatically, so 
we use
+               // version-testing.  If Firefox fixes the bug, they'll jump 
twice, but
+               // better twice than not at all, so make the fix hit future 
versions as
+               // well.
+               if ( profile.layout === 'gecko' ) {
+                       $( function () {
+                               if ( window.location.hash === fragment ) {
+                                       window.location.hash = fragment;
+                               }
+                       } );
+               }
+       }
+}( mediaWiki, jQuery ) );
diff --git a/skins/common/wikibits.js b/skins/common/wikibits.js
index d28ca0a..cb63f79 100644
--- a/skins/common/wikibits.js
+++ b/skins/common/wikibits.js
@@ -6,7 +6,6 @@
                win = window,
                ua = navigator.userAgent.toLowerCase(),
                isIE6 = ( /msie ([0-9]{1,}[\.0-9]{0,})/.exec( ua ) && 
parseFloat( RegExp.$1 ) <= 6.0 ),
-               isGecko = /gecko/.test( ua ) && 
!/khtml|spoofer|netscape\/7\.0/.test( ua ),
                onloadFuncts = [];
 
 if ( mw.config.get( 'wgBreakFrames' ) ) {
@@ -17,36 +16,6 @@
                win.top.location = win.location;
        }
 }
-
-win.redirectToFragment = function ( fragment ) {
-       var webKitVersion,
-               match = navigator.userAgent.match( /AppleWebKit\/(\d+)/ );
-       if ( match ) {
-               webKitVersion = parseInt( match[1], 10 );
-               if ( webKitVersion < 420 ) {
-                       // Released Safari w/ WebKit 418.9.1 messes up horribly
-                       // Nightlies of 420+ are ok
-                       return;
-               }
-       }
-       if ( !win.location.hash ) {
-               win.location.hash = fragment;
-
-               // Mozilla needs to wait until after load, otherwise the window 
doesn't
-               // scroll.  See 
<https://bugzilla.mozilla.org/show_bug.cgi?id=516293>.
-               // There's no obvious way to detect this programmatically, so 
we use
-               // version-testing.  If Firefox fixes the bug, they'll jump 
twice, but
-               // better twice than not at all, so make the fix hit future 
versions as
-               // well.
-               if ( isGecko ) {
-                       $( function () {
-                               if ( win.location.hash === fragment ) {
-                                       win.location.hash = fragment;
-                               }
-                       } );
-               }
-       }
-};
 
 /**
  * User-agent sniffing.

-- 
To view, visit https://gerrit.wikimedia.org/r/94412
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic10c060c3a2cbab455348e57740fc8abdc66ff9a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <umherirrender_de...@web.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to