r101737 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101736‎ | r101737 | r101738 >
Date:23:06, 2 November 2011
Author:preilly
Status:ok
Tags:
Comment:
move javascript section support to onclick event
Modified paths:
  • /trunk/extensions/MobileFrontend/MobileFrontend.php (modified) (history)
  • /trunk/extensions/MobileFrontend/javascripts/application.js (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/javascripts/application.js
@@ -8,7 +8,7 @@
99 function initClearSearchLink() {
1010 clearSearch.setAttribute( 'title','Clear' );
1111 clearSearch.addEventListener( 'mousedown', clearSearchBox, true );
12 - search.addEventListener( 'keyup', _handleClearSearchLink, false );
 12+ search.addEventListener( 'keyup', handleClearSearchLink, false );
1313 }
1414
1515 function navigateToLanguageSelection() {
@@ -21,7 +21,7 @@
2222 }
2323 }
2424
25 -function _handleClearSearchLink() {
 25+function handleClearSearchLink() {
2626 if ( clearSearch ) {
2727 if ( search.value.length > 0 ) {
2828 clearSearch.style.display = 'block';
@@ -58,16 +58,6 @@
5959 }
6060 };
6161
62 -// Also problematic, not working until the page loads...
63 -for( var h = document.getElementsByTagName( 'h2' ), i = 0; i < h.length; i++ ) {
64 - if ( h[i].className == 'section_heading' ) {
65 - h[i].onclick = function() {
66 - var section_idx = parseInt( this.id.replace( /section_(\d+)/, '$1' ) );
67 - wm_toggle_section( section_idx );
68 - }
69 - }
70 -};
71 -
7262 // And this...
7363 for ( var a = document.getElementsByTagName( 'a' ), i = 0; i < a.length; i++ ) {
7464 a[i].onclick = function() {
@@ -75,7 +65,7 @@
7666 wm_reveal_for_hash( this.hash );
7767 }
7868 }
79 -};
 69+}
8070
8171 if ( document.location.hash.indexOf( '#' ) == 0 ) {
8272 wm_reveal_for_hash( document.location.hash );
Index: trunk/extensions/MobileFrontend/MobileFrontend.php
@@ -863,17 +863,25 @@
864864 Html::closeElement( 'div' );
865865 // generate the HTML we are going to inject
866866 $buttons = Html::element( 'button',
867 - array( 'class' => 'section_heading show',
868 - 'section_id' => $headings ),
869 - $show ) .
870 - Html::element( 'button',
871 - array( 'class' => 'section_heading hide',
872 - 'section_id' => $headings ),
873 - $hide );
874 - $base .= Html::openElement( 'h2',
875 - array( 'class' => 'section_heading',
876 - 'id' => 'section_' . $headings ) ) .
877 - $buttons .
 867+ array( 'class' => 'section_heading show',
 868+ 'section_id' => $headings ),
 869+ $show ) .
 870+ Html::element( 'button',
 871+ array( 'class' => 'section_heading hide',
 872+ 'section_id' => $headings ),
 873+ $hide );
 874+ if ( self::$device['supports_javascript'] ) {
 875+ $h2OnClick = 'javascript:wm_toggle_section(' . $headings . ');';
 876+ $base .= Html::openElement( 'h2',
 877+ array( 'class' => 'section_heading',
 878+ 'id' => 'section_' . $headings,
 879+ 'onclick' => $h2OnClick ) );
 880+ } else {
 881+ $base .= Html::openElement( 'h2',
 882+ array( 'class' => 'section_heading',
 883+ 'id' => 'section_' . $headings ) );
 884+ }
 885+ $base .= $buttons .
878886 Html::rawElement( 'span',
879887 array( 'id' => $headlineId ),
880888 $matches[2] ) .

Follow-up revisions

RevisionCommit summaryAuthorDate
r1017381.18wmf1: MFT r101714, r101737preilly23:07, 2 November 2011

Status & tagging log