jQuery(document).ready(function ($) {
if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) {
var showchosen = false;
} else {
var showchosen = true;
}
/* Nach dem Laden Dropdowns initialisieren */
if (showchosen) {
$(".ebf_select").chosen({ width: '100%' });
}
update_ebf_selects();
/* Eventlistener: Ein Dropdown wird geändert */
$(".ebf_select").change(function() {
if($(this).val() == "reset") {
$(this).val("");
}
/* Dropdowns aktualiseren */
update_ebf_selects();
});
/* Eventlistener: Bei Form Reset Ergebnis ausblenden, alle Dropdowns auf Null setzen und neu initialisieren*/
$("#ebf_form").on('reset',function(e) {
/* Dropdowns auf Null setzen */
$(".ebf_select").each(function(e) {
$(this).val("");
});
/* Dropdowns aktualiseren */
update_ebf_selects();
});
function update_ebf_selects () {
var ebf_data = $("#ebf_form").serialize();
$(".ebf_select").each(function(e) {
update_ebf_select ($(this).data("sel"), this.id, ebf_data);
});
/* Eventlistener: Wenn alle AJAX-Requests fertig sind, Chosen Plugin starten und Event-Listener killen */
$(document).ajaxStop(function() {
if (showchosen) {
$('.ebf_select').trigger('chosen:updated');
}
$(this).unbind("ajaxStop");
});
}
function update_ebf_select (ebf_selector, ebf_id, ebf_data) {
var ebf_select = $("#" + ebf_id);
var ebf_select_value = ebf_select.val();
ebf_select.html('');
$.getJSON("/ebf_module/inc/json_get_selects.php?selector=" + ebf_selector, ebf_data)
.done(function(json) {
var items = [];
var counter = 0;
var ebf_select_selected = false;
$.each(json, function(value, text){
if (ebf_select_value == value && value != '') {
items += '';
ebf_select_selected = true;
} else {
items += '';
}
counter ++;
});
if (ebf_select_selected) {
items = items + '';
}
if (counter < 1) {
items = '' + items;
} else if (!ebf_select_selected) {
items = '' + items;
}
ebf_select.html(items);
});
}
});