Skip to content

Instantly share code, notes, and snippets.

@Nimos
Created May 4, 2019 16:47
Show Gist options
  • Save Nimos/3da833f282d8e8c767036885f18f5216 to your computer and use it in GitHub Desktop.
Save Nimos/3da833f282d8e8c767036885f18f5216 to your computer and use it in GitHub Desktop.
const $ = $jQueryWom;
let boxes = $('.wom_hidecheckbox2');
let form = $('.wom_hidecheckbox2').parents('form');
let ids = [];
boxes.each(function () {ids.push(this.name)});
boxes.prop('checked', false);
let baseQuery = form.attr('action') + "?" + form.serialize() + "&";
let results = [];
let requests = [];
// Ergebnisse abfragen
for (let n = 0; n<ids.length; n+=8) {
let subset = ids.slice(n, n+8);
let query = baseQuery + subset.map((id) => id+"=1&").join("");
let promise = $.get(query, function (res) {
$('.wom_ergebnis_list li', $(res)).each(function () {
let pct = parseFloat($(this).find('.wom_ergebnis_partei_span').text().replace(",", "."));
results.push( [pct, this] );
});
}).promise();
requests.push(promise);
}
// Ergebnisse sortieren und anzeigen
Promise.all(requests).then((values) => {
let resultElement = $('<ul class="wom_ergebnis_list" role="tablist"></ul>');
results = results.sort((a, b) => b[0] - a[0]);
for (let n in results) {
resultElement.append(results[n][1]);
}
$(".wom_main_content").html("<div style='width: 100%; height: 2px;'></div>")
resultElement.appendTo($(".wom_main_content"));
$('.wom_ergebnis_prozent').addClass('transition');
$('.wom_ergebnis_list li').each(function(){
$(this).find('.wom_ergebnis_prozent').width($jQueryWom(this).find('> div.wom_ergebnis_balken').width());
var percent = ($jQueryWom(this).find('> div.wom_ergebnis_balken').width() /100) *parseInt($jQueryWom(this).find('.wom_ergebnis_prozent').attr('data-ergebnis'));
$(this).find('.wom_ergebnis_prozent').css('background-position',$jQueryWom(this).find('> div.wom_ergebnis_balken').width()-percent);
});
initonReady();
openThesen();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment