PageSourceSearch

https://papardeszieds.lv/wp-content/plugins/omniva-woocommerce/assets/js/terminal-mapping.js

js papardeszieds.lv collected 2026-10-01 12:26:23 UTC 60,686 bytes, 1,487 lines download raw bytes

1/******/ (() => { // webpackBootstrap
2/******/ 	"use strict";
3/******/ 	var __webpack_modules__ = ([
4/* 0 */,
5/* 1 */
6/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
7
8__webpack_require__.r(__webpack_exports__);
9// extracted by mini-css-extract-plugin
10
11
12/***/ }),
13/* 2 */
14/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
15
16__webpack_require__.r(__webpack_exports__);
17/* harmony export */ __webpack_require__.d(__webpack_exports__, {
18/* harmony export */   DependencyCheck: () => (/* binding */ DependencyCheck)
19/* harmony export */ });
20function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
21function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
22function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
23function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
24function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
25function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
26var DependencyCheck = /*#__PURE__*/function () {
27  function DependencyCheck(TMJS) {
28    _classCallCheck(this, DependencyCheck);
29    this.TMJS = TMJS;
30    this.prefix = TMJS.prefix;
31    this.leafletJsCdn = "https://unpkg.com/[email protected]/dist/leaflet.js";
32    this.leafletCssCdn = "https://unpkg.com/[email protected]/dist/leaflet.css";
33    this.leafletMarkerClusterJsCdn = "https://unpkg.com/[email protected]/dist/leaflet.markercluster.js";
34    this.leafletMarkerClusterCssCdn = "https://unpkg.com/[email protected]/dist/MarkerCluster.css";
35    this.leafletMarkerClusterDefaultCssCdn = "https://unpkg.com/[email protected]/dist/MarkerCluster.Default.css";
36  }
37  _createClass(DependencyCheck, [{
38    key: "isLeaflet",
39    value: function isLeaflet() {
40      return typeof L !== "undefined";
41    }
42  }, {
43    key: "isMarkerCluster",
44    value: function isMarkerCluster() {
45      return typeof L.markerClusterGroup !== 'undefined';
46    }
47  }, {
48    key: "makeIdFromUrl",
49    value: function makeIdFromUrl(url) {
50      return url.split('/').pop().replace(/\./gi, '-').toLowerCase();
51    }
52  }, {
53    key: "doNotBlockFn",
54    value: function doNotBlockFn(customFn) {
55      setTimeout(function () {
56        customFn();
57      }, 1);
58    }
59  }, {
60    key: "loadScript",
61    value: function loadScript(url, callback) {
62      var script_id = this.makeIdFromUrl(url);
63      if (document.getElementById(script_id)) {
64        // wait a lil bit
65        setTimeout(function () {
66          callback();
67        }, 250);
68        return;
69      }
70      var script = document.createElement("script");
71      script.type = "text/javascript";
72      script.id = script_id;
73      var originalFn = null;
74      var that = this;
75      if (script.readyState) {
76        //IE
77        if (typeof script.onreadystatechange === 'function') {
78          originalFn = script.onreadystatechange;
79        }
80        script.onreadystatechange = function () {
81          if (script.readyState == "loaded" || script.readyState == "complete") {
82            script.onreadystatechange = null;
83            if (originalFn) {
84              that.doNotBlockFn(originalFn);
85            }
86            that.doNotBlockFn(callback);
87          }
88        };
89      } else {
90        //Others
91        if (typeof script.onload === 'function') {
92          originalFn = script.onload;
93        }
94        script.onload = function () {
95          if (originalFn) {
96            that.doNotBlockFn(originalFn);
97          }
98          that.doNotBlockFn(callback);
99        };
100      }
101      script.src = url;
102      document.getElementsByTagName("body")[0].appendChild(script);
103    }
104  }, {
105    key: "loadCSS",
106    value: function loadCSS(url) {
107      var cssId = this.makeIdFromUrl(url);
108      if (document.getElementById(cssId)) {
109        return;
110      }
111      var head = document.getElementsByTagName('head')[0];
112      var link = document.createElement('link');
113      link.id = cssId;
114      link.rel = 'stylesheet';
115      link.type = 'text/css';
116      link.href = url;
117      link.media = 'all';
118      head.appendChild(link);
119    }
120  }, {
121    key: "loadScripts",
122    value: function loadScripts() {
123      var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
124      this.loadScript(this.leafletJsCdn, function () {
125        if (callback && typeof callback === "function") {
126          callback();
127        }
128      });
129    }
130  }, {
131    key: "loadStyles",
132    value: function loadStyles() {
133      this.loadCSS(this.leafletCssCdn);
134    }
135  }, {
136    key: "loadLeaflet",
137    value: function loadLeaflet() {
138      var _this = this;
139      var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
140      if (this.isLeaflet()) {
141        console.info(this.prefix + 'Found Leaflet version:', L.version);
142        this.loadLeafletPlugins(callback);
143      } else {
144        console.info(this.prefix + 'Loading Leaflet');
145        var that = this;
146        this.loadScript(this.leafletJsCdn, function () {
147          return _this.loadLeaflet(callback);
148        });
149        // add leaflet css
150        this.loadCSS(this.leafletCssCdn);
151      }
152    }
153
154    /**
155     * Check and if needed loads required Leaflet plugins
156     * @param {Function} callback - Function to call when finished adding plugins
157     */
158  }, {
159    key: "loadLeafletPlugins",
160    value: function loadLeafletPlugins() {
161      var _this2 = this;
162      var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
163      if (this.isMarkerCluster()) {
164        console.info(this.prefix + 'Leaflet.markercluster plugin found');
165        if (callback && typeof callback === "function") {
166          callback();
167        }
168      } else {
169        console.info(this.prefix + 'Loading Leaflet.markercluster plugin');
170        var that = this;
171        this.loadScript(this.leafletMarkerClusterJsCdn, function () {
172          return _this2.loadLeafletPlugins(callback);
173        });
174        // add Leaflet.markercluster default css
175        this.loadCSS(this.leafletMarkerClusterCssCdn);
176        this.loadCSS(this.leafletMarkerClusterDefaultCssCdn);
177      }
178    }
179  }]);
180  return DependencyCheck;
181}();
182
183/***/ }),
184/* 3 */
185/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
186
187__webpack_require__.r(__webpack_exports__);
188/* harmony export */ __webpack_require__.d(__webpack_exports__, {
189/* harmony export */   DOMManipulator: () => (/* binding */ DOMManipulator)
190/* harmony export */ });
191/* harmony import */ var _Tools_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4);
192function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
193function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
194function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
195function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
196function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
197function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
198
199
200/**
201 * DOM manipulation class
202 */
203var DOMManipulator = /*#__PURE__*/function () {
204  /**
205   * @param TMJS
206   * {string} this.prefix - prefix to use with console messages
207   */
208  function DOMManipulator(TMJS) {
209    _classCallCheck(this, DOMManipulator);
210    this.TIMEOUT_DEBOUCE = 1000;
211    this.TMJS = TMJS;
212    this.prefix = TMJS.prefix;
213    this._searchTimeoutId = null;
214    this._lastSearchTerm = '';
215    this.containerParent = null;
216    this.modalParent = null;
217    this.isModal = true;
218    this.hideContainer = true;
219    this.hideSelectBtn = false;
220    this.cssThemeRule = '';
221    this.UI = {
222      container: null,
223      modal: null,
224      map: null,
225      overlay: null
226    };
227    this.registerSubs();
228  }
229  _createClass(DOMManipulator, [{
230    key: "registerSubs",
231    value: function registerSubs() {
232      var _this = this;
233      this.TMJS.sub('terminal-selected', function (data) {
234        _this.UI.container.querySelector('.tmjs-selected-terminal').innerText = data.name;
235      });
236      this.TMJS.sub('terminal-selected-text', function (data) {
237        _this.UI.container.querySelector('.tmjs-selected-terminal').innerText = data.text;
238      });
239      this.TMJS.sub('geolocation', function (coords) {
240        _this.UI.modal.querySelector('.tmjs-search-result').innerText = "Lat: ".concat(coords.lat, " Long: ").concat(coords.lng);
241      });
242      this.TMJS.sub('add-search-loader', function (data) {
243        _this.UI.modal.querySelector('.tmjs-search-result').innerHTML = "<div id=\"tmjs-terminals-loader\" class=\"tmjs-loading\"></div>";
244      });
245      this.TMJS.sub('reset-search-result', function (data) {
246        _this.UI.modal.querySelector('.tmjs-search-result').innerText = '';
247      });
248      this.TMJS.sub('search-result', function (data) {
249        _this.UI.modal.querySelector('.tmjs-search-result').innerText = data.address;
250        console.info('GEOCODE RESPONSE:', data);
251      });
252      this.TMJS.sub('list-updated', function (data) {
253        _this.showSelected();
254      });
255      this.TMJS.sub('close-map-modal', function (data) {
256        _this.closeModal();
257      });
258      this.TMJS.sub('open-map-modal', function (data) {
259        _this.openModal();
260      });
261    }
262  }, {
263    key: "setContainerParent",
264    value: function setContainerParent(el) {
265      if (el instanceof HTMLElement) {
266        this.containerParent = el;
267        this.attachContainerToParent(this.UI.container, el);
268        return this;
269      }
270      console.error(this.prefix + 'Container parent element not changed! Must be HTMLElement');
271    }
272  }, {
273    key: "setModalParent",
274    value: function setModalParent(el) {
275      if (el instanceof HTMLElement) {
276        this.modalParent = el;
277        this.attachContainerToParent(this.UI.modal, el);
278        return this;
279      }
280      console.error(this.prefix + 'Modal parent element not changed! Must be HTMLElement');
281    }
282  }, {
283    key: "attachContainerToParent",
284    value: function attachContainerToParent(child) {
285      var parent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
286      if (!child) {
287        return null;
288      }
289      if (parent && child) {
290        return parent.appendChild(child);
291      }
292
293      // default attach to body tag
294      return document.body.appendChild(child);
295    }
296
297    /**
298     * Creates loading overlay (only one active overlay is allowed)
299     * @param {HTMLElement} parentNode - HTML Element to attach overlay to.
300     */
301  }, {
302    key: "addOverlay",
303    value: function addOverlay(parentNode) {
304      this.removeOverlay();
305      // default attach to body tag
306      if (parentNode instanceof HTMLElement === false) {
307        parentNode = document.body;
308      }
309      var overlayNode = document.createElement('div');
310      overlayNode.className = 'tmjs-loading-overlay ' + this.cssThemeRule;
311      overlayNode.innerHTML = '<div class="lds-ellipsis"><div></div><div></div><div></div><div></div></div>';
312      this.UI.overlay = parentNode.appendChild(overlayNode);
313      this.bodyOverflow(false);
314    }
315
316    /**
317     * Removes loading overlay
318     */
319  }, {
320    key: "removeOverlay",
321    value: function removeOverlay() {
322      if (this.UI.overlay) {
323        this.UI.overlay.parentNode.removeChild(this.UI.overlay);
324        this.UI.overlay = null;
325        this.bodyOverflow(true);
326      }
327    }
328
329    /**
330     * Add or remove `overflow: hidden` style to body tag
331     * 
332     * true - removes style (default)
333     * 
334     * false - adds style
335     * 
336     * @param {boolean} show 
337     */
338  }, {
339    key: "bodyOverflow",
340    value: function bodyOverflow() {
341      var show = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
342      show ? document.body.classList.remove('tmjs-hide-overflow') : document.body.classList.add('tmjs-hide-overflow');
343    }
344  }, {
345    key: "addContainer",
346    value: function addContainer(id, strings) {
347      var template = "\n    <div class=\"tmjs-selected-terminal\" data-tmjs-string=\"select_pickup_point\">".concat(strings.select_pickup_point, "</div>\n    <a href=\"#tmjsmodal\" class=\"tmjs-open-modal-btn\" data-tmjs-string=\"modal_open_btn\">").concat(strings.modal_open_btn, "</a>\n    ");
348      var container = this.createElement('div', {
349        classList: ['tmjs-container', this.cssThemeRule, this.hideContainer ? 'tmjs-hidden' : ''],
350        innerHTML: template
351      });
352      container.id = id;
353      this.UI.container = container;
354      this.attachContainerToParent(container, this.containerParent);
355      this.addModal(id + '_modal', strings);
356      this.attachListeners();
357    }
358  }, {
359    key: "updateString",
360    value: function updateString(stringName, newValue) {
361      document.querySelectorAll("[data-tmjs-string=\"".concat(stringName, "\"]")).forEach(function (el) {
362        return el.innerText = newValue;
363      });
364    }
365  }, {
366    key: "createElement",
367    value: function createElement(tag) {
368      var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
369        innerHTML: '',
370        classList: []
371      };
372      /**
373       * @type HTMLElement
374       */
375      var el = document.createElement(tag);
376      if (options.classList instanceof Array && options.classList.length) {
377        el.className = options.classList.join(' ');
378      }
379      if (options.innerHTML) {
380        el.innerHTML = options.innerHTML;
381      }
382      return el;
383    }
384  }, {
385    key: "addModal",
386    value: function addModal(id, strings) {
387      var close_button_class = this.isModal ? '' : 'tmjs-hidden';
388      var template = "\n      <div class=\"tmjs-modal-content\">\n\n        <div class=\"tmjs-modal-body\">\n          <div class=\"tmjs-map-container\"><div class=\"tmjs-map\"></div></div>\n          <div class=\"tmjs-terminal-sidebar\">\n            <div class=\"tmjs-terminal-finder\">\n              <h2 data-tmjs-string=\"modal_header\">".concat(strings.modal_header, "</h2>\n              <div class=\"tmjs-close-modal-btn ").concat(close_button_class, "\"></div>\n              <h3 class=\"tmjs-pt-2\" data-tmjs-string=\"seach_header\">").concat(strings.seach_header, "</h3>\n\n              <div class=\"tmjs-d-block\">\n                <input type=\"text\" class=\"tmjs-search-input\">\n                <a href=\"#search\" class=\"tmjs-search-btn\" ><img src=\"").concat(this.TMJS.imagePath, "search.svg\" width=\"18\"></a>\n              </div>\n\n              <div class=\"tmjs-d-block tmjs-pt-1\">\n                <a href=\"#useMyLocation\" class=\"tmjs-geolocation-btn\"><img src=\"").concat(this.TMJS.imagePath, "gps.svg\" width=\"15\"><span data-tmjs-string=\"geolocation_btn\">").concat(strings.geolocation_btn, "</span></a>\n              </div>\n              <div class=\"tmjs-search-result tmjs-d-block tmjs-pt-2\"></div>\n            </div>\n\n            <div class=\"tmjs-terminal-block\">\n              <h3 data-tmjs-string=\"terminal_list_header\">").concat(strings.terminal_list_header, "</h3>\n              <ul class=\"tmjs-terminal-list\"></ul>\n            </div>\n          </div>\n        </div>\n      </div>\n    ");
389      var modal = this.createElement('div', {
390        classList: [this.cssThemeRule, this.isModal ? 'tmjs-modal' : 'tmjs-modal-flat', this.isModal ? 'tmjs-hidden' : ''],
391        innerHTML: template
392      });
393      modal.id = id;
394
395      /* if exists destroy and rebuild */
396      if (this.UI.modal !== null) {
397        this.UI.modal.parentNode.removeChild(this.UI.modal);
398        this.UI.modal = null;
399      }
400      this.UI.modal = modal;
401      this.UI.map = modal.querySelector('.tmjs-map');
402      this.UI.terminalList = modal.querySelector('.tmjs-terminal-list');
403      this.attachContainerToParent(modal, this.modalParent);
404      //document.body.appendChild(this.UI.modal);
405    }
406  }, {
407    key: "attachListeners",
408    value: function attachListeners() {
409      var _this2 = this;
410      this.UI.container.querySelector('.tmjs-open-modal-btn').addEventListener('click', function (e) {
411        e.preventDefault();
412        _this2.openModal();
413      });
414      this.UI.modal.querySelector('.tmjs-close-modal-btn').addEventListener('click', function (e) {
415        e.preventDefault();
416        _this2.closeModal();
417      });
418      this.UI.modal.querySelector('.tmjs-terminal-list').addEventListener('click', function (event) {
419        _this2.handleTerminalListEvents(event, _this2.findTerminalElement(event.target));
420      });
421      this.UI.modal.querySelector('.tmjs-search-input').addEventListener('keyup', function (e) {
422        e.preventDefault();
423        e.stopPropagation();
424        _this2.searchNearestDebounce(e.target.value, e.keyCode == '13');
425      });
426      this.UI.modal.querySelector('.tmjs-search-btn').addEventListener('click', function (e) {
427        e.preventDefault();
428        e.stopPropagation();
429        _this2.searchNearest(_this2.UI.modal.querySelector('.tmjs-search-input').value);
430      });
431      this.UI.modal.querySelector('.tmjs-geolocation-btn').addEventListener('click', function (e) {
432        e.preventDefault();
433        _this2.useGeolocation();
434      });
435    }
436  }, {
437    key: "openModal",
438    value: function openModal() {
439      if (!this.isModal) {
440        return this;
441      }
442      this.bodyOverflow(false);
443      this.UI.modal.classList.remove('tmjs-hidden');
444      this.TMJS.map.zoomMap();
445      this.TMJS.publish('modal-opened', true);
446      return this;
447    }
448  }, {
449    key: "closeModal",
450    value: function closeModal() {
451      if (!this.isModal) {
452        return this;
453      }
454      this.bodyOverflow();
455      this.UI.modal.classList.add('tmjs-hidden');
456      this.TMJS.publish('modal-closed', true);
457      return this;
458    }
459  }, {
460    key: "findTerminalElement",
461    value: function findTerminalElement(target) {
462      if (target.tagName === 'BODY') {
463        return null;
464      }
465      if (target instanceof HTMLElement && target.classList.contains('tmjs-terminal')) {
466        return target;
467      }
468      return target.parentElement ? this.findTerminalElement(target.parentElement) : null;
469    }
470  }, {
471    key: "useGeolocation",
472    value: function useGeolocation() {
473      if (!navigator.geolocation) {
474        console.log('Browser doesnt support geolocation');
475      } else {
476        //status.textContent = 'Locating…';
477        console.log('Getting coords...');
478        this.TMJS.publish('add-search-loader');
479        navigator.geolocation.getCurrentPosition(this.geoLocationSuccess.bind(this), this.geoLocationError.bind(this));
480      }
481    }
482  }, {
483    key: "geoLocationSuccess",
484    value: function geoLocationSuccess(position) {
485      this._lastSearchTerm = '';
486      var referencePoint = {
487        lat: position.coords.latitude,
488        lng: position.coords.longitude
489      };
490      console.log('Your position', referencePoint);
491      this.TMJS.map.addReferencePosition(referencePoint);
492      this.TMJS.publish('geolocation', referencePoint);
493      this.renderTerminalList(this.TMJS.map.addDistance(referencePoint), true);
494    }
495  }, {
496    key: "geoLocationError",
497    value: function geoLocationError() {
498      this.UI.modal.querySelector('.tmjs-search-result').innerText = this.TMJS.strings.geolocation_not_supported;
499      console.log('wasnt able to retrieve position');
500    }
501
502    /**
503     * 
504     * @param {MouseEvent} event 
505     * @param {HTMLElement} data 
506     */
507  }, {
508    key: "handleTerminalListEvents",
509    value: function handleTerminalListEvents(event, data) {
510      event.stopPropagation();
511      event.preventDefault();
512
513      // non terminal element
514      if (!data) {
515        return;
516      }
517      if (event.target.classList.contains('tmjs-select-btn')) {
518        console.log('Trying to select terminal:', data.dataset.id);
519        this.TMJS.publish('terminal-selected', this.TMJS.map.getActiveLocation());
520        // seting scrollIntoView as false since we already see it.
521        //this.setActiveTerminal(target.dataset.id, false);
522        return;
523      }
524
525      // Everything else assume as selecting terminal
526
527      console.log('Pressed on terminal:', data.dataset.id, data.innerText);
528      // seting scrollIntoView as false since we already see it.
529      this.setActiveTerminal(data.dataset.id, false);
530    }
531  }, {
532    key: "renderTerminalList",
533    value: function renderTerminalList(terminals) {
534      var _this3 = this;
535      var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
536      var listHTML = [];
537      var city = false;
538      if (this.UI.terminalList) {
539        this.UI.terminalList.innerHTML = '';
540      }
541      terminals.forEach(function (loc) {
542        if (city !== loc.city.toLowerCase()) {
543          city = loc.city.toLowerCase();
544          var cityEl = _this3.createElement('li', {
545            classList: ['tmjs-city']
546          });
547          cityEl.innerText = loc.city.toLocaleUpperCase();
548          listHTML.push(cityEl);
549        }
550        var selectBtnHidden = _this3.hideSelectBtn ? 'tmjs-hidden' : '';
551        var name = loc.name == null ? '' : "".concat(loc.name, ", ");
552        var locationName = "".concat(name).concat(loc.address);
553        if (typeof _this3.TMJS.parseLocationName === 'function') {
554          locationName = _this3.TMJS.parseLocationName(loc);
555        }
556        var locationComment = loc['comment'] || null;
557        if (typeof _this3.TMJS.parseLocationComment === 'function') {
558          locationComment = _this3.TMJS.parseLocationComment(loc);
559        }
560        var template = "<span class=\"tmjs-terminal-name\">".concat(locationName);
561        if (typeof loc.distance != 'undefined' && loc.distance !== null) {
562          template += "<span class=\"tmjs-terminal-distance\"><img src=\"".concat(_this3.TMJS.imagePath, "gps.svg\" width=\"13\">").concat(loc.distance.toFixed(2), " km.</span>");
563        }
564        template += "</span><div class=\"tmjs-terminal-info\"><p class=\"tmjs-terminal-comment\">";
565        if (locationComment) {
566          template += "<img src=\"".concat(_this3.TMJS.imagePath, "info.svg\" width=\"17\" style=\"margin-bottom:-1px; padding-right:5px;\">").concat(locationComment);
567        }
568        template += "</p><a href=\"#terminalSelected\" class=\"tmjs-select-btn ".concat(selectBtnHidden, "\" data-tmjs-string=\"select_btn\">").concat(_this3.TMJS.strings.select_btn, "</a>\n      </div>\n      ");
569        /* check if we allready have html object, otherwise create new one */
570        var li = Object.prototype.toString.call(loc._li) == '[object HTMLLIElement]' && !force ? loc._li : _this3.createElement('li', {
571          classList: ['tmjs-terminal'],
572          innerHTML: template
573        });
574        li.dataset.id = loc.id;
575        listHTML.push(li);
576        loc._li = li;
577      });
578      var docFrag = document.createDocumentFragment();
579      listHTML.forEach(function (el) {
580        return docFrag.appendChild(el);
581      });
582      this.UI.terminalList.appendChild(docFrag);
583      this.TMJS.publish('list-updated', this.UI.terminalList);
584      return this;
585    }
586  }, {
587    key: "setActiveTerminal",
588    value: function setActiveTerminal(id) {
589      var scrollIntoView = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
590      if (this.TMJS.map.isActive(id)) {
591        console.log('Allready active');
592        if (scrollIntoView) {
593          var _location = this.TMJS.map.getActiveLocation();
594          this.scrollIntoView(_location._li);
595        }
596        return;
597      }
598      var location = this.TMJS.map.getLocationById(id);
599      if (!location) {
600        console.log('Location has no List element associated');
601        return;
602      }
603      this.UI.terminalList.querySelectorAll("li.tmjs-active").forEach(function (el) {
604        return el.classList.remove('tmjs-active');
605      });
606      location._li.classList.add('tmjs-active');
607      console.log(location);
608      if (scrollIntoView) {
609        this.scrollIntoView(location._li);
610      }
611      if (!this.UI.modal.classList.contains('tmjs-hidden')) {
612        this.TMJS.map.zoomToMarker(location._marker);
613      }
614      this.TMJS.map.setActiveLocation(location);
615    }
616  }, {
617    key: "scrollIntoView",
618    value: function scrollIntoView(el) {
619      el.scrollIntoView({
620        behavior: 'smooth',
621        block: 'nearest',
622        inline: 'start'
623      });
624    }
625  }, {
626    key: "searchNearestDebounce",
627    value: function searchNearestDebounce(search) {
628      var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
629      clearTimeout(this._searchTimeoutId);
630      /* if enter is pressed no need to wait */
631      if (force) {
632        this.searchNearest(search);
633        return;
634      }
635      this._searchTimeoutId = setTimeout(this.searchNearest.bind(this), this.TIMEOUT_DEBOUCE, search);
636    }
637  }, {
638    key: "resetSearch",
639    value: function resetSearch() {
640      this._lastSearchTerm = '';
641      this.renderTerminalList(this.TMJS.map.resetDistance(), true);
642      this.TMJS.map.removeReferencePosition();
643      this.TMJS.publish('reset-search-result');
644    }
645  }, {
646    key: "searchNearest",
647    value: function searchNearest(search) {
648      var _this4 = this;
649      clearTimeout(this._searchTimeoutId);
650      /* reset dropdown if search is empty */
651      if (!search.length) {
652        this.resetSearch();
653        return;
654      }
655      if (search === this._lastSearchTerm) {
656        console.log('Search term hasnt changed');
657        return;
658      }
659      this.TMJS.publish('add-search-loader');
660      this._lastSearchTerm = search;
661      var queryParams = {
662        sourceCountry: this.TMJS.country_code ? this.TMJS.country_code : false,
663        singleLine: search,
664        category: '',
665        outFields: 'Postal',
666        maxLocations: 1,
667        forStorage: 'false',
668        f: 'pjson'
669      };
670      var query = (0,_Tools_js__WEBPACK_IMPORTED_MODULE_0__.makeQueryParams)(queryParams);
671      fetch("https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates?" + query).then(function (response) {
672        if (!response.ok) throw new Error(response.status);
673        return response.json();
674      }).then(function (json) {
675        return _this4.updateDistanceByCandidate(json);
676      })["catch"](function (error) {
677        return _this4.candidateError(error);
678      });
679    }
680  }, {
681    key: "candidateError",
682    value: function candidateError(error) {
683      console.log(error);
684    }
685  }, {
686    key: "updateDistanceByCandidate",
687    value: function updateDistanceByCandidate(json) {
688      if (typeof json.candidates === 'undefined' || !json.candidates.length) {
689        this.UI.modal.querySelector('.tmjs-search-result').innerText = this.TMJS.strings.no_cities_found;
690        console.log('Response had no candidates');
691        return false;
692      }
693      var candidates = json.candidates;
694      var referencePoint = {
695        lat: candidates[0].location.y,
696        lng: candidates[0].location.x
697      };
698      this.TMJS.map.addReferencePosition(referencePoint);
699      this.renderTerminalList(this.TMJS.map.addDistance(referencePoint), true);
700      this.TMJS.publish('search-result', candidates[0]);
701      return true;
702    }
703  }, {
704    key: "showSelected",
705    value: function showSelected() {
706      if (this.TMJS.map._activeLocation) {
707        this.TMJS.map._activeLocation._li.classList.add('tmjs-active');
708        this.scrollIntoView(this.TMJS.map._activeLocation._li);
709      }
710    }
711  }]);
712  return DOMManipulator;
713}();
714
715/***/ }),
716/* 4 */
717/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
718
719__webpack_require__.r(__webpack_exports__);
720/* harmony export */ __webpack_require__.d(__webpack_exports__, {
721/* harmony export */   generateId: () => (/* binding */ generateId),
722/* harmony export */   makeQueryParams: () => (/* binding */ makeQueryParams)
723/* harmony export */ });
724/**
725 * Generates random 6 number string
726 */
727function generateId() {
728  return Math.random().toString(36).substr(2, 6);
729}
730function makeQueryParams(queryParams) {
731  var keys = Object.keys(queryParams);
732  if (!keys.length) {
733    return null;
734  }
735  return keys.map(function (key) {
736    if (queryParams[key] !== false && queryParams[key] !== null && queryParams[key] !== '') {
737      return key + '=' + queryParams[key];
738    }
739    return false;
740  }).filter(function (el) {
741    return el !== false;
742  }).join('&');
743}
744
745/***/ }),
746/* 5 */
747/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
748
749__webpack_require__.r(__webpack_exports__);
750/* harmony export */ __webpack_require__.d(__webpack_exports__, {
751/* harmony export */   Map: () => (/* binding */ Map)
752/* harmony export */ });
753function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
754function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
755function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
756function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
757function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
758function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
759var Map = /*#__PURE__*/function () {
760  function Map(root, TMJS) {
761    _classCallCheck(this, Map);
762    this.TMJS = TMJS;
763    this.prefix = TMJS.prefix;
764    this._tileServerUrl = 'https://www.terminalmappingjs.com/tile/{z}/{x}/{y}.png';
765    if (TMJS.customTileServerUrl !== null) {
766      this._tileServerUrl = TMJS.customTileServerUrl;
767    }
768    this._attribution = "\n      &copy; <a href=\"https://www.mijora.lt\">Mijora</a>\n      | Map data &copy; <a href=\"https://www.openstreetmap.org/\">OpenStreetMap</a> contributors,\n      <a href=\"https://creativecommons.org/licenses/by-sa/2.0/\">CC-BY-SA</a>\n    ";
769    if (TMJS.customTileAttribution !== null) {
770      this._attribution = TMJS.customTileAttribution;
771    }
772
773    /* default map center Lithuania Kaunas */
774    this._defaultMapPos = [54.890926, 23.919338];
775    this._map = null;
776    this._icons = {};
777    this.locations = [];
778    this._activeLocation = null;
779    this._dummyMarker = null;
780    this._referenceMarker = null;
781
782    /* zoom levels for map */
783    this.ZOOM_DEFAULT = 8;
784    this.ZOOM_SELECTED = 13;
785    this.ZOOM_MAX = 18;
786    this.ZOOM_MIN = 4;
787
788    /* for Icon creation */
789    this.Icon = L.Icon.extend({
790      options: {
791        iconSize: [30, 40],
792        iconAnchor: [15, 40],
793        popupAnchor: [0, -40]
794      }
795    });
796
797    // create map
798    this.setupLeafletMap(root);
799  }
800  _createClass(Map, [{
801    key: "loadIcons",
802    value: function loadIcons() {
803      var _this = this;
804      this._icons["default"] = new this.Icon({
805        iconUrl: this.TMJS.imagePath + 'default_icon.svg'
806      });
807      this._icons.reference = new this.Icon({
808        iconUrl: this.TMJS.imagePath + 'reference_icon.svg'
809      });
810      if (this.TMJS.apiMode) {
811        fetch(this.TMJS.api_server_url + 'parcel_machines_images').then(function (response) {
812          return response.json();
813        }).then(function (json) {
814          json.result.parcel_machines_images.forEach(function (item) {
815            return _this._icons[item.identifier] = new _this.Icon({
816              iconUrl: item.svg
817            });
818          });
819          if (_this._markerLayer.getLayers().length > 0) {
820            _this.refreshMarkerIcons();
821          }
822        })["catch"](function (err) {
823          return console.error(_this.prefix + 'Failed to load icons.', err);
824        });
825      }
826    }
827  }, {
828    key: "createIcon",
829    value: function createIcon(identifier, iconUrl) {
830      this._icons[identifier] = new this.Icon({
831        iconUrl: iconUrl
832      });
833    }
834  }, {
835    key: "getIcon",
836    value: function getIcon() {
837      var identifier = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
838      if (Object.keys(this._icons).indexOf(identifier) !== -1) {
839        return this._icons[identifier];
840      }
841      return this._icons["default"];
842    }
843  }, {
844    key: "refreshMarkerIcons",
845    value: function refreshMarkerIcons() {
846      var _this2 = this;
847      this.locations.forEach(function (terminal) {
848        //terminal._marker.options.icon = this.getIcon(terminal.identifier);
849        terminal._marker.setIcon(_this2.getIcon(terminal.identifier));
850        if (_this2._map.hasLayer(terminal._marker)) {
851          console.log('Found visible marker');
852          // terminal._marker.refreshIconOptions();
853        }
854      });
855
856      if (this._dummyMarker && this._activeLocation) {
857        this._dummyMarker.setIcon(this.getIcon(this._activeLocation.identifier));
858      }
859      this.updateActiveMarkerClass();
860    }
861  }, {
862    key: "setupLeafletMap",
863    value: function setupLeafletMap(rootEl) {
864      this._map = L.map(rootEl, {
865        zoomControl: false,
866        minZoom: this.ZOOM_MIN,
867        maxZoom: this.ZOOM_MAX
868      });
869      new L.Control.Zoom({
870        position: 'bottomright'
871      }).addTo(this._map);
872      this.loadIcons();
873      L.tileLayer(this._tileServerUrl, {
874        attribution: this._attribution
875      }).addTo(this._map);
876      this._markerLayer = L.markerClusterGroup({
877        //zoomToBoundsOnClick: false
878      });
879      this._activeMarkerLayer = L.markerClusterGroup({
880        //zoomToBoundsOnClick: false
881      });
882      this._map.addLayer(this._markerLayer);
883      this._map.addLayer(this._activeMarkerLayer);
884      if (!this.TMJS.dom.isModal) {
885        this._map.setView(this._defaultMapPos, this.ZOOM_DEFAULT);
886      }
887      return this;
888    }
889  }, {
890    key: "sortByCity",
891    value: function sortByCity(a, b) {
892      var result = a.city.toLocaleLowerCase().localeCompare(b.city.toLocaleLowerCase());
893      var aName = a['name'] || null;
894      if (typeof this.TMJS.parseLocationName === 'function') {
895        aName = this.TMJS.parseLocationName(a);
896      }
897      var bName = b['name'] || null;
898      if (typeof this.TMJS.parseLocationName === 'function') {
899        bName = this.TMJS.parseLocationName(b);
900      }
901      if (result == 0 && bName != null) {
902        result = aName.toLocaleLowerCase().localeCompare(bName.toLocaleLowerCase());
903      } else if (result == 0) {
904        result = a.address.toLocaleLowerCase().localeCompare(b.address.toLocaleLowerCase());
905      }
906      return result;
907    }
908  }, {
909    key: "sortByDistance",
910    value: function sortByDistance(a, b) {
911      return a.distance - b.distance;
912    }
913  }, {
914    key: "setLocations",
915    value: function setLocations(locations) {
916      this.locations = JSON.parse(JSON.stringify(locations));
917      this.locations.sort(this.sortByCity.bind(this));
918      if (this._map) {
919        this.updateMapMarkers();
920      }
921    }
922  }, {
923    key: "addMarker",
924    value: function addMarker(latLong, id) {
925      var identifier = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
926      var className = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
927      return L.marker(latLong, {
928        icon: this.getIcon(identifier),
929        terminalId: id,
930        tmjs_map: this,
931        className: className
932      }).bindPopup(this.markerPopUpInfo);
933    }
934
935    /**
936    * Finds location by id and puts location comment into popup.
937    * TODO: Could be too resource intensive, maybe better rework addMarker to have exclusive parameter for popup text.
938    */
939  }, {
940    key: "markerPopUpInfo",
941    value: function markerPopUpInfo(e) {
942      var defaultText = '';
943      if (typeof e.options.terminalId !== 'undefined') {
944        var location = e.options.tmjs_map.getLocationById(e.options.terminalId);
945        if (typeof e.options.tmjs_map.TMJS.parseMapTooltip === 'function') {
946          return e.options.tmjs_map.TMJS.parseMapTooltip(location, e.getLatLng());
947        }
948        if (location) {
949          var text = location.comment ? location.comment : location.address;
950          var distance = location.distance ? " ( ".concat(location.distance.toFixed(2), " km )") : '';
951          return "".concat(text, " [ ").concat(e.options.terminalId, " ]").concat(distance);
952        }
953        defaultText = e.options.terminalId + '<br/>';
954      }
955      if (typeof e.options.tmjs_map.TMJS.parseMapTooltip === 'function') {
956        return e.options.tmjs_map.TMJS.parseMapTooltip(null, e.getLatLng());
957      }
958      var latLng = e.getLatLng();
959      if (!latLng) {
960        return '';
961      }
962      return "".concat(defaultText, "Lat: ").concat(latLng.lat, " Long: ").concat(latLng.lng);
963    }
964  }, {
965    key: "addReferencePosition",
966    value: function addReferencePosition(coords) {
967      this.removeReferencePosition();
968      this._referenceMarker = this.addMarker(coords, this.TMJS.strings.your_position, 'reference');
969      this._map.addLayer(this._referenceMarker);
970      this._map.setView(coords, this.ZOOM_SELECTED);
971    }
972  }, {
973    key: "removeReferencePosition",
974    value: function removeReferencePosition() {
975      if (this._referenceMarker) {
976        this._map.removeLayer(this._referenceMarker);
977      }
978    }
979  }, {
980    key: "updateMapMarkers",
981    value: function updateMapMarkers() {
982      var _this3 = this;
983      // only update markers if we have terminal list
984      if (!this.locations.length) {
985        return this;
986      }
987      if (this._markerLayer !== null) {
988        this._markerLayer.clearLayers();
989      }
990
991      /* add markers to marker layer and link icon in locations list */
992      var markers = [];
993      this.locations.forEach(function (location) {
994        location._marker = _this3.addMarker(location.coords, location.id, location.identifier);
995        markers.push(location._marker);
996      });
997      this._markerLayer.addLayers(markers);
998      this._activeMarkerLayer.on('click', function (e) {
999        _this3._map.setView(e.layer.getLatLng(), _this3._map.getZoom());
1000        _this3.TMJS.dom.setActiveTerminal(e.layer.options.terminalId);
1001      });
1002      this._markerLayer.on('click', function (e) {
1003        _this3._map.setView(e.layer.getLatLng(), _this3._map.getZoom());
1004        _this3.TMJS.dom.setActiveTerminal(e.layer.options.terminalId);
1005      });
1006      this._markerLayer.on('animationend', function (e) {
1007        _this3.updateActiveMarkerClass();
1008      });
1009
1010      // Update default center
1011      this._defaultMapPos = this._markerLayer.getBounds().getCenter();
1012      return this;
1013    }
1014  }, {
1015    key: "updateActiveMarkerClass",
1016    value: function updateActiveMarkerClass() {
1017      if (this._dummyMarker && this._dummyMarker._icon) {
1018        // there is dummy with icon
1019        this._dummyMarker._icon.classList.add('tmjs-active-marker');
1020      }
1021      // hide marker in general layer
1022      if (this._activeLocation && this._activeLocation._marker._icon) {
1023        this._activeLocation._marker._icon.classList.add('tmjs-active-marker-hidden');
1024      }
1025    }
1026  }, {
1027    key: "setActiveLocation",
1028    value: function setActiveLocation(location) {
1029      this.removeActiveMarkerAnimations();
1030      this._activeLocation = location;
1031      this.updateActiveMarkerLayer();
1032      this.updateActiveMarkerClass();
1033    }
1034  }, {
1035    key: "zoomToActiveMarker",
1036    value: function zoomToActiveMarker() {
1037      // assume marker is in activeMarkerLayer
1038      this._markerLayer.zoomToShowLayer(this._activeLocation._marker);
1039    }
1040  }, {
1041    key: "zoomMap",
1042    value: function zoomMap() {
1043      if (this._activeLocation) {
1044        this._map.setView(this._activeLocation.coords, this.ZOOM_MAX);
1045        return;
1046      }
1047      this._map.setView(this._defaultMapPos, this.ZOOM_DEFAULT);
1048    }
1049  }, {
1050    key: "zoomToMarker",
1051    value: function zoomToMarker(marker) {
1052      this._markerLayer.zoomToShowLayer(marker);
1053    }
1054  }, {
1055    key: "updateActiveMarkerLayer",
1056    value: function updateActiveMarkerLayer() {
1057      if (this._dummyMarker) {
1058        this._map.removeLayer(this._dummyMarker);
1059      }
1060      this._dummyMarker = this.addMarker(this._activeLocation._marker._latlng, this._activeLocation.id, this._activeLocation.identifier, 'tmjs-active-marker');
1061      this._map.addLayer(this._dummyMarker);
1062      console.log('Current dummy:', this._dummyMarker);
1063    }
1064  }, {
1065    key: "handleActiveMarkers",
1066    value: function handleActiveMarkers(location) {
1067      // no need to do anything if its already active
1068      if (this._activeLocation == location._marker) {
1069        return;
1070      }
1071
1072      // move current active
1073      if (this._activeLocation) {
1074        this._markerLayer.addLayer(this._activeLocation._marker);
1075        this._activeMarkerLayer.clearLayers();
1076      }
1077      // move new active
1078      this._markerLayer.removeLayer(location._marker);
1079      this._activeMarkerLayer.addLayer(location._marker);
1080      console.log('active now', this._activeMarkerLayer.getLayers(), this._activeLocation);
1081      // add active-marker class
1082      location._marker._icon.classList.add('tmjs-active-marker');
1083    }
1084  }, {
1085    key: "removeActiveMarkerAnimations",
1086    value: function removeActiveMarkerAnimations() {
1087      this.TMJS.dom.UI.modal.querySelectorAll('.tmjs-active-marker-hidden').forEach(function (el) {
1088        return el.classList.remove('tmjs-active-marker-hidden');
1089      });
1090    }
1091  }, {
1092    key: "getLocationById",
1093    value: function getLocationById(id) {
1094      if (!this.locations) {
1095        return undefined;
1096      }
1097      return this.locations.find(function (loc) {
1098        return loc.id === id;
1099      });
1100    }
1101  }, {
1102    key: "resetDistance",
1103    value: function resetDistance() {
1104      this.locations.forEach(function (loc) {
1105        loc.distance = null;
1106      });
1107      this.locations.sort(this.sortByCity);
1108      return this.locations;
1109    }
1110  }, {
1111    key: "addDistance",
1112    value: function addDistance(origin) {
1113      var _this4 = this;
1114      this.locations.forEach(function (loc) {
1115        loc.distance = _this4.calculateDistance(origin, loc.coords);
1116      });
1117      this.locations.sort(this.sortByDistance);
1118      return this.locations;
1119    }
1120  }, {
1121    key: "deg2rad",
1122    value: function deg2rad(degress) {
1123      return degress * Math.PI / 180;
1124    }
1125  }, {
1126    key: "rad2deg",
1127    value: function rad2deg(radians) {
1128      return radians * 180 / Math.PI;
1129    }
1130  }, {
1131    key: "calculateDistance",
1132    value: function calculateDistance(loc1, loc2) {
1133      var distance = null;
1134      if (loc1.lat == loc2.lat && loc1.lng == loc2.lng) {
1135        return 0;
1136      } else {
1137        var theta = loc1.lng - loc2.lng;
1138        var dist = Math.sin(this.deg2rad(loc1.lat)) * Math.sin(this.deg2rad(loc2.lat)) + Math.cos(this.deg2rad(loc1.lat)) * Math.cos(this.deg2rad(loc2.lat)) * Math.cos(this.deg2rad(theta));
1139        dist = Math.acos(dist);
1140        dist = this.rad2deg(dist);
1141        distance = dist * 60 * 1.1515 * 1.609344;
1142      }
1143      return distance;
1144    }
1145  }, {
1146    key: "isActive",
1147    value: function isActive(id) {
1148      return this._activeLocation && this._activeLocation.id == id;
1149    }
1150  }, {
1151    key: "getActiveLocation",
1152    value: function getActiveLocation() {
1153      return this._activeLocation;
1154    }
1155  }]);
1156  return Map;
1157}();
1158
1159/***/ })
1160/******/ 	]);
1161/************************************************************************/
1162/******/ 	// The module cache
1163/******/ 	var __webpack_module_cache__ = {};
1164/******/ 	
1165/******/ 	// The require function
1166/******/ 	function __webpack_require__(moduleId) {
1167/******/ 		// Check if module is in cache
1168/******/ 		var cachedModule = __webpack_module_cache__[moduleId];
1169/******/ 		if (cachedModule !== undefined) {
1170/******/ 			return cachedModule.exports;
1171/******/ 		}
1172/******/ 		// Create a new module (and put it into the cache)
1173/******/ 		var module = __webpack_module_cache__[moduleId] = {
1174/******/ 			// no module.id needed
1175/******/ 			// no module.loaded needed
1176/******/ 			exports: {}
1177/******/ 		};
1178/******/ 	
1179/******/ 		// Execute the module function
1180/******/ 		__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
1181/******/ 	
1182/******/ 		// Return the exports of the module
1183/******/ 		return module.exports;
1184/******/ 	}
1185/******/ 	
1186/************************************************************************/
1187/******/ 	/* webpack/runtime/define property getters */
1188/******/ 	(() => {
1189/******/ 		// define getter functions for harmony exports
1190/******/ 		__webpack_require__.d = (exports, definition) => {
1191/******/ 			for(var key in definition) {
1192/******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
1193/******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
1194/******/ 				}
1195/******/ 			}
1196/******/ 		};
1197/******/ 	})();
1198/******/ 	
1199/******/ 	/* webpack/runtime/hasOwnProperty shorthand */
1200/******/ 	(() => {
1201/******/ 		__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
1202/******/ 	})();
1203/******/ 	
1204/******/ 	/* webpack/runtime/make namespace object */
1205/******/ 	(() => {
1206/******/ 		// define __esModule on exports
1207/******/ 		__webpack_require__.r = (exports) => {
1208/******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
1209/******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1210/******/ 			}
1211/******/ 			Object.defineProperty(exports, '__esModule', { value: true });
1212/******/ 		};
1213/******/ 	})();
1214/******/ 	
1215/************************************************************************/
1216var __webpack_exports__ = {};
1217// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
1218(() => {
1219__webpack_require__.r(__webpack_exports__);
1220/* harmony export */ __webpack_require__.d(__webpack_exports__, {
1221/* harmony export */   TerminalMapping: () => (/* binding */ TerminalMapping)
1222/* harmony export */ });
1223/* harmony import */ var _styles_main_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
1224/* harmony import */ var _modules_DependencyCheck_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
1225/* harmony import */ var _modules_DOMManipulator_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(3);
1226/* harmony import */ var _modules_Map_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(5);
1227/* harmony import */ var _modules_Tools_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(4);
1228function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
1229function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1230function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
1231function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
1232function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
1233function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
1234
1235
1236
1237
1238
1239var TerminalMapping = /*#__PURE__*/function () {
1240  function TerminalMapping(api_server_url) {
1241    var _this = this;
1242    _classCallCheck(this, TerminalMapping);
1243    /* Terminal Mapping version */
1244    this.version = '1.2.3';
1245    this._isDebug = false;
1246    this.prefix = '[TMJS] ';
1247
1248    // Default path to images
1249    this.imagePath = '';
1250    this.apiMode = true;
1251
1252    // Terminal API server URL
1253    if (typeof api_server_url == 'undefined') {
1254      // console.error(this.prefix + 'Terminal server API MUST be provided');
1255      this.apiMode = false;
1256      // return;
1257    }
1258
1259    // Location name and comment parsers
1260    this.parseLocationName = null;
1261    this.parseLocationComment = null;
1262    this.parseMapTooltip = null;
1263    this.api_server_url = null;
1264    if (this.apiMode) {
1265      this.api_server_url = api_server_url + '/';
1266    }
1267
1268    // Parcels country and identifier
1269    this.country_code = null;
1270    this.identifier = null;
1271    this.containerId = 'tmjs_' + (0,_modules_Tools_js__WEBPACK_IMPORTED_MODULE_4__.generateId)();
1272
1273    // Default strings and proxy to detect changes
1274    this.strings = new Proxy({
1275      modal_header: 'Terminal map',
1276      terminal_list_header: 'Terminal list',
1277      seach_header: 'Search around',
1278      search_btn: 'Find',
1279      modal_open_btn: 'Select terminal',
1280      geolocation_btn: 'Use my location',
1281      your_position: 'Distance calculated from this point',
1282      nothing_found: 'Nothing found',
1283      no_cities_found: 'There were no cities found for your search term',
1284      geolocation_not_supported: 'Geolocation is not supported',
1285      select_pickup_point: 'Select a pickup point',
1286      // Unused strings
1287      search_placeholder: 'Enter postcode/address',
1288      workhours_header: 'Workhours',
1289      contacts_header: 'Contacts',
1290      no_pickup_points: 'No points to select',
1291      select_btn: 'select',
1292      back_to_list_btn: 'reset search',
1293      no_information: 'No information'
1294    }, {
1295      set: function set(obj, prop, value) {
1296        // update DOM
1297        _this.dom.updateString(prop, value);
1298
1299        // default functionality
1300        obj[prop] = value;
1301        return true;
1302      }
1303    });
1304    this.subscribers = {};
1305    this.depend = new _modules_DependencyCheck_js__WEBPACK_IMPORTED_MODULE_1__.DependencyCheck(this);
1306    this.dom = new _modules_DOMManipulator_js__WEBPACK_IMPORTED_MODULE_2__.DOMManipulator(this);
1307    this.map = null;
1308  }
1309  _createClass(TerminalMapping, [{
1310    key: "init",
1311    value: function init() {
1312      var _this2 = this;
1313      var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
1314        _ref$country_code = _ref.country_code,
1315        country_code = _ref$country_code === void 0 ? null : _ref$country_code,
1316        _ref$identifier = _ref.identifier,
1317        identifier = _ref$identifier === void 0 ? null : _ref$identifier,
1318        _ref$postal_code = _ref.postal_code,
1319        postal_code = _ref$postal_code === void 0 ? null : _ref$postal_code,
1320        _ref$city = _ref.city,
1321        city = _ref$city === void 0 ? null : _ref$city,
1322        _ref$receiver_address = _ref.receiver_address,
1323        receiver_address = _ref$receiver_address === void 0 ? null : _ref$receiver_address,
1324        _ref$isModal = _ref.isModal,
1325        isModal = _ref$isModal === void 0 ? true : _ref$isModal,
1326        _ref$modalParent = _ref.modalParent,
1327        modalParent = _ref$modalParent === void 0 ? null : _ref$modalParent,
1328        _ref$hideContainer = _ref.hideContainer,
1329        hideContainer = _ref$hideContainer === void 0 ? false : _ref$hideContainer,
1330        _ref$hideSelectBtn = _ref.hideSelectBtn,
1331        hideSelectBtn = _ref$hideSelectBtn === void 0 ? false : _ref$hideSelectBtn,
1332        _ref$cssThemeRule = _ref.cssThemeRule,
1333        cssThemeRule = _ref$cssThemeRule === void 0 ? 'tmjs-default-theme' : _ref$cssThemeRule,
1334        _ref$terminalList = _ref.terminalList,
1335        terminalList = _ref$terminalList === void 0 ? [] : _ref$terminalList,
1336        _ref$customTileServer = _ref.customTileServerUrl,
1337        customTileServerUrl = _ref$customTileServer === void 0 ? null : _ref$customTileServer,
1338        _ref$customTileAttrib = _ref.customTileAttribution,
1339        customTileAttribution = _ref$customTileAttrib === void 0 ? null : _ref$customTileAttrib,
1340        _ref$parseLocationNam = _ref.parseLocationName,
1341        parseLocationName = _ref$parseLocationNam === void 0 ? null : _ref$parseLocationNam,
1342        _ref$parseLocationCom = _ref.parseLocationComment,
1343        parseLocationComment = _ref$parseLocationCom === void 0 ? null : _ref$parseLocationCom,
1344        _ref$parseMapTooltip = _ref.parseMapTooltip,
1345        parseMapTooltip = _ref$parseMapTooltip === void 0 ? null : _ref$parseMapTooltip;
1346      this.country_code = country_code;
1347      this.identifier = identifier;
1348      this.dom.isModal = isModal;
1349      this.dom.hideContainer = hideContainer;
1350      this.dom.hideSelectBtn = hideSelectBtn;
1351      this.dom.cssThemeRule = cssThemeRule;
1352      this.customTileServerUrl = customTileServerUrl;
1353      this.customTileAttribution = customTileAttribution;
1354      if (parseLocationName !== null) {
1355        this.parseLocationName = parseLocationName;
1356      }
1357      if (parseLocationComment) {
1358        this.parseLocationComment = parseLocationComment;
1359      }
1360      if (parseMapTooltip) {
1361        this.parseMapTooltip = parseMapTooltip;
1362      }
1363      if (modalParent) {
1364        this.dom.setModalParent(modalParent);
1365      }
1366      console.info(this.prefix + 'Initializing Terminal Mapping');
1367      this.dom.addOverlay();
1368      this.dom.addContainer(this.containerId, this.strings);
1369      // load check for leaflet and plugins first
1370      this.depend.loadLeaflet(function () {
1371        _this2.map = new _modules_Map_js__WEBPACK_IMPORTED_MODULE_3__.Map(_this2.dom.UI.map, _this2);
1372        if (!_this2.apiMode) {
1373          _this2.setTerminals(terminalList);
1374          _this2.dom.renderTerminalList(_this2.map.locations);
1375          console.info(_this2.prefix + 'Terminals loaded');
1376          _this2.dom.removeOverlay();
1377          _this2.publish('tmjs-ready', _this2);
1378          return;
1379        }
1380
1381        // Get terminal list in API mode
1382        var params = (0,_modules_Tools_js__WEBPACK_IMPORTED_MODULE_4__.makeQueryParams)({
1383          'q[country_code_eq]': country_code,
1384          'q[identifier_eq]': identifier,
1385          'country_code': country_code,
1386          'postal_code': postal_code,
1387          'city': city,
1388          'receiver_address': receiver_address
1389        });
1390        fetch(_this2.api_server_url + 'parcel_machines' + (params ? '?' + params : '')).then(function (response) {
1391          return response.json();
1392        }).then(function (json) {
1393          console.log(json);
1394          var terminals = json.result.parcel_machines.map(function (terminal) {
1395            terminal['coords'] = {
1396              lat: terminal.y_cord,
1397              lng: terminal.x_cord
1398            };
1399            return terminal;
1400          }); //.filter(terminal => terminal.identifier == 'lp_express');
1401          _this2.setTerminals(terminals);
1402          _this2.dom.renderTerminalList(_this2.map.locations);
1403          console.info(_this2.prefix + 'Terminals loaded');
1404          _this2.dom.removeOverlay();
1405          _this2.publish('tmjs-ready', _this2);
1406        });
1407      });
1408    }
1409  }, {
1410    key: "setImagesPath",
1411    value: function setImagesPath() {
1412      var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
1413      this.imagePath = path;
1414      return this;
1415    }
1416  }, {
1417    key: "setTranslation",
1418    value: function setTranslation() {
1419      var newStrings = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1420      this.strings = Object.assign(this.strings, newStrings);
1421      console.info(this.prefix + 'Translation updated');
1422      return this;
1423    }
1424  }, {
1425    key: "setTerminals",
1426    value: function setTerminals(terminals) {
1427      this.map.setLocations(terminals);
1428      return this;
1429    }
1430  }, {
1431    key: "setParseLocationName",
1432    value: function setParseLocationName() {
1433      var parseLocationName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
1434      this.parseLocationName = parseLocationName;
1435      return this;
1436    }
1437  }, {
1438    key: "setParseLocationComment",
1439    value: function setParseLocationComment() {
1440      var parseLocationComment = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
1441      this.parseLocationComment = parseLocationComment;
1442      return this;
1443    }
1444  }, {
1445    key: "setParseMapTooltip",
1446    value: function setParseMapTooltip() {
1447      var parseMapTooltip = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
1448      this.parseMapTooltip = parseMapTooltip;
1449      return this;
1450    }
1451  }, {
1452    key: "sub",
1453    value: function sub(eventName, callback) {
1454      if (!this.subscribers[eventName]) {
1455        this.subscribers[eventName] = [];
1456      }
1457      this.subscribers[eventName].push(callback);
1458      return this;
1459    }
1460  }, {
1461    key: "unsub",
1462    value: function unsub(eventName, reference) {
1463      if (!this.subscribers[eventName]) {
1464        return true;
1465      }
1466      this.subscribers[eventName] = this.subscribers[eventName].filter(function (callback) {
1467        return callback !== reference;
1468      });
1469    }
1470  }, {
1471    key: "publish",
1472    value: function publish(eventName, data) {
1473      if (!this.subscribers[eventName]) {
1474        return;
1475      }
1476      this.subscribers[eventName].forEach(function (callback) {
1477        return callback(data);
1478      });
1479    }
1480  }]);
1481  return TerminalMapping;
1482}();
1483window.TerminalMappingOmnivalt = TerminalMapping;
1484})();
1485
1486/******/ })()
1487;

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.