function triggerInputChange(element, event) { element = ('' + element === element) ? document.getElementById(element) : element; if (element.triggeredInputChange) { element.triggeredInputChange = false; return; } element.triggeredInputChange = true; event = document.createEvent('Event'); event.initEvent('change', true, true); element.dispatchEvent(event); } jQuery(function($) { $ = jQuery; if (!document.getElementById('dlcenterform')) return; //initSetUnifiedHeight('dlcenterform'); var sectionsSelect = document.getElementById('filter-tables'); var typesHolder = document.getElementById('filter-types'); var $allLines = [], option, $sections = []; var types = {}, type = 0, filters = {}; var typesItem = '' + '
' + '' + '' + '
'; $('.productTable').each(function($section, $tr) { $tr = $(this).find('tbody').find('tr'); $section = $(this).closest('section'); $sections.push($section[0]); title = $section.find('h3')[0].innerHTML; id = $section[0].id; $item = $(typesItem.replace(/%ID%/g, id).replace(/%TITLE%/g, title)); typesHolder.appendChild($item[0]); }); $sections = $($sections); $allLines = $($allLines).addClass('filter-item_visible'); function toggleSections() { if (!!sectionsSelect.value) return; for (var i = 0; $sections[i]; i++) $sections.eq(i).toggle( !!$('.filter-item_visible', $sections[i]).length ); } setTimeout(function() { $(sectionsSelect).change(function() { $sections .hide() .filter(!!this.value ? '#' + this.value : '*') .show(); toggleSections(); }); $('#filter-types').find('input:checkbox').change(function() { if (this.checked) { filters[this.value] = true; } else { delete filters[this.value]; } types = Object.keys(filters); $allLines.each(function() { if (types.length && !filters[this.getAttribute('filter-type')]) { $(this).removeClass('filter-item_visible').hide(); } else { $(this).addClass('filter-item_visible').show(); } }); toggleSections(); }); }, 1000); });