r76598 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76597‎ | r76598 | r76599 >
Date:21:24, 12 November 2010
Author:tparscal
Status:resolved (Comments)
Tags:
Comment:
jQueryified things, made the most recent bar the current one on load.
Modified paths:
  • /trunk/extensions/ContributionReporting/FundraiserStatistics.js (modified) (history)
  • /trunk/extensions/ContributionReporting/FundraiserStatistics_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ContributionReporting/FundraiserStatistics_body.php
@@ -92,8 +92,9 @@
9393 // HTML-time!
9494 $view = 0;
9595 $htmlViews = '';
96 - foreach ( $egFundraiserStatisticsFundraisers as $fundraiser ) {
 96+ foreach ( $egFundraiserStatisticsFundraisers as $fundraiserIndex => $fundraiser ) {
9797 $days = $this->query( 'dailyTotals', $fundraiser['start'], $fundraiser['end'] );
 98+ $mostRecentFundraiser = $fundraiserIndex == count( $egFundraiserStatisticsFundraisers ) - 1;
9899 foreach ( $charts as $name => $chart ) {
99100 $column = 0;
100101 foreach( $days as $i => $day ) {
@@ -103,9 +104,12 @@
104105 $height = $chart['factor'] * $day[$chart['index']];
105106 $attributes = array(
106107 'style' => "height:{$height}px",
107 - 'class' => "fundraiserstats-bar-{$fundraiser['id']}",
108 - 'onMouseOver' => "replaceView( 'fundraiserstats-view-box-{$view}' )"
 108+ 'class' => "fundraiserstats-bar fundraiserstats-bar-{$fundraiser['id']}",
 109+ 'rel' => "fundraiserstats-view-box-{$view}",
109110 );
 111+ if ( $mostRecentFundraiser && $i == count( $days ) -1 ) {
 112+ $attributes['class'] .= ' fundraiserstats-current';
 113+ }
110114 $charts[$name]['data'][$column] .= Xml::tags(
111115 'td', array( 'valign' => 'bottom' ), Xml::element( 'div', $attributes, '', false )
112116 );
@@ -166,8 +170,8 @@
167171 'div',
168172 array(
169173 'id' => "fundraiserstats-chart-{$chart}-tab",
170 - 'class' => 'fundraiserstats-chart-tab-' . ( $first ? 'current' : 'normal' ),
171 - 'onClick' => "replaceChart( 'fundraiserstats-chart-{$chart}' )"
 174+ 'class' => 'fundraiserstats-chart-tab fundraiserstats-chart-tab-' . ( $first ? 'current' : 'normal' ),
 175+ 'rel' => "fundraiserstats-chart-{$chart}"
172176 ),
173177 wfMsg( 'fundraiserstats-tab-' . $chart )
174178 );
Index: trunk/extensions/ContributionReporting/FundraiserStatistics.js
@@ -1,22 +1,36 @@
22 /* JavaScript */
33
4 -var currentViewID = 'fundraiserstats-view-box-0';
5 -function replaceView( newLayerID ) {
6 - var currentLayer = document.getElementById( currentViewID );
7 - var newLayer = document.getElementById( newLayerID );
8 - currentLayer.style.display = 'none';
9 - newLayer.style.display = 'block';
10 - currentViewID = newLayerID;
11 -}
12 -var currentChartID = 'fundraiserstats-chart-totals';
13 -function replaceChart( newLayerID ) {
14 - var currentLayer = document.getElementById( currentChartID );
15 - var currentTab = document.getElementById( currentChartID + '-tab' );
16 - var newLayer = document.getElementById( newLayerID );
17 - var newTab = document.getElementById( newLayerID + '-tab' );
18 - currentLayer.style.display = 'none';
19 - currentTab.setAttribute( 'class', 'fundraiserstats-chart-tab-normal' );
20 - newLayer.style.display = 'block';
21 - newTab.setAttribute( 'class', 'fundraiserstats-chart-tab-current' );
22 - currentChartID = newLayerID;
23 -}
 4+$j( document ).ready( function() {
 5+
 6+ var currentViewID = 'fundraiserstats-view-box-0';
 7+ function replaceView( newLayerID ) {
 8+ var currentLayer = document.getElementById( currentViewID );
 9+ var newLayer = document.getElementById( newLayerID );
 10+ currentLayer.style.display = 'none';
 11+ newLayer.style.display = 'block';
 12+ currentViewID = newLayerID;
 13+ }
 14+
 15+ var currentChartID = 'fundraiserstats-chart-totals';
 16+ function replaceChart( newLayerID ) {
 17+ var currentLayer = document.getElementById( currentChartID );
 18+ var currentTab = document.getElementById( currentChartID + '-tab' );
 19+ var newLayer = document.getElementById( newLayerID );
 20+ var newTab = document.getElementById( newLayerID + '-tab' );
 21+ currentLayer.style.display = 'none';
 22+ currentTab.setAttribute( 'class', 'fundraiserstats-chart-tab-normal' );
 23+ newLayer.style.display = 'block';
 24+ newTab.setAttribute( 'class', 'fundraiserstats-chart-tab-current' );
 25+ currentChartID = newLayerID;
 26+ }
 27+
 28+ $j( '.fundraiserstats-bar' ).hover( function() {
 29+ replaceView( $j(this).attr( 'rel' ) )
 30+ } );
 31+ $j( '.fundraiserstats-chart-tab' ).click( function() {
 32+ replaceChart( $j(this).attr( 'rel' ) )
 33+ } );
 34+ $j( '.fundraiserstats-current' ).each( function() {
 35+ replaceView( $j(this).attr( 'rel' ) )
 36+ } );
 37+} );

Follow-up revisions

RevisionCommit summaryAuthorDate
r78414Merging r76598 from trunkawjrichards23:53, 14 December 2010
r78421Merging r76595, r76598 of trunkawjrichards00:35, 15 December 2010

Comments

#Comment by Awjrichards (talk | contribs)   00:13, 15 December 2010

The JS appears to be broken. When mousing over the stat bars with this JS, I get the error 'replaceView not defined' in Firefox.

#Comment by Brion VIBBER (talk | contribs)   00:23, 15 December 2010

It looks ok unless something else is slipping 'replaceView' hardcoded somewhere else. Can you confirm the .js and .php are in sync?

#Comment by Brion VIBBER (talk | contribs)   00:25, 15 December 2010

r78414 doesn't carry over both changes from this commit to 1.16wmf4 -- is it on that branch that you have the problem?

#Comment by Awjrichards (talk | contribs)   00:39, 15 December 2010

Whoops, indeed not. Hastily reading the commit messages, I thought the change had already been picked up by Tomasz's merge. I'll update shortly.

#Comment by Awjrichards (talk | contribs)   01:22, 15 December 2010

Yeah - that totally did the trick. Nice catch - I was totally banging my head on the wall since I had this working locally and couldn't figure out why it wasn't working on the cluster...

Status & tagging log