PageSourceSearch

https://www.philpenman.com/lib/g/2.0/scripts/artlogic_modules/galleries_js/artwork_filters.js

js philpenman.com collected 2026-09-28 12:33:18 UTC 36,021 bytes, 766 lines download raw bytes

1var artwork_filters = {
2    
3    init: function() {
4        
5        Artlogic.import('galleries_js/pageload_load_more_pagination.js');
6        
7        window.galleries.artwork_filters.checked_items();
8        window.galleries.artwork_filters.clear_filters();
9        window.galleries.artwork_filters.range_slider();
10        window.galleries.artwork_filters.responsive_filter_btn();
11        // Responsive show/hide filter menu handler
12        $('.artwork-filter-responsive-btn').off('click.filters').on('click.filters', function(e){
13            $('#artwork-filter-panel').toggleClass('show')
14        });
15        
16        // Individual filter item click handler
17        if ($('.filters_panel').hasClass('filters_enable_autosubmit')) {
18            $('#filterpanel_form input').off('change.filters').not('[type="text"]').not(".fp-ignore-autosubmit").on('change.filters', function(e){
19                window.galleries.artwork_filters.checked_items();
20                window.galleries.artwork_filters.processUniqueOptionCheckbox($(this));
21                if ($('#filterpanel_form').data('artworks_api_enabled') === true) {
22                    window.galleries.artwork_filters.load_works_api();
23                } else {
24                    window.galleries.artwork_filters.load_works();
25                }
26            });
27        } else {
28            // bind the unique option processor for non autosubmit, non dropdown selections
29            // fixes issue with users being able to select multiple sort options
30            // in the case where 'panel above grid' or 'sidebar panel' is used and 'show submit button' is enabled
31            $('#filterpanel_form input').off('change.filters').not('[type="text"]').not(".fp-ignore-autosubmit").on('change.filters', function(e) {
32                window.galleries.artwork_filters.processUniqueOptionCheckbox($(this));
33            })
34        }
35        
36        $('#filterpanel_form .fp-button-submit, #filterpanel_form .fp-keyword-submit').off('click.filters').on('click.filters', function() {
37            window.galleries.artwork_filters.checked_items();
38            window.galleries.artwork_filters.processUniqueOptionCheckbox($(this));
39            $('body').addClass('artwork-filters-active');
40            if ($('#filterpanel_form').data('artworks_api_enabled') === true) {
41                window.galleries.artwork_filters.load_works_api();
42            } else {
43                window.galleries.artwork_filters.load_works();
44            }
45            return false;
46        });
47        
48        $('#filterpanel_form input[type="text"]').off('keypress.filters')
49            .on('keypress.filters', function(event) {
50                if (event.which == 13) {
51                    event.preventDefault();
52                    $('#filterpanel_form .fp-button-submit').trigger('click');
53                    return false;
54                }
55            })
56        ;
57        
58        $('#filterpanel_form label').on('click', function(e) {
59            // Prevents a bug where the checkbox click event was triggered twice.
60            e.stopPropagation();
61        });
62        
63        // /**
64        //  * OPEN/CLOSE THE FILTER LIST CONTAINER
65        //  */
66        var isTouch = false;
67        $('.fp-module').on('touchstart', function(e) {
68            isTouch = true;
69        }).on('mouseover', function(e) {
70            if (!isTouch) {
71                $('.fp-module').removeClass('visible');
72                $(this).addClass('visible');
73            }
74        }).on('mouseout', function(e) {
75            if (!isTouch) {
76                $(this).removeClass('visible');
77            }
78        }).on('click', function(e) {
79            if (isTouch && $(this).hasClass('visible') && !$(e.target).hasClass('fp-textfield')) {
80                $(this).removeClass('visible');
81            }
82        });
83        $('.fp-legend').on('click', function(e){
84            
85            if(!$(this).closest('.fp-module').hasClass('visible')){
86                // Prevent the window handler from being triggered.
87                e.stopPropagation();
88                // Hide any already open panels
89                $('.fp-module').removeClass('visible');
90                // Show the list attached to the clicked heading
91                $(this).closest('.fp-module').toggleClass('visible');
92              
93                // Clicking anywhere else on the page will close the opened group
94                $(window).one('click', function(e){
95                    if (!$(e.target).hasClass('fp-textfield')) {
96                        $('.fp-module').removeClass('visible');
97                    }
98                });
99            } else {
100                // No need to do anything as the click listener on window will remove the visible class.
101                return;
102            }
103        });
104        
105        if (typeof window.site != 'undefined') {
106            if (typeof window.site.filter_ui != 'undefined') {
107                window.site.filter_ui();
108            }
109        }
110
111        window.galleries.artwork_filters.after_setup_callback();
112    },
113
114    after_setup_callback: function() {
115                
116    },
117    
118    checked_items: function(){
119        
120        $('#filterpanel_form input[type="text"]')
121            .each(function() {
122                if ($(this).val() != '') {
123                    $(this).closest('.fp-module').addClass('active');
124                } else {
125                    $(this).closest('.fp-module').removeClass('active');
126                }
127            })
128        ;
129        $('#filterpanel_form .fp-module').each(function(){
130            if ($(this).find('input[type="checkbox"]').length) {
131                var checked_count = $(this).find('input[type="checkbox"]:checked').length;
132                if(checked_count > 0) {
133                    $(this).addClass('active');
134                    $(this).find('.group-count').html('('+ String(checked_count) + ')');
135                } else {
136                    $(this).removeClass('active');
137                    $(this).find('.group-count').html('');
138                }
139            }
140        });
141        
142    },          
143    
144    range_slider: function() {
145        
146        $('.multi-range-slider').not('.initialised').each(function() {
147            
148            var $this = $(this);
149            
150            $this.addClass('initialised');
151            
152            var html5Slider = $this[0];
153            
154            //Slider absolute max and min
155            var slider_min = parseFloat($this.attr('data-min'));
156            var slider_max = parseFloat($this.attr('data-max'));
157            
158            //Set the absolute max and min as default handle start positions
159            var start_min = slider_min;
160            var start_max = slider_max;
161            
162            //If we are suppying start positions on load, use these instead
163            var received_starting_values = false;
164            if ($this.attr('data-start-min') && typeof $this.attr('data-start-min') != 'undefined') {
165                start_min = parseFloat($this.attr('data-start-min'));
166                received_starting_values = true;
167            }
168            if ($this.attr('data-start-max') && typeof $this.attr('data-start-max') != 'undefined') {
169                start_max = parseFloat($this.attr('data-start-max'));
170                received_starting_values = true;
171            }
172            
173            //Create the start variable
174            var start = [start_min, start_max];
175            
176            // //Define the form inputs that the slider values get placed into
177            var $min_input = $this.closest('.multi-range-slider-wrap').find('.slider_min');
178            var $max_input = $this.closest('.multi-range-slider-wrap').find('.slider_max');
179            
180            if ($min_input.val() == '') {
181                $min_input.attr('disabled',true);
182            }
183            if ($max_input.val() == '') {
184                $max_input.attr('disabled',true);
185            }
186            
187            //default range without steps.. probably best suited to dimensions
188            var range = {
189                'min': slider_min,  
190                'max': slider_max
191            }
192            var step = 1;
193            //default range without steps.. probably best suited to dimensions
194            if ($this.hasClass('multi-range-price')){
195                var step = 100;
196                /* 
197                    CREATE DYNAMIC RANGES BASED ON MAX VALUE
198                */
199                var rounded_slider_max = Math.ceil(slider_max/100000)*100000; // Round up the max value to the nearest 100,000
200                var rules = [0, 500, 5000, 10000, 50000, 100000, 300000, 500000, 750000, 1000000]; // list of predefined steps. These need to match the obect keys in rule_dict
201                var rule_dict = {
202                    0       : [0, 100],
203                    500     : [500, 500],
204                    5000    : [5000, 1000],
205                    10000   : [10000, 10000],
206                    50000   : [50000, 10000],
207                    100000  : [100000, 10000],
208                    300000  : [300000, 50000],
209                    500000  : [500000, 30000],
210                    750000  : [750000, 40000],
211                    1000000 : [1000000, 50000]
212                }
213                
214                var rules_target;
215                for (var i = 0; i < rules.length; i++) {
216                    // Loop through the rules array until we find the one with a key greater than the price max.
217                    if(rules[i] >= rounded_slider_max) {
218                        // store the index of the key so we can use only the items in the rules dict upto and including that index...
219                        rules_target = i;
220                        break;
221                    }
222                }
223                
224                // The range object we'll pass to NoUI
225                var dynamic_range = {};
226                
227                if(rules_target){
228                    // Just the items from rules dict that we need...
229                    var rules_slice = rules.slice(0, rules_target+1);
230                    
231                    // Calculate the percentage 'steps' we're going to use 
232                    var dynamic_steps = Math.round(100 / rules_slice.length);
233                    
234                    // dynamic_range.min = []
235                    for (var i = 0; i < rules_slice.length; i++) {
236                        if(i == 0) {
237                            dynamic_range.min = rule_dict[rules_slice[i]];
238                        } else if(i == rules_slice.length-1) {
239                            dynamic_range.max = rule_dict[rules_slice[i]];
240                        } else {
241                            dynamic_range[dynamic_steps * i + '%'] = rule_dict[rules_slice[i]];
242                            
243                        }
244                    }
245                    
246                    if(!received_starting_values){
247                        start = [start_min, dynamic_range.max[0]];
248                    }
249                }
250            
251                var range = {
252                    'min': [0,100],  //Minimum value, step size
253                    '10%': [500,500], // So, above 500, jump in steps of 500
254                    '40%': [5000,1000],  // Above5000, jump in steps of 1000  etc etc                 		
255                    '50%': [10000,10000],
256                    '80%': [300000,50000],
257                    'max': [Math.ceil(slider_max/100000)*100000,50000]  //round up to the nearest 100000
258                }
259            }
260
261            Artlogic.import('plugins/nouislider.js')
262                .then(function() {
263                    //Create the slider
264                    noUiSlider.create(html5Slider, {
265                        start: start,
266                        step: step,
267                        connect: true,
268                        range: dynamic_range || range
269                    });
270                    
271                    var format = 'dimensions';
272                    //Listener. Places the slider values into the inputs
273                    
274                    
275                    
276                    html5Slider.noUiSlider.on('update', function( values, handle, format ) {
277                    
278                        var value = values[handle];
279                        var target = $(this)[0].target;
280                        var target_parents = $(target).parents('.fp-module-content');
281                        
282                        var min_label = parseInt(values[0]);
283                        var max_label = parseInt(values[1]);
284                        
285                        target_parents.find('.slider_label .min').text(min_label);
286                        target_parents.find('.slider_label .max').text(max_label);
287                        
288                    });
289                    
290                    html5Slider.noUiSlider.on('change', function( values, handle, format ) {
291                    
292                        var value = values[handle];
293                        var target = $(this)[0].target;
294                        var target_parents = $(target).parents('.fp-module-content');
295                        
296                        var min_label = parseInt(values[0]);
297                        var max_label = parseInt(values[1]);
298                        
299                        target_parents.find('.slider_label .min').text(min_label);
300                        target_parents.find('.slider_label .max').text(max_label);
301                        
302                        var value = values[handle];
303                        
304                        if ( handle ) {
305                         
306                            // $max_input.attr('disabled',false);
307                            $max_input[0].value = value.replace('.00', '')
308                            // $min_input.trigger('change'); //DC Unsure why these are here and are triggering multiple ajax calls
309                            
310                            if (Math.round(slider_min) == Math.round(value) && Math.round(slider_max) == Math.round(value)) {
311                                $min_input.attr('disabled',true);
312                                $max_input.attr('disabled',true);
313                            } else {
314                                $min_input.removeAttr('disabled');
315                                $max_input.removeAttr('disabled');
316                            }
317                            
318                           $max_input.trigger('change.filters');
319                           
320                        } else {
321                        
322                            // $min_input.attr('disabled',false);
323                            $min_input[0].value = value.replace('.00', '');
324                            // $min_input.trigger('change'); //DC Unsure why these are here and are triggering multiple ajax calls
325                            
326                            if (Math.round(slider_min) == Math.round(value) && Math.round(slider_max) == Math.round(value)) {
327                                $min_input.attr('disabled',true);
328                                $max_input.attr('disabled',true);
329                            } else {
330                                $min_input.removeAttr('disabled');
331                                $max_input.removeAttr('disabled');
332                            }
333                            
334                            $min_input.trigger('change.filters');
335                        }
336                        
337                        if (window.ga || window.gtag) {
338                            var filter_value = false;
339                            if (handle == 0) {
340                                filter_value = $min_input.val();
341                                $min_input.trigger('change');
342                            } else if (handle == 1) {
343                                filter_value = $max_input.val();
344                                $max_input.trigger('change');
345                            }
346
347                            if (filter_value) {
348                                var filter_key = $(target_parents).closest('.fp-module').find('.fp-legend button').text().replace(/^\s+|\s+$/g, '');
349
350                                if (window.ga) {
351                                    var analyticsdata = {
352                                        'hitType': 'event',
353                                        'eventCategory': 'Artwork Filters',
354                                        'eventAction': filter_key + ': ' + filter_value,
355                                        'eventLabel': ''
356                                    };
357                                    ga('send', analyticsdata);
358                                }
359
360                                if (window.gtag) {
361                                    gtag('event', 'artwork_filters', {
362                                        'filter_key': filter_key,
363                                        'filter_value': filter_value,
364                                    });
365                                }
366                            }
367                        }                        
368                    });
369
370                    $(html5Slider.noUiSlider.target).find('.noUi-handle').each(function () {
371                        
372                        var $handle = $(this);
373                        
374                        $handle.on('keydown', function (e) {
375                        
376                            var values = html5Slider.noUiSlider.get();
377                            
378                            var value_index = 1;
379                            
380                            if ($handle.hasClass('noUi-handle-lower')) {
381                                value_index = 0;
382                            }
383
384                            if (e.which === 37) {
385                                values[value_index] = String(parseFloat(values[value_index]) - 10);
386                                html5Slider.noUiSlider.set(values);
387                            }
388                        
389                            if (e.which === 39) {
390                                values[value_index] = String(parseFloat(values[value_index]) + 10);
391                                html5Slider.noUiSlider.set(values);
392                            }
393                        });
394                                                
395                    });
396                })
397                .catch(function(){ console.log('Could not load nouislider.js') })
398            ;
399            
400            
401        
402        });
403
404    },
405    
406    processUniqueOptionCheckbox: function(instance) {
407        if (instance && instance.length) {
408            if (instance.closest('.unique-option-parent').length) {
409                instance.closest('.unique-option-parent').find('input').not(instance).prop('checked', false);
410            }
411        }
412    },
413    
414    processRangeCheckbox: function(){
415        /**
416         * This function requires: data-min and data-max to be set on the checkbox input and 2 hidden input
416s, .range_min and .range_max to be added as children of .range_parent. The hidden inputs need to be disabled by default.
417         * For all the selected checkboxes find the data-min and data-max values(which should be set on the input element). 
418         * Assign the min/max values to relevant array selectedMins/selectedMaxs and then use the ARRAY.sort() func to order them in ascending order.
419         * Set the min value as the FIRST item in the sorted selectedMins array. Set the max value as the LAST item in the selectedMaxs array.
420         * Assign these to the hidden inputs so they are passed when the form is serialized/submitted.
421         */
422        $('.range-parent').each(function(){
423            var selectedRanges = $(this).find('input:checked');
424            
425            if(!selectedRanges.length){ 
426                $(this).find('.range_min, .range_max').attr('disabled', true); // Disable the min and max fields so the empty values aren't sent when the form is submitted.
427                return; // Don't bother to process if there aren't any checked checkboxes
428            } 
429            
430            // Remove the disabled attribute for the min and max inputs as a checkbox is selected
431            $(this).find('.range_min, .range_max').removeAttr('disabled');
432            
433            var parent = $(this).closest('.range-parent');
434            var selectedMins = [];
435            var selectedMaxs = [];
436            for (var i = 0; i < selectedRanges.length; i++) {
437                selectedMins.push(parseInt( ($(selectedRanges[i]).data('min') || 0) ));
438                selectedMaxs.push(parseInt( ($(selectedRanges[i]).data('max') || 100000000) ));
439            }
440            // Order the min and max arrays in ascending order
441            var selectedMinsSorted = selectedMins.sort(function(a,b){return a-b}); // By default the sort is alphabetical, the weird callback function forces it to sort numerically.
442            var selectedMaxsSorted = selectedMaxs.sort(function(a,b){return a-b}); // By default the sort is alphabetical, the weird callback function forces it to sort numerically.
443            
444            var minValue = selectedMinsSorted[0];
445            var maxValue = selectedMaxsSorted[selectedMaxsSorted.length - 1]; // the last item
446            
447            // Update the hidden inputs with the corresponding values
448            $(this).find('.range_min').val(minValue).trigger('change');
449            $(this).find('.range_max').val(maxValue).trigger('change');
450        });  
451    },
452    
453    load_works: function($filterPanelForm) {
454        /**
455         * Serializes and submits the form.
456         * The result will be loaded into the inner_content_selector element.
457         */
458        if(typeof $filterPanelForm == 'undefined') {
459            $filterPanelForm = $('#filterpanel_form');
460        }
461        
462        var pathToSubmitForm = $filterPanelForm.attr('data-action') && typeof $filterPanelForm.attr('data-action') != 'undefined' ? $filterPanelForm.attr('data-action') : $filterPanelForm.attr('action');
463        if (pathToSubmitForm){
464            window.galleries.artwork_filters.processRangeCheckbox();
465            window.galleries.artwork_filters.processUniqueOptionCheckbox();
466            
467            var serializedArray = $filterPanelForm.serializeArray();
468            var serializedObject = serializedArray.reduce(function(obj, param) {
469                if (!obj[param.name]) {
470                    obj[param.name] = param.value;
471                } else {
472                    obj[param.name] = obj[param.name] + ',' + param.value;
473                }
474                return obj;
475            }, {});
476            var serializedForm = '';
477            Object.keys(serializedObject).forEach(function(k) {
478                if (serializedObject[k]) {
479                    serializedForm += (serializedForm.length ? '&' : '') + k + '=' + serializedObject[k];
480                }
481            });
482            // var serializedForm = $filterPanelForm.serialize();
483            var keyword = $('input.fp-textfield').attr('name');
484            if (keyword && keyword.length) {
485                // Remove empty '&keyword=' parameter from the query string.
486                serializedForm = serializedForm.replace(new RegExp('(&?' + keyword + '=)(&|$)', 'g'), "$2");
487                serializedForm = serializedForm.replace(/^&?/, "");
488                serializedForm = serializedForm.replace(/&?$/, "");;
489            }
490
491            if(serializedForm.length){
492                var updated_url = pathToSubmitForm + '?' + serializedForm;
493            } else {
494                var updated_url = pathToSubmitForm
495            }
496
497        }   
498        
499        if ($('.filter_results').length && !$('.filter_results_no_results').length) {
500            var incoming_content_type = 'inner';
501            var pushstate = false;
502        } else {
503            var incoming_content_type = 'standard';
504            var pushstate = true;
505        }
506        
507        $.pageload.load(updated_url, pushstate, function(new_page_inner_content, element_href, new_page_main_content) {
508                        
509            if (new_page_inner_content) {
510                $('.filter_results')
511                    .addClass('filter_transition')
512                    .delay(400)
513                    .queue(function() {
514
515                        history.replaceState({'ajaxPageLoad': true}, null, updated_url);
516                        
517                        var full_html = $(new_page_main_content);
518                        var results_html = full_html.find('.filter_results').html();
519                        var pagestats_id = full_html.find('.filter_results').attr('data-pagestats-id');
520                        var page_stats = full_html.find('.filter_results_pagination').html();
521                        
522                        $('.filter_results').html(results_html).attr('data-pagestats-id', pagestats_id);
523                        // we remove initialised & scatter-list-initialised classes to allow for the grid to get setup again
524                        $('.filter_results').removeClass('filter_transition initialised scatter-list-initialised');
525                        
526                        $('.filter_results_pagination').remove();
527                        if (page_stats && typeof page_stats != 'undefined') {
528                            $('.filter_results').after('<div class="filter_results_pagination"></div>');
529                            $('.filter_results_pagination').append(page_stats);
530                        }
531                        
532                        window.galleries.responsive.records_lists();
533                        window.galleries.pageload_load_more_pagination.init();
534                        if (window.cart && typeof window.cart != 'undefined') {
535                            window.cart.init();
536                        }
537                        
538                        window.galleries.misc.init();
539                        window.galleries.responsive.tile_list_append_refresh($('.filter_results'));
540                        window.galleries.layout.inview.init();
541                        
542                        $(window).trigger('scroll');
543                        $(window).trigger('resize');
544                        
545                        $.pageload.refresh();
546                        
547                        $(this).dequeue();
548                    })
549                ;
550            }
551        }, null, null, null, incoming_content_type);
552
553    },
554
555    load_works_api: function(url) {
556        /**
557         * Serializes and submits the form.
558         * The result will be loaded into the inner_content_selector element.
559         */
560            
561        $('body').addClass('ajax-loading loader-active ajax-initial-loading');
562            
563        var $filterPanelForm = $('#filterpanel_form');
564
565        var pathToSubmitForm = $filterPanelForm.attr('data-action') && typeof $filterPanelForm.attr('data-action') != 'undefined' ? $filterPanelForm.attr('data-action') : $filterPanelForm.attr('action');
566        if (pathToSubmitForm && url == undefined){
567            window.galleries.artwork_filters.processRangeCheckbox();
568            window.galleries.artwork_filters.processUniqueOptionCheckbox();
569
570            var serializedForm = $filterPanelForm.serialize();
571            var keyword = $('input.fp-textfield').attr('name');
572            if (keyword && keyword.length) {
573                // Remove empty '&keyword=' parameter from the query string.
574                serializedForm = serializedForm.replace(new RegExp('(&?' + keyword + '=)(&|$)', 'g'), "$2");
575                serializedForm = serializedForm.replace(/^&?/, "");
576                serializedForm = serializedForm.replace(/&?$/, "");
577            }
578
579            var queryString = '';
580
581            if(serializedForm.length){
582                var updated_url = pathToSubmitForm + '?' + serializedForm;
583                // Update the query string in the url bar so the selection of
584                // filters can be shared as a link.
585                queryString = '?' + serializedForm;
586                $('#artworks_filter_panel').data('query_string', serializedForm);
587            } else {
588                var updated_url = pathToSubmitForm
589            }
590
591            // if (queryString != window.location.search) {
592            //     window.history.pushState(
593            //         "object or string",
594            //         window.title,
595            //         window.location.pathname + queryString
596            //     );
597            // }
598            
599            if (queryString && queryString != '') {
600                $('#filterpanel_form').addClass('forced-hash-change');
601                window.location.hash = queryString.replace('?', 'filters=');
602                $('body').addClass('artwork-filters-active');
603            }
604        } else {
605            var updated_url = url;
606        }
607
608        if (window.archimedes.proxy_dir && typeof window.archimedes.proxy_dir !='undefined' && updated_url.indexOf('lang=') == -1) {
609            var lang_code = window.archimedes.proxy_dir.replace('/', '');
610            updated_url = updated_url.indexOf('?') > -1 ? updated_url + '&lang=' + lang_code : updated_url + '?lang=' + lang_code;
611        }
612
613        $.get(updated_url, function(html) {
614            if (html) {
615                $('.filter_results')
616                    .addClass('filter_transition')
617                    .delay(400)
618                    .queue(function() {
619                        $('#artworks_grid_ajax').removeClass('loader_simple');
620                        $('.filter_results').html(html);
621                        $('.filter_results').removeClass('filter_transition');
622                        
623                        if ($('.filter_results .list_no_results_message').length > 0) {
624                            $('.filter_results').addClass('filter_results_no_results_found');
625                        } else {
626                            $('.filter_results').removeClass('filter_results_no_results_found');
627                        }
628
629                        window.galleries.responsive.records_lists();
630                        window.galleries.pageload_load_more_pagination.init();
631                        if (window.cart && typeof window.cart != 'undefined') {
632                            window.cart.init();
633                        }
634
635                        window.galleries.misc.init();
636                        window.galleries.responsive.tile_list_append_refresh($('.filter_results'));
637                        window.galleries.layout.inview.init();
638                        window.galleries.contact_form_popup.init();
639                        $(window).trigger('scroll');
640                        $(window).trigger('resize');
641
642                        $('.filter_results').find('.filter_results_pagination')
643                                            .find('a.ps_link')
644                                            .click(function(event) {
645                            event.preventDefault();
646                            var url = $(this).attr('href');
647                            $(this).attr('href', '#');
648
649                            window.galleries.artwork_filters.checked_items();
650                            window.galleries.artwork_filters.processUniqueOptionCheckbox();
651                            window.galleries.artwork_filters.load_works_api(url);
652                        });
653
654                        window.galleries.artwork_filters.load_works_api_after_callback();
655                        $.pageload.refresh('#artworks_grid_ajax');
656                        
657                    
658                        //Quick method to check if scrollup is needed - probably improve this later
659                        var header_height = ($('.header-fixed-wrapper').length ? $('.header-fixed-wrapper').height() : 0);
660                
661                        
662                        if (!$filterPanelForm.hasClass('disable-autoscroll')) {
663                            var buffer = 100;
664                            
665                            var top_of_results = $(".filter_results").offset().top;
666                            var bottom_of_screen = $(window).scrollTop() + $(window).innerHeight() - buffer;
667                            var top_of_screen = $(window).scrollTop() - buffer;
668                            
669                            if ((top_of_screen > top_of_results)){ 
670                                $("html, body").animate({scrollTop: top_of_results - header_height - 60}, 500, function() {
671                                    $('#artworks_grid_ajax').focus();
672                                });
673                            } else if (top_of_results > bottom_of_screen){ 
674                                $("html, body").animate({scrollTop: top_of_results - header_height - 60}, 500, function() {
675                                    $('#artworks_grid_ajax').focus();
676                                });
677                            }
678                        }
679
680                        $('body').removeClass('ajax-loading loader-active ajax-initial-loading');
681                        
682                        $(this).dequeue();
683                    })
684                ;
685            }
686        });
687
688        if (window.gtag) {
689            gtag('event', 'artwork_filters', {
690                'updated_url': updated_url,
691            });
692        }
693
694        if (window.ga) {
695            // Track the click in Analytics
696            ga('send', {
697                'hitType': 'event',
698                'eventCategory': 'Artwork filters',
699                'eventAction': updated_url,
700                'eventLabel': $(document).attr('title')
701            });
702            // Track the click in second Analytics account
703            ga('tracker2.send', {
704                'hitType': 'event',
705                'eventCategory': 'Artwork filters',
706                'eventAction': updated_url,
707                'eventLabel': $(document).attr('title')
708            });
709            ga('artlogic_tracker.send', {
710                'hitType': 'event',
711                'eventCategory': 'Artwork filters',
712                'eventAction': updated_url,
713                'eventLabel': $(document).attr('title')
714            });
715        }
716    },
717
718    load_works_api_after_callback: function() {
719
720    },
721
722    clear_filters: function(){
723        
724        $('.clear_filters').on('click', function(e){
725            e.preventDefault();
726            $('#filterpanel_form input[type="checkbox"]').not('.fp-ignore-autosubmit').prop('checked', false);
727            $('#filterpanel_form input[type="hidden"]').val('');
728            $('#filterpanel_form input[type="text"]').val('');
729            $('#filterpanel_form .multi-range-slider').each(function() {
730                $(this)[0].noUiSlider.set([$(this).attr('data-min'), $(this).attr('data-max')]);
731            });
732            $('#filterpanel_form').find('.group-count').html('');
733            if (window.location.hash.startsWith('#filters=')) {
734                window.location.hash = '#filters=';
735            }
736            if ($('#filterpanel_form').data('artworks_api_enabled') === true) {
737                window.galleries.artwork_filters.load_works_api();
738            } else {
739                window.galleries.artwork_filters.load_works();
740            }
741            $('body').removeClass('artwork-filters-active');
742            return false;
743        });
744        
745    },
746    
747    responsive_filter_btn: function() {
748        
749        $('.artwork-filter-open-btn').on('click', function() {
750            console.log('open responsive');
751            if($('#filterpanel_form').hasClass('open')){
752                $('#filterpanel_form').removeClass('open');
753                $('#filterpanel_form').attr('style','')
754            } else {
755                $('#filterpanel_form').addClass('open');
756                window.galleries.helpers.animate_height($('#filterpanel_form'));
757            }
758        });
759        
760    }
761    
762};
763
764window.galleries = window.galleries || {};
765window.galleries.artwork_filters = artwork_filters;
766export default artwork_filters;

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.