http://www.mediawiki.org/wiki/Special:Code/MediaWiki/73011
Revision: 73011
Author: adam
Date: 2010-09-14 19:56:12 +0000 (Tue, 14 Sep 2010)
Log Message:
-----------
Followup to r3010 - adding better comments
Modified Paths:
--------------
trunk/extensions/CentralNotice/newCentralNotice.js
Modified: trunk/extensions/CentralNotice/newCentralNotice.js
===================================================================
--- trunk/extensions/CentralNotice/newCentralNotice.js 2010-09-14 19:39:33 UTC
(rev 73010)
+++ trunk/extensions/CentralNotice/newCentralNotice.js 2010-09-14 19:56:12 UTC
(rev 73011)
@@ -53,19 +53,25 @@
if ( bannerList.length == 0 ) return false;
var totalWeight = 0;
+ // run through the bannerlist and sum the
weights of all banners
for( var i = 0; i < bannerList.length; i++ ) {
totalWeight += bannerList[i].weight;
}
+
+ // select a random integer between 0 and our
total weight
var pointer = Math.floor( Math.random() *
totalWeight ),
selectedBanner = bannerList[0],
w = 0;
+ // run through the banner list and start
accumulating weights
for( var i = 0; i < bannerList.length; i++ ) {
w += bannerList[i].weight;
+ // when the weight tally exceeds the
random integer, return the banner and stop the loop
if( w < pointer ) {
selectedBanner = bannerList[i];
break;
}
}
+ // return our selected banner
$.centralNotice.fn.loadBanner(
selectedBanner.name
);
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs