$(function(){ $('body').click(function(){ $('.suggestions').hide(); }); }); function isMobile() { return $(window).width() < 800; } function mobileHorizontal() { return isMobile() && window.innerWidth > window.innerHeight; } function mobileVertical() { return isMobile() && window.innerWidth < window.innerHeight; } function resized() { $('[ratio]:visible, .map:visible').each(function(){ var windowWidth = $( window ).width(); if (mobileHorizontal() && $(this).hasClass('map')) { $(this).css('width', '90%'); } else { $(this).css('width', '100%'); } var width = $(this).width(); $(this).height(width * (($(this).attr('ratio')-0))/100); }); var searchWidth = $('.search').outerWidth(); var navigationInner = $('.navigationInner').outerWidth(); var buttons = 0; $('.navigation .link').each(function(){ buttons += $(this).outerWidth(); }); console.log([searchWidth, navigationInner, buttons]); if (searchWidth+buttons>navigationInner) { $('.search').hide(); } else { $('.search').show(); } } window.onresize = function(){ resized(); }; setTimeout(function(){resized()}, 1); function popupClose() { $('.black').fadeOut(200); $('.popup').animate({top: '40%', opacity: 0},300, 'easeOutBack', function(){ $(this).hide(); $('.popupBodyInner').html(""); }); } function popup2Close() { $('.black2').fadeOut(200); $('.popup2').fadeOut(function(){ $('.popup2').html(""); }); } function popupOpen(html, locked) { $('.popupError').html('').hide(); $('.black').fadeIn(200); $('.black').off(); $('.black').click(function(){ popupClose(); }); $('.popupClose').show(); $('.popup').show().css({opacity:0, top: '40%'}).animate({top: '50%', opacity: 1},300, 'easeOutBack'); $('.popupBodyInner').html(html); $(".popupBody").scrollTop(0); if (locked) { $('.popupClose').hide(); $('.black').off(); } if ($('#popupTitleValue').length > 0) $('.popupTitle').html($('.popupBody #popupTitleValue').val()); var href = document.location.href.split("#")[0]+"#p"; window.history.pushState({},document.title,href); } function popup2Open(html) { $('.black2').fadeIn(200); $('.popup2').show(); $('.popup2').html(html); } function popupErrorClear() { $('.popupError').html('').hide(); } function popupError(message) { $('.popupError').html(message).fadeOut(200).fadeIn(200); } function popupLoad(url, locked) { $.get(url, function(resp){ popupOpen(resp, locked); }); } function popup2Load(url) { $.get(url, function(resp){ popup2Open(resp); }); } function popupNavigate(url, direction) { var d = direction=='right' ? 1 : -1; $.get(url, function(resp){ var oldWidth = $('.popupBodyInner').width(); var oldHeight = $('.popupBodyInner').height(); $('.popupBodyInner').stop().animate({left:-50*d, opacity: 0}, 200, function(){ $('.popupBodyInner').html(resp); if ($('#popupTitleValue').length > 0) $('.popupTitle').html($('#popupTitleValue').val()); var newWidth = $('.popupBodyInner').width(); var newHeight = $('.popupBodyInner').height(); $('.popupBodyInner').css({width: oldWidth, height: oldHeight}); $('.popupBodyInner').css({left:50*d}); $('.popupBodyInner').stop().animate({left:0, opacity: 1,width: newWidth, height: newHeight}, 200, function(){ $('.popupBodyInner').css({width: 'auto', height: 'auto'}); }); }); }); } function validateEmail(email) { const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(String(email).toLowerCase()); } function authorizeEmail() { var email = $("#authorizeEmail").val(); if (!validateEmail(email)) { popupError("Epasta formāts nav pareizs."); $('#authorizeEmail').select(); return false; } popupErrorClear(); popupNavigate("/account/authorize2?email="+email, 'right'); } function register() { var email = $('#registerEmail').html(); var name = $('#registerName').val(); if (!$('#registerAgree').prop('checked')) { popupError('Nepieciešams piekrist lietošanas noteikumiem'); return false; } if (name == '') { popupError("Norādi vārdu un uzvārdu"); return false; } popupErrorClear(); poster.post('/account/register', {email: email, name:name}, function(resp){ if (resp == 'OK') { popupNavigate("/account/registerComplete", 'right'); } else if (resp == 'CODE') { popupNavigate("/account/authorize2?email="+email, 'right'); } else { popupError(resp); } }); } function authorizeCode() { var code = $('#authorizeCode').val(); var email = $('#authorizeEmail').html(); poster.post('/account/authorizeCode', {email: email, code:code}, function(resp){ if (resp == "OK") { if (poster.backlink) document.location = poster.backlink; else document.location.reload(); } else { popupError(resp); } }); } function resendCode() { var email = $('#authorizeEmail').html(); popupNavigate("/account/authorize2?email="+email, 'right'); } function myProfileOver() { var button = $('.myProfile'); var offset = button.offset(); var width = $(button).outerWidth(); var height = $(button).height(); var myPanelWidth = $('.myPanel').outerWidth(); console.log(offset.left+" "+width); $('.myPanel').css({top: offset.top + height, left: offset.left+width-myPanelWidth}); $('.myPanel').stop().slideDown(200); if (myPanelCloseTimeout) clearTimeout(myPanelCloseTimeout); } function myPanelOver() { if (myPanelCloseTimeout) clearTimeout(myPanelCloseTimeout); } var myPanelCloseTimeout = false; function myProfileOut() { if (myPanelCloseTimeout) clearTimeout(myPanelCloseTimeout); myPanelCloseTimeout = setTimeout("myPanelClose()", 300); } function myPanelClose() { $('.myPanel').stop().slideUp(200); } function myLangOver() { var button = $('.myLang'); var offset = button.offset(); var width = $(button).outerWidth(); var height = $(button).height(); var langPanelWidth = $('.langPanel').outerWidth(); console.log(offset.left+" "+width); $('.langPanel').css({top: offset.top + height, left: offset.left}); $('.langPanel').stop().slideDown(200); if (langPanelCloseTimeout) clearTimeout(langPanelCloseTimeout); } function langPanelOver() { if (langPanelCloseTimeout) clearTimeout(langPanelCloseTimeout); } var langPanelCloseTimeout = false; function myLangOut() { if (langPanelCloseTimeout) clearTimeout(langPanelCloseTimeout); langPanelCloseTimeout = setTimeout("langPanelClose()", 300); } function langPanelClose() { $('.langPanel').stop().slideUp(200); } var searchTimeout = false; var searchVal = ''; function searchPlacesTrigger(inner) { if (searchTimeout) clearTimeout(searchTimeout); searchTimeout = setTimeout(function(){searchPlaces(inner)}, 1000); } function searchPlaces(inner) { var q = searchVal; var url = '/place/list?q='+encodeURIComponent(q); if (inner) { $.get(url, function(resp){ $('.placeInfo').html($(resp).find(".placeInfo").html()); var html = $(resp).find(".placeList"); $('.placeList').html(html); }) } else { dynamic.go(url); } } function sendContactMessage() { var data = {}; data.name = $("#name").val(); data.email = $("#email").val(); data.phone = $("#phone").val(); data.text = $("#text").val(); poster.post("/index/sendContactMessage", data, function(resp){ if (resp != 'OK') { alert(resp); } else { $('.emailSent, .emailForm').slideToggle(); } }); } function switchLang(lang) { $.get('index/setLang/?lang='+lang, function(resp){ document.location = "/"; }) } function initLangBlock(el, lang) { $(el).find('[lang]').hide(); $(el).find("[lang='"+lang+"']").show(); $(el).find('[sellang]').removeClass('active'); $(el).find("[sellang='"+lang+"']").addClass('active'); $(el).find('[sellang]').click(function(e){ var lang = $(this).attr('sellang'); $(el).find('[lang]').hide(); $(el).find("[lang='"+lang+"']").show(); $(el).find('[sellang]').removeClass('active'); $(el).find("[sellang='"+lang+"']").addClass('active'); e.preventDefault(); return false; }); } var flashTimeout = false; function flash(str) { if (flashTimeout) clearTimeout(flashTimeout); $('.flash').html(str); $('.flash').stop().hide().fadeIn(); flashTimeout = setTimeout(function(){ $('.flash').fadeOut(); },2000); } function selectCategory() { popup2Load("/offer/selectCategory"); } function requireAuthorization() { popupLoad("/account/authorize", true); } function Map() { this.maps = {}; this.markers = {}; this.mx = 0; this.my = 0; this.locationIcon = false; $(function($) { $(document).mousemove(function(event) { map.mx = event.pageX; map.my = event.pageY; }); }); this.vectorStyle = new ol.style.Style({ fill: new ol.style.Fill({ color: 'rgba(255, 255, 255, 0.7)', }), stroke: new ol.style.Stroke({ color: '#0099FF', width: 2, }) }); this.create = function(label, position) { $('#'+label).wrap("
"); if (!position) position = [24.505078, 56.846285]; var zoom = 7; if (mobileVertical()) zoom = 6; var m = {}; this.maps[label] = m; m.source = new ol.source.Vector(); m.layer = new ol.layer.Vector({source: m.source, style: this.vectorStyle}); var interactions = ol.interaction.defaults({altShiftDragRotate:false, pinchRotate:false}); m.map = new ol.Map({ interactions: interactions, target: label, layers: [ new ol.layer.Tile({ source: new ol.source.OSM() }), m.layer ], view: new ol.View({ center: ol.proj.fromLonLat(position), zoom: zoom, minZoom: 5, maxZoom: 15, }) }); setTimeout(function(){ resized(); }, 100); } this.enableSetLocation = function(label, locationLabel) { var m = this.maps[label]; if (!locationLabel) locationLabel = 'red'; m.map.on('click', function(evt){ var feature = new ol.Feature(new ol.geom.Point(evt.coordinate)); feature.setStyle(map.markers[locationLabel]); m.source.clear(); m.source.addFeature(feature); var lonlat = ol.proj.transform(evt.coordinate, 'EPSG:3857', 'EPSG:4326'); $('#placeLongitude').val(lonlat[0]).trigger('change'); $('#placeLatitude').val(lonlat[1]).trigger('change'); //map.translateLatLon(lonlat[1], lonlat[0]); }); } this.addMarker = function(label, latitude, longitude, marker, placeId) { var m = this.maps[label]; var coordinate = ol.proj.transform([latitude, longitude], 'EPSG:4326', 'EPSG:3857') var feature = new ol.Feature(new ol.geom.Point(coordinate)); feature.placeId = placeId; feature.setStyle(this.markers[marker]); m.source.addFeature(feature); } this.enableSetDelivery = function(label) { var m = this.maps[label]; m.modify = new ol.interaction.Modify({source: m.source}); m.map.addInteraction(m.modify); m.addInteractions = function() { m.drawInteraction = new ol.interaction.Draw({ source: m.source, type: $('.drawType.active').attr('value'), }); m.map.addInteraction(m.drawInteraction); } m.addInteractions(); $('.drawType').click(function(e){ $('.drawType').removeClass('active'); $(this).addClass('active'); m.map.removeInteraction(m.drawInteraction); m.addInteractions(); e.preventDefault(); return false; }); $('.drawClear').click(function(e){ m.source.clear(); e.preventDefault(); return false; }); } this.registerMarker = function(label, marker) { this.markers[label] = new ol.style.Style({ image: new ol.style.Icon({ anchor: [25, 43], anchorXUnits: 'pixels', anchorYUnits: 'pixels', opacity: .9, scale: .6, src: '/img/'+marker+'Marker.png' }) }); this.markers[label+"Trans"] = new ol.style.Style({ image: new ol.style.Icon({ anchor: [25, 43], anchorXUnits: 'pixels', anchorYUnits: 'pixels', opacity: .1, scale: .6, src: '/img/'+marker+'Marker.png' }) }); } this.setDelivery = function(label, data) { if (!Array.isArray(data)) return; for (i=0; i