PageSourceSearch

https://syariahcourt.gov.sg/-/media/Base-Themes/SearchTheme/Scripts/component-search-url.js

js syariahcourt.gov.sg collected 2026-09-25 00:35:36 UTC 15,182 bytes, 346 lines download raw bytes

1
2/**
3 * Creates instance of urlHelperModel
4 * @module searchUrl
5 * @param  {jQuery} $ Instance of jQuery
6 * @param  {Document} document dom document object
7 * @return {Object} list of methods for working with search url
8*/
9XA.component.search.url = (function ($, document) {
10    /**
11     * 
12     * @param {String} data 
13     * @returns {String}
14     */
15    var clearIdData = function (data) {
16        data = data + "";
17        var parts = data.split("||"), urlData = [], details;
18        _.each(parts, function (part) {
19            details = part.split('|');
20            if (_.contains(part, '|') && details.length === 3) {
21                urlData.push(details[1] + '|' + details[2]);
22            } else {
23                urlData.push(part);
24            }
25        });
26        return urlData.join("||");
27    };
28
29    /**
30    * @name module:searchUrl.UrlHelperModel
31    * @constructor
32    * @augments Backbone.Model
33    */
34    var UrlHelperModel = Backbone.Model.extend(
35        /** @lends module:searchUrl.UrlHelperModel.prototype **/
36        {
37            /**
38             * creates url for search components
39             * @param {Object} dataProp component properties stored in data attribute
40             * @param {String} signature component signature
41             * @returns {String} created url
42             * @memberof searchUrl.UrlHelperModel
43             * @alias searchUrl.UrlHelperModel#createSearchUrl
44             */
45            createSearchUrl: function (dataProp, signature) {
46                var url = this.setEndpoint(dataProp.endpoint);
47
48                url += (dataProp.l) ? "&l=" + dataProp.l : "";  //language
49                url += (dataProp.s) ? "&s=" + dataProp.s : "";  //scope
50                url += (dataProp.itemid) ? "&itemid=" + dataProp.itemid : "";
51                url += this.getFacetParams(dataProp, signature);
52                url = this.fixUrl(url);
53
54                return url;
55            },
56            /**
57             * creates url for search components for redirect
58             * @param {String} redirectUrl target url
59             * @param {Object} query query for redirect
60             * @param {String} targetSignature target component signature
61             * @param {String} signature component signature
62             * @returns {String} created url
63             * @memberof searchUrl.UrlHelperModel
64             * @alias searchUrl.UrlHelperModel#createSearchUrl
65             */
66            createRedirectSearchUrl: function (redirectUrl, query, signature, targetSignature) {
67                var originalHash = XA.component.search.query.get("hashObj"),
68                    updatedQuery = {},
69                    hash = {},
70                    index = 0,
71                    clearParam,
72                    paramSignature,
73                    param,
74                    url;
75
76                if (signature !== "") {
77                    //if signature is provided, then filter only params with the same signature
78                    for (param in originalHash) {
79                        clearParam = param.substring(param.indexOf('_') + 1);
80                        paramSignature = param.substr(0, param.indexOf('_'));
81                        if (paramSignature === signature) {
82                            hash[param] = originalHash[param];
83                        }
84                    }
85                } else {
86                    hash = originalHash;
87                }
88
89                query = $.extend({}, hash, query);
90
91                if (targetSignature !== "") {
92                    //if target signature is provided, replace signature with target signature in all params
93                    for (param in query) {
94                        clearParam = param.substring(param.indexOf('_') + 1);
95                        paramSignature = param.substr(0, param.indexOf('_'));
96                        if (paramSignature === signature) {
97                            updatedQuery[targetSignature + "_" + clearParam] = query[param];
98                        } else if (paramSignature === targetSignature) {
99                            updatedQuery[param] = query[param];
100                        }
101                    }
102                } else {
103                    updatedQuery = query;
104                }
105
106                url = this.setEndpoint(redirectUrl + "#");
107
108                _.each(updatedQuery, function (item, key) {
109                    url += (index === 0 ? "" : "&") + key + "=" + item;
110                    index++;
111                });
112
113                return url;
114            },
115            /**
116             * creates predictive url for search components
117             * @param {String} endpoint target url
118             * @param {Object} query query for redirect
119             * @param {String} dataProp target component signature
120             * @memberof searchUrl.UrlHelperModel
121             * @alias searchUrl.UrlHelperModel#createPredictiveSearchUrl
122             * @returns {String} url predictive url
123             */
124            createPredictiveSearchUrl: function (endpoint, dataProp, query
124) {
125                var url = this.setEndpoint(endpoint);
126
127                url += "?q=" + encodeURIComponent(query);
128                url += "&v=" + dataProp.v;
129                url += "&p=" + dataProp.p;
130                url += (dataProp.l) ? "&l=" + dataProp.l : "";
131                url += (dataProp.s) ? "&s=" + dataProp.s : "";
132                url += (dataProp.itemid) ? "&itemid=" + dataProp.itemid : "";
133
134                return url;
135            },
136            /**
137             * creates facet url for search components
138             * @param {Object} query query for redirect
139             * @param {String} dataProp target component signature
140             * @memberof searchUrl.UrlHelperModel
141             * @alias searchUrl.UrlHelperModel#createFacetUrl
142             * @returns {String} url for facets
143             */
144            createFacetUrl: function (dataProp, query) {
145                var url = this.setEndpoint(dataProp.endpoint);
146
147                url += "?f=" + dataProp.f.toLowerCase();
148                url += (dataProp.s) ? "&s=" + dataProp.s : "";
149                url += (dataProp.l) ? "&l=" + dataProp.l : "";
150                url += (query) ? "&q=" + encodeURIComponent(query) : "";
151
152                url += this.getFacetParams(dataProp);
153
154                return url;
155            },
156            /**
157             * creates facet url for search components when enabled multifacet search
158             * @param {String} dataProp target component signature
159             * @param {Array} facetList list of existing facets
160             * @param {String} sig component signature
161             * @param {String} itemId component id
162             * @memberof searchUrl.UrlHelperModel
163             * @alias searchUrl.UrlHelperModel#createMultiFacetUrl
164             * @returns {String} url for multi facet search
165             */
166            createMultiFacetUrl: function (dataProp, facetList, sig, itemId) {
167                var url = this.setEndpoint(dataProp.endpoint);
168
169                url += "?f=" + facetList.join("||").toLowerCase();
170                url += (dataProp.s) ? "&s=" + dataProp.s : "";
171                url += (dataProp.l) ? "&l=" + dataProp.l : "";
172                url += itemId ? "&itemid=" + itemId : "";
173
174                url += this.getFacetParams(dataProp, sig);
175
176                url += "&sig=" + encodeURIComponent(sig);
177
178                return url;
179            },
180            /**
181             * Clears hash parameters
182             * @param {String} dataProperties component properties
183             * @param {Array} properties 
184             * @memberof searchUrl.UrlHelperModel
185             * @alias searchUrl.UrlHelperModel#clearUrlParams
186             * @returns {Array} array with cleared properties
187             */
188            clearUrlParams: function (dataProperties, properties) {
189                var facetName = dataProperties.f.toLowerCase(),
190                    hash = {};
191
192                delete properties[facetName];
193                delete hash[facetName];
194                XA.component.search.query.updateHash(hash);
195
196                return properties;
197            },
198            /**
199             * Returns url with facet parameters
200             * @param {Object} dataProp component properties
201             * @param {String} searchResultsSignature signature of search result component
202             * @memberof searchUrl.UrlHelperModel
203             * @alias searchUrl.UrlHelperModel#getFacetParams
204             * @returns {String} url with facet parameters
205             */
206            getFacetParams: function (dataProp, searchResultsSignature) {
207                var url = "",
208                    clearFacetName,
209                    facetSignature,
210                    skipParams = ['endpoint', 'l', 's', 'e', 'f', 'sig', 'itemid'], //params which will be skipped while adding facet params
211                    specialParams = ['g', 'o', 'q', 'p', 'e', 'v']; //params which are not facets but can have signature
212
213
214                if (dataProp.hasOwnProperty("sig")) {
215                    url += "&sig=" + encodeURIComponent(dataProp["sig"]);
216                }
217
218                for (facet in dataProp) {
219                    if (skipParams.indexOf(facet) === -1 && facet && dataProp[facet]) {
220                        clearFacetName = facet.substring(facet.indexOf('_') + 1);
221                        facetSignature = facet.substr(0, facet.indexOf('_'));
222                        if (searchResultsSignature === facetSignature && specialParams.indexOf(clearFacetName) === -1) {
223                            url += "&" + clearFacetName + "=" + encodeURIComponent(clearIdData(dataProp[facet]));
224                        }
225                    }
226                }
227
228                //gets params that are not facets but can have signature
229                url = this.getSpecialParams(dataProp, searchResultsSignature, specialParams, url);
230
231                return url;
232            },
233            /**
234             * Returns url with special parameters
235             * @param {Object} dataProp component properties
236             * @param {String} searchResultsSignature signature of search result component
237             * @param {String} specialParams special parameters
238             * @param {String} url url for special parameters
239             * @memberof searchUrl.UrlHelperModel
240             * @alias searchUrl.UrlHelperModel#getSpecialParams
241             * @returns {String} url with special parameters
242             */
243            getSpecialParams: function (dataProp, searchResultsSignature, specialParams, url) {
244                var param,
245                    paramValue,
246                    clearParamName,
247                    paramSignature;
248
249                for (param in dataProp) {
250                    clearParamName = param.substring(param.indexOf('_') + 1);
251                    paramSignature = param.substr(0, param.indexOf('_'));
252                    if (specialParams.indexOf(clearParamName) !== -1) {
253                        paramValue = typeof dataProp[param] !== "undefined" ? dataProp[param] : "";
254                        if (searchResultsSignature === paramSignature) {
255                            url += "&" + clearParamName + "=" + encodeURIComponent(paramValue);
256                        }
257                    }
258                }
259
260                return url;
261            },
262            /**
263             * Returns url POI content
264             * @param {Object} dataProp component properties
265             * @param {String} poiId POI ID
266             * @param {String} poiVariantId POI variant ID
267             * @memberof searchUrl.UrlHelperModel
268             * @alias searchUrl.UrlHelperModel#getSpecialParams
269             * @returns {String} url with poi parameters
270             */
271            createGetPoiContentUrl: function (dataProp, poiId, poiVariantId) {
272                var url = this.setEndpoint(dataProp.endpoint);
273                url += "/" + poiVariantId + "/" + poiId;
274                return url;
275            },
276            /**
277             * Returns url with geo POI content
278             * @param {Object} dataProp component properties
279             * @param {String} poiId POI ID
280             * @param {String} poiVariantId POI variant ID
281             * @param {String} coordinates POI coordinates
282             * @param {String} units unit of coordinates
283             * @param {String} itemId context item ID
284             * @memberof searchUrl.UrlHelperModel
285             * @alias searchUrl.UrlHelperModel#createGetGeoPoiContentUrl
286             * @returns {String} url with geo poi content parameters
287             */
288            createGetGeoPoiContentUrl: function (dataProp, poiId, poiVariantId, coordinates, units, itemId) {
289                var url = this.setEndpoint(dataProp.endpoint);
290                url += "/" + poiVariantId + "/" + poiId + "/" + coordinates + "/" + units + "/" + itemId;
291                return url;
292            },
293            /**
294             * Returns url with geo POI content
295             * @param {string} url url for site
296             * @param {String} siteName site name
297             * @memberof searchUrl.UrlHelperModel
298             * @alias searchUrl.UrlHelperModel#createSiteUrl
299             * @returns {String} site url
300             */
301            createSiteUrl: function (url, siteName) {
302                if (typeof siteName !== "undefined" && siteName !== null && siteName !== "") {
303                    return url + "&sc_site=" + siteName;
304                }
305                return url;
306            },
307            /**
308             * Returns url with endpoint
309             * @param {string} endpoint endpoint parameter from component properties
310             * @memberof searchUrl.UrlHelperModel
311             * @alias searchUrl.UrlHelperModel#setEndpoint
312             * @returns {String} url with endpoint
313             */
314            setEndpoint: function (endpoint) {
315                var url = window.location.origin;
316
317                if (endpoint.startsWith("http")) {
318                    return endpoint;
319                }
320
321                url += endpoint;
322                return url.replace(/([^:]\/)\/+/g, "$1");
323            },
324            /**
325             * Fixes url with special characters
326             * @param {string} url url string for fixing
327             * @memberof searchUrl.UrlHelperModel
328             * @alias searchUrl.UrlHelperModel#fixUrl
329             * @returns {String} url with endpoint
330             */
331            fixUrl: function (url) {
332                var index;
333
334                url = url.replace(/[?]/g, "&");
335                index = url.indexOf("&");
336                url = url.substr(0, index) + "?" + url.substr(index + 1)
337
338                return url;
339            }
340        });
341
342    var urlHelperModel = new UrlHelperModel();
343
344    return urlHelperModel;
345
346}(jQuery, 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.