"use strict"; var adsbygoogle = window.adsbygoogle || [], custom = { domain: "taxigator.ru", googleKey: "AIzaSyBDhpoX-O5dWuAoixfYIQ2wEgrbL-1Lic8", mapboxKey: "pk.eyJ1IjoibWV0cm9taXhmbSIsImEiOiJjamxpMWxjMTIwOG1iM3BuejA3bjR5eHVyIn0.yj7R1y-Lpo2AOfsl8tFU9w", init: function() { this.updatefare(), this.updatetownratelist(),this.initflex(), this.lazyimages(), this.places(), this.townbrowse(), this.calculateRoute(), /*,this.maps()*/ this.submitUserComment(), this.showmaps() }, updatetownratelist: function() { var e = document.getElementById("updatetownratelist"); e && e.addEventListener("click", function(e) { return e.preventDefault(), town ? (custom.loading("show"), void custom.lookupTown(town, function(e, t) { e ? (alert(e), custom.loading("hide")) : window.location.href = "http://taxi-" + t.subdomain + "." + custom.domain })) : !1 }, !1) }, showmaps: function(e) { var e = document.getElementById("showmaplink"); e && e.addEventListener("click", function(e) { e.preventDefault(); var s = document.getElementById("showmapdiv"); s.style.display = "none"; custom.maps() }) }, loadJS: function(e, t) { var n = window.document.getElementsByTagName("script")[0], a = window.document.createElement("script"); return a.src = e, a.async = !0, n.parentNode.insertBefore(a, n), t && "function" == typeof t && (a.onload = t), a }, loadCSS: function(e) { var t = document.createElement("link"); t.rel = "stylesheet", t.type = "text/css", t.href = e, document.getElementsByTagName("head")[0].appendChild(t) }, parseJSON: function(e) { try { return JSON.parse(e) } catch (e) { return null } }, shuffle: function(e) { for (var t = e.length - 1; 0 < t; t--) { var n = Math.floor(Math.random() * (t + 1)), a = e[t]; e[t] = e[n], e[n] = a } return e }, throttle: function(e, t) { var n = !1; return function() { n || (e.call(), n = !0, setTimeout(function() { n = !1 }, t)) } }, isAnyPartOfElementInViewport: function(e) { var t = e.getBoundingClientRect(), n = window.innerHeight || document.documentElement.clientHeight, a = window.innerWidth || document.documentElement.clientWidth, o = t.top <= n && 0 <= t.top + t.height, i = t.left <= a && 0 <= t.left + t.width; return o && i }, lazyimages: function() { var t = Array.from(document.querySelectorAll("img[data-src]")); if ("IntersectionObserver" in window) for (var e = new IntersectionObserver(function(e, t) { for (var n = 0; n < e.length; n++) e[n].isIntersecting && (e[n].target.setAttribute("src", e[n].target.getAttribute("data-src")), e[n].target.removeAttribute("data-src"), t.unobserve(e[n].target)) }, { root: null, rootMargin: "0px", threshold: 0 }), n = 0; n < t.length; n++) e.observe(t[n]); else { var a = custom.throttle(function() { for (var e = t.length; e--;) custom.isAnyPartOfElementInViewport(t[e]) && (t[e].setAttribute("src", t[e].getAttribute("data-src")), t[e].removeAttribute("data-src"), t.splice(e, 1)); 0 === t.length && (window.removeEventListener("resize", a), window.removeEventListener("scroll", a)) }, 250); window.addEventListener("resize", a), window.addEventListener("scroll", a), a() } }, loading: function(e) { var t = document.getElementById("loading"); switch (e) { case "show": t || ((t = document.createElement("div")).id = "loading", t.className = "loading", t.innerText = "Loading", document.body.appendChild(t)), t.style.display = "block"; break; case "hide": t && (t.style.display = "none") } }, initflex: function() { /* var e = document.getElementsByClassName("flex"); if (0 < e.length) for (var t = 0, n = e.length; t < n; t++) { var a = e[t].getAttribute("data-type") || "auto", o = "link" === a ? "8753795304" : "1440631709"; "autorelaxed" === a && (o = "1440631709"), e[t].innerHTML = '', (adsbygoogle = window.adsbygoogle || []).push({}) }(adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-7135221251051092", enable_page_level_ads: !0 }), setTimeout(function() { var e = Array.from(document.getElementsByClassName("adsbygoogle")), t = custom.shuffle([{ title: "Get €50 OFF your first Airbnb stay", url: "https://goo.gl/jPhZCt" }]); e[0] && 0 === e[0].innerHTML.replace(/\s/g, "").length && window.GoogleAnalyticsObject && ga("send", "event", "Adblock"); for (var n = 0, a = e.length; n < a; n++) t[n] && e[n] && 0 === e[n].innerHTML.replace(/\s/g, "").length && (e[n].outerHTML = '' + t[n].title + "") }, 3600) */ }, places: function() { var e = document.getElementById("calculator"), o = document.getElementById("pickup"), i = document.getElementById("dropoff"), r = document.getElementById("getfare"), t = !1; function n() { if (t) return !0; t = !0, custom.loadJS("https://maps.googleapis.com/maps/api/js?libraries=places&language=ru&key=" + custom.googleKey, function() { o = new google.maps.places.Autocomplete(o), o.setFields(['address_components', 'adr_address', 'formatted_address', 'geometry', 'id', 'name', 'permanently_closed', 'place_id', 'type', 'vicinity']), i = new google.maps.places.Autocomplete(i), i.setFields(['address_components', 'adr_address', 'formatted_address', 'geometry', 'id', 'name', 'permanently_closed', 'place_id', 'type', 'vicinity']), e.addEventListener("submit", function(e) { e.preventDefault() }, !1), r.addEventListener("click", function(e) { e.preventDefault(), custom.loading("show"), r.disabled = !0; var t = o.getPlace(), n = i.getPlace(); if (!t || !n) return alert("Either pickup or drop off location is missing"), r.disabled = !1, custom.loading("hide"), !1; var a = { pickup_g: t, pickup_name: t.name, pickup_geo: t.geometry.location.lat() + "," + t.geometry.location.lng(), dropoff_g: n, dropoff_name: n.name, dropoff_geo: n.geometry.location.lat() + "," + n.geometry.location.lng() }; custom.lookupRoute(a, function(e, t) { e ? (alert(e), r.disabled = !1, custom.loading("hide")) : window.location.href = "http://" + custom.domain + "/r/" + t.id // "http://taxi-" + t.subdomain + "." + custom.domain + "/r/" + t.id }) }, !1) }) } e && o && i && (o.addEventListener("focus", n, !1), i.addEventListener("focus", n, !1)) }, calculateRoute: function() { var e = document.getElementById("calculatorLocal"), o = document.getElementById("pickupKey"), i = document.getElementById("dropoffKey"), r = document.getElementById("getroute"), t = !1; function n() { if (t) return !0; t = !0, custom.loadJS("http://example.com", function() { o, i, e.addEventListener("submit", function(e) { e.preventDefault() }, !1), r.addEventListener("click", function(e) { e.preventDefault(), custom.loading("show"), r.disabled = !0; var t = document.getElementById("pickupValue").value, n = document.getElementById("dropoffValue").value; if (!t || !n) return alert("Either pickup or drop off location is missing"), r.disabled = !1, custom.loading("hide"), !1; var a = { pickup_place_id: t, dropoff_place_id: n, }; //start here!!!!!!!!!! custom.lookupRoute(a, function(e, t) { e ? (alert(e), r.disabled = !1, custom.loading("hide")) : window.location.href = "http://" + custom.domain + "/r/" + t.id }) }, !1) }) } e && o && i && (o.addEventListener("focus", n, !1), i.addEventListener("focus", n, !1)) }, submitUserComment: function() { var e = document.getElementById("commentForm"), o = document.getElementById("commentMessage"), i = document.getElementById("commentName"), ti = document.getElementById("townId"), ts = document.getElementById("townSubdomain"), r = document.getElementById("commentSubmit"), t = !1; function n() { if (t) return !0; t = !0, e.addEventListener("submit", function(e) { e.preventDefault() }, !1), r.addEventListener("click", function(e) { e.preventDefault(), custom.loading("show"), r.disabled = !0; var tiv = ti.value, tsv = ts.value, t = o.value, n = i.value; if (!t || !n) return alert("Пожалуйста, введите «Текст сообщения» и «Ваше имя»"), r.disabled = !1, custom.loading("hide"), !1; var a = { town_id: tiv, town_subdomain: tsv, comment_message: t, comment_name: n }; custom.saveUserComment(a, function(e, t) { e ? (alert(e), r.disabled = !1, custom.loading("hide")) : window.location.href = "http://taxi-" + t.subdomain + "." + custom.domain + "/#comment-" + t.id, window.location.reload(true) }) }, !1) } e && o && i && (o.addEventListener("focus", n, !1), i.addEventListener("focus", n, !1)) }, townbrowse: function() { var e = document.getElementById("townCalculator"), o = document.getElementById('townText'), r = document.getElementById("townGo"), t = !1; function n() { if (t) return !0; t = !0, custom.loadJS("https://maps.googleapis.com/maps/api/js?libraries=places&key=" + custom.googleKey, function() { o = new google.maps.places.Autocomplete(o,{types: ['(regions)']}), e.addEventListener("submit", function(e) { e.preventDefault() }, !1), r.addEventListener("click", function(e) { e.preventDefault(), custom.loading("show"), r.disabled = !0; var t = o.getPlace(); if (!t) return alert("Location is missing"), r.disabled = !1, custom.loading("hide"), !1; var a = { town_g: t, town_name: t.name, town_formatted: t.formatted_address, town_geo: t.geometry.location.lat() + "," + t.geometry.location.lng() }; custom.saveTown(a, function(e, t) { e ? (alert(e), r.disabled = !1, custom.loading("hide")) : window.location.href = t.url }) }, !1) }) } e && o && (o.addEventListener("focus", n, !1)) }, lookupRoute: function(e, t) { if (!e) return t("Missing route"), !1; /*if (!e.pickup_name) return t("Missing pickup name"), !1; */ if (!e.pickup_geo && !e.pickup_place_id) return t("Missing pickup geo"), !1; /*if (!e.dropoff_name) return t("Missing dropoff name"), !1; */ if (!e.dropoff_geo && !e.dropoff_place_id) return t("Missing dropoff geo"), !1; var o = new XMLHttpRequest; o.open("POST", "/api/routes.php", !0), o.setRequestHeader("Content-Type", "application/json; charset=UTF-8"), o.onload = function() { if (200 === o.status) { var e = JSON.parse(o.responseText); t(null , e) } else t("Oh sorry, there was an error. Please try again later!") } , o.send(JSON.stringify(e)) }, saveUserComment: function(e, t) { if (!e) return t("Cообщение отсутствует"), !1; if (!e.comment_name) return t("Имя отсутствует"), !1; if (!e.comment_message) return t("Текст сообщения отсутствует"), !1; var o = new XMLHttpRequest; o.open("POST", "/api/saveUserComment.php", !0), o.setRequestHeader("Content-Type", "application/json; charset=UTF-8"), o.onload = function() { if (200 === o.status) { var e = JSON.parse(o.responseText); t(null , e) } else t("Извините, произошла ошибка. Пожалуйста, попробуйте еще раз позднее!") } , o.send(JSON.stringify(e)) }, saveTown: function(e, t) { if (!e) return t("Missing town"), !1; var o = new XMLHttpRequest; o.open("POST", "/api/saveTown.php", !0), o.setRequestHeader("Content-Type", "application/json; charset=UTF-8"), o.onload = function() { if (200 === o.status) { var e = JSON.parse(o.responseText); t(null , e) } else t("Oh sorry, there was an error. Please try again later!") } , o.send(JSON.stringify(e)) }, lookupTown: function(e, t) { if (!e) return t("Missing town"), !1; var o = new XMLHttpRequest; o.open("POST", "/api/towns.php", !0), o.setRequestHeader("Content-Type", "application/json; charset=UTF-8"), o.onload = function() { if (200 === o.status) { var e = JSON.parse(o.responseText); t(null , e) } else t("Oh sorry, there was an error. Please try again later!") } , o.send(JSON.stringify(e)) }, maps: function() { if (/bot|google|baidu|bing|msn|yandex/i.test(navigator.userAgent)) return !1; var a = document.getElementById("map"); if (a) { if ("IntersectionObserver" in window) { var n = new IntersectionObserver(function(e, t) { 0 < e.length && e[0].isIntersecting && (o(), n.disconnect()) }, { root: null, rootMargin: "0px", threshold: 0 }); n.observe(a) } else { var e = custom.throttle(function() { custom.isAnyPartOfElementInViewport(a) && (o(), window.removeEventListener("resize", e), window.removeEventListener("scroll", e)) }, 250); window.addEventListener("resize", e), window.addEventListener("scroll", e), e() } var o = function() { custom.loadCSS("https://unpkg.com/leaflet@1.3.4/dist/leaflet.css"), custom.loadCSS("https://unpkg.com/leaflet-routing-machine@3.2.9/dist/leaflet-routing-machine.css"), custom.loadJS("https://unpkg.com/leaflet@1.3.4/dist/leaflet.js", function() { custom.loadJS("https://unpkg.com/leaflet-routing-machine@3.2.9/dist/leaflet-routing-machine.js", function() { /*custom.loadJS("https://ahorn.lima-city.de/owm/leaflet/leaflet-languageselector.js", function() { */ var e = L.map("map"), t = a.getAttribute("data-pickup").split(","), n = a.getAttribute("data-dropoff").split(","); L.tileLayer("https://stamen-tiles-{s}.a.ssl.fastly.net/toner-lite/{z}/{x}/{y}{r}.{ext}", { attribution: 'Stamen Design & OpenStreetMap', subdomains: "abcd", minZoom: 0, maxZoom: 16, ext: "png" }).addTo(e); L.Routing.control({ router: L.Routing.mapbox(custom.mapboxKey), waypoints: [L.latLng(t[0], t[1]), L.latLng(n[0], n[1])], routeWhileDragging: !1, showAlternatives: !1, draggableWaypoints: !1, show: !1, collapsible: !1, lineOptions: { styles: [{ color: "black", opacity: .15, weight: 9 }, { color: "white", opacity: .8, weight: 6 }, { color: "#1fbad6", opacity: 1, weight: 2 }] } }).addTo(e) }) // }) }) } } }, updatefare: function() { var e = document.getElementById("update"); e && e.addEventListener("click", function(e) { return e.preventDefault(), route ? (custom.loading("show"), //window.GoogleAnalyticsObject && ga("send", "event", "Route", "Update", route.pickup_name + " to " + route.dropoff_name), void custom.lookupRoute(route, function(e, t) { e ? (alert(e), custom.loading("hide")) : window.location.href = "http://taxi-" + t.subdomain + "." + custom.domain + "/r/" + t.id })) : !1 }, !1) } }; custom.init();