Last change
on this file was
3207,
checked in by mylan, 13 years ago
|
Fixed typo in js script
|
File size:
997 bytes
|
Rev | Line | |
---|
[3207] | 1 | // Hide #portal-bounty-program container BEFORE it will be loaded |
---|
[3204] | 2 | // This will be done only for browser with javascript support. |
---|
[3185] | 3 | $("<style type='text/css'>#portal-bounty-program .hidden{display:none;}</style>").appendTo("head"); |
---|
| 4 | |
---|
| 5 | function getRandomSubset(array, choice_num) { |
---|
[3204] | 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). |
---|
[3205] | 9 | if (array.length <= choice_num) |
---|
[3204] | 10 | return array; |
---|
| 11 | |
---|
[3185] | 12 | var tmp, current, top = array.length; |
---|
[3204] | 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; |
---|
[3185] | 18 | } |
---|
[3204] | 19 | return array.slice(array.length-choice_num,array.length) |
---|
[3185] | 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.