Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.37 KB | None | 0 0
  1. if ($('.hb_header_filter_block').length > 0) {
  2.         let allInputs = $('.hb_header_filter_block input');
  3.  
  4.         allInputs.on('change', function(event) {
  5.  
  6.                 let allFilters = $('.hb_header_filter_block .filter_list_list');
  7.                 let dataArrFilter = eachAllFilters(allFilters);
  8.                 // console.log(dataArrFilter);
  9.  
  10.                 $.ajax({
  11.                                 url: hbFilterCat.url,
  12.                                 type: 'POST',
  13.                                 dataType: 'json',
  14.                                 // dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
  15.                                 data: {
  16.                                         action: 'hb_ajax_filter',
  17.                                         filter: dataArrFilter,
  18.                                         cat: hbFilterCat.cat_id
  19.                                 },
  20.                         })
  21.                         .done(function(data) {
  22.                                 console.log(data);
  23.                         })
  24.                         .fail(function(data) {
  25.                                 console.log(data);
  26.                         })
  27.                         .always(function() {
  28.                                 console.log("complete");
  29.                         });
  30.         });
  31. }
  32.  
  33. function eachAllFilters(block) {
  34.     let data = [];
  35.     $.each(block, function(index, val) {
  36.         let termName = $(this).data('term');
  37.         let checked = getCheckedInputs($(this));
  38.  
  39.         data.push({
  40.             termName: termName,
  41.             checked: checked,
  42.         })
  43.     });
  44.  
  45.     return data;
  46. }
  47.  
  48.  
  49. function getCheckedInputs(block) {
  50.         let allCheckboxInputs = block.find("input:checkbox:checked");
  51.         let idChecked = [];
  52.  
  53.         $.each(allCheckboxInputs, function(index, val) {
  54.                 idChecked.push($(this).data('term-id'));
  55.         });
  56.  
  57.         return idChecked;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement