source: products/ploneorg.kudobounty/trunk/ploneorg/kudobounty/browser/ploneorg_bounty.js

Last change on this file was 3207, checked in by mylan, 13 years ago

Fixed typo in js script

File size: 997 bytes
Line 
1// Hide #portal-bounty-program container BEFORE it will be loaded
2// This will be done only for browser with javascript support.
3$("<style type='text/css'>#portal-bounty-program .hidden{display:none;}</style>").appendTo("head");
4
5function getRandomSubset(array, choice_num) {
6    // Return randomly selected *choice_num* elements from the array.
7    // Solution is based on the Fisher-Yates (Knuth) algorithm
8    // (http://en.wikipedia.org/wiki/Fisher–Yates_shuffle).
9    if (array.length <= choice_num)
10        return array;
11
12    var tmp, current, top = array.length;
13    for(top=array.length-1; top>array.length-choice_num; --top) {
14        current = Math.floor(Math.random() * top);
15        tmp = array[current];
16        array[current] = array[top];
17        array[top] = tmp;
18    }
19    return array.slice(array.length-choice_num,array.length)
20};
21
22$(document).ready(function() {
23    $(getRandomSubset($("#portal-bounty-program ul li"), 5))
24        .each(function(i, el){
25            $(el).removeClass('hidden');
26        })
27});
Note: See TracBrowser for help on using the repository browser.