Jdlrobson has uploaded a new change for review.

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


Change subject: Alpha: Experiment to collapse sections in JavaScript
......................................................................

Alpha: Experiment to collapse sections in JavaScript

I'm not sure how shifting so many DOM nodes in JS is but it might
be worth exploring as if we can achieve this in this way, there is
an easy path to making the mobile skin a registered desktop skin..

Introduce isBetaGroupMember and isAlphaGroupMember since this pattern
occurs all over the place in our code

Change-Id: Icea395047a2c9ae4713d461103cb2bee20006249
---
M includes/formatters/MobileFormatter.php
M javascripts/common/application.js
M javascripts/modules/mf-toggle.js
3 files changed, 47 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/45/94245/1

diff --git a/includes/formatters/MobileFormatter.php 
b/includes/formatters/MobileFormatter.php
index 4bb2304..3465445 100644
--- a/includes/formatters/MobileFormatter.php
+++ b/includes/formatters/MobileFormatter.php
@@ -3,7 +3,7 @@
 /**
  * Converts HTML into a mobile-friendly version
  */
-abstract class MobileFormatter extends HtmlFormatter {
+class MobileFormatter extends HtmlFormatter {
        /*
                String prefixes to be applied at start and end of output from 
Parser
        */
@@ -60,7 +60,11 @@
                        $wmlContext = new WmlContext( $context );
                        $formatter = new MobileFormatterWML( $html, $title, 
$wmlContext );
                } else {
-                       $formatter = new MobileFormatterHTML( $html, $title );
+                       if ( $context->isAlphaGroupMember() ) {
+                               $formatter = new MobileFormatter( $html, $title 
);
+                       } else {
+                               $formatter = new MobileFormatterHTML( $html, 
$title );
+                       }
                        $formatter->enableExpandableSections( !$isMainPage && 
!$isSpecialPage );
                        $formatter->flattenRedLinks( 
!$context->isBetaGroupMember() );
                }
@@ -80,7 +84,9 @@
        /**
         * @return string: Output format
         */
-       public abstract function getFormat();
+       public function getFormat() {
+               return 'HTML';
+       }
 
        /**
         * @todo: kill with fire when there will be minimum of pre-1.1 app 
users remaining
diff --git a/javascripts/common/application.js 
b/javascripts/common/application.js
index c1a921d..ab36560 100644
--- a/javascripts/common/application.js
+++ b/javascripts/common/application.js
@@ -49,6 +49,38 @@
                $viewportMeta.attr( 'content', viewport );
        }
 
+       function preparePageContent( $content ) {
+               var $h1s = $content.find( 'h1' ),
+                       $headings = $h1s.length > 0 ? $h1s : $content.find( 
'h2' ),
+                       tagName = $h1s.length > 0 ? 'h1' : 'h2', sections = [];
+
+               // wrap text nodes in spans so that they can be collapsed later
+               $content.contents().filter( function() {
+                       return this.nodeType !== 1;
+               } ).wrap( '<span></span>' );
+
+               // Loop through headings working out where the sections are
+               $headings.each( function() {
+                       var $heading = $( this );
+                       $content = $heading.nextUntil( tagName ).detach();
+                       sections.push( [ $heading, $content ] );
+               } );
+
+               // Re-insert back in DOM
+               $.each( sections, function( i, section ) {
+                       var $container = $( '<div>' ).insertAfter( section[0] );
+                       $container.append( section[1] );
+               } );
+       }
+
+       function isBetaGroupMember() {
+               return mw.config.get( 'wgMFMode' ) === 'beta';
+       }
+
+       function isAlphaGroupMember() {
+               return mw.config.get( 'wgMFMode' ) === 'alpha';
+       }
+
        // TODO: separate main menu navigation code into separate module
        function init() {
                var
@@ -56,6 +88,9 @@
                        $doc = $( 'html' ),
                        $viewport = $( '#mw-mf-viewport' );
 
+               if ( isAlphaGroupMember() && !inNamespace( 'special' ) ) {
+                       preparePageContent( $( '#content' ) );
+               }
 
                $doc.removeClass( 'page-loading' ); // FIXME: Kill with fire. 
This is here for historic reasons in case old HTML is cached
 
@@ -270,6 +305,8 @@
                        return $( '#content div' ).eq( 0 );
                },
                getSessionId: getSessionId,
+               isBetaGroupMember: isBetaGroupMember,
+               isAlphaGroupMember: isAlphaGroupMember(),
                isLoggedIn: isLoggedIn,
                isWideScreen: isWideScreen,
                lockViewport: lockViewport,
diff --git a/javascripts/modules/mf-toggle.js b/javascripts/modules/mf-toggle.js
index 6f28e60..4963105 100644
--- a/javascripts/modules/mf-toggle.js
+++ b/javascripts/modules/mf-toggle.js
@@ -85,7 +85,7 @@
 
        // avoid this running on Watchlist
        if ( !M.inNamespace( 'special' ) && !mw.config.get( 'wgIsMainPage' ) ) {
-               init();
+               $( init );
        }
 
        M.on( 'page-loaded', function( page ) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icea395047a2c9ae4713d461103cb2bee20006249
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>

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

Reply via email to