PageSourceSearch

https://mbclub.ru/js/AL/FilterFramework/search_form-xf23.js?_v=af3faf70

js mbclub.ru collected 2026-10-02 11:50:24 UTC 6,523 bytes, 198 lines download raw bytes

1/** 
2* @author AddonsLab
3* @license https://addonslab.com/
4* @link https://addonslab.com/
5This software is furnished under a license and may be used and copied
6only  in  accordance  with  the  terms  of such  license and with the
7inclusion of the above copyright notice.  This software  or any other
8copies thereof may not be provided or otherwise made available to any
9other person.  No title to and  ownership of the  software is  hereby
10transferred.                                                         
11                                                                     
12You may not reverse  engineer, decompile, defeat  license  encryption
13mechanisms, or  disassemble this software product or software product
14license.  AddonsLab may terminate this license if you don't comply with
15any of these terms and conditions.  In such event,  licensee  agrees 
16to return licensor  or destroy  all copies of software  upon termination 
17of the license.
18*/
19(function (window, document) {
20    "use strict";
21
22    var filterContainer = document.getElementById('itemFilterContainer');
23    var apiUrl = filterContainer.dataset.api;
24    var containerForm = filterContainer.closest('form');
25
26    var lastFormData = false;
27
28    function loadFilterFields() {
29        var originalFormData = new FormData(containerForm);
30        var formData = Array.from(originalFormData.entries()).map(function (entry) {
31            return {name: entry[0], value: entry[1]};
32        });
33
34        if (lastFormData === false) {
35            // the first submission
36            // take the data in URL
37            lastFormData = convertObjectToFormParams(JSON.parse(filterContainer.dataset.preload));
38            // merge it into form data overwriting it
39            formData = mergeData(lastFormData, formData, true);
40            // keep the merged version as latest data
41            lastFormData = formData;
42        } else {
43            // make sure the data that existed the last time is merged into the current, no overwrite of current
44            formData = mergeData(formData, lastFormData, false);
45
46            // merge the data from this submission in the last state, overwrite the existing
47            lastFormData = mergeData(lastFormData, formData, true);
48        }
49
50        // Convert formData back into FormData object
51        var formDataObject = formData.reduce(function (acc, entry) {
52            acc.append(entry.name, entry.value);
53            console.log(`Number of entries in FormData: ${Array.from(acc.entries()).length}`);
54            console.log(`Entry: ${entry.name} = ${entry.value}`);
55            return acc;
56        }, new FormData());
57        console.log(formDataObject);
58        console.log(Array.from(formDataObject.entries()));
59
60        XF.ajax('get', apiUrl, formDataObject, function (data) {
61            if (data.html && data.html.content) {
62                XF.setupHtmlInsert(data.html, (html, data, onComplete) => {
63                    if (html) {
64                        filterContainer.innerHTML = html.outerHTML
65
66                        XF.layoutChange();
67
68                        XF.activate(filterContainer);
69                        onComplete()
70                    }
71                });
72            } else {
73                filterContainer.innerHTML = '';
74                XF.layoutChange();
75            }
76        });
77    }
78
79
80
81    function convertObjectToFormParams(obj, prefix) {
82        var formParams = [];
83
84        function buildParams(obj, prefix) {
85            for (var key in obj) {
86                if (obj.hasOwnProperty(key)) {
87                    var value = obj[key];
88                    var newKey = prefix ? `${prefix}[${key}]` : key;
89
90                    if (typeof value === 'object' && value !== null) {
91                        buildParams(value, newKey);
92                    } else {
93                        formParams.push({
94                            name: newKey,
95                            value: value
96                        });
97                    }
98                }
99            }
100        }
101
102        buildParams(obj, prefix);
103        return formParams;
104    }
105
106    // Example usage:
107    var obj = {
108        a: 1,
109        b: 2,
110        c: {
111            node_id: 10,
112            sub: {
113                sub_node_id: 20
114            }
115        },
116        d: [1, 2, 3]
117    };
118
119    function mergeData(state1, state2, overwrite) {
120        var processedKeys = [];
121
122        state2.forEach(function (state2Entry) {
123            var stateKey = state2Entry.name;
124
125            if (processedKeys.indexOf(stateKey) > -1) {
126                return;
127            }
128
129            var state2Data = getStatesByKey(state2, stateKey);
130            var state1Data = getStatesByKey(state1, stateKey);
131
132            if (state1Data.length === 0) {
133                state1 = state1.concat(state2Data);
134            } else if (overwrite) {
135                state1 = deleteStatesByKey(state1, stateKey);
136                state1 = state1.concat(state2Data);
137            }
138
139            processedKeys.push(stateKey);
140        });
141
142        return state1;
143    }
144
145    function deleteStatesByKey(state, stateKey) {
146        return state.filter(function (stateEntry) {
147            return stateEntry.name !== stateKey;
148        });
149    }
150
151    function getStatesByKey(state, stateKey) {
152        return state.filter(function (stateEntry) {
153            return stateEntry.name === stateKey;
154        });
155    }
156
157    document.addEventListener('DOMContentLoaded', loadFilterFields);
158    containerForm.querySelectorAll('select').forEach(function (select) {
159        select.addEventListener('change', loadFilterFields);
160    });
161
162    if (!Array.prototype.map) {
163        Array.prototype.map = function (callback, thisArg) {
164            var T, A, k;
165
166            if (this == null) {
167                throw new TypeError(" this is null or not defined");
168            }
169
170            var O = Object(this);
171            var len = O.length >>> 0;
172
173            if (typeof callback !== "function") {
174                throw new TypeError(callback + " is not a function");
175            }
176
177            if (thisArg) {
178                T = thisArg;
179            }
180
181            A = new Array(len);
182            k = 0;
183
184            while (k < len) {
185                var kValue, mappedValue;
186
187                if (k in O) {
188                    kValue = O[k];
189                    mappedValue = callback.call(T, kValue, k, O);
190                    A[k] = mappedValue;
191                }
192                k++;
193            }
194
195            return A;
196        };
197    }
198})(window, document);

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.