PageSourceSearch

https://nepremicnine.siol.net/static/custom/js/subset_picker.js?v=1.1.2

js siol.net collected 2026-09-24 08:43:55 UTC 4,185 bytes, 117 lines download raw bytes

1function initializeSubsetPicker(pickerMain, pickerSubset, data, filterFunction, beforeSetSubsetOptions=null) {
2    /*
3    * A subset picker is a pair of select elements, where the second select element
4    * is filtered based on the value of the first select element.
5    * @param pickerMain: the main select element
6    * @param pickerSubset: the subset select element
7    * @param data: the data to be filtered
8    * @param filterFunction: the function to filter the data
9    * @param beforeSetSubsetOptions: a function to be called before setting the subset options
10    */
11
12    const subsetHandler = {
13        "select": _handleElementSelect,
14        "checkbox": _handleElementCheckboxes,
15    }
16    const subsetHandlerType = pickerSubset.is("select") ? "select" : "checkbox";
17    const handlerFunction = subsetHandler[subsetHandlerType];
18
19    let initialSubset = pickerSubset.val();
20    function setSubsetOptions(value) {
21        if (beforeSetSubsetOptions) {
22            beforeSetSubsetOptions(value);
23        }
24
25        // Skip setting the options
26        if (!value)
27            return;
28        const filteredOptions = filterFunction(data, value);
29        handlerFunction(filteredOptions);
30    }
31    setSubsetOptions(pickerMain.val());
32    pickerMain.on("change", event => setSubsetOptions($(event.target).val()));
33
34    function _handleElementSelect(filteredOptions) {
35        initialSubset = pickerSubset.val()
36        
37        // Clear the current options
38        pickerSubset.empty();
39    
40        // Hide element if there are no options
41        if (filteredOptions.length === 0) {
42            pickerSubset.closest(".select-area").hide();
43            return;
44        } else {
45            pickerSubset.closest(".select-area").show();
46        }
47
48        function checkIfSelected(option) {
49            if (Array.isArray(initialSubset)) {
50                return initialSubset.includes(String(option.id))
51            }
52            return initialSubset == option.id
53        }
54
55        // Add the filtered options to the select element
56        filteredOptions.forEach(option => {
57            pickerSubset.append(`
58                <option value="${option.id}" ${checkIfSelected(option) ? "selected" : ""}>
59                    ${option.name}
60                </option>`
61            );
62        });
63
64        // Refresh the selectpicker
65        pickerSubset.selectpicker('refresh')
66    }
67
68    function _handleElementCheckboxes(filteredOptions) {
69        initialSubset = []
70        pickerSubset.find("*:checked").each(function() {
71            initialSubset.push($(this).val())
72        })
73
74        // Clear the current options
75        pickerSubset.empty();
76
77        // Hide element if there are no options
78        if (filteredOptions.length === 0) {
79            pickerSubset.closest(".widget-wrapper").hide();
80            return;
81        } else {
82            pickerSubset.closest(".widget-wrapper").show();
83        }
84
85        // Add the filtered options to the select element
86        filteredOptions.forEach(option => {
87            pickerSubset.append(
88                `<label class="custom_checkbox" for="${pickerSubset.attr("id")}_${option.id}">
89                    <input
90                        type="checkbox"
91                        name="real_estate_subtype"
92                        value="${option.id}"
93                        id="${pickerSubset.attr("id")}_${option.id}"
94                        ${initialSubset.includes(option.id) ? "checked" : ""}
95                    >
96                    <span class="checkmark"></span>
97                    ${option.name}
98                </label>`
99            );
100        });
101    }
102}
103
104// real estate type helper
105function initializeRealEstateTypePicker(pickerMain, pickerSubset, data, beforeSetSubsetOptions=null) {
106    function filterSubtype(data, value) {
107        return data.filter(option => Math.floor(option.id / 100) * 100 === parseInt(value));
108    }
109    function beforeSetSubsetOptions(value) {
110        if (!value) {
111            $(".advanced-re-subtype").hide();
112            return;
113        }
114        $(".advanced-re-subtype").show();
115    }
116    initializeSubsetPicker(pickerMain, pickerSubset, data, filterSubtype, beforeSetSubsetOptions);
117}

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.