PageSourceSearch

https://adra.gov.ae/assets/ADRA/js/search.js?v=30092026051055

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

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.