diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2016-08-08 12:55:44 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-08 12:55:44 +0300 |
commit | 5f76ae1645166c79437a923aeb450c3c762bc506 (patch) | |
tree | 2000fcc519c9c4667b1e5e6b8a1c25e6c63dd540 /page-providers.php | |
parent | aae10b45db1a25222625ee02996eb04ee6de4e5f (diff) |
Shuffle providers
Fixes https://github.com/nextcloud/nextcloud.com/issues/84
Diffstat (limited to 'page-providers.php')
-rw-r--r-- | page-providers.php | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/page-providers.php b/page-providers.php index 8141858b..b431af8b 100644 --- a/page-providers.php +++ b/page-providers.php @@ -25,7 +25,27 @@ var countries = []; var selectedCountryCode = 'all'; var filterFreePlans = false; + var filterHosting = 'both'; + /** + * Based on the Apache licensed https://github.com/coolaj86/knuth-shuffle + */ + function shuffle(array) { + var currentIndex = array.length, temporaryValue, randomIndex; + + // While there remain elements to shuffle... + while (0 !== currentIndex) { + // Pick a remaining element... + randomIndex = Math.floor(Math.random() * currentIndex); + currentIndex -= 1; + + // And swap it with the current element. + temporaryValue = array[currentIndex]; + array[currentIndex] = array[randomIndex]; + array[randomIndex] = temporaryValue; + } + return array; + } function filterItems(country, plan, hosting) { var filteredItems = []; $.each(items, function (key, provider) { @@ -92,6 +112,7 @@ } $.getJSON('<?php echo get_template_directory_uri() ?>/assets/providers.json', function (data) { items = data; + shuffle(items); filterItems(selectedCountryCode, filterFreePlans, filterHosting); $.each(countries, function (key, countryCode) { $('#countryPicker').append($('<option/>', { |