PageSourceSearch

https://www.bonuscopyright.se/wp-content/themes/bonus/js/bonus-upsales-search.js?ver=1.0

js bonuscopyright.se collected 2026-09-26 01:15:33 UTC 3,292 bytes, 90 lines download raw bytes

1jQuery(document).ready(function($) {
2    var typingTimer;
3    var doneTypingInterval = 300; // Time in ms
4
5    // Cache selectors
6    var $searchField = $('.bonus-upsales-search-field');
7    var $resultsContainer = $('.bonus-upsales-search-results');
8    var $loadingIcon = $('.bonus-upsales-search-loading');
9    var $displayDiv = $('.bonus-upsales-display');
10
11    $searchField.on('keyup', function () {
12        clearTimeout(typingTimer);
13        var searchTerm = $(this).val();
14
15        // Clear the display div when typing
16        $displayDiv.empty().hide();
17
18        if (searchTerm.length >= 3) {
19            typingTimer = setTimeout(function() {
20                // Show the loading icon
21                $loadingIcon.show();
22
23                $.ajax({
24                    url: bonusUpsalesSearch.ajax_url,
25                    type: 'POST',
26                    dataType: 'json',
27                    data: {
28                        action: 'bonus_upsales_search',
29                        nonce: bonusUpsalesSearch.nonce,
30                        searchTerm: searchTerm
31                    },
32                    success: function(response) {
33                        
34                        $loadingIcon.hide();
35
36                        $resultsContainer.empty();
37
38                        if (response.success) {
39                            var results = response.data;
40
41                            if (results.length > 0) {
42                                
43                                $resultsContainer.show();
44
45                                $.each(results, function(index, company) {
46                                    var $companyItem = $('<div class="company-item" data-id="' + company.id + '">' + company.name + '</div>');
47                                    $resultsContainer.append($companyItem);
48                                });
49                            } else {
50                                $resultsContainer.append('<div class="no-results">Inga företag hittades</div>');
51                                $resultsContainer.show();
52                            }
53                        } else {
54                            $resultsContainer.append('<div class="error-message">' + response.data + '</div>');
55                            $resultsContainer.show();
56                        }
57                    },
58                    error: function(xhr, status, error) {
59                        // Hide the loading icon
60                        $loadingIcon.hide();
61
62                        console.error(error);
63                    }
64                });
65            }, doneTypingInterval);
66        } else {
67            $resultsContainer.empty().hide();
68            
69            $loadingIcon.hide();
70        }
71    });
72
73    // Handle click on company item
74    $resultsContainer.on('click', '.company-item', function() {
75        var companyName = $(this).text();
76        var companyId = $(this).data('id');
77
78        $searchField.val(companyName);
79
80        $resultsContainer.empty().hide();
81
82        $displayDiv.html('<h4>' + companyName + '</h4><p>Har tecknat arbetsplatslicens</p>');
83        $displayDiv.show();
84    });
85
86    // Select the text in the search field when clicked after selection
87    $searchField.on('click', function() {
88        $(this).select();
89    });
90});

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.