const onDOMReady = function() {
  // Clear Filters button
  $('.clear_filters_btn').click(function(event) {
    const params = window.location.search.slice(1).split('&');
    const regex = /^(q\[|q%5B|q%5b|page|commit)/;
    const cleanedParams = params.filter(param => !param.match(regex));

    if (typeof Turbolinks !== 'undefined') {
      event.preventDefault();
      Turbolinks.visit(window.location.href.split('?')[0] + '?' + cleanedParams.join('&'));
    } else {
      window.location.search = cleanedParams.join('&');
    }
  });

  // Filter form: don't send any inputs that are empty
  $('.filter_form').submit(function(event) {
    $(this)
      .find(':input')
      .filter(function() {
        return this.value === '';
      })
      .prop('disabled', true);

    if (typeof Turbolinks !== 'undefined') {
      event.preventDefault();
      Turbolinks.visit(window.location.href.split('?')[0] + '?' + $(this).serialize());
    }
  });

  // Filter form: for filters that let you choose the query method from
  // a dropdown, apply that choice to the filter input field.
  $('.filter_form_field.select_and_search select').change(function() {
    $(this).siblings('input').prop({name: `q[${this.value}]`});
  });
};

$(document).
  ready(onDOMReady).
  on('page:load turbolinks:load', onDOMReady);

@@ -1,46 +1,35 @@
-const onDOMReady = function()
+(($, ActiveAdmin) =%3E
  %7B%0A
+%0A
   
-// Clear
+class
  Fil
@@ -37,128 +37,44 @@
 ers 
-button%0A  $('.clear_filters_btn').click(function(event) %7B%0A    const params = window.location.search.slice(1).split('&');%0A
+%7B%0A%0A    static _clearForm(event) %7B%0A  
     
@@ -109,16 +109,21 @@
 5b%7Cpage%7C
+utf8%7C
 commit)/
@@ -132,59 +132,101 @@
     
+  
 const 
-cleanedParams = params.filter(param
+params = ActiveAdmin%0A        .queryStringToParams()%0A        .filter((%7Bname%7D)
  =%3E !
-par
+n
 am
+e
 .mat
@@ -242,53 +242,8 @@
 );%0A%0A
-    if (typeof Turbolinks !== 'undefined') %7B%0A
     
@@ -272,100 +272,92 @@
 ();%0A
+%0A
       
-Turbolinks.visit(window.location.href.split('?')%5B0%5D + '?' + cleanedParams.join('&')
+if (ActiveAdmin.turbolinks) %7B%0A        ActiveAdmin.turbolinksVisit(params
 );%0A
+  
     
@@ -371,16 +371,18 @@
 %7B%0A      
+  
 window.l
@@ -402,149 +402,123 @@
 h = 
-cleanedParams.join('&'
+ActiveAdmin.toQueryString(params
 );%0A    
-%7D%0A
   %7D
-);%0A%0A  // Filter form: don't send any inputs that are empty%0A  $('.filter_form').submit(function(event) %7B%0A   
+%0A    %7D%0A%0A    static _disableEmptyInputFields(event) %7B%0A      const params =
  $(t
@@ -528,16 +528,18 @@
 )%0A      
+  
 .find(':
@@ -552,24 +552,26 @@
 )%0A      
+  
 .filter(
 function
@@ -566,40 +566,27 @@
 ter(
-function() %7B%0A        return this
+(i, input) =%3E input
 .val
@@ -598,19 +598,12 @@
 = ''
-;
+)
 %0A  
-    %7D)%0A
     
@@ -614,17 +614,18 @@
 rop(
-'
+%7B 
 disabled
 ', t
@@ -624,27 +624,71 @@
 bled
-',
+:
  true
+ %7D)%0A        .end()%0A        .serializeArray(
 );%0A%0A
+  
     if (
 type
@@ -687,45 +687,36 @@
 if (
-typeof Turbolinks !== 'undefined'
+ActiveAdmin.turbolinks
 ) %7B%0A
+  
     
@@ -747,17 +747,31 @@
 ;%0A      
-T
+  ActiveAdmin.t
 urbolink
@@ -775,77 +775,131 @@
 inks
-.v
+V
 isit(
-window.location.href.split('?')%5B0%5D + '?' + $(this).serialize()
+params);%0A      %7D%0A    %7D%0A%0A    static _setSearchType() %7B%0A      $(this).siblings('input').prop(%7Bname: %60q%5B$%7Bthis.value%7D%5D%60%7D
 );%0A 
@@ -907,153 +907,173 @@
   %7D%0A
+%0A
   %7D
-);
 %0A%0A  
-// Filter form: for filters that let you choose the query method from%0A  // a dropdown, apply that choice to the filter i
+$(document).%0A    on('click', '.clear_filters_btn', Filters._clearForm).%0A    on('submit', '.filter_form', Filters._disableEmptyI
 nput
- f
+F
 ield
+s)
 .%0A  
-$(
+  on('change', 
 '.fi
@@ -1117,181 +1117,64 @@
 ect'
-).change(function() %7B%0A    $(this).siblings('input').prop(%7Bname: %60q%5B$%7Bthis.value%7D%5D%60%7D);%0A  %7D);%0A%7D;%0A%0A$(document).%0A  ready(onDOMReady).%0A  on('page:load turbolinks:load', onDOMReady
+, Filters._setSearchType);%0A%0A%7D)(jQuery, window.activeadmin
 );%0A

Simplify filters and use delegated events