PageSourceSearch

https://www.theparliamentmagazine.eu/_scripts/cloudsearch.js?1

js theparliamentmagazine.eu collected 2026-10-01 08:49:17 UTC 9,103 bytes, 220 lines download raw bytes

1
2(function ($, undefined) {
3    'use strict';
4
5    $.fn.isleCloudSearch = function (options) {
6
7        $.loadScript('/_scripts/moustache.js');
8
9        // async handles
10        var ajaxSearch;
11        var toDelay;
12
13        $('.js-search-form:eq(0)').each(function () {
14            var $el = $(this);
15
16            // Onload, grab the current search request vars and do the search
17            var pg = parseInt($el.find('.js-search-value-pg').val(), 10);
18            var filters = $el.find('.js-search-value-filters').val();
19            var sort = $el.find('.js-search-value-sort').val();
20            var $elTerm = $el.find('.js-search-term');
21
22            // Check a search has been submitted
23            if ($elTerm.val() != '') {
24                scrollToSearchTop('.js-search-wrap');
25                doSearch($el, isNaN(pg) ? 0 : pg, filters, sort);
26            }
27            else {
28                // Clear the loaders + show a helper message
29                var $elWrap = $el.closest('.js-search-wrap');
30                $elWrap.removeClass('is-loading is-loading-partial');
31                $elWrap.find('.js-search-initial').show();
32            }
33        });
34
35
36        $('.js-search-go').on('click', function (e) {
37            e.preventDefault();
38
39            // Submit the current search and update the url
40            var $elForm = $(this).closest('.js-search-form');
41            var $elTerm = $elForm.find('.js-search-term');
42            doSearch($elForm);
43            updateQueryString($elTerm.val(), '', '', '');
44        });
45
46        function doSearch($elForm, pg = 0, filters = '', sort = '', partial = false) {
47            clearTimeout(toDelay);
48
49            // Get the search values
50            var $elTerm = $elForm.find('.js-search-term');
51            var term = $elTerm.val();
52            var check = $elForm.find('.js-search-check').val();
53
54            // Check the loader
55            var clsLoading = (partial ? 'is-loading-partial' : 'is-loading');
56            var $elWrap = $elForm.closest('.js-search-wrap');
57            $elWrap.addClass(clsLoading);
58
59            // Remove any 'initial' helper message
60            $elWrap.find('.js-search-initial').remove();
61
62            // Define the results array and set the default error message
63            var resultsData = [];
64            var errMessage = 'There was a problem with the search, please try again later';
65
66            if (ajaxSearch) {
67                ajaxSearch.abort();
68            }
69            ajaxSearch = $.ajax({
70                url: '/_handlers/search/results.ashx',
71                type: 'post',
72                data: {
73                    check: check,
74                    term: term,
75                    pg: pg <= 0 ? 1 : pg,
76                    new: pg == 0 ? 1 : 0,
77                    filters: filters,
78                    sort: sort
79                },
80                dataType: 'json',
81                success: function (data) {
82                    resultsData = data;
83
84                    if (!data.success) {
85                        // There was a problem with the search, show error message
86                        resultsData.error_message = errMessage;
87                    }
88                },
89                error: function (xhr, textStatus, errorThrown) {
90                    resultsData.error_message = errMessage;
91                },
92                complete: function () {
93
94                    // Output the filters + results to the page
95                    renderTemplate($elWrap.find('.js-search-results'), '#templateSearch', resultsData, function () {
96
97                        // Reverse the year filters
98                        var $yearFilters = $('.js-search-filter-year > p');
99                        var $yearItems = $yearFilters.children('a');
100                        $yearFilters.append($yearItems.get().reverse());
101                        $yearItems.after(" ") // Add a space to ensure the items aren't flush
102
103                        // Set the correct sort value
104                        $('.js-search-sort').val(sort);
105
106
107                        // Bind the filter links
108                        $('.js-search-filter,.js-search-filter-remove').on('click', function (e) {
109                            e.preventDefault();
110
111                            // Show the loader and take the user to the top of the page
112                            $elWrap.addClass('is-loading-partial');
113                            scrollToSearchTop();
114
115                            var filter = $(this).attr('data-type') + "~" + $(this).attr('data-value') + "|";
116
117                            // Check if filter is being added or removed
118                            if (filters.indexOf(filter) < 0) {
119                                if ($(this).hasClass('js-search-filter')) {
120                                    filters += filter;
121                                }
122                            }
123                            else if ($(this).hasClass('js-search-filter-remove')) {
124                                filters = filters.replace(filter, '');
125                            }
126
127                            // With a delay, do the filtering
128                            clearTimeout(toDelay);
129                            toDelay = setTimeout(function () {
130                                $elTerm.val(term);
131                                doSearch($elForm, 0, filters, sort, true);
132                                updateQueryString(term, 0, filters, sort);
133                            }, 500);
134                        });
135
136
137                        // Bind the paging links
138                        $('.js-search-paging').on('click', function (e) {
139                            e.preventDefault();
140
141                            // Show the loader and take the user to the top of the page
142                            $elWrap.addClass('is-loading-partial');
143                            scrollToSearchTop();
144
145                            // Check if prev or next
146                            var dir = $(this).data('pg-dir');
147
148                            // With a delay, do the paging
149                            clearTimeout(toDelay);
150                            toDelay = setTimeout(function () {
151                                $elTerm.val(term);
152                                var newPg = dir == 'prev' ? resultsData.result.pg - 1 : resultsData.result.pg + 1;
153                                doSearch($elForm, newPg, filters, sort, true);
154                                updateQueryString(term, newPg, filters, sort);
155                            }, 500);
156                        });
157
158
159                        // Bind the sorting
160                        $('.js-search-sort').on('change', function () {
161                            var sortNew = $(this).val();
162
163                            // Show the loader
164                            $elWrap.addClass('is-loading-partial');
165
166                            // With a delay, do the paging
167                            clearTimeout(toDelay);
168                            toDelay = setTimeout(function () {
169                                $elTerm.val(term);
170                                doSearch($elForm, 0, filters, sortNew, true);
171                                updateQueryString(term, 0, filters, sortNew);
172                            }, 500);
173                        });
174
175                        // Clear the loaders
176                        $elWrap.removeClass('is-loading is-loading-partial');
177
178                        // Filters toggle class for mobile
179                        $('.ss-filters .news-title').on('click', function () {
180                            $('.ss-filters').toggleClass('on');
181                        });
182
183                    });
184
185                }
186            });
187
188        }
189
190        function updateQueryString(term, pg, filters, sort) {
191            window.history.pushState("", "", "/search.htm?search=" + term + "&filters=" + filters + "&pg=" + pg + "&sort=" + sort);
192        }
193
194        function scrollToSearchTop(target = '.js-search-results') {
195            var offsetTop = $(target).offset().top;
196            $('html, body').animate({ scrollTop: (offsetTop - 20) + 'px' });
197        }
198
199        /* Render a mustache js template with the provided data */
200        function renderTemplate($target, template, data, callback) {
201            if (!$target || !template) { return; }
202            if (typeof Mustache === 'undefined' || !Mustache) {
203                setTimeout(function () { renderTemplate($target, template, data, callback); }, 150);
204            }
205            else {
206                var tmpl = $(template).html();
207                if (tmpl !== "") {
208                    Mustache.parse(tmpl);
209                    $target.html(Mustache.render(tmpl, data));
210                }
211
212                if (typeof callback == 'function') {
213                    callback();
214                }
215            }
216        }
217
218    };
219
220}(jQuery));

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.