r73011 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73010‎ | r73011 | r73012 >
Date:19:56, 14 September 2010
Author:adam
Status:ok
Tags:
Comment:
Followup to r3010 - adding better comments
Modified paths:
  • /trunk/extensions/CentralNotice/newCentralNotice.js (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/newCentralNotice.js
@@ -53,19 +53,25 @@
5454 if ( bannerList.length == 0 ) return false;
5555
5656 var totalWeight = 0;
 57+ // run through the bannerlist and sum the weights of all banners
5758 for( var i = 0; i < bannerList.length; i++ ) {
5859 totalWeight += bannerList[i].weight;
5960 }
 61+
 62+ // select a random integer between 0 and our total weight
6063 var pointer = Math.floor( Math.random() * totalWeight ),
6164 selectedBanner = bannerList[0],
6265 w = 0;
 66+ // run through the banner list and start accumulating weights
6367 for( var i = 0; i < bannerList.length; i++ ) {
6468 w += bannerList[i].weight;
 69+ // when the weight tally exceeds the random integer, return the banner and stop the loop
6570 if( w < pointer ) {
6671 selectedBanner = bannerList[i];
6772 break;
6873 }
6974 }
 75+ // return our selected banner
7076 $.centralNotice.fn.loadBanner(
7177 selectedBanner.name
7278 );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r3010* non-existing discussion link formatting...gabrielwicke14:43, 7 April 2004

Status & tagging log