http://www.mediawiki.org/wiki/Special:Code/MediaWiki/73010

Revision: 73010
Author:   adam
Date:     2010-09-14 19:39:33 +0000 (Tue, 14 Sep 2010)

Log Message:
-----------
Followup to r72759 - implimenting Roan's suggestions

Modified Paths:
--------------
    trunk/extensions/CentralNotice/newCentralNotice.js

Modified: trunk/extensions/CentralNotice/newCentralNotice.js
===================================================================
--- trunk/extensions/CentralNotice/newCentralNotice.js  2010-09-14 19:30:43 UTC 
(rev 73009)
+++ trunk/extensions/CentralNotice/newCentralNotice.js  2010-09-14 19:39:33 UTC 
(rev 73010)
@@ -52,24 +52,22 @@
                                // Make sure there are some banners to choose 
from
                                if ( bannerList.length == 0 ) return false;
                                
-                               var groomedBannerList = [];
-                               
+                               var totalWeight = 0;
                                for( var i = 0; i < bannerList.length; i++ ) {
-                                       // only include this banner if it's 
inteded for the current user
-                                       if( ( wgUserName ? 
bannerList[i].display_account == 1 : bannerList.display_anon == 1 ) ) {
-                                               // add the banner to our list 
once per weight
-                                               for( var j=0; j < 
bannerList[i].weight; j++ ) {
-                                                       groomedBannerList.push( 
bannerList[i] );
-                                               }
+                                       totalWeight += bannerList[i].weight;
+                               }
+                               var pointer = Math.floor( Math.random() * 
totalWeight ),
+                                       selectedBanner = bannerList[0],
+                                       w = 0;
+                               for( var i = 0; i < bannerList.length; i++ ) {
+                                       w += bannerList[i].weight;
+                                       if( w < pointer ) {
+                                               selectedBanner = bannerList[i];
+                                               break;
                                        }
                                }
-                               
-                               // return if there's nothing left after the 
grooming
-                               if( groomedBannerList.length == 0 ) return 
false;
-                               // load a random banner from our groomed list
-                               
                                $.centralNotice.fn.loadBanner( 
-                                       groomedBannerList[ Math.floor( 
Math.random() * groomedBannerList.length ) ].name
+                                       selectedBanner.name
                                 );
                        },
                        'displayBanner': function( bannerHTML ) {



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to