Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  if ($filter) {
  2.         //price filter_slider;
  3.         var select_model = $filter.find('select[name="model"]'),
  4.             select_body = $filter.find('select[name="kuzov"]'),
  5.             select_engine = $filter.find('select[name="dvigun"]');
  6.  
  7.         $('#filterReset').click(function () {
  8.             select_body.find('option').each(function () {
  9.                 $(this).removeAttr('disabled');
  10.             });
  11.             select_engine.find('option').each(function () {
  12.                 $(this).removeAttr('disabled');
  13.             });
  14.             select_model.find('option').each(function () {
  15.                 $(this).removeAttr('disabled');
  16.             });
  17.             $('.cars-filter__form').trigger('reset');
  18.             filter_slider.noUiSlider.set(['2000000']);
  19.             filterCars();
  20.             $(this).removeClass('active');
  21.         });
  22.  
  23.         select_model.change(function () {
  24.  
  25.             select_body.find('option').each(function () {
  26.                 $(this).removeAttr('disabled');
  27.             });
  28.             select_engine.find('option').each(function () {
  29.                 $(this).removeAttr('disabled');
  30.             });
  31.             // select_model.find('option').each(function () {
  32.             //     $(this).removeAttr('disabled');
  33.             // });
  34.             filterCars();
  35.             var val = $(this).val(),
  36.                 selected = $(this).find('option:selected'),
  37.                 bodies = selected.data('body'),
  38.                 engines = selected.data('engines');
  39.  
  40.             if (val != 0) {
  41.                 !$('#filterReset').hasClass('active') ? $('#filterReset').addClass('active') : console.log('model already showed');
  42.                 bodies = bodies.split(',');
  43.                 console.log(bodies);
  44.  
  45.                 engines = engines.split(',');
  46.                 console.log(engines);
  47.  
  48.                 // select_model.find('option').attr('disabled', 'true');
  49.                 select_body.find('option').each(function () {
  50.                     var val_arr = $(this).val().split(','),
  51.                         elem = $(this);
  52.                     if (val_arr.length >= 1) {
  53.                         var valid = 0;
  54.                         for (var i = 0; i <= val_arr.length; i++) {
  55.                             if (bodies.includes(val_arr[i]) && val_arr[i] != 0)
  56.                                 valid++;
  57.                         }
  58.                         if (valid == 0)
  59.                             elem.attr('disabled', true);
  60.  
  61.                     } else if (!bodies.includes($(this).val()) && $(this).val() != 0) {
  62.                         $(this).attr('disabled', true);
  63.                     }
  64.                 });
  65.  
  66.                 select_engine.find('option').each(function () {
  67.                     // $(this).removeAttr('disabled');
  68.                     if (!engines.includes($(this).val()) && $(this).val() != 0) {
  69.                         $(this).attr('disabled', true);
  70.                     }
  71.                 });
  72.  
  73.             }
  74.         });
  75.  
  76.         select_body.change(function () {
  77.             select_engine.find('option').each(function () {
  78.                 $(this).removeAttr('disabled');
  79.             });
  80.             if (select_model.val() != 0) {
  81.                 select_model.find('option').each(function () {
  82.                     $(this).removeAttr('disabled');
  83.                 });
  84.             }
  85.             filterCars();
  86.             var val = $(this).val(),
  87.                 selected = $(this).find('option:selected'),
  88.                 models = selected.data('models'),
  89.                 engines = selected.data('engines');
  90.             if (val != 0) {
  91.                 !$('#filterReset').hasClass('active') ? $('#filterReset').addClass('active') : console.log('body already showed');
  92.  
  93.                 models = models.split(',');
  94.                 console.log(models);
  95.                 engines = engines.split(',');
  96.                 console.log(engines);
  97.                 // select_model.find('option').attr('disabled', 'true');
  98.                 select_model.find('option').each(function () {
  99.                     // $(this).removeAttr('disabled');
  100.                     console.log(models.includes($(this).val()));
  101.                     if (!models.includes($(this).val()) && $(this).val() != 0) {
  102.                         $(this).attr('disabled', true);
  103.                     }
  104.                 });
  105.                 select_engine.find('option').each(function () {
  106.                     // $(this).removeAttr('disabled');
  107.                     console.log(engines.includes($(this).val()));
  108.                     if (!engines.includes($(this).val()) && $(this).val() != 0) {
  109.                         $(this).attr('disabled', true);
  110.                     }
  111.                 })
  112.  
  113.             }
  114.         });
  115.  
  116.         select_engine.change(function () {
  117.             select_body.find('option').each(function () {
  118.                 $(this).removeAttr('disabled');
  119.             });
  120.             // select_engine.find('option').each(function () {
  121.             //     $(this).removeAttr('disabled');
  122.             // });
  123.             select_model.find('option').each(function () {
  124.                 $(this).removeAttr('disabled');
  125.             });
  126.             filterCars();
  127.             var val = $(this).val(),
  128.                 selected = $(this).find('option:selected'),
  129.                 models = selected.data('models'),
  130.                 bodies = selected.data('bodies');
  131.             console.log('av models:' + models);
  132.             console.log('av bodies:' + bodies);
  133.  
  134.             if (val != 0) {
  135.                 !$('#filterReset').hasClass('active') ? $('#filterReset').addClass('active') : console.log('energy already showed');
  136.  
  137.                 bodies = bodies.split(',');
  138.                 console.log(bodies);
  139.  
  140.                 models = models.split(',');
  141.                 console.log(models);
  142.  
  143.                 select_model.find('option').each(function () {
  144.                     // $(this).removeAttr('disabled');
  145.                     if (!models.includes($(this).val()) && $(this).val() != 0) {
  146.                         $(this).attr('disabled', true);
  147.                     }
  148.                 });
  149.                 // select_model.find('option').attr('disabled', 'true');
  150.                 select_body.find('option').each(function () {
  151.                     // $(this).removeAttr('disabled');
  152.                     // if($(this).val().split())
  153.                     if (!bodies.includes($(this).val()) && $(this).val() != 0) {
  154.                         $(this).attr('disabled', true);
  155.                     }
  156.                 });
  157.  
  158.             }
  159.         });
  160.  
  161.  
  162.         if (filter_slider) {
  163.             filter_slider.noUiSlider.on('change', function () {
  164.                 filterCars();
  165.             });
  166.         }
  167.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement