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

Revision: 112208
Author:   jdlrobson
Date:     2012-02-23 15:26:07 +0000 (Thu, 23 Feb 2012)
Log Message:
-----------
use javascript to generate buttons for expandable sections

update fixtures so that buttons are not initially in html
and are added by the javascript code

I believe this resolves #34422

Modified Paths:
--------------
    trunk/extensions/MobileFrontend/MobileFormatter.php
    trunk/extensions/MobileFrontend/javascripts/application.js
    trunk/extensions/MobileFrontend/javascripts/beta_application.js
    trunk/extensions/MobileFrontend/tests/js/fixtures.js

Modified: trunk/extensions/MobileFrontend/MobileFormatter.php
===================================================================
--- trunk/extensions/MobileFrontend/MobileFormatter.php 2012-02-23 15:23:16 UTC 
(rev 112207)
+++ trunk/extensions/MobileFrontend/MobileFormatter.php 2012-02-23 15:26:07 UTC 
(rev 112208)
@@ -339,14 +339,6 @@
                                                                '↑' . 
$backToTop ) .
                                Html::closeElement( 'div' );
                // generate the HTML we are going to inject
-               $buttons = Html::element( 'button',
-                                       array( 'class' => 'section_heading 
show',
-                                                       'section_id' => 
$this->headings ),
-                                                       $show ) .
-                       Html::element( 'button',
-                                       array( 'class' => 'section_heading 
hide',
-                                                       'section_id' => 
$this->headings ),
-                                                       $hide );
                if ( $this->expandableSections ) {
                        $base .= Html::openElement( 'h2',
                                                        array( 'class' => 
'section_heading',
@@ -356,7 +348,7 @@
                                                        array( 'class' => 
'section_heading',
                                                                        'id' => 
'section_' . $this->headings ) );
                }
-               $base .= $buttons .
+               $base .=
                                Html::rawElement( 'span',
                                                array( 'id' => $headlineId ),
                                                                $matches[2] ) .

Modified: trunk/extensions/MobileFrontend/javascripts/application.js
===================================================================
--- trunk/extensions/MobileFrontend/javascripts/application.js  2012-02-23 
15:23:16 UTC (rev 112207)
+++ trunk/extensions/MobileFrontend/javascripts/application.js  2012-02-23 
15:26:07 UTC (rev 112208)
@@ -3,7 +3,7 @@
 MobileFrontend = (function() {
 
        function init() {
-               var i, search, clearSearch, results, languageSelection, a,
+               var i, search, clearSearch, results, languageSelection, a, 
heading,
                        sectionHeadings = document.getElementsByClassName( 
'section_heading' ),
                        dismissNotification, cookieNameZeroVisibility, 
zeroRatedBanner, zeroRatedBannerVisibility;
                utilities( document.body ).addClass( 'jsEnabled' );
@@ -13,8 +13,20 @@
                                wm_toggle_section( sectionNumber );
                        }
                }
+               function createButton( visible ) {
+                       var btn, label;
+                       btn = document.createElement( 'button' );
+                       label = document.createTextNode( visible ? 'Show' : 
'Hide' );
+                       btn.className = visible ? 'show' : 'hide';
+                       btn.appendChild( label );
+                       btn.style.display = visible ? 'inline-block' : 'none';
+                       return btn;
+               }
                for( i = 0; i < sectionHeadings.length; i++ ) {
-                       utilities( sectionHeadings[i] ).bind( 'click', 
openSectionHandler, false );
+                       heading = sectionHeadings[i];
+                       heading.insertBefore( createButton( true ), 
heading.firstChild );
+                       heading.insertBefore( createButton( false ), 
heading.firstChild );
+                       utilities( heading ).bind( 'click', openSectionHandler, 
false );
                }
                search = document.getElementById( 'search' );
                clearSearch = document.getElementById( 'clearsearch' );

Modified: trunk/extensions/MobileFrontend/javascripts/beta_application.js
===================================================================
--- trunk/extensions/MobileFrontend/javascripts/beta_application.js     
2012-02-23 15:23:16 UTC (rev 112207)
+++ trunk/extensions/MobileFrontend/javascripts/beta_application.js     
2012-02-23 15:26:07 UTC (rev 112208)
@@ -7,7 +7,7 @@
 MobileFrontend = (function() {
 
        function init() {
-               var i, search, clearSearch, results, languageSelection, a,
+               var i, search, clearSearch, results, languageSelection, a, 
heading,
                        sectionHeadings = document.getElementsByClassName( 
'section_heading' ),
                        dismissNotification, cookieNameZeroVisibility, 
zeroRatedBanner, zeroRatedBannerVisibility;
                utilities( document.body ).addClass( 'jsEnabled' );
@@ -17,8 +17,20 @@
                                wm_toggle_section( sectionNumber );
                        }
                }
+               function createButton( visible ) {
+                       var btn, label;
+                       btn = document.createElement( 'button' );
+                       label = document.createTextNode( visible ? 'Show' : 
'Hide' );
+                       btn.className = visible ? 'show' : 'hide';
+                       btn.appendChild( label );
+                       btn.style.display = visible ? 'inline-block' : 'none';
+                       return btn;
+               }
                for( i = 0; i < sectionHeadings.length; i++ ) {
-                       utilities( sectionHeadings[i] ).bind( 'click', 
openSectionHandler, false );
+                       heading = sectionHeadings[i];
+                       heading.insertBefore( createButton( true ), 
heading.firstChild );
+                       heading.insertBefore( createButton( false ), 
heading.firstChild );
+                       utilities( heading ).bind( 'click', openSectionHandler, 
false );
                }
                search = document.getElementById( 'search' );
                clearSearch = document.getElementById( 'clearsearch' );

Modified: trunk/extensions/MobileFrontend/tests/js/fixtures.js
===================================================================
--- trunk/extensions/MobileFrontend/tests/js/fixtures.js        2012-02-23 
15:23:16 UTC (rev 112207)
+++ trunk/extensions/MobileFrontend/tests/js/fixtures.js        2012-02-23 
15:26:07 UTC (rev 112208)
@@ -27,8 +27,6 @@
                '       <div id="results">search results here</div>',
                '       <div id="content">',
                '               <h2 class="section_heading" id="section_1">',
-               '                       <button class="section_heading show" 
section_id="1">Show</button>',
-               '                       <button class="section_heading hide" 
section_id="1" style="display:none">Hide</button>',
                '                       <span id="First_Section">First 
Section</span>',
                '               </h2>',
                '               <div class="content_block" id="content_1" 
style="display:none">',
@@ -41,8 +39,6 @@
                '                       <a href="#section_1" 
class="back_to_top">&#8593;Jump back a section</a>',
                '               </div>',
                '               <h2 class="section_heading" id="section_2">',
-               '                       <button class="section_heading show" 
section_id="2">Show</button>',
-               '                       <button class="section_heading hide" 
section_id="2" style="display:none">Hide</button>',
                '                       <span id="Second_Section">Second 
Section</span>',
                '               </h2>',
                '               <div class="content_block" id="content_2"  
style="display:none"><p>Text with a <a href="#First_Section">section 1</a> 
link! and to <a href="#First_Section_2">section 1.2</a></p></div>',


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

Reply via email to