PageSourceSearch

https://added.gov.ae/assets/DED/js/search.js?v=02102026084254

js added.gov.ae collected 2026-10-02 04:43:50 UTC 15,840 bytes, 445 lines download raw bytes

1var filters = [];
2var pageNo = 1;
3var pageSize = 6;
4var culture = $("#culture").val();
5var filterObj = {};
6var hasResult = false;
7
8$(document).ready(function () {
9
10    $('.bannerSearchBtn').on('click', function () {
11        var keyword = $('.lookingSelect').val();
12        var contentIds = $('.contentType').val();
13
14        if ($(contentIds)[0] == "All") contentIds.shift()
15
16        var url = (isRTL ? '/ar-AE' : '/en') + '/search-results';
17        if (keyword && keyword !== "Any") {
18            url += '?keyword=' + keyword;
19        }
20        var contentArray = contentIds + "";
21        if (contentArray) {
22            if (keyword && keyword !== "Any") {
23                url += '&contentIds=' + contentArray;
24            }
25            else {
26                url += '?contentIds=' + contentArray;
27            }
28        }
29
30        window.location.href = url;
31    });
32
33    filterObj = getDataSet();
34    if (filterObj) {
35        if (filterObj.page == "searchResults") {
36                getSearchResultListing(filterObj);
37                setFilters();
38        }
39    }
40
41    function getDataSet() {
42        var query = getQueryParams();
43        filterObj = {
44            page: $('#page').val(),
45            ownerIds: query.ownerIds,
46            contentIds: query.contentIds,
47            tagIds: query.tagIds,
48            keyword: HtmlSanitizer.SanitizeHtml(query.keyword),
49            sortby: query.sortby
50        }
51        return filterObj;
52    }
53
54    function getSearchResultListing(obj) {
55        let data = { ownerIds: obj.ownerIds, contentIds: obj.contentIds, tagIds: obj.tagIds, keyword: obj.keyword, sortBy: obj.sortby, pageNo: pageNo, pageSize: pageSize, culture: culture };
56            $("#skeyrequired").css("display", "none");
57            getSearchResultAPI(data)
58            .then(response => {
59                if (response != "" && response != undefined && response != null) {
60                    if (response.Items.length > 0) {
61                        hasResult = true;
62                        var html = _searchResultTemplate(response.Items);
63                        $('.searchResultsFound .searchList').html('');
64                        $('.searchResultsFound .searchList').html(html);
65                        $('.searchResultsFound .resultNumber b').text(response.TotalRecordCount);
66                        var showingCaption = $('.searchResultsFound .searchResultShowing').attr('data-title');
67                        showingCaption = showingCaption.replace("{0}", response.PageRecordTo);
68                        showingCaption = showingCaption.replace("{1}", response.TotalRecordCount);
69                        $('.searchResultsFound .searchResultShowing').html('<h6><span class="resizable">' + showingCaption + '</span></h6>');
70                        animateElements();
71
72                        highlightKeyword(obj.keyword);
73
74                        $('html, body').animate({
75                            scrollTop: $('.searchResultsFound').offset().top - headerHeight - 20
76                        }, 600);
77
78                        if (hasResult) {
79                            if (response.TotalRecordCount > response.PageSize) {
80                                $('.searchResultPagination .general-pagination').show();
81                                $(".Pager").ASPSnippets_Pager({
82                                    ActiveCssClass: "active",
83                                    PagerCssClass: "pager",
84                                    PageIndex: response.PageNo,
85                                    PageSize: response.PageSize,
86                                    RecordCount: response.TotalRecordCount
87                                });
88                            }
89                            else {
90                                $('.general-pagination').hide();
91                            }
92                        }
93
94                        setTimeout(function () {
95                            $(".page").each(function () {
96                                $(this).bind("click", function () {
97                                    pageNo = parseInt($(this).attr('page'));
98                                    var obj = getDataSet();
99                                    if (obj) {
100                                        getSearchResultListing(obj);
101                                    }
102                                })
103                            });
104                        }, 800);
105                    }
106                    else {
107                        noRecordFound(response);
108                    }
109                }
110            });
111    }
112
113    $('.filter-owner input[type="checkbox"]').change(function () {
114        applyFilter();
115    });
116
117    $('.filter-content-type input[type="checkbox"]').change(function () {
118        applyFilter();
119    });
120
121    $('.filter-tags input[type="checkbox"]').change(function () {
122        applyFilter();
123    });
124
125    $("#filterHeaderSearch").on("click", function () {
126        applyFilter();
127    });
128
129    $('body').on('click', '.filterBadges ul li a.clear-filter', function () {
130        var type = $(this).attr('data-type');
131        if (type) {
132            if (type == "keyword") {
133                $('#searchResult').val('');
134                $(this).parent().remove();
135            }
136            else if (type == "owner") {
137                var ownerId = $(this).attr('data-owner-id');
138                if (ownerId) {
139                    $(this).parent().remove();
140                    $('#' + ownerId).prop('checked', false);
141                }
142            }
143            else if (type == "content") {
144                var contentId = $(this).attr('data-content-id');
145                if (contentId) {
146                    $(this).parent().remove();
147                    $('#' + contentId).prop('checked', false);
148                }
149            }
150            else if (type == "tag") {
151                var tagId = $(this).attr('data-tag-id');
152                if (tagId) {
153                    $(this).parent().remove();
154                    $('#' + tagId).prop('checked', false);
155                }
156            }
157            applyFilter();
158        }
159    });
160
161    $('.searchSortBy').on('change', function () {
162        applyFilter();
163    });
164
165    //checked All option in content Type selectbox if all options selected
166
167    $("body").on("click", ".select2-results__option", () => {
168        let isAllSelected = true;
169        if ($(".select2-selection__rendered").length > 0) {
170            $(".select2-results__options li:not(:first-child)").each(function (index, element) {
171                if (!$(element).hasClass("select2-results__option--selected")) {
172                    isAllSelected = false;
173                }
174            })
175            if (isAllSelected) {
176                $(".select2-results__options li:first").addClass("select2-results__option--selected").trigger("change");
177                maxChild();
178                $(".select2-selection__rendered").addClass("first-enable");
179            }
180            else {
181                $(".select2-results__options li:first").removeClass("select2-results__option--selected").trigger("change");
182                //maxChild();
183            }
184        }
185    })
186
187    $('.searchResultForm').keypress((e) => {
188        if (e.which === 13) {
189            applyFilter();
190        }
191    });
192
193    $('.searchResultForm').on('keyup', function (e) {
194        e.preventDefault();
195        if (e.which === 13) {
196            applyFilter();
197        }
198    });
199});
200
201function applyFilter() {
202    var sortBy = $('select[name=sortby]').val();
203    var ownerIDs = $(".filter-owner input:checkbox:checked").map(function () {
204        return $(this).attr('id');
205    }).get();
206
207    var contentIDs = $(".filter-content-type input:checkbox:checked").map(function () {
208        return $(this).attr('id');
209    }).get();
210
211    var tagIDs = $(".filter-tags input:checkbox:checked").map(function () {
212        return $(this).attr('id');
213    }).get();
214
215    var url = (isRTL ? '/ar-AE' : '/en') + '/search-results';
216    var keyword = $('#searchResult').val();
217
218    if (keyword) {
219        keyword = keyword.replace(/(<([^>]+)>)/ig, "");
220        url += '?keyword=' + keyword;
221    }
222
223    if (ownerIDs && ownerIDs.length > 0) {
224        var ownerArray = ownerIDs + "";
225        if (keyword) {
226            url += '&ownerIds=' + ownerArray;
227        }
228        else {
229            url += '?ownerIds=' + ownerArray;
230        }
231    }
232
233    if (contentIDs && contentIDs.length > 0) {
234        var contentArray = contentIDs + "";
235        if (keyword) {
236            url += '&contentIds=' + contentArray;
237        }
238        else {
239            if (ownerIDs && ownerIDs.length > 0) {
240                url += '&contentIds=' + contentArray;
241            }
242            else {
243                url += '?contentIds=' + contentArray;
244            }
245        }
246    }
247
248    if (tagIDs && tagIDs.length > 0) {
249        var tagArray = tagIDs + "";
250        if (keyword) {
251            url += '&tagIds=' + tagArray;
252        }
253        else {
254            if ((ownerIDs && ownerIDs.length > 0) || (contentIDs && contentIDs.length > 0)) {
255                url += '&tagIds=' + tagArray;
256            }
257            else {
258                url += '?tagIds=' + tagArray;
259            }
260        }
261    }
262
263    if (sortBy) {
264        if (keyword || (contentIDs && contentIDs.length > 0) || (ownerIDs && ownerIDs.length > 0) || (tagIDs && tagIDs.length > 0)) {
265            url += '&sortby=' + sortBy;
266        }
267        else {
268            url += '?sortby=' + sortBy;
269        }
270    }
271
272    window.location.href = url;
273}
274
275function setFilters() {
276    
277    var query = getQueryParams();
278    filterObj = {
279        page: $('#page').val(),
280        ownerIds: query.ownerIds,
281        contentIds: query.contentIds,
282        tagIds: query.tagIds,
283        keyword: HtmlSanitizer.SanitizeHtml(query.keyword),
284        sortby: query.sortby
285    }
286
287    if (filterObj.keyword) {
288        $('#searchResult').val(filterObj.keyword);
289        $('.filterBadges nav ul').html('');
290        $('.filterBadges nav ul').append('<li><a href="javascript:" data-type="keyword" class="badge badge-offWhite clear-filter"><span class="resizable">' + HtmlSanitizer.SanitizeHtml(filterObj.keyword) + '</span><i class="icon-close"></i></a></li>');
291    }
292
293    if (filterObj.ownerIds) {
294        var ownerIds = filterObj.ownerIds.split(',');
295        if (ownerIds) {
296            $.each(ownerIds, function (ind, val) {
297                $('#' + val).prop('checked', true);
298            });
299
300        }
301    }
302
303    if (filterObj.contentIds) {
304        var contentIds = filterObj.contentIds.split(',');
305        if (contentIds) {
306            $.each(contentIds, function (ind, val) {
307                $('#' + val).prop('checked', true);
308            });
309
310        }
311    }
312
313    if (filterObj.tagIds) {
314        var tagIds = filterObj.tagIds.split(',');
315        if (tagIds) {
316            $.each(tagIds, function (ind, val) {
317                $('#' + val).prop('checked', true);
318            });
319
320        }
321    }
322
323    var ownerIDs = $(".filter-owner input:checkbox:checked").map(function () {
324        return { id: $(this).attr('id'), value: $(this).val() };
325    }).get();
326
327    var contentIDs = $(".filter-content-type input:checkbox:checked").map(function () {
328        return { id: $(this).attr('id'), value: $(this).val() };
329    }).get();
330
331    var tagIDs = $(".filter-tags input:checkbox:checked").map(function () {
332        return { id: $(this).attr('id'), value: $(this).val() };
333    }).get();
334
335    if (ownerIDs) {
336        let template = ``;
337        $.each(ownerIDs, function (ind, val) {
338            template += `<li><a href="javascript:" data-type="owner" data-owner-id="${val.id}" class="badge badge-offWhite clear-filter"><span class="resizable">${val.value}</span><i class="icon-close"></i></a></li>`;
339        });
340        $('.filterBadges nav ul').append(template);
341    }
342
343    if (contentIDs) {
344        let template = ``;
345        $.each(contentIDs, function (ind, val) {
346            template += `<li><a href="javascript:" data-type="content" data-content-id="${val.id}" class="badge badge-offWhite clear-filter"><span class="resizable">${val.value}</span><i class="icon-close"></i></a></li>`;
347        });
348        $('.filterBadges nav ul').append(template);
349    }
350
351    if (tagIDs) {
352        let template = ``;
353        $.each(tagIDs, function (ind, val) {
354            template += `<li><a href="javascript:" data-type="tag" data-tag-id="${val.id}" class="badge badge-offWhite clear-filter"><span class="resizable">${val.value}</span><i class="icon-close"></i></a></li>`;
355        });
356        $('.filterBadges nav ul').append(template);
357    }
358
359    if (filterObj.sortby) {
360        $('.searchSortBy').val(filterObj.sortby).change();
361    }
362}
363
364function getQueryParams() {
365    const paramArr = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
366    const params = {};
367    paramArr.map(param => {
368        var [key, val] = param.split('=');
369        val = decodeURIComponent((val + '').replace(/\+/g, '%20'));
370        const stripHTMLTags = str => str.replace(/<[^>]*>/g, '');
371        params[key] = stripHTMLTags(val);
372    });
373    return params;
374}
375
376function _searchResultTemplate(data) {
377    let _template = ``;
378    $.each(data, function (ind, val) {
379        let _description = ``;
380        if (val.Description) {
381            _description = `<p class="lead"><span class="resizable">${val.Description}</span></p>`;
382        }
383        _template += `<div class="searchItem animate" data-animation="fadeInUp" data-duration="300">
384                      <h4><a href="${val.DetailPageUrl}"><span class="resizable">${val.Title}</span></a></h4>
385                            ${_description}
386                        </div>`;
387    });
388    return _template;
389}
390
391function setupPagination(pn, ps, rc) {
392    $(".Pager").ASPSnippets_Pager({
393        ActiveCssClass: "active",
394        PagerCssClass: "pager",
395        PageIndex: pn,
396        PageSize: ps,
397        RecordCount: rc
398    });
399}
400
401function highlightKeyword(keyword) {
402    if (!keyword) return;
403
404    const resultsContainer = document.querySelector('.searchList');
405    const regex = new RegExp(`(${keyword.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')})`, 'gi');
406
407    // Walk through all text nodes
408    const walker = document.createTreeWalker(
409        resultsContainer,
410        NodeFilter.SHOW_TEXT,
411        null,
412        false
413    );
414
415    let node;
416    const nodesToProcess = [];
417
418    while (node = walker.nextNode()) {
419        if (node.nodeValue.trim()) {
420            nodesToProcess.push(node);
421        }
422    }
423
424    nodesToProcess.forEach(textNode => {
425        const parent = textNode.parentNode;
426        if (parent.tagName === 'SCRIPT' || parent.tagName === 'STYLE') return;
427
428        const text = textNode.nodeValue;
429        const newHtml = text.replace(regex, '<span class="highlight">$&</span>');
430
431        if (newHtml !== text) {
432            const newSpan = document.createElement('span');
433            newSpan.innerHTML = newHtml;
434            parent.replaceChild(newSpan, textNode);
435        }
436    });
437}
438
439function noRecordFound(response) {
440    $('.searchResultsFound .searchList').html('');
441    $('.searchResultsFound .resultNumber b').text('0');
442    $('.searchResultsFound .general-pagination').hide();
443    $('.searchResultsFound .searchList').html('<h3 style="justify-content:center"><span class="resizable">' + $('#noRecordFound').val() + '</span></h3>');
444    $('.searchResultsFound .searchResultShowing').html('');
445}

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.