r111733 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111732‎ | r111733 | r111734 >
Date:09:22, 17 February 2012
Author:jdlrobson
Status:ok
Tags:
Comment:
attach click handlers in javascript not html

rather than set onclick attributes in the html attach
them in the javascript init function.
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)

Diff [purge]

Index: trunk/extensions/MobileFrontend/MobileFormatter.php
@@ -338,11 +338,9 @@
339339 'section_id' => $this->headings ),
340340 $hide );
341341 if ( $this->expandableSections ) {
342 - $h2OnClick = 'javascript:wm_toggle_section(' . $this->headings . ');';
343342 $base .= Html::openElement( 'h2',
344343 array( 'class' => 'section_heading',
345 - 'id' => 'section_' . $this->headings,
346 - 'onclick' => $h2OnClick ) );
 344+ 'id' => 'section_' . $this->headings ) );
347345 } else {
348346 $base .= Html::openElement( 'h2',
349347 array( 'class' => 'section_heading',
Index: trunk/extensions/MobileFrontend/javascripts/beta_application.js
@@ -66,6 +66,15 @@
6767
6868 function init() {
6969 document.body.className = "jsEnabled";
 70+ var sectionHeadings = document.getElementsByClassName( 'section_heading' );
 71+ for( var i = 0; i < sectionHeadings.length; i++ ) {
 72+ sectionHeadings[i].addEventListener( 'click', function() {
 73+ var sectionNumber = this.id ? this.id.split( '_' )[1] : -1;
 74+ if(sectionNumber > -1) {
 75+ wm_toggle_section( sectionNumber );
 76+ }
 77+ }, false );
 78+ }
7079 initClearSearchLink();
7180 search.onpaste = function() {
7281 handleDefaultText();
Index: trunk/extensions/MobileFrontend/javascripts/application.js
@@ -58,6 +58,15 @@
5959
6060 function init() {
6161 document.body.className = "jsEnabled";
 62+ var sectionHeadings = document.getElementsByClassName( 'section_heading' );
 63+ for( var i = 0; i < sectionHeadings.length; i++ ) {
 64+ sectionHeadings[i].addEventListener( 'click', function() {
 65+ var sectionNumber = this.id ? this.id.split( '_' )[1] : -1;
 66+ if(sectionNumber > -1) {
 67+ wm_toggle_section( sectionNumber );
 68+ }
 69+ }, false );
 70+ }
6271 initClearSearchLink();
6372 document.getElementById( 'logo' ).addEventListener( 'click', logoClick );
6473 var dismissNotification = document.getElementById( 'dismiss-notification' );

Sign-offs

UserFlagDate
Nikerabbitinspected09:34, 17 February 2012

Follow-up revisions

RevisionCommit summaryAuthorDate
r113028provide toggle buttons in html for Wikipedia Mobile app...jdlrobson13:14, 5 March 2012

Status & tagging log