Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ($filter) {
- //price filter_slider;
- var select_model = $filter.find('select[name="model"]'),
- select_body = $filter.find('select[name="kuzov"]'),
- select_engine = $filter.find('select[name="dvigun"]');
- $('#filterReset').click(function () {
- select_body.find('option').each(function () {
- $(this).removeAttr('disabled');
- });
- select_engine.find('option').each(function () {
- $(this).removeAttr('disabled');
- });
- select_model.find('option').each(function () {
- $(this).removeAttr('disabled');
- });
- $('.cars-filter__form').trigger('reset');
- filter_slider.noUiSlider.set(['2000000']);
- filterCars();
- $(this).removeClass('active');
- });
- select_model.change(function () {
- select_body.find('option').each(function () {
- $(this).removeAttr('disabled');
- });
- select_engine.find('option').each(function () {
- $(this).removeAttr('disabled');
- });
- // select_model.find('option').each(function () {
- // $(this).removeAttr('disabled');
- // });
- filterCars();
- var val = $(this).val(),
- selected = $(this).find('option:selected'),
- bodies = selected.data('body'),
- engines = selected.data('engines');
- if (val != 0) {
- !$('#filterReset').hasClass('active') ? $('#filterReset').addClass('active') : console.log('model already showed');
- bodies = bodies.split(',');
- console.log(bodies);
- engines = engines.split(',');
- console.log(engines);
- // select_model.find('option').attr('disabled', 'true');
- select_body.find('option').each(function () {
- var val_arr = $(this).val().split(','),
- elem = $(this);
- if (val_arr.length >= 1) {
- var valid = 0;
- for (var i = 0; i <= val_arr.length; i++) {
- if (bodies.includes(val_arr[i]) && val_arr[i] != 0)
- valid++;
- }
- if (valid == 0)
- elem.attr('disabled', true);
- } else if (!bodies.includes($(this).val()) && $(this).val() != 0) {
- $(this).attr('disabled', true);
- }
- });
- select_engine.find('option').each(function () {
- // $(this).removeAttr('disabled');
- if (!engines.includes($(this).val()) && $(this).val() != 0) {
- $(this).attr('disabled', true);
- }
- });
- }
- });
- select_body.change(function () {
- select_engine.find('option').each(function () {
- $(this).removeAttr('disabled');
- });
- if (select_model.val() != 0) {
- select_model.find('option').each(function () {
- $(this).removeAttr('disabled');
- });
- }
- filterCars();
- var val = $(this).val(),
- selected = $(this).find('option:selected'),
- models = selected.data('models'),
- engines = selected.data('engines');
- if (val != 0) {
- !$('#filterReset').hasClass('active') ? $('#filterReset').addClass('active') : console.log('body already showed');
- models = models.split(',');
- console.log(models);
- engines = engines.split(',');
- console.log(engines);
- // select_model.find('option').attr('disabled', 'true');
- select_model.find('option').each(function () {
- // $(this).removeAttr('disabled');
- console.log(models.includes($(this).val()));
- if (!models.includes($(this).val()) && $(this).val() != 0) {
- $(this).attr('disabled', true);
- }
- });
- select_engine.find('option').each(function () {
- // $(this).removeAttr('disabled');
- console.log(engines.includes($(this).val()));
- if (!engines.includes($(this).val()) && $(this).val() != 0) {
- $(this).attr('disabled', true);
- }
- })
- }
- });
- select_engine.change(function () {
- select_body.find('option').each(function () {
- $(this).removeAttr('disabled');
- });
- // select_engine.find('option').each(function () {
- // $(this).removeAttr('disabled');
- // });
- select_model.find('option').each(function () {
- $(this).removeAttr('disabled');
- });
- filterCars();
- var val = $(this).val(),
- selected = $(this).find('option:selected'),
- models = selected.data('models'),
- bodies = selected.data('bodies');
- console.log('av models:' + models);
- console.log('av bodies:' + bodies);
- if (val != 0) {
- !$('#filterReset').hasClass('active') ? $('#filterReset').addClass('active') : console.log('energy already showed');
- bodies = bodies.split(',');
- console.log(bodies);
- models = models.split(',');
- console.log(models);
- select_model.find('option').each(function () {
- // $(this).removeAttr('disabled');
- if (!models.includes($(this).val()) && $(this).val() != 0) {
- $(this).attr('disabled', true);
- }
- });
- // select_model.find('option').attr('disabled', 'true');
- select_body.find('option').each(function () {
- // $(this).removeAttr('disabled');
- // if($(this).val().split())
- if (!bodies.includes($(this).val()) && $(this).val() != 0) {
- $(this).attr('disabled', true);
- }
- });
- }
- });
- if (filter_slider) {
- filter_slider.noUiSlider.on('change', function () {
- filterCars();
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement