r112208 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112207‎ | r112208 | r112209 >
Date:15:26, 23 February 2012
Author:jdlrobson
Status:ok
Tags:
Comment:
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 (modified) (history)
  • /trunk/extensions/MobileFrontend/javascripts/application.js (modified) (history)
  • /trunk/extensions/MobileFrontend/javascripts/beta_application.js (modified) (history)
  • /trunk/extensions/MobileFrontend/tests/js/fixtures.js (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/MobileFormatter.php
@@ -339,14 +339,6 @@
340340 '↑' . $backToTop ) .
341341 Html::closeElement( 'div' );
342342 // generate the HTML we are going to inject
343 - $buttons = Html::element( 'button',
344 - array( 'class' => 'section_heading show',
345 - 'section_id' => $this->headings ),
346 - $show ) .
347 - Html::element( 'button',
348 - array( 'class' => 'section_heading hide',
349 - 'section_id' => $this->headings ),
350 - $hide );
351343 if ( $this->expandableSections ) {
352344 $base .= Html::openElement( 'h2',
353345 array( 'class' => 'section_heading',
@@ -356,7 +348,7 @@
357349 array( 'class' => 'section_heading',
358350 'id' => 'section_' . $this->headings ) );
359351 }
360 - $base .= $buttons .
 352+ $base .=
361353 Html::rawElement( 'span',
362354 array( 'id' => $headlineId ),
363355 $matches[2] ) .
Index: trunk/extensions/MobileFrontend/tests/js/fixtures.js
@@ -27,8 +27,6 @@
2828 ' <div id="results">search results here</div>',
2929 ' <div id="content">',
3030 ' <h2 class="section_heading" id="section_1">',
31 - ' <button class="section_heading show" section_id="1">Show</button>',
32 - ' <button class="section_heading hide" section_id="1" style="display:none">Hide</button>',
3331 ' <span id="First_Section">First Section</span>',
3432 ' </h2>',
3533 ' <div class="content_block" id="content_1" style="display:none">',
@@ -41,8 +39,6 @@
4240 ' <a href="#section_1" class="back_to_top">&#8593;Jump back a section</a>',
4341 ' </div>',
4442 ' <h2 class="section_heading" id="section_2">',
45 - ' <button class="section_heading show" section_id="2">Show</button>',
46 - ' <button class="section_heading hide" section_id="2" style="display:none">Hide</button>',
4743 ' <span id="Second_Section">Second Section</span>',
4844 ' </h2>',
4945 ' <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>',
Index: trunk/extensions/MobileFrontend/javascripts/beta_application.js
@@ -7,7 +7,7 @@
88 MobileFrontend = (function() {
99
1010 function init() {
11 - var i, search, clearSearch, results, languageSelection, a,
 11+ var i, search, clearSearch, results, languageSelection, a, heading,
1212 sectionHeadings = document.getElementsByClassName( 'section_heading' ),
1313 dismissNotification, cookieNameZeroVisibility, zeroRatedBanner, zeroRatedBannerVisibility;
1414 utilities( document.body ).addClass( 'jsEnabled' );
@@ -17,8 +17,20 @@
1818 wm_toggle_section( sectionNumber );
1919 }
2020 }
 21+ function createButton( visible ) {
 22+ var btn, label;
 23+ btn = document.createElement( 'button' );
 24+ label = document.createTextNode( visible ? 'Show' : 'Hide' );
 25+ btn.className = visible ? 'show' : 'hide';
 26+ btn.appendChild( label );
 27+ btn.style.display = visible ? 'inline-block' : 'none';
 28+ return btn;
 29+ }
2130 for( i = 0; i < sectionHeadings.length; i++ ) {
22 - utilities( sectionHeadings[i] ).bind( 'click', openSectionHandler, false );
 31+ heading = sectionHeadings[i];
 32+ heading.insertBefore( createButton( true ), heading.firstChild );
 33+ heading.insertBefore( createButton( false ), heading.firstChild );
 34+ utilities( heading ).bind( 'click', openSectionHandler, false );
2335 }
2436 search = document.getElementById( 'search' );
2537 clearSearch = document.getElementById( 'clearsearch' );
Index: trunk/extensions/MobileFrontend/javascripts/application.js
@@ -3,7 +3,7 @@
44 MobileFrontend = (function() {
55
66 function init() {
7 - var i, search, clearSearch, results, languageSelection, a,
 7+ var i, search, clearSearch, results, languageSelection, a, heading,
88 sectionHeadings = document.getElementsByClassName( 'section_heading' ),
99 dismissNotification, cookieNameZeroVisibility, zeroRatedBanner, zeroRatedBannerVisibility;
1010 utilities( document.body ).addClass( 'jsEnabled' );
@@ -13,8 +13,20 @@
1414 wm_toggle_section( sectionNumber );
1515 }
1616 }
 17+ function createButton( visible ) {
 18+ var btn, label;
 19+ btn = document.createElement( 'button' );
 20+ label = document.createTextNode( visible ? 'Show' : 'Hide' );
 21+ btn.className = visible ? 'show' : 'hide';
 22+ btn.appendChild( label );
 23+ btn.style.display = visible ? 'inline-block' : 'none';
 24+ return btn;
 25+ }
1726 for( i = 0; i < sectionHeadings.length; i++ ) {
18 - utilities( sectionHeadings[i] ).bind( 'click', openSectionHandler, false );
 27+ heading = sectionHeadings[i];
 28+ heading.insertBefore( createButton( true ), heading.firstChild );
 29+ heading.insertBefore( createButton( false ), heading.firstChild );
 30+ utilities( heading ).bind( 'click', openSectionHandler, false );
1931 }
2032 search = document.getElementById( 'search' );
2133 clearSearch = document.getElementById( 'clearsearch' );

Follow-up revisions

RevisionCommit summaryAuthorDate
r112222Killed all the vestiges of server-side expandable sections after r112208maxsem17:12, 23 February 2012

Status & tagging log