$(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; iAtpakaļ"); b.data('parentId', cat.parentId); b.click(function(e){ offerMapSearchClear(); activeFilterCategory = $(this).data('parentId'); drawFilterCategories($(this).data('parentId'), 'left'); e.preventDefault(); }); $('.filterCategories').append(b); var b = $(""+cat.title+" ("+offerCounts[cat.id]+")"); b.data('catid', cat.id); b.click(function(e){ activateFilterCategory($(this).data('catid')); e.preventDefault(); }); $('.filterCategories').append(b); } for (i=0; i"+cat.title+" ("+offerCounts[cat.id]+")"); b.data('catid', cat.id); b.data('hasChildren', hasChildren); b.click(function(e){ offerMapSearchClear(); if ($(this).data('hasChildren')) { activeFilterCategory = $(this).data('catid'); drawFilterCategories($(this).data('catid'), 'right'); } else { activateFilterCategory($(this).data('catid')); } e.preventDefault(); }); $('.filterCategories').append(b); } } //activate if (activeFilterCategory) { activateFilterCategory(activeFilterCategory); } else { offerMapRefresh(); } $('.filterCategories').css({left:pos2}); $('.filterCategories').animate({left: 0, opacity: 1}, time); }); } function placeTypeClick(element) { $('.placeType').removeClass('active'); $(element).addClass('active'); } function placeInsertMove(i) { if (currentStep == 5 && i == 1) { map.extractDeliveryData('setDelivery'); } //error checks if (i==1) { //check if type is selected if ( currentStep == 1 && $('.placeType.active').length==0) { alert("Norādi vietas veidu"); return; } //check if name is filled if (currentStep == 2 && $('#placeName').val().trim() == '') { alert("Norādi vietas nosaukumu"); return; } //check if email is filled if (currentStep == 3 && !validateEmail($('#placeEmail').val().trim())) { alert("Norādi derīgu e-pasta adresi"); return; } //check if phone is filled if (currentStep == 3 && $('#placePhone').val() == '') { alert("Norādi telefona numuru"); return; } //check if location is set if (currentStep == 4 && $('#placeLatitude').val() == '') { alert("Norādi atrašanās vietu uz kartes"); return; } } currentStep+=i; if (i==1 && currentStep == 4 && $('#setLocation').html() == '') { setTimeout(function(){ initMapSetLocation(); resized(); },400); setTimeout(function(){ $(window).trigger('resize'); resized(); }, 300); } $('.step').hide(); $('.step'+currentStep).show(); if (currentStep == 1) $('.back').hide(); else $('.back').show(); if (currentStep == 6) { $('.forward').hide(); $('.confirm').show(); } else { $('.forward').show(); $('.confirm').hide(); } if (i == -1) { $(window).trigger('resize'); resized(); } } function placeConfirm() { var place = {}; place.type = $('.placeType.active').attr('typeId'); place.name = $('#placeName').val(); place.info_lv = $('#placeInfo_lv').val(); place.info_en = $('#placeInfo_en').val(); place.info_ru = $('#placeInfo_ru').val(); place.email = $('#placeEmail').val(); place.phone = $('#placePhone').val(); place.webpage = $('#placeWebpage').val(); place.facebookLink = $('#placeFacebookLink').val(); place.address = $('#placeAddress').val(); place.latitude = $('#placeLatitude').val(); place.longitude = $('#placeLongitude').val(); place.delivery = $('.deliveryAvailable').val(); place.deliveryData = $('#deliveryData').val(); place.images = []; $('.imageUploaded').each(function(){ place.images.push($(this).attr('hash')); }); place.images = place.images.join(","); place.image = $('.imageUploaded.active').length > 0 ? $('.imageUploaded.active').attr('hash') : ''; poster.post("/place/insertConfirm", place, function(resp){ if (resp.substr(0,2) == "OK") { var id = resp.split(":")[1]; document.location = "/place/edit?id="+id+"&offers"; } else { alert("Neizdevās saglabāt vietu. Mēģini vēlreiz"); } //$('.finish').slideDown(); //$('.step, .buttonArea').slideUp(); }); } function initMain() { map.markers['myLocation'] = new ol.style.Style({ image: new ol.style.Icon({ anchor: [94, 90], anchorXUnits: 'pixels', anchorYUnits: 'pixels', opacity: 1, scale: .2, src: '/img/myPlaceMarker.png' }) }); map.create('map'); drawMain(); $('.placeFilter').click(function(){ $(this).toggleClass('active'); drawMain(); }); var m = map.maps['map']; m.map.on('pointermove', function (e) { var placeId = false; m.map.forEachFeatureAtPixel(e.pixel, function (f) { placeId = f.placeId; return true; }); if (placeId) { this.getTargetElement().style.cursor = 'pointer'; placeMouseMove(placeId); } else { this.getTargetElement().style.cursor = ''; placeMouseOut(); } }); $('#map').mouseout(function(){ placeMouseOut(); }) m.map.on('click', function (e) { var placeId = false; m.map.forEachFeatureAtPixel(e.pixel, function (f) { placeId = f.placeId; return true; }); if (placeId) { popupLoad("/place/view/"+placeId+"?popup"); } }); } function drawMain(){ var m = map.maps['map']; m.source.clear(); var activeTypes = []; $('.placeFilterType.active').each(function(){ activeTypes.push($(this).attr('typeId')); }); var activeCategories = []; $('.placeFilterCategory.active').each(function(){ activeCategories.push($(this).attr('categoryId')); }); if (activeDelivery && activeDelivery.length > 0) { map.setDelivery("map", activeDelivery); } console.log(activeCategories); for (i=0; i activeCategories.includes(value)); if (d[2] == 1 && filteredArray.length == 0 && !noOfferMatch) visible = false; if (d[3] == 1942) { console.log([activeCategories, d[4], noOfferMatch]); } var label = 'type'+d[2]; if (d[2] == 1 && d[5] == 1) label = 'redDelivery'; if (visible) { map.addMarker('map', d[1],d[0], label, d[3]); } } if (m.myLocation && !isMobile()) { var feature = new ol.Feature(new ol.geom.Point(m.myLocation)); feature.setStyle(map.markers['myLocation']); m.source.addFeature(feature); } } function checkAllPlaceType(element) { if ($(element).data('status')) { $('.placeFilterType').addClass('active'); $(element).data('status', false); } else { $('.placeFilterType').removeClass('active'); $(element).data('status', true); } drawMain(); } function checkAllPlaceCategory(element) { if ($(element).data('status')) { $('.placeFilterCategory').addClass('active'); $(element).data('status', false); } else { $('.placeFilterCategory').removeClass('active'); $(element).data('status', true); } drawMain(); } var activeDelivery = false; var mainMapPlaceId = false; function placeMouseMove(placeId) { if (!isMobile()) if (!mainMapPlaceId || mainMapPlaceId != placeId) { $('.hoverPopup').html("Ielādē..."); $('.hoverPopup').stop().fadeIn(200); var myLocation = "";//lonlat(map.maps['map'].myLocation); if (map.maps['map'].myLocation) { var lonlat = ol.proj.transform(map.maps['map'].myLocation, 'EPSG:3857', 'EPSG:4326'); myLocation = lonlat[1]+","+lonlat[0]; } if (placeId == 'myLocation') { $.get("/place/myLocationInfo", function(resp){ $('.hoverPopup').html(resp); }) } else { var url = mapType == 'offer' ? "/place/hoverInfo?placeId="+placeId : '/demand/view?userId='+placeId; $.get(url, function(resp){ $('.hoverPopup').html(resp); }) } } mainMapPlaceId = placeId; $('.hoverPopup').css({ left: map.mx+20, top: map.my-30, }); } function placeMouseOut() { if (mainMapPlaceId) { $('.hoverPopup').stop().fadeOut(200); //activeDelivery = false; //drawMain(); } mainMapPlaceId = false; } function initMapSetLocation() { console.log(1); if ($('#setLocation').html() != "") return; console.log(2); map.create("setLocation"); map.enableSetLocation("setLocation"); } function initMapSetDelivery() { if ($('#setDelivery').html() != "") return; map.create("setDelivery"); map.enableSetDelivery('setDelivery'); }function initDropzone(multiple, id) { if (!id) id = 'imageArea'; var dropzoneMultiple = false; var myDropZone = false; dropzoneMultiple = multiple; var strInsert = "Ielādēt attēlu(s)"; strInsert = strInsert.split("{"+"{").join("").split("+"+"}").join(""); $('#'+id).append(""+strInsert+""); myDropZone = new Dropzone("#"+id+" #imageInsert", { url: "/image/receive", clickable: "#"+id+" #imageInsert", sending: function(){ $("#"+id+" #imageInsert").html("Ielādējas..."); }, queuecomplete: function(){ $("#"+id+" #imageInsert").html(strInsert); }, success: function (file, response) { if (response[0] == '{') { var d = JSON.parse(response); var hash = d.hash; imageAdd(hash, false, true, id); } else { alert("Neizdevās ielādēt attēlu. Pamēģini citu failu vai formātu."); } }, }); //$('#imageArea').sortable(); } function imageRemove(element) { var newActive = $(element).parent().hasClass('active'); $(element).parent().fadeOut(function(){ $(this).remove(); if (newActive) { $('.imageUploaded').first().addClass('active'); } }) } function imageAdd(hash, active, isNew, id) { if (!id) id = 'imageArea'; var uploaded = $(""); uploaded.insertBefore('#'+id+' #imageInsert'); uploaded.click(function(){ $('#'+id+' .imageUploaded.active').removeClass('active'); $(this).addClass('active'); }); if (isNew) { uploaded.css('opacity', 0); uploaded.animate({opacity: 1}, 500); if($('#'+id+' .imageUploaded.active').length == 0) { $('#'+id+' .imageUploaded').first().addClass('active'); } } if (active) { uploaded.addClass('active'); } }var offerSearchTimeout = false; var offerFilterPlaceIds = false; function offerMapSearchClear() { $(".mapSearch").val(''); offerFilterPlaceIds = false; } function offerMapSearch() { if (offerSearchTimeout) clearTimeout(offerSearchTimeout); offerSearchTimeout = setTimeout(function(){ var str = $(".mapSearch").val(); if (str.trim() == '') { activeFilterCategory = 0; offerFilterPlaceIds = false; drawFilterCategories(0); activateFilterCategory(0); offerMapRefresh(); $('.suggestions').hide(); return; } poster.post("/offer/filter", {str: str}, function(resp){ var obj = JSON.parse(resp); offerFilterPlaceIds = obj.placeIds; drawFilterCategories(0); offerMapRefresh(); $('.suggestions .options').html(""); for (i=0; i"+s.title+""); opt.data('parentId', s.parentId); opt.data('catid', s.id); opt.click(function(e){ var cid = 0; for (i=0; i userCategories.includes(value)); //var label = visible ? 'red' : 'redTrans'; if (visible) { var label = 'red'; if (userPlace.length > 0) { label = 'blue'; } if (p.delivery == 'yes') { label = label + "Delivery"; } if (p.typeId != 1) { label = 'type5'; } //if (noCategories) // label = 'type3'; map.addMarker('map', p.longitude,p.latitude, label, p.id); } } if (userLocation) { map.addMarker('map', userLocation[1], userLocation[0], 'myLocation', 'myLocation'); console.log(userLocation); } }function initDemandMap() { map.create('map'); var m = map.maps['map']; for (i=0; i"); if (parentId) { var td = $("←"); td.click(function(){ var el = chooseCatPath.pop(); el = chooseCatPath.pop(); if (el) switchCatChooser(el[0],el[1]); else switchCatChooser(0); }); tr.append(td); n++; } $('.chooseCat table').html(""); for (i=0; i"); n=0; } n++; var subCatCount = 0; for (j=0; j"+title+""); td.click(function(){ var elementId = $(this).attr('elementid'); var target = $(this).hasClass("target"); if (!target) { switchCatChooser(elementId, $(this).html()); } else { chooseCat(elementId); } }); tr.append(td); } for (i=n; i<((isMobile && isMobile()) ? 4 : 5); i++) { tr.append(" "); } $('.chooseCat table').append(tr); } function switchCatChooser(pid, title) { if (title) { chooseCatPath.push([pid, title]); } var path = []; for (i=0; i"+chooseCatPath[i][1]+""); } $('#chooseCatPath').html(path.join("")); drawCatChooser(pid); }