PageSourceSearch

https://koegekafferisteri.dk/wp-content/plugins/kk-gls-toolbox/assets/kk-gls-toolbox.js?ver=1784065599

js koegekafferisteri.dk collected 2026-10-06 04:18:14 UTC 5,511 bytes, 135 lines download raw bytes

1(function($){
2  'use strict';
3
4  function setStatus($box, text, type) {
5    $box.find('.kk-gls-status').attr('class', 'kk-gls-status ' + (type || '')).text(text || '');
6  }
7
8  function normalizePoints(data) {
9    var rows = [];
10    var points = data && data.Point ? data.Point : [];
11    $.each(points, function(_, point){
12      if (!point || !point.PointId) return;
13      var info = point.Information || {};
14      rows.push({
15        id: String(point.PointId),
16        name: String(info.Name || ''),
17        address: String(info.Address || ''),
18        distance: point.Distance === null || typeof point.Distance === 'undefined' ? null : Number(point.Distance),
19        carrier: point.Carrier && point.Carrier.Id ? Number(point.Carrier.Id) : 70
20      });
21    });
22    rows.sort(function(a,b){ return (a.distance === null ? 99999999 : a.distance) - (b.distance === null ? 99999999 : b.distance); });
23    return rows.slice(0, 12);
24  }
25
26  function geocode($box, address) {
27    return $.post(KKGLSToolbox.ajaxUrl, {
28      action: 'kk_gls_geocode',
29      nonce: KKGLSToolbox.geocodeNonce,
30      address1: address.Streetname1,
31      postcode: address.PostalCode,
32      city: address.City,
33      country: address.Country
34    });
35  }
36
37  function fetchPoints($box, address) {
38    return $.ajax({
39      url: KKGLSToolbox.officialAjax,
40      method: 'GET',
41      dataType: 'json',
42      data: {
43        action: 'GLSDk_pickup_locations',
44        CarrierId: Number($box.data('carrier') || 70),
45        Address: address
46      }
47    });
48  }
49
50  function renderPoints($box, data) {
51    if (data && data.Error && Number(data.Error.Id || 0) !== 0) {
52      setStatus($box, data.Error.Info || KKGLSToolbox.labels.error, 'error');
53      return;
54    }
55    var points = normalizePoints(data);
56    if (!points.length) {
57      setStatus($box, KKGLSToolbox.labels.none, 'error');
58      return;
59    }
60    setStatus($box, points.length + ' PakkeShops fundet.', 'success');
61    var $list = $('<div class="kk-gls-point-list"></div>');
62    $.each(points, function(_, p){
63      var dist = p.distance === null ? '' : '<span class="kk-gls-distance">' + Math.round(p.distance) + ' m</span>';
64      var $row = $('<div class="kk-gls-point"><div><strong></strong><div class="kk-gls-point-address"></div></div><div>' + dist + '<button type="button" class="button button-primary kk-gls-select">Vælg</button></div></div>');
65      $row.find('strong').text(p.name);
66      $row.find('.kk-gls-point-address').text(p.address + ' · ID ' + p.id);
67      $row.find('.kk-gls-select').on('click', function(){ save($box, p); });
68      $list.append($row);
69    });
70    $box.find('.kk-gls-results').html($list);
71  }
72
73  function search($box) {
74    var address = {
75      Streetname1: $box.find('.kk-gls-address1').val() || '',
76      Streetname2: '', HouseNumber: '', NumberExtension: '',
77      PostalCode: $box.find('.kk-gls-postcode').val() || '',
78      s_postcode: $box.find('.kk-gls-postcode').val() || '',
79      City: $box.find('.kk-gls-city').val() || '',
80      Country: ($box.find('.kk-gls-country').val() || 'DK').toUpperCase(),
81      State: '', Lat: '', Long: ''
82    };
83    if (!address.PostalCode || !address.City) {
84      setStatus($box, 'Postnummer og by skal udfyldes.', 'error');
85      return;
86    }
87
88    setStatus($box, 'Finder adressens position…', 'working');
89    $box.find('.kk-gls-results').empty();
90
91    geocode($box, address).done(function(resp){
92      if (!resp || !resp.success || !resp.data) {
93        setStatus($box, resp && resp.data && resp.data.message ? resp.data.message : 'Adressen kunne ikke placeres.', 'error');
94        return;
95      }
96      address.Lat = resp.data.lat;
97      address.Long = resp.data.lng;
98      setStatus($box, KKGLSToolbox.labels.searching, 'working');
99
100      fetchPoints($box, address).done(function(data){
101        renderPoints($box, data);
102      }).fail(function(xhr){
103        var message = KKGLSToolbox.labels.error;
104        if (xhr.responseJSON && xhr.responseJSON.data && xhr.responseJSON.data.message) message = xhr.responseJSON.data.message;
105        setStatus($box, message + ' HTTP ' + xhr.status, 'error');
106      });
107    }).fail(function(xhr){
108      var message = 'Adressen kunne ikke placeres.';
109      if (xhr.responseJSON && xhr.responseJSON.data && xhr.responseJSON.data.message) message = xhr.responseJSON.data.message;
110      setStatus($box, message, 'error');
111    });
112  }
113
114  function save($box, point) {
115    setStatus($box, KKGLSToolbox.labels.saving, 'working');
116    $.post(KKGLSToolbox.ajaxUrl, {
117      action: 'kk_gls_save_pickup', nonce: KKGLSToolbox.nonce,
118      object_id: Number($box.data('object-id')),
119      pickup_id: point.id, pickup_name: point.name, pickup_address: point.address,
120      carrier_id: point.carrier || 70
121    }).done(function(resp){
122      if (!resp || !resp.success) {
123        setStatus($box, resp && resp.data && resp.data.message ? resp.data.message : KKGLSToolbox.labels.error, 'error');
124        return;
125      }
126      $box.find('.kk-gls-current').html('<strong>Nuværende PakkeShop:</strong> ' + $('<div>').text(resp.data.label).html());
127      setStatus($box, resp.data.message || KKGLSToolbox.labels.saved, 'success');
128    }).fail(function(xhr){
129      var message = xhr.responseJSON && xhr.responseJSON.data && xhr.responseJSON.data.message ? xhr.responseJSON.data.message : KKGLSToolbox.labels.error;
130      setStatus($box, message, 'error');
131    });
132  }
133
134  $(document).on('click', '.kk-gls-search', function(){ search($(this).closest('.kk-gls-picker')); });
135})(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.