PageSourceSearch

https://www.farnham.gov.uk/wp-content/themes/sg-child/includes/sg_…dule_interactivefilter_v1.js?ver=1757079775

js farnham.gov.uk collected 2026-10-02 06:08:23 UTC 8,622 bytes, 229 lines download raw bytes

1let combinedPostIds = [];
2
3function collectPostIdsFromCheckedInputs() {
4
5    var container = jQuery('.ifilter');
6
7    combinedPostIds = null;
8
9    container.find('input[type=radio]:checked').each(function () {
10        var nameAttr = jQuery(this).attr('name');
11        if (nameAttr !== 'ifilter-main_taxes') {
12            let thesePostIds = jQuery(this).attr("data-postidswiththisterm");
13            if (thesePostIds) {
14                let splitIds = thesePostIds.split(',').map(id => id.trim());
15
16                if (combinedPostIds === null) {
17                    // First question — set initial postIds
18                    combinedPostIds = splitIds;
19                } else {
20                    // From second question onward — intersect with current
21                    combinedPostIds = combinedPostIds.filter(id => splitIds.includes(id));
22                }
23            }
24        }
25    });
26    //-->console.log('NEW Combined Post IDs:', combinedPostIds);
27}
28
29function filterQuestions(){
30    // Reset all match-related classes
31    jQuery(".ifilter-matched, .ifilter-nomatch, .ifilter-question-nomatches, .ifilter-question-hasmatches").removeClass("ifilter-matched ifilter-nomatch ifilter-question-nomatches ifilter-question-hasmatches");
32
33
34    // Get the currently visible block
35    let currentBlock = jQuery(".ifilter-question:visible");
36    let currentPath = currentBlock.attr("data-maintaxpath");
37    let firstBlockInSet =  jQuery('.ifilter-question[data-maintaxpath="'+currentPath+'"]:hidden');
38    collectPostIdsFromCheckedInputs();
39
40
41    // Get all hidden question blocks that follow the current one
42    let hiddenBlocksAfter = currentBlock.nextAll(".ifilter-question:hidden");
43
44    hiddenBlocksAfter.each(function () {
45        let block = jQuery(this);
46        let hasMatch = false;
47        let blockTitle = block.find(".ifilter-question-title").text();
48        //-->console.log("LOOKING IN "+blockTitle)
49        block.find("input[data-postidswiththisterm]").each(function () {
50            let input = jQuery(this);
51            let inputTitle = input.parent().find("label").text();
52            //-->console.log("Looking for match with term "+inputTitle);
53            let dataAttr = input.data("postidswiththisterm").toString();
54            let inputPostIds = dataAttr.split(",");
55
56            //-->console.log(inputPostIds);
57
58            // Check if ALL combinedPostIds are in this input's list
59            let isMatch = combinedPostIds.some(function (id) {
60                return inputPostIds.includes(id);
61            });
62
63            if (isMatch) {
64                //-->console.log("found match with "+inputTitle);
65                input.addClass("ifilter-matched");
66                input.parent().addClass("ifilter-matched");
67                hasMatch = true;
68            } else {
69                //-->console.log("No match with "+inputTitle);
70                input.addClass("ifilter-nomatch");
71                input.parent().addClass("ifilter-nomatch");
72            }
73        });
74
75        // Set match class on block
76        if (hasMatch) {
77            //-->console.log("FOUND MATCH")
78            block.addClass("ifilter-question-hasmatches");
79        } else {
80            //-->console.log("NO MATCH")
81            block.addClass("ifilter-question-nomatches");
82        }
83    });
84
85}
86
87function ifilterGoNext(currentQuestionId,takeThisPath = "") {
88    //-->console.log("Looking for question "+ currentQuestionId);
89    var currentQuestion = jQuery('#' + currentQuestionId);
90    var checkedRadio = currentQuestion.find('.ifilter-radio:checked');
91
92    // Clear previous errors
93    currentQuestion.find('.ifilter-question-error').empty();
94    var nextQuestionId = "";
95    if(takeThisPath){
96        nextQuestionId = takeThisPath;
97    } else {
98        // If no option selected, show error
99        if (checkedRadio.length === 0) {
100            var errorHTML = `
101            <div class="alert sg-alert sg-danger alert-dismissible fade show pt-2" role="alert">
102                <strong>Error:</strong> please select an option below before continuing.
103                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
104            </div>
105        `;
106            currentQuestion.find('.ifilter-question-error').html(errorHTML);
107            return;
108        }
109
110        // Find checked radio input and check whether we need to filter questions
111        if (checkedRadio.is('[data-postidswiththisterm]')) {
112            filterQuestions();
113
114            //check for blocks
115            //hidden-blocks left
116            let currentBlock = jQuery(".ifilter-question:visible");
117            let currentPath = currentBlock.attr("data-maintaxpath");
118            let hiddenBlocksAfter = currentBlock.nextAll('.ifilter-question-hasmatches[data-maintaxpath="'+currentPath+'"]:hidden');
119            //-->console.log("WORKING OUT FILTERING");
120            //-->console.log(currentBlock);
121            //-->console.log(currentPath);
122            //-->console.log(hiddenBlocksAfter);
123            if(hiddenBlocksAfter.length){
124                //-->console.log("This has MATCHED hidden blocks after");
125                // Get the next path ID from data-path attribute
126                nextQuestionId = hiddenBlocksAfter.first().attr('id');
127                //-->console.log("WANT TO SET NEXT BLOCK TO "+hiddenBlocksAfter.first().attr('id'))
128
129            } else {
130                //-->console.log("COMPLETE - No more matched questions")
131                ifilter_complete();
132            }
133
134        } else {
135            // Get the next path ID from data-path attribute
136            nextQuestionId = checkedRadio.data('path');
137        }
138
139    }
140
141
142    // Slide up the current question
143    currentQuestion.slideUp(300, function () {
144        var nextQuestion = jQuery('#' + nextQuestionId);
145        if (nextQuestion.length > 0) {
146            nextQuestion.slideDown();
147        } else {
148            //-->console.log("COMPLETE - No next question found")
149            ifilter_complete();
150
151        }
152    });
153}
154
155function ifilter_reset() {
156    let question_blocks = jQuery(".ifilter-question:visible");
157    let start_block = jQuery("#ifilter-start");
158    question_blocks.slideUp();
159    start_block.slideDown();
160
161    //reset everything
162   jQuery(".ifilter").find("input[type=radio]:checked").prop("checked", false);
163
164
165
166}
167
168function ifilter_complete(){
169    //-->console.log("COMPLETE THE IFILTER");
170    var container = jQuery('.ifilter');
171
172    jQuery(".ifilter-question:visible").slideUp();
173    jQuery(".ifilter-processing").slideDown();
174
175    var postIds = null;
176    let labelChain = [];
177    let valueChain = [];
178    container.find('input[type=radio]:checked').each(function () {
179        var nameAttr = jQuery(this).attr('name');
180
181        var idAttr = jQuery(this).attr('id');
182        var label = jQuery('label[for="' + idAttr + '"]').text().trim();
183
184        if (label) {
185            labelChain.push(label);
186        }
187
188        if (nameAttr !== 'ifilter-main_taxes') {
189            var value = jQuery(this).attr('value');
190            if (value) {
191                valueChain.push(value);
192            }
193
194            let thesePostIds = jQuery(this).attr("data-postidswiththisterm");
195            if (thesePostIds) {
196                let splitIds = thesePostIds.split(',').map(id => id.trim());
197
198                if (postIds === null) {
199                    // First question — set initial postIds
200                    postIds = splitIds;
201                } else {
202                    // From second question onward — intersect with current
203                    postIds = postIds.filter(id => splitIds.includes(id));
204                }
205            }
206        }
207    });
208
209    let formattedString = labelChain.join(' > ');
210    //-->console.log(formattedString); // Things To Do > Markets > Gardens
211
212    var termids = valueChain.join(',');
213
214    if (postIds.length > 0) {
215        var baseLink = container.data('rdlink');
216
217        // Join as comma-delimited string
218        var csv = postIds.join(',');
219
220        // Base64 encode
221        var encoded = btoa(csv); // browser built-in function
222
223        var finalURL = baseLink + (baseLink.includes('?') ? '&' : '?') + 'ifilter&post_ids=' + encodeURIComponent(encoded) + '&labels='+encodeURIComponent(formattedString)+'&termids='+termids;
224        //-->console.log("FINAL URL"+finalURL);
225        //-->console.log("REDIRECTING")
226        window.location.href = finalURL;
227
228    }
229}

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.