PageSourceSearch

https://www.norrtalje.se/Static/js/Abou.linknavbox.js?v=639237714360000000

js norrtalje.se collected 2026-09-24 22:13:56 UTC 14,268 bytes, 319 lines download raw bytes

1// Example of js-plugin; How to extend the Abou namespace
2;(function (window, document, Abou, $, undefined) {
3
4    /*
5
6    NOTE: 2014-11-11, This file should be deleted eventually. It's kept for now while the sort order adjuster is to be reimplemented.
7
8    */
9
10
11    // Custom namespace (plugin)
12    Abou.linknavbox = (function () {
13
14        var showMoreItemsStep = 3;
15        var visibleItemsPropName = "visibleItems";
16        var disabledClass = "disabled";
17        var matchClass = "match";
18        var nomatchClass = "nomatch";
19        var spinnerContainerSelector = ".spinnerContainer";        
20        
21        //var initVisibleItems = function ($listContainer) {
22        //    //init value to visible items. These are determined by css.
23        //    var visibleItemCount = $listContainer.find(".pageList > li:visible").length;
24
25        //    if ($(window).width() < 768) {
26        //        //in mobile mode the lists start collapsed. Set visible items programmatically.
27        //        visibleItemCount = 3;
28        //    }
29
30        //    $listContainer.data(visibleItemsPropName, visibleItemCount);
31        //};
32
33        
34        var setVisibleItems = function ($listContainer) {
35            // number of visible li items
36            var itemsToShowCount = $listContainer.data(visibleItemsPropName);
37            // all li items that belongs to .pageList ul
38            var allItems = $listContainer.find(".pageList > li");
39            // all li items that have a match class and belongs to .pageList ul
40            var allMatchItems = $listContainer.find(".pageList > li." + matchClass);
41
42            // if we have li's with match class after filtering
43            var itemsToShow;
44            if (allMatchItems.length > 0) {
45                // hide "visa fler" if we have less or equal filter results than items to show
46                if (allMatchItems.length <= itemsToShowCount) {
47                    allMatchItems.addClass("visible");
48                    $listContainer.find(".showMore").hide();
49                } else {
50                    allItems.removeClass("visible");
51                    itemsToShow = allMatchItems.slice(0, itemsToShowCount);
52                    itemsToShow.addClass("visible");
53                    
54                    // show "visa fler" cause we have more results than items to show
55                    $listContainer.find(".showMore").css("display", "inline-block");
56                }
57            } else {
58                // if we weren't able to find any results after filtering, hide "visa fler"
59                if (itemsToShowCount >= allItems.length || $listContainer.find(".pageList > li." + nomatchClass).length === allItems.length) {
60                    allItems.addClass("visible");
61                    $listContainer.find(".showMore").hide();
62                } else {
63                    itemsToShow = allItems.slice(0, itemsToShowCount);
64                    itemsToShow.addClass("visible");
65                    var itemsToHide = allItems.slice(itemsToShowCount, allItems.length);
66                    itemsToHide.removeClass("visible");
67
68                    // show "visa fler" cause we have more results than items to show
69                    $listContainer.find(".showMore").css("display", "inline-block");
70                }
71            }
72        };
73
74        //var showMore = function(event) {
75        //    var $button = $(this);
76        //    var $listContainer = $button.closest(".pageListWrapper");
77
78        //    //update items to show count
79        //    var currentToShow = parseInt($listContainer.data(visibleItemsPropName));
80        //    var newToShow = currentToShow + showMoreItemsStep;
81        //    $listContainer.data(visibleItemsPropName, newToShow);
82
83        //    setVisibleItems($listContainer);
84        //    event.preventDefault();
85        //};
86        
87        var spinnerOpts = {
88            lines: 15, // The number of lines to draw
89            length: 5, // The length of each line
90            width: 2, // The line thickness
91            radius: 5, // The radius of the inner circle
92            corners: 1, // Corner roundness (0..1)
93            rotate: 0, // The rotation offset
94            direction: 1, // 1: clockwise, -1: counterclockwise
95            color: '#333', // #rgb or #rrggbb or array of colors
96            speed: 1, // Rounds per second
97            trail: 60, // Afterglow percentage
98            shadow: false, // Whether to render a shadow
99            hwaccel: false, // Whether to use hardware acceleration
100            className: 'spinner', // The CSS class to assign to the spinner
101            zIndex: 2e9, // The z-index (defaults to 2000000000)
102            top: 'auto', // Top position relative to parent in px
103            left: 'auto' // Left position relative to parent in px
104        };
105
106        var showSpinner = function($itemContainer) {
107            var $spinner = $itemContainer.find(spinnerContainerSelector);
108            $spinner.spin(spinnerOpts);
109        };
110
111        var enableItemContainer = function ($itemContainer) {
112            var $spinner = $itemContainer.find(spinnerContainerSelector);
113            $spinner.spin(false);
114
115            $itemContainer.removeClass(disabledClass);
116        };
117        
118        // adapted from http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/
119        var sortElements = function ($listContainer) {
120            //listContainer is a wrapper element, we need the ul-list
121            var $ulList = $listContainer.find(".pageList");
122            
123            var listitemsArray = $ulList.children('li').get();
124            listitemsArray.sort(function (a, b) {
125                var compA = parseFloat( $(a).find(".pageValue").text() );
126                var compB = parseFloat( $(b).find(".pageValue").text() );
127                return (compA < compB) ? 1 : (compA > compB) ? -1 : 0;
128            });
129            $.each(listitemsArray, function (idx, itm) { $ulList.append(itm); });
130        };
131        
132        
133        var adjustRelevance = function (event, $button, urlInputIdentifier) {
134            var $itemContainer = $button.closest(".relevanceContainer");
135            var $listContainer = $itemContainer.closest(".pageListWrapper");
136
137            if ($itemContainer.hasClass(disabledClass)) {
138                return null; //abort click event
139            }
140            //disable control for clicks until method returns
141            $itemContainer.addClass(disabledClass);
142            showSpinner($itemContainer);
143
144            var id = $itemContainer.data("pageid");
145            var url = $listContainer.find(urlInputIdentifier).val();            
146            var dataObject = {
147                pageId: id
148            };
149
150            var jqxhr = $.post(url, dataObject)
151                .done(function (response, textStatus, jqXHR) {
152
153                    $itemContainer.find(".pageValue").html(response.relevance);
154                    $itemContainer.closest("li").attr("data-pageValue", response.relevance);
155
156                    sortElements($listContainer);
157                    setVisibleItems($listContainer);
158                    enableItemContainer($itemContainer);
159                })
160                .fail(function (jqXHR, textStatus, errorThrown) {
161                    
162                    enableItemContainer($itemContainer);
163
164                    alert("Något gick snett. Försök igen om en liten stund, kontakta systemansvarig om felet kvarstår.");
165                });
166
167            event.preventDefault();
168        };
169
170        var increaseRelevance = function (event) {
171            var $button = $(this);
172            adjustRelevance(event, $button, "input[name=increaseRelevanceUrl]");
173        };
174        
175        var decreaseRelevance = function (event) {
176            var $button = $(this);
177            adjustRelevance(event, $button, "input[name=decreaseRelevanceUrl]");
178        };
179
180        //var filterOnText = function (self, textRegExp, match) {
181
182        //    var title = self.find('.linkItem .linkLabel').html().toLowerCase();
183        //    if (typeof title == 'undefined')
184        //        title = '';
185
186        //    var tooltip = self.find('.linkItem').attr('title');
187        //    if (typeof tooltip == 'undefined')
188        //        tooltip = '';
189
190        //    var tags = ' ' + title + ' ' + tooltip;
191
192        //    var wordsMatch = textRegExp.test(tags);
193        //    match = match && wordsMatch;
194
195        //    return match;
196        //};
197
198        // Public properties
199        return {
200
201            init: function () {                
202                //$(".linkNavBox .pageListWrapper").each(function () {
203                //    var $listContainer = $(this);
204                //    initVisibleItems($listContainer);
205                //    setVisibleItems($listContainer);
206                //});
207                //bind click on show more button
208                //$(".linkNavBox .showMore").click(showMore);
209                $(".linkNavBox .increaseRelevance").click(increaseRelevance);
210                $(".linkNavBox .decreaseRelevance").click(decreaseRelevance);
211
212            }
213            //,
214
215            //filterOnSituationAndOrText: function () {
216
217            //    var situationsArray = [];
218            //    var value = $('#filterText').val();
219            //    var text = $.trim(value.toLowerCase());
220
221            //    //Regexp created once for performance reasons.
222            //    //Note: Js has trouble with word boundaries and 'åäö' the current solution gives false positives for words when 
223            //    // search phrase begins with åäö. Ie: searching for "äga" matches "säga". This seems however to be the least bad solution.
224            //    var textRegExp = new XRegExp('\\p{Separator}' + text, 'i');
225
226            //    var items = $('.situations li').find('input:checked');
227            //    items.each(function() {
228            //        var situationId = $(this).val();
229            //        situationsArray.push(situationId);
230            //    });
231
232            //    $('.linkNavBox').each(function () {
233            //        var $linkNavBox = $(this);
234            //        var $ulList = $linkNavBox.find('.pageList');
235
236            //        $ulList.children('li').each(function () {
237
238            //            var self = $(this);
239            //            var match = false;
240
241            //            //If no situation selected, no text is given, all li element should be visible.
242            //            if (!situationsArray.length > 0 && text.length == 0) {
243            //                self.addClass(matchClass);
244            //                self.removeClass(nomatchClass);
245            //                return;
246            //            } else if (situationsArray.length == 0 && text.length > 0) {
247            //                match = filterOnText(self, textRegExp, true);
248            //            }
249
250            //            var taggedSituationPages = self.attr('data-taggedsituationpages').split(',');
251            //            $(situationsArray).each(function (index, element) {
252            //                if ($.inArray(element, taggedSituationPages) > -1) {
253            //                    match = filterOnText(self, textRegExp, true);
254            //                }
255            //            });
256
257            //            if (!match) {
258            //                self.addClass(nomatchClass).removeClass(matchClass);
259
260            //            } else {
261            //                self.removeClass(nomatchClass).addClass(matchClass);
262            //            }
263            //        });
264
265            //        //Update the quantity of items shown in the lists.
266            //        var quantity = $ulList.children('li.match').length;
267            //        var quantitySpan = $linkNavBox.find('h3').find('.h3');
268            //        quantitySpan.text('(' + quantity + ' st' + ')');
269
270            //        if ($ulList.children('li.match').length == 0) {
271            //            //visa text
272            //            $linkNavBox.find('.nohit').show();
273            //        } else {
274            //            //dölj text
275            //            $linkNavBox.find('.nohit').hide();
276            //        }
277
278            //        var $itemContainer = $linkNavBox.find('.pageListWrapper');
279            //        setVisibleItems($itemContainer);
280            //    });
281            //},
282            
283            //sortOnWords : function(sort) {
284            //    $('.linkNavBox').each(function () {
285            //        var $linkNavBox = $(this);
286            //        var $ulList = $linkNavBox.find(".pageList");
287
288            //        var listitemsArray = $ulList.children('li').get();
289            //        listitemsArray.sort(sort);
290            //        $.each(listitemsArray, function (idx, itm) { $ulList.append(itm); });
291                    
292            //        var $itemContainer = $linkNavBox.find(".pageListWrapper");
293            //        setVisibleItems($itemContainer);
294
295            //    });
296            //},
297            
298            //sortOnWeight : function() {
299            //    $('.linkNavBox').each(function () {
300            //        var $linkNavBox = $(this);
301            //        var $ulList = $linkNavBox.find(".pageList");
302
303            //        var listitemsArray = $ulList.children('li').get();
304            //        listitemsArray.sort(function (a, b) {
305            //            var compA = parseFloat($(a).attr('data-pageValue'));
306            //            var compB = parseFloat($(b).attr('data-pageValue'));
307            //            return (compA < compB) ? 1 : (compA > compB) ? -1 : 0;
308            //        });
309            //        $.each(listitemsArray, function (idx, itm) { $ulList.append(itm); });
310
311            //        var $itemContainer = $linkNavBox.find(".pageListWrapper");
312            //        setVisibleItems($itemContainer);
313
314            //    });
315            //}    
316        };
317    }());
318
319}(this, this.document, window.Abou = window.Abou || {}, 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.