1Object.defineProperty(Array.prototype, 'chunk', { 2 value: function(chunkSize) { 3 var R = []; 4 for (var i=0; i<this.length; i+=chunkSize) 5 R.push(this.slice(i,i+chunkSize)); 6 return R; 7 } 8}); 9Vue.config.devtools = false; 10var profile = new Vue({ 11 el: '#profile_page', 12 data : { 13 talkas_id: '', 14 profile: {}, 15 leader_talkas: [], 16 loggedIn: false, 17 action: 'view', //login/edit 18 showModal:false, 19 talkaNotFound:false, 20 news: [], 21 participants: [], 22 }, 23 mounted() { 24 let that = this; 25 // console.log('profile mounted') 26 this.talkas_id = jQuery("#talkas_id").val(); 27 let action = jQuery("#action").val(); 28 if( action) { 29 this.action = action; 30 // console.log(action) 31 } 32 this.initTalka(this.talkas_id); 33 34 jQuery('#confirmApplication').on('click', function (e) { 35 e.preventDefault(); 36 that.applyTalka(); 37}); 38 jQuery('#login-button').on('click', function (e) { 39 e.preventDefault(); 40 41 }); 42 }, 43 methods: { 44 logoutAction() { 45 let that = this; 46 var url = 'https://api.talkas.lv/index.php/talkas-api/' + that.talkas_id + '/logout'; 47 var redirect = 'https://talkas.lv/apstiprinatas-talkas/' + that.talkas_id; 48 49 jQuery.ajax({ 50 type:'POST', 51 data: { 52 token: jQuery("#token").val() 53 }, 54 url: url, 55 success: function(data) { 56 window.location.href = redirect; 57 } 58 }); 59 }, 60 loginAction() { 61 let that = this; 62 jQuery.ajax({ 63 type: 'POST', 64 data: jQuery('#login-form').serializeArray(), 65 url: 'https://api.talkas.lv/index.php/talkas-api/' + that.talkas_id + '/login', 66 success: function (response) { 67 68 if(! response.token) { 69 jQuery("#msgBox").css('color','red').html('AutorizÄcija neizdevÄs!') 70 return false; 71 } 72 jQuery.ajax({ 73 type: 'POST', 74 url: ajax_url, 75 data: { 76 action: 'set_auth', 77 token: response.token, 78 talkas_id: that.talkas_id 79 }, 80 success: function(data) { 81 window.location.href = 'https://talkas.lv/apstiprinatas-talkas/'+that.talkas_id+'/edit' 82 } 83 }) 84 } 85 }).done(function(data) { 86 }); 87 }, 88 isBoth() { 89 return this.isTrash() && this.isImprovements(); 90 }, 91 isTrash() { 92 return this.profile.collect_trash === 1; 93 94 }, 95 isImprovements() { 96 return this.profile.improvements === 1; 97 }, 98 applyTalka() { 99 let that = this; 100 var url = 'https://api.talkas.lv/index.php/talkas-api/' + this.talkas_id + '/apply'; 101 if(jQuery("#social_id").val() =="" && jQuery("#email").val() == "") { 102 alert('autorizÄjes ar facebook vai ievadi e-pastu!'); 103 return false; 104 } 105 jQuery.ajax({ 106 type:'POST', 107 data: jQuery("#applyForm").serializeArray(), 108 url: url, 109 success: function(data) { 110 111 jQuery("#applyToCleanup").modal('hide'); 112 113 location.reload(); 114 115 } 116 }); 117 118 }, 119 deleteTalkasInfo(id) { 120 let that = this; 121 var url = 'https://api.talkas.lv/index.php/talkas-api/' + that.talkas_id + '/delete-info'; 122 jQuery.ajax({ 123 type:'POST', 124 url: url, 125 data: { 126 token:jQuery("#token").val(), 127 id: id 128 }, 129 success: function(data) { 130 location.reload(); 131 } 132 }); 133 }, 134 initTalka(talkas_id) { 135 let that = this; 136 var url = 'https://api.talkas.lv/index.php/talkas-api/' + talkas_id; 137 jQuery.ajax({ 138 type: 'GET', 139 url: url, 140 141 success: function(data) { 142 that.profile = data[0]; 143 that.news = that.profile ? that.profile.infos : null; 144 that.participants = that.profile && that.profile.participants ? that.profile.participants : null; 145 if(that.participants && that.participants.length) { 146 that.participants = that.participants.reverse(); 147 } 148 if((! that.profile) || !that.profile.approved) { 149 that.talkaNotFound = true; 150 // console.log("talka not found") 151 } 152 } 153 }); 154 jQuery.ajax({ 155 type: 'GET', 156 url: 'https://api.talkas.lv/index.php/talkas-api/leader-talkas/' + that.talkas_id, 157 158 success: function(data) { 159 that.leader_talkas = data; 160 } 161 }); 162 }, 163 showEditForm() { 164 let that = this; 165 var $modal = jQuery("#base-modal"); 166 var url = 'https://api.talkas.lv/index.php/talkas-api/' + that.talkas_id + '/edit-form'; 167 jQuery.ajax({ 168 type:'POST', 169 url: url, 170 data: { 171 token:jQuery("#token").val() 172 }, 173 success: function(data) { 174 jQuery("#base-modal-content").html(data); 175 $modal.modal() 176 } 177 }); 178 }, 179 showAddInfoForm() { 180 let that = this; 181 var $modal = jQuery("#base-modal"); 182 var url = 'https://api.talkas.lv/index.php/talkas-api/' + that.talkas_id + '/info-form'; 183 jQuery.ajax({ 184 type:'POST', 185 data: { 186 token:jQuery("#token").val() 187 }, 188 url: url, 189 success: function(data) { 190 jQuery("#base-modal-content").html(data); 191 $modal.modal() 192 } 193 }); 194 }, 195 isViewAction() { 196 return this.action == 'view'; 197 }, 198 isEditAction() { 199 return this.action == 'edit'; 200 }, 201 isLoginAction() { 202 return this.action == 'login'; 203 }, 204 isTalkaFound() { 205 return !this.talkaNotFound 206 }, 207 scrollTo(to) { 208 scroll_to('#' + to); 209 }, 210 socialShare(type) { 211 let url = 'https://talkas.lv/apstiprinatas-talkas/' + this.talkas_id; 212 let text = this.profile.title; 213 if(type === 'fb') { 214 FB.ui({ 215 method: 'share', 216 href: url, 217 }, function(response){}); 218 } 219 if(type === 'tw') { 220 221 this.open_window("https://twitter.com/intent/tweet?text="+text+" &url="+ url,500,500) 222 223 } 224 225 if(type === 'dr') { 226 let baseUrl = "https://www.draugiem.lv/say/ext/add.php?title=" + text 227 + "&link=" + url + "&titlePrefix=Talkas.lv"; 228 229 this.open_window(baseUrl,500,500) 230 } 231 232 }, 233 open_window(url, width, height) { 234 var my_window; 235 var center_left = (screen.width / 2) - (width / 2); 236 var center_top = (screen.height / 2) - (height / 2); 237 238 my_window = window.open(url, "Share", "scrollbars=0, width="+width+", height="+height+", left="+center_left+", top="+center_top); 239 my_window.focus(); 240} 241 }, 242}); 243var app = new Vue({ 244 el: '#laimes_koki', 245 data: { 246 laimes_koki:[], 247 koki:[], 248 perPage: 12, 249 250 }, 251 watch: { 252 laimes_koki: function (value) { 253 this.koki = value.chunk(3); 254 } 255 }, 256 mounted() { 257 258 this.getData(); 259 var that = this; 260 this.$on("save",function(payload) { 261 that.getData(); 262 }) 263 264 }, methods: {
265 loadMore() { 266 this.getData(); 267 }, 268 getData() { 269 var that = this; 270 271 272 jQuery.ajax({ 273 type: 'POST', 274 url: ajax_url, 275 data: { action: 'get_laimeskoki_data', limit:that.perPage,year:jQuery("#year").val() }, 276 success: function(data) { 277 var response = JSON.parse(data); 278 that.laimes_koki = response; 279 that.perPage = that.perPage+12; 280 jQuery('img.avatar').error( function() { 281 jQuery(this).attr('src', 'https://api.talkas.lv/images/avatar.png'); 282 }); 283 } 284 }) 285 } 286 } 287}); 288jQuery(document).ready(function(){ 289 toggle_sub_menu(); 290 set_sticky_footer(); 291 remove_main_padding(); 292 init_autocomplete(); 293 load_more(); 294 handle_laimeskoki_form(); 295 handle_talkas_form(); 296 handle_pollution_form(); 297 handle_pollution_form_new(); 298 handle_volunteer_form(); 299 handle_referendum_form(); 300 youtube_videos(); 301 countdown(); 302 303 304 jQuery(document).on('click', '[data-toggle="ekko-lightbox"]', function(event) { 305 event.preventDefault(); 306 jQuery(this).ekkoLightbox(); 307 }); 308 309}); 310 311var regions; 312 313function countdown() { 314 var elements = { 315 thanks: jQuery('#countdown #thanks'), 316 timer: jQuery('#countdown #timer'), 317 days: jQuery(this.timer).find('#days').find('h1'), 318 hours: jQuery(this.timer).find('#hours').find('h1'), 319 minutes: jQuery(this.timer).find('#minutes').find('h1') 320 } 321 322 function format(number) { 323 if (number < 10) { 324 return '0' + number; 325 } else { 326 return number; 327 } 328 } 329 330 setInterval(function() { 331 332 var timer = { 333 end_time: new Date('Apr 28, 2018 00:00:00').getTime(), 334 current: new Date().getTime(), 335 distance: function() { return this.end_time - this.current }, 336 days: function() { return Math.floor(timer.distance() / (1000 * 60 * 60 * 24)) }, 337 hours: function() { return Math.floor((timer.distance() % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)) }, 338 minutes: function() { return Math.floor((timer.distance() % (1000 * 60 * 60)) / (1000 * 60)) }, 339 expired: function() { 340 jQuery(elements.timer).addClass('hidden'); 341 jQuery(elements.thanks).removeClass('hidden'); 342 }, 343 running: function() { 344 jQuery(elements.timer).removeClass('hidden'); 345 jQuery(elements.thanks).addClass('hidden'); 346 jQuery(elements.days).text(format(this.days())); 347 jQuery(elements.hours).text(format(this.hours())); 348 jQuery(elements.minutes).text(format(this.minutes())); 349 } 350 } 351 352 if (timer.distance() < 0) { 353 timer.expired(); 354 clearInterval(); 355 } else { 356 timer.running(); 357 } 358 359 360 }, 1000); 361} 362 363function youtube_videos() { 364 jQuery.get( 365 'https://www.googleapis.com/youtube/v3/channels', { 366 part: 'contentDetails', 367 id: 'UC_NouHzDIU98aLf-FVM5B7Q', 368 key: 'AIzaSyCYIFHvRW6l8YC-NJJBAC3yB8qDD0Ae4Os' }, 369 function(data) { 370 for (var i = 0; i < data.items.length; i++) { 371 var playlist_id = data.items[i].contentDetails.relatedPlaylists.uploads; 372 display(playlist_id); 373 } 374 } 375 ); 376 377 function display(playlist_id) { 378 jQuery.get( 379 'https://www.googleapis.com/youtube/v3/playlistItems', { 380 part: 'snippet', 381 maxResults: 10, 382 playlistId: playlist_id, 383 key: 'AIzaSyCYIFHvRW6l8YC-NJJBAC3yB8qDD0Ae4Os' }, 384 function(data) { 385 jQuery('.video-feed .item').each(function(i) { 386 var video_url = 'https://www.youtube.com/embed/' + data.items[i].snippet.resourceId.videoId; 387 jQuery(this).attr('src', video_url); 388 }) 389 } 390 ); 391 } 392} 393 394 395function init_autocomplete() { 396 jQuery.ajax({ 397 type: 'POST', 398 url: ajax_url, 399 data: { action: 'get_regions' }, 400 success: function(data) { 401 var response = JSON.parse(data); 402 regions = jQuery.map(response, function(str) { 403 if (str != 'RÄ«ga') { 404 return str + ' novads'; 405 } else { 406 return str; 407 } 408 }) 409 410 jQuery('#region').autocomplete({ 411 source: regions 412 }); 413 } 414 }) 415} 416 417function set_equal_height(target_class) { 418 var heights = []; 419 jQuery('.' + target_class).each(function() { heights.push(this.offsetHeight); }); 420 var max_height = Math.max.apply(null, heights); 421 jQuery('.' + target_class).height(max_height); 422} 423 424function toggle_sub_menu() { 425 jQuery('header .mobile-nav .menu li.menu-item-has-children > a').on('click', function(e) { 426 e.preventDefault(); 427 jQuery(this).parent().find('.sub-menu').toggleClass('hidden'); 428 }) 429 jQuery('header .desktop-nav .menu li').on('hover', function() { 430 jQuery(this).find('.sub-menu').toggleClass('hidden'); 431 }) 432} 433 434function toggle_mobile_nav() { 435 jQuery('.mobile-nav').toggleClass('hidden'); 436} 437 438function set_sticky_footer() { 439 var footer = jQuery('footer'); 440 var wrapper = jQuery('main #wrapper'); 441 442 jQuery(window).on('resize', function() { 443 wrapper.css({ paddingBottom: footer.outerHeight() }) 444 footer.css({ marginTop: -footer.outerHeight() }) 445 }).resize(); 446} 447 448function init_profile_map() { 449 if (jQuery('.talkas-profile').length > 0) { 450 var map_container = jQuery('#profile-map'); 451 var main = jQuery('main'); 452 var defaultLat = 56.946285; 453 var defaultLng = 24.105078; 454 // console.log("initialized"); 455 if (map_container.length > 0) { 456 457 jQuery(window).on('resize', function() { 458 if (jQuery(window).width() > 767) { 459 map_container.css({ height: 743 }) 460 } else { 461 map_container.css({ height: 400 }) 462 } 463 }).resize(); 464 465 466 main.css({ padding: 0 }) 467 468 var geocoder = new google.maps.Geocoder(); 469 var marker_icon = jQuery('#marker-icons').find('option').last().attr('data-marker-icon'); 470 var marker_add_icon = jQuery('#marker-icons').find('option').first().attr('data-marker-icon'); 471 var center_address = 'RÄ«ga, Latvia'; 472 473 var map = new google.maps.Map(document.getElementById('profile-map'), { 474 mapTypeControl: false, 475 scrollwheel: false, 476 zoom: 8, 477 center: { 478 lat: defaultLat, 479 lng: defaultLng 480 }, 481 zoomControlOptions: { position: google.maps.ControlPosition.LEFT_TOP }, 482 streetViewControlOptions: { position: google.maps.ControlPosition.LEFT_TOP } 483 }); 484 485 var talkas_id = jQuery('#talkas_id').val(); 486 if(! talkas_id) talkas_id = 'approved'; 487 jQuery.ajax({ 488 type: 'GET', 489 url: 'https://api.talkas.lv/index.php/talkas-api/' + talkas_id, 490 data: {}, 491 success: function(response) { 492 if(response.length) { 493 response.forEach(function(item, index) { 494 var lng = parseFloat(item.longitude); 495 var lat = parseFloat(item.latitude); 496 var info_window = new google.maps.InfoWindow(); 497 var talkas_type; 498 // console.log(item, item.collect_trash, item.improvements) 499 if(item.collect_trash == 1 && item.improvements == 1) { 500 talkas_type = 'both'; 501 } else if(item.collect_trash == 1) { 502 talkas_type = 'cleanup'; 503 } else { 504 talkas_type = 'improvements'; 505 } 506 507 marker_icon = jQuery('#marker-'+ talkas_type).attr('data-marker-icon'); 508 509 function create_marker(lat, lng, content) { 510 511 let icon = { 512 url: marker_icon, 513 scaledSize: new google.maps.Size(30, 45), 514 origin: new google.maps.Point(0,0), 515 anchor: new google.maps.Point(15, 45) 516 } 517 var marker = new google.maps.Marker({ 518 position: { lat: lat, lng: lng }, 519 map: map, 520 icon: icon 521 }); 522 523 google.maps.event.addListener(marker, 'click', function () { 524 info_window.setContent(content); 525 info_window.open(map, marker); 526 }); 527 528 } 529 530 var marker_data = item; 531 532 var html = '<div style="font-size: 12px">' + 533 '<p>' + marker_data.region + '</p>' + 534 '<p>' + marker_data.address + '</p>' + 535 '<p><img src="https://s3.us-east-2.amazonaws.com/upload-icon/uploads/icons/png/15536426391556279788-32.png"/></p>' + 536 537 '<p><b>Apraksts:</b><p><p>' + marker_data.description + '</p>'; 538 html = '<div class="iw-container">' + 539 '<div class="iw-title">'+ marker_data.title +'</div>' + 540 '<p>' + marker_data.region + '</p>' + 541 '<p>' + marker_data.address + '</p>' + 542 '<p><b>Apraksts:</b><p><p>' + marker_data.description + '</p>' + 543 '<a class="btn btn-default btn-xs center-block" href="https://talkas.lv/apstiprinatas-talkas/'+ marker_data.talkas_id + '">SKATĪT VAIRÄK</a>' + 544 '</div>'; 545 546 547 if (marker_data.approved == "1") { create_marker(lat, lng, html); } 548 549 550 google.maps.event.addListener(info_window, 'domready', function() { 551 552 // Reference to the DIV which receives the contents of the infowindow using jQuery 553 var iwOuter = jQuery('.gm-style-iw'); 554 555 /* The DIV we want to change is above the .gm-style-iw DIV. 556 * So, we use jQuery and create a iwBackgroun
556d variable, 557 * and took advantage of the existing reference to .gm-style-iw for the previous DIV with .prev(). 558 */ 559 var iwBackground = iwOuter.prev(); 560 561 // Remove the background shadow DIV 562 iwBackground.children(':nth-child(2)').css({'display' : 'none'}); 563 564 // Remove the white background DIV 565 iwBackground.children(':nth-child(4)').css({'display' : 'none'}); 566 567 }); 568 }); 569 570 571 } 572 573 574 } 575 }) 576 577 } 578 } 579} 580 581function init_talkas_map() { 582 if (jQuery('.add-a-point.talkas-map').length > 0) { 583 var map_container = jQuery('#map'); 584 var aside = jQuery('aside'); 585 var main = jQuery('main'); 586 var form = jQuery('.talkas-map form'); 587 var initial_stage = jQuery('.stage-1'); 588// console.log("initialized") 589 if (map_container.length > 0) { 590 591 jQuery(window).on('resize', function() { 592 if (jQuery(window).width() > 767) { 593 map_container.css({ height: aside.outerHeight() }) 594 } else { 595 map_container.css({ height: 400 }) 596 } 597 }).resize(); 598 599 initial_stage.find('a.btn').on('click', function() { 600 var next_stage = jQuery('.stage-2'); 601 initial_stage.addClass('hidden'); 602 next_stage.removeClass('hidden'); 603 window.dispatchEvent(new Event('resize')); 604 }) 605 606 main.css({ padding: 0 }) 607 608 var geocoder = new google.maps.Geocoder(); 609 var marker_icon = jQuery('#marker-icons').find('option').last().attr('data-marker-icon'); 610 var marker_add_icon = jQuery('#marker-icons').find('option').first().attr('data-marker-icon'); 611 var center_address = 'RÄ«ga, Latvia'; 612 613 var map = new google.maps.Map(document.getElementById('map'), { 614 mapTypeControl: false, 615 scrollwheel: false, 616 zoom: 8, 617 // zoomControlOptions: { position: google.maps.ControlPosition.LEFT_TOP }, 618 // streetViewControlOptions: { position: google.maps.ControlPosition.LEFT_TOP }, 619 // gestureHandling: 'greedy', 620 zoomControl: true, 621 zoomControlOptions: { 622 position: google.maps.ControlPosition.RIGHT_TOP 623 }, 624 fullscreenControl: false, 625 streetViewControl: true, 626 streetViewControlOptions: { 627 position: google.maps.ControlPosition.LEFT_TOP 628 } 629 }); 630 631 var marker_add = new google.maps.Marker({ 632 map: map, 633 draggable: true, 634 optimized: false, 635 zIndex: 9999999999, 636 icon: marker_add_icon, 637 animation: google.maps.Animation.BOUNCE 638 }); 639 640 marker_add.addListener('dragstart', function() { 641 this.setAnimation(''); 642 }) 643 644 marker_add.addListener('dragend', function() { 645 // form.find('input').prop('disabled', false); 646 form.find('textarea').prop('disabled', false); 647 form.find('a.btn').removeAttr('disabled'); 648 649 var lat = this.getPosition().lat(); 650 var lng = this.getPosition().lng() 651 var lat_lng = new google.maps.LatLng(lat, lng); 652 geocoder.geocode({ 'latLng': lat_lng }, function(results, status) { 653 if (status == google.maps.GeocoderStatus.OK) { 654 var address = results[0].formatted_address; 655 // console.log(results); 656 // const formatted_address = results[0].address_components; 657 // console.log(formatted_address); 658 // let pretty_address = results[1].long_name+', '+results[2].long_name+', '+results[3].long_name+', '+results[4].short_name+'-'+results[5].long_name; 659 660 form.find('#address').val(address.replace('Unnamed Road, ', '')); 661 form.find('#lat').val(lat); 662 form.find('#lng').val(lng); 663 } 664 }) 665 }) 666 667 var center = geocoder.geocode({'address': center_address}, function(results, status) { 668 if (status == google.maps.GeocoderStatus.OK) { 669 map.setCenter(results[0].geometry.location); 670 marker_add.setPosition(results[0].geometry.location); 671 } 672 }); 673 674 jQuery.ajax({ 675 type: 'POST', 676 url: ajax_url, 677 data: { action: 'get_talkas_data' }, 678 success: function(data) { 679 return; 680 var response = JSON.parse(data); 681 // console.log(data); 682 683 var info_window = new google.maps.InfoWindow() 684 685 function create_marker(lat, lng, content) { 686 var marker = new google.maps.Marker({ 687 position: { lat: lat, lng: lng }, 688 map: map, 689 icon: marker_icon 690 }); 691 692 google.maps.event.addListener(marker, 'click', function () { 693 info_window.setContent(content); 694 info_window.open(map, marker); 695 }); 696 697 } 698 699 for (i = 0; i < response.length; i++) { 700 701 var marker_data = response[i]; 702 var lng = parseFloat(marker_data.longitude); 703 var lat = parseFloat(marker_data.latitude); 704 var html = '<div style="font-size: 10px">' + 705 '<p>' + marker_data.region + '</p>' + 706 '<p>' + marker_data.address + '</p>' + 707 '<p><b>VadÄ«tÄjs: </b>' + marker_data.leader + '</p>'+ 708 '<p><b>Tel.: </b>' + marker_data.phone_number + '</p>'+ 709 '<p><b>E-pasts: </b>' + marker_data.email + '</p>'+ 710 '<p><b>Apraksts:</b><p><p>' + marker_data.description + '</p>'; 711 712 if (marker_data.approved == "1") { create_marker(lat, lng, html); } 713 } 714 715 716 717 } 718 }) 719 720 } 721 } 722} 723 724function init_pollution_map() { 725 726 if (jQuery('.add-a-point.pollution-map').length > 0) { 727 var map_container = jQuery('#map'); 728 var aside = jQuery('aside'); 729 var main = jQuery('main'); 730 var form = jQuery('.pollution-map form'); 731 var initial_stage = jQuery('.stage-1'); 732 733 if (map_container.length > 0) { 734 735 jQuery(window).on('resize', function() { 736 if (jQuery(window).width() > 767) { 737 map_container.css({ height: aside.outerHeight() }) 738 } else { 739 map_container.css({ height: 400 }) 740 } 741 }).resize(); 742 743 main.css({ padding: 0 }) 744 745 var geocoder = new google.maps.Geocoder(); 746 var marker_icon = jQuery('#marker-icons').find('option').last().attr('data-marker-icon'); 747 var marker_add_icon = jQuery('#marker-icons').find('option').first().attr('data-marker-icon'); 748 var center_address = 'RÄ«ga, Latvia'; 749 750 var map = new google.maps.Map(document.getElementById('map'), { 751 mapTypeControl: false, 752 scrollwheel: false, 753 zoom: 8, 754 zoomControlOptions: { position: google.maps.ControlPosition.LEFT_TOP }, 755 streetViewControlOptions: { position: google.maps.ControlPosition.LEFT_TOP } 756 }); 757 758 var marker_add = new google.maps.Marker({ 759 map: map, 760 draggable: true, 761 optimized: false, 762 zIndex: 9999999999, 763 icon: marker_add_icon,
764 animation: google.maps.Animation.BOUNCE 765 }); 766 767 marker_add.addListener('dragstart', function() { 768 this.setAnimation(''); 769 }) 770 771 marker_add.addListener('dragend', function() { 772 form.find('input').prop('disabled', false); 773 form.find('textarea').prop('disabled', false); 774 form.find('a.btn').removeAttr('disabled'); 775 776 var lat = this.getPosition().lat(); 777 var lng = this.getPosition().lng() 778 var lat_lng = new google.maps.LatLng(lat, lng); 779 geocoder.geocode({ 'latLng': lat_lng }, function(results, status) { 780 if (status == google.maps.GeocoderStatus.OK) { 781 var address = results[0].formatted_address; 782 form.find('#address').val(address.replace('Unnamed Road, ', '')); 783 form.find('#lat').val(lat); 784 form.find('#lng').val(lng); 785 } 786 }) 787 }) 788 789 var center = geocoder.geocode({'address': center_address}, function(results, status) { 790 if (status == google.maps.GeocoderStatus.OK) { 791 map.setCenter(results[0].geometry.location); 792 marker_add.setPosition(results[0].geometry.location); 793 } 794 }); 795 796 jQuery.ajax({ 797 type: 'POST', 798 url: ajax_url, 799 data: { action: 'get_pollution_data' }, 800 success: function(data) { 801 var response = JSON.parse(data); 802 803 var info_window = new google.maps.InfoWindow() 804 805 function create_marker(lat, lng, content, icon) { 806 if(typeof icon === typeof undefined){ 807 icon = marker_icon 808 } 809 var marker = new google.maps.Marker({ 810 position: { lat: lat, lng: lng }, 811 map: map, 812 icon: { 813 url: icon, 814 scaledSize: new google.maps.Size(32, 44), 815 origin: new google.maps.Point(0,0), 816 anchor: new google.maps.Point(16, 44) 817 } 818 }); 819 820 google.maps.event.addListener(marker, 'click', function () { 821 info_window.setContent(content); 822 info_window.open(map, marker); 823 }); 824 825 } 826 for (i = 0; i < response.length; i++) { 827 var lng = parseFloat(response[i].longitude); 828 var lat = parseFloat(response[i].latitude); 829 830 if (response[i].image != '') { 831 var html = '<div style="font-size: 10px">' + 832 '<a href="'+response[i].image+'" data-toggle="ekko-lightbox">' + 833 '<div style="margin-bottom: 10px; background-repeat: no-repeat; background-size: cover; background-position: center; width: 100px; height: 100px; background-image: url('+response[i].image+');"></div></a>' + 834 '<p>' + response[i].region + '</p>' + 835 '<p>' + response[i].address + '</p>' + 836 '<p><b>Apraksts:</b><p><p>' + response[i].description + '</p></div>'; 837 } else { 838 var html = '<div style="font-size: 10px">' + 839 '<p>' + response[i].region + '</p>' + 840 '<p>' + response[i].address + '</p>' + 841 '<p><b>Apraksts:</b><p><p>' + response[i].description + '</p></div>'; 842 } 843 844 create_marker(lat, lng, html); 845 } 846 847 jQuery.ajax({ 848 type: 'GET', 849 url: 'https://api.talkas.lv/index.php/talkas-api/approved', 850 data: {}, 851 success: function(response) { 852 if (response.length) { 853 response.forEach(function (item, index) { 854 var lng = parseFloat(item.longitude); 855 var lat = parseFloat(item.latitude); 856 var info_window = new google.maps.InfoWindow(); 857 var talkas_type; 858 // console.log(item, item.collect_trash, item.improvements) 859 if (item.collect_trash == 1 && item.improvements == 1) { 860 talkas_type = 'both'; 861 } else if (item.collect_trash == 1) { 862 talkas_type = 'cleanup'; 863 } else { 864 talkas_type = 'improvements'; 865 }
866 if(talkas_type !== 'improvements' && item.approved == '1') { 867 marker_icon = jQuery('#marker-' + talkas_type).val(); 868 html = '<div class="iw-container">' + 869 '<div class="iw-title">' + item.title + '</div>' + 870 '<p>' + item.region + '</p>' + 871 '<p>' + item.address + '</p>' + 872 '<p><b>Apraksts:</b><p><p>' + item.description + '</p>' + 873 '<a class="btn btn-default btn-xs center-block" href="https://talkas.lv/apstiprinatas-talkas/' + item.talkas_id + '">SKATĪT VAIRÄK</a>' + 874 '</div>'; 875 create_marker(lat, lng, html); 876 } 877 }); 878 } 879 } 880 }); 881 882 if(typeof customMarkers !== typeof undefined) { 883 let jsonData = JSON.parse(customMarkers); 884 jQuery.each(jsonData, function(key, val) { 885 let html = '<div style="font-size: 10px">' + 886 '<p>' + val.point.address + '</p>' + 887 '<p><b>' + val.title + '</b><p><p>' + val.text + '</p></div>'; 888 create_marker(val.point.lat, val.point.lng, html); 889 }); 890 } 891 } 892 }) 893 } 894 } 895} 896 897function init_pollution_map_new() { 898 if (jQuery('.add-a-point.pollution-map-new').length > 0) { 899 var map_container = jQuery('#map'); 900 var aside = jQuery('aside'); 901 var main = jQuery('main'); 902 var form = jQuery('.pollution-map-new form'); 903 var initial_stage = jQuery('.stage-1'); 904 905 if (map_container.length > 0) { 906 907 jQuery(window).on('resize', function() { 908 if (jQuery(window).width() > 767) { 909 map_container.css({ height: aside.outerHeight() }) 910 } else { 911 map_container.css({ height: 400 }) 912 } 913 }).resize(); 914 915 main.css({ padding: 0 }) 916 917 var geocoder = new google.maps.Geocoder(); 918 var marker_icon = jQuery('#marker-icons').find('option').last().attr('data-marker-icon'); 919 var marker_add_icon = jQuery('#marker-icons').find('option').first().attr('data-marker-icon'); 920 var center_address = 'RÄ«ga, Latvia'; 921 922 var map = new google.maps.Map(document.getElementById('map'), { 923 mapTypeControl: false, 924 scrollwheel: false, 925 zoom: 8, 926 zoomControlOptions: { position: google.maps.ControlPosition.LEFT_TOP }, 927 streetViewControlOptions: { position: google.maps.ControlPosition.LEFT_TOP } 928 }); 929 930 var marker_add = new google.maps.Marker({ 931 map: map, 932 draggable: true, 933 optimized: false, 934 zIndex: 9999999999, 935 icon: marker_add_icon, 936 animation: google.maps.Animation.BOUNCE 937 }); 938 939 marker_add.addListener('dragstart', function() { 940 this.setAnimation(''); 941 }) 942 943 marker_add.addListener('dragend', function() { 944 form.find('input').prop('disabled', false); 945 form.find('textarea').prop('disabled', false); 946 form.find('a.btn').removeAttr('disabled'); 947 948 var lat = this.getPosition().lat(); 949 var lng = this.getPosition().lng() 950 var lat_lng = new google.maps.LatLng(lat, lng); 951 geocoder.geocode({ 'latLng': lat_lng }, function(results, status) { 952 if (status == google.maps.GeocoderStatus.OK) { 953 var address = results[0].formatted_address; 954 form.find('#address').val(address.replace('Unnamed Road, ', '')); 955 form.find('#lat').val(lat); 956 form.find('#lng').val(lng); 957 } 958 }) 959 }) 960 961 var center = geocoder.geocode({'address': center_address}, function(results, status) { 962 if (status == google.maps.GeocoderStatus.OK) { 963 map.setCenter(results[0].geometry.location); 964 marker_add.setPosition(results[0].geometry.location); 965 } 966 }); 967 968 jQuery.ajax({ 969 type: 'POST', 970 url: ajax_url, 971 data: { action: 'get_pollution_data_new' }, 972 success: function(data) { 973 var response = JSON.parse(data); 974 975 var info_window = new google.maps.InfoWindow() 976 977 function create_marker(lat, lng, content) { 978 var marker = new google.maps.Marker({ 979 position: { lat: lat, lng: lng }, 980 map: map, 981 icon: marker_icon 982 }); 983 984 google.maps.event.addListener(marker, 'click', function () { 985 info_window.setContent(content); 986 info_window.open(map, marker); 987 }); 988 989 } 990 for (i = 0; i < response.length; i++) { 991 var lng = parseFloat(response[i].longitude); 992 var lat = parseFloat(response[i].latitude); 993 994 if (response[i].image != '') { 995 var html = '<div style="font-size: 10px">' + 996 '<a href="'+response[i].image+'" data-toggle="ekko-lightbox">' + 997 '<div style="margin-bottom: 10px; background-repeat: no-repeat; background-size: cover; background-position: center; width: 100px; height: 100px; background-image: url('+response[i].image+');"></div></a>' + 998 '<p>' + response[i].region + '</p>' + 999 '<p>' + response[i].address + '</p>' + 1000 '<p><b>Apraksts:</b><p><p>' + response[i].description + '</p></div>'; 1001 } else { 1002 var html = '<div style="font-size: 10px">' + 1003 '<p>' + response[i].region + '</p>' + 1004 '<p>' + response[i].address + '</p>' + 1005 '<p><b>Apraksts:</b><p><p>' + response[i].description + '</p></div>'; 1006 } 1007 1008 create_marker(lat, lng, html); 1009 } 1010 } 1011 }) 1012 } 1013 } 1014} 1015 1016function init_laimeskoki_map() {
1017 if (jQuery('.add-a-point.laimeskoki-map').length > 0) { 1018 var map_container = jQuery('#map'); 1019 var aside = jQuery('aside'); 1020 var main = jQuery('main'); 1021 var form = jQuery('.laimeskoki-map form'); 1022 var initial_stage = jQuery('.stage-1'); 1023 1024 if (map_container.length > 0) { 1025 1026 jQuery(window).on('resize', function() { 1027 if (jQuery(window).width() > 767) { 1028 map_container.css({ height: aside.outerHeight() }) 1029 } else { 1030 map_container.css({ height: 400 }) 1031 } 1032 }).resize(); 1033 1034 main.css({ padding: 0 }) 1035 1036 var geocoder = new google.maps.Geocoder(); 1037 var marker_icon = jQuery('#marker-icons').find('option').last().attr('data-marker-icon'); 1038 var marker_add_icon = jQuery('#marker-icons').find('option').first().attr('data-marker-icon'); 1039 var center_address = 'RÄ«ga, Latvia'; 1040 1041 var map = new google.maps.Map(document.getElementById('map'), { 1042 mapTypeControl: false, 1043 scrollwheel: false, 1044 zoom: 8, 1045 zoomControlOptions: { position: google.maps.ControlPosition.LEFT_TOP }, 1046 streetViewControlOptions: { position: google.maps.ControlPosition.LEFT_TOP } 1047 }); 1048 1049 var marker_add = new google.maps.Marker({ 1050 map: map, 1051 draggable: true, 1052 optimized: false, 1053 zIndex: 9999999999, 1054 icon: marker_add_icon, 1055 animation: google.maps.Animation.BOUNCE 1056 }); 1057 1058 marker_add.addListener('dragstart', function() { 1059 this.setAnimation(''); 1060 }) 1061 1062 marker_add.addListener('dragend', function() { 1063 form.find('input').prop('disabled', false); 1064 form.find('textarea').prop('disabled', false); 1065 form.find('a.btn').removeAttr('disabled'); 1066 1067 var lat = this.getPosition().lat(); 1068 var lng = this.getPosition().lng() 1069 var lat_lng = new google.maps.LatLng(lat, lng); 1070 geocoder.geocode({ 'latLng': lat_lng }, function(results, status) { 1071 if (status == google.maps.GeocoderStatus.OK) { 1072 var address = results[0].formatted_address; 1073 form.find('#address').val(address.replace('Unnamed Road, ', '')); 1074 form.find('#lat').val(lat); 1075 form.find('#lng').val(lng); 1076 } 1077 }) 1078 }) 1079 1080 var center = geocoder.geocode({'address': center_address}, function(results, status) { 1081 if (status == google.maps.GeocoderStatus.OK) { 1082 map.setCenter(results[0].geometry.location); 1083 marker_add.setPosition(results[0].geometry.location); 1084 } 1085 }); 1086 1087 // Å¡o atkomentÄt, ja vajag rÄdÄ«t arÄ« talkas laimes koku kartÄ 1088 1089 // jQuery.ajax({ 1090 // type: 'GET', 1091 // url: 'https://api.talkas.lv/index.php/talkas-api/approved', 1092 // data: {}, 1093 // success: function(response) { 1094 // if(response.length) { 1095 // response.forEach(function (item, index) { 1096 // var lng = parseFloat(item.longitude); 1097 // var lat = parseFloat(item.latitude); 1098 // var info_window = new google.maps.InfoWindow(); 1099 // var talkas_type; 1100 // // console.log(item, item.collect_trash, item.improvements) 1101 // if(item.collect_trash == 1 && item.improvements == 1) { 1102 // talkas_type = 'both'; 1103 // } else if(item.collect_trash == 1) { 1104 // talkas_type = 'cleanup'; 1105 // } else { 1106 // talkas_type = 'improvements'; 1107 // } 1108 // 1109 // marker_icon = jQuery('#marker-'+ talkas_type).attr('data-marker-icon'); 1110 // function create_marker(lat, lng, content) { 1111 // 1112 // let icon = { 1113 // url: marker_icon, 1114 // scaledSize: new google.maps.Size(30, 45), 1115 // origin: new google.maps.Point(0,0), 1116 // anchor: new google.maps.Point(15, 45) 1117 // } 1118 // var marker = new google.maps.Marker({ 1119 // position: { lat: lat, lng: lng }, 1120 // map: map, 1121 // icon: icon 1122 // }); 1123 // 1124 // google.maps.event.addListener(marker, 'click', function () { 1125 // info_window.setContent(content); 1126 // info_window.open(map, marker); 1127 // }); 1128 // 1129 // } 1130 // 1131 // var marker_data = item; 1132 // 1133 // var html = '<div style="font-size: 12px">' + 1134 // '<p>' + marker_data.region + '</p>' + 1135 // '<p>' + marker_data.address + '</p>' + 1136 // '<p><img src="https://s3.us-east-2.amazonaws.com/upload-icon/uploads/icons/png/15536426391556279788-32.png"/></p>' + 1137 // 1138 // '<p><b>Apraksts:</b><p><p>' + marker_data.description + '</p>'; 1139 // html = '<div class="iw-container">' + 1140 // '<div class="iw-title">'+ marker_data.title +'</div>' + 1141 // '<p>' + marker_data.region + '</p>' + 1142 // '<p>' + marker_data.address + '</p>' + 1143 // '<p><b>Apraksts:</b><p><p>' + marker_data.description + '</p>' + 1144 // '<a class="btn btn-default btn-xs center-block" href="https://talkas.lv/apstiprinatas-talkas/'+ marker_data.talkas_id + '">SKATĪT VAIRÄK</a>' + 1145 // '</div>'; 1146 // 1147 // 1148 // if (marker_data.approved == "1") { create_marker(lat, lng, html); } 1149 // 1150 // 1151 // google.maps.event.addListener(info_window, 'domready', function() { 1152 // 1153 // // Reference to the DIV which receives the contents of the infowindow using jQuery 1154 // var iwOuter = jQuery('.gm-style-iw'); 1155 // 1156 // /* The DIV we want to change is above the .gm-style-iw DIV. 1157 // * So, we use jQuery and create a iwBackgroun
1157d variable, 1158 // * and took advantage of the existing reference to .gm-style-iw for the previous DIV with .prev(). 1159 // */ 1160 // var iwBackground = iwOuter.prev(); 1161 // 1162 // // Remove the background shadow DIV 1163 // iwBackground.children(':nth-child(2)').css({'display' : 'none'}); 1164 // 1165 // // Remove the white background DIV 1166 // iwBackground.children(':nth-child(4)').css({'display' : 'none'}); 1167 // 1168 // }); 1169 // }); 1170 // } 1171 // } 1172 // }); 1173 jQuery.ajax({ 1174 type: 'POST', 1175 url: ajax_url, 1176 data: { action: 'get_laimeskoki_data', limit:0, year: jQuery("#year").val(),no_avatars:true}, 1177 success: function(data) { 1178 var response = JSON.parse(data); 1179 1180 var info_window = new google.maps.InfoWindow() 1181 1182 function create_marker(lat, lng, content) { 1183 var marker = new google.maps.Marker({ 1184 position: { lat: lat, lng: lng }, 1185 map: map, 1186 icon: marker_icon 1187 }); 1188 1189 google.maps.event.addListener(marker, 'click', function () { 1190 info_window.setContent(content); 1191 info_window.open(map, marker); 1192 }); 1193 1194 } 1195 for (i = 0; i < response.length; i++) { 1196 var lng = parseFloat(response[i].longitude); 1197 var lat = parseFloat(response[i].latitude); 1198 1199 if (response[i].image != '') { 1200 var html = '<div style="font-size: 10px">' + 1201 '<a href="'+response[i].image+'" data-toggle="ekko-lightbox">' + 1202 '<div style="margin-bottom: 10px; background-repeat: no-repeat; background-size: cover; background-position: center; width: 100px; height: 100px; background-image: url('+response[i].image+');"></div></a>' + 1203 '<p>' + response[i].region + '</p>' + 1204 '<p>' + response[i].address + '</p>' + 1205 '<p><b>NovÄlÄjums:</b><p><p>' + response[i].description + '</p></div>'; 1206 } else { 1207 var html = '<div style="font-size: 10px">' + 1208 '<p>' + response[i].region + '</p>' + 1209 '<p>' + response[i].address + '</p>' + 1210 '<p><b>NovÄlÄjums:</b><p><p>' + response[i].description + '</p></div>'; 1211 } 1212 1213 create_marker(lat, lng, html); 1214 } 1215 } 1216 }) 1217 } 1218 } 1219} 1220 1221jQuery('.laimeskoki-map form').find('#description').on('click change keyup keydown', function() { 1222 if (jQuery(this).hasClass('failed')) { 1223 jQuery(this).parents().find('span.error-text').hide(); 1224 jQuery(this).removeClass('failed'); 1225 } 1226}); 1227function handle_laimeskoki_form() { 1228 var form = jQuery('.laimeskoki-map form'); 1229 var button = form.find('a.btn'); 1230 var validation = []; 1231 var send = false; 1232 var regions_match = false; 1233 1234 function readURL(input) { 1235 if (input.files && input.files[0]) { 1236 var reader = new FileReader(); 1237 reader.onload = function(e) { 1238 jQuery('#image-preview').removeClass('hidden'); 1239 jQuery('#image-preview').attr('src', e.target.result); 1240 } 1241 reader.readAsDataURL(input.files[0]); 1242 } 1243 } 1244 1245 jQuery('#image-upload').change(function() { readURL(this); }) 1246 1247 button.on('click', function() { 1248 validation = []; 1249 1250 form.find('input').each(function() { 1251 if (jQuery(this).attr('id') != 'image-upload') { 1252 if (jQuery(this).val().length == 0) { 1253 jQuery(this).addClass('failed'); 1254 jQuery(this).on('focus', function() { jQuery(this).removeClass('failed'); }) 1255 validation.push(false); 1256 } else { 1257 validation.push(true); 1258 } 1259 } 1260 1261 if (jQuery(this).attr('id') == 'region') { 1262 var self = jQuery(this); 1263 1264 for (i = 0; i < regions.length; i++) { 1265 if (self.val() == regions[i]) { 1266 regions_match = true; 1267 break; 1268 } else { 1269 regions_match = false;
1270 } 1271 1272 if ((i == (regions.length - 1))) { 1273 if (!regions_match) { 1274 self.addClass('failed'); 1275 self.val(''); 1276 jQuery('#region-tip').removeClass('hidden'); 1277 self.on('focus', function() { 1278 jQuery('#region-tip').addClass('hidden'); 1279 jQuery(this).removeClass('failed'); 1280 }) 1281 } 1282 } 1283 } 1284 } 1285 }) 1286 1287 for (i in validation) { 1288 if (validation[i]) { 1289 send = true; 1290 } else { 1291 send = false; 1292 break; 1293 } 1294 } 1295 1296 if (send && regions_match) { 1297 var form_data = new FormData(); 1298 form_data.append('latitude', form.find('#lat').val()); 1299 form_data.append('longitude', form.find('#lng').val()); 1300 form_data.append('address', form.find('#address').val()); 1301 form_data.append('region', form.find('#region').val()); 1302 form_data.append('description', form.find('#description').val()); 1303 form_data.append('full_name', form.find('#full_name').val()); 1304 form_data.append('avatar_url', form.find('#avatar_url').val()); 1305 if (form.find('#image-upload').val() != '') { 1306 form_data.append('image', form.find('#image-upload')[0].files[0]); 1307 } 1308 form_data.append('action', 'store_laimeskoki_data'); 1309 1310 jQuery.ajax({ 1311 type: 'POST', 1312 url: ajax_url, 1313 data: form_data, 1314 success: function(data) { 1315 var response = JSON.parse(data); 1316 if (response.error) { 1317 if (response.error === 'description_too_long') { 1318 form.find('#description').addClass('failed'); 1319 form.find('#description').parents().find('span.error-text').show(); 1320 return; 1321 } 1322 } 1323 jQuery("#share_image").attr("src","//api.talkas.lv/index.php/get-image/" + response.hash + "/share-image.png") 1324 jQuery("#share_button").attr("data-link","https://api.talkas.lv/index.php/get-image/" + response.hash + "/share-image.png") 1325 jQuery("#share_button").attr("data-caption", form.find('#description').val()); 1326 jQuery("#poster_pdf").attr("href","//api.talkas.lv/index.php/poster/?description=" + encodeURIComponent(form.find('#description').val()) 1327 + '&full_name='+encodeURIComponent(form.find('#full_name').val())); 1328 app.getData(); 1329 setTimeout(function() { 1330 jQuery('.stage-1').addClass('hidden'); 1331 jQuery('.stage-2').removeClass('hidden'); 1332 window.dispatchEvent(new Event('resize')); 1333 1334 },500) 1335 1336 1337 }, 1338 processData: false, 1339 contentType: false 1340 }) 1341 } 1342 1343 }) 1344 1345} 1346 1347function handle_talkas_form() { 1348 var form = jQuery('.talkas-map form'); 1349 var button = form.find('a.btn'); 1350 var validation = []; 1351 var send = false; 1352 var regions_match = false; 1353 var objectives = []; 1354 1355 button.on('click', function() { 1356 validation = []; 1357 form.find('input').not('input[type="checkbox"]').each(function() { 1358 if (jQuery(this).val().length == 0) { 1359 jQuery(this).addClass('failed'); 1360 jQuery(this).on('focus', function() { jQuery(this).removeClass('failed'); }) 1361 validation.push(false); 1362 } else { 1363 validation.push(true); 1364 } 1365 1366 if (jQuery(this).attr('id') == 'address') { 1367 let t = jQuery(this); 1368 if (t.val().length < 1) { 1369 t.addClass('failed') 1370 jQuery('#address-tip').removeClass('hidden'); 1371 t.on('change', function() { 1372 jQuery('#address-tip').addClass('hidden'); 1373 t.removeClass('failed'); 1374 }) 1375 } 1376 } 1377 1378 if (jQuery(this).attr('id') == 'region') { 1379 var self = jQuery(this); 1380 1381 for (i = 0; i < regions.length; i++) { 1382 if (self.val() == regions[i]) { 1383 regions_match = true; 1384 break; 1385 } else { 1386 regions_match = false;
1387 } 1388 1389 if ((i == (regions.length - 1))) { 1390 if (!regions_match) { 1391 self.addClass('failed'); 1392 self.val(''); 1393 jQuery('#region-tip').removeClass('hidden'); 1394 self.on('focus', function() { 1395 jQuery('#region-tip').addClass('hidden'); 1396 jQuery(this).removeClass('failed'); 1397 }) 1398 } 1399 } 1400 } 1401 } 1402 }) 1403 1404 if (form.find('.objectives input[type="checkbox"]:checked').length == 0) { 1405 form.find('.objectives').addClass('failed'); 1406 form.find('.objectives input[type="checkbox"]').on('change', function() { form.find('.objectives').removeClass('failed'); }) 1407 validation.push(false); 1408 } else { 1409 form.find('.objectives input[type="checkbox"]').each(function(i) { 1410 if (jQuery(this).is(':checked')) { 1411 objectives[i] = jQuery(this).next('label').text(); 1412 } 1413 }) 1414 validation.push(true); 1415 } 1416 1417 1418 for (i in validation) { 1419 if (validation[i]) { 1420 send = true; 1421 } else { 1422 send = false; 1423 break; 1424 } 1425 } 1426 1427 if (send && regions_match) { 1428 var ajax_data = { 1429 action: 'store_talkas_data', 1430 form_data: form.serialize(), 1431 form_data_objectives: objectives, 1432 form_data_type: form.find('select.selectpicker').val() 1433 } 1434 1435 jQuery.ajax({ 1436 type: 'POST', 1437 url: ajax_url, 1438 data: ajax_data, 1439 success: function(data) { 1440 data = JSON.parse(data); 1441 1442 if (data.error) { 1443 if (data.error === 'email') { 1444 jQuery("input#e-mail").addClass('failed'); 1445 return; 1446 } 1447 } 1448 jQuery('.stage-2').addClass('hidden') 1449 jQuery('.stage-3').removeClass('hidden'); 1450 window.dispatchEvent(new Event('resize')); 1451 1452 jQuery.ajax({ 1453 type: 'POST', 1454 url: 'https://api.talkas.lv/index.php/talkas-api/' + data.talkas_id + '/create-user', 1455 data: {} 1456 }) 1457 } 1458 }) 1459 } 1460 1461 }) 1462} 1463 1464function handle_pollution_form() { 1465 var form = jQuery('.pollution-map form'); 1466 var button = form.find('a.btn'); 1467 var validation = []; 1468 var send = false; 1469 var regions_match = false; 1470 1471 function readURL(input) { 1472 if (input.files && input.files[0]) { 1473 var reader = new FileReader(); 1474 reader.onload = function(e) { 1475 jQuery('#image-preview').removeClass('hidden'); 1476 jQuery('#image-preview').attr('src', e.target.result); 1477 } 1478 reader.readAsDataURL(input.files[0]); 1479 } 1480 } 1481 1482 jQuery('#image-upload').change(function() { readURL(this); }) 1483 1484 button.on('click', function() { 1485 validation = []; 1486 1487 form.find('input').each(function() { 1488 if (jQuery(this).attr('id') != 'image-upload') { 1489 if (jQuery(this).val().length == 0) { 1490 jQuery(this).addClass('failed'); 1491 jQuery(this).on('focus', function() { jQuery(this).removeClass('failed'); }) 1492 validation.push(false); 1493 } else { 1494 validation.push(true); 1495 } 1496 } 1497 1498 if (jQuery(this).attr('id') == 'region') { 1499 var self = jQuery(this); 1500 1501 for (i = 0; i < regions.length; i++) { 1502 if (self.val() == regions[i]) { 1503 regions_match = true; 1504 break; 1505 } else { 1506 regions_match = false;
1507 } 1508 1509 if ((i == (regions.length - 1))) { 1510 if (!regions_match) { 1511 self.addClass('failed'); 1512 self.val(''); 1513 jQuery('#region-tip').removeClass('hidden'); 1514 self.on('focus', function() { 1515 jQuery('#region-tip').addClass('hidden'); 1516 jQuery(this).removeClass('failed'); 1517 }) 1518 } 1519 } 1520 } 1521 } 1522 }) 1523 1524 for (i in validation) { 1525 if (validation[i]) { 1526 send = true; 1527 } else { 1528 send = false; 1529 break; 1530 } 1531 } 1532 1533 if (send && regions_match) { 1534 var form_data = new FormData(); 1535 form_data.append('latitude', form.find('#lat').val()); 1536 form_data.append('longitude', form.find('#lng').val()); 1537 form_data.append('address', form.find('#address').val()); 1538 form_data.append('region', form.find('#region').val()); 1539 form_data.append('description', form.find('#description').val()); 1540 form_data.append('date', form.find('#date').val()); 1541 if (form.find('#image-upload').val() != '') { 1542 form_data.append('image', form.find('#image-upload')[0].files[0]); 1543 } 1544 form_data.append('action', 'store_pollution_data'); 1545 1546 jQuery.ajax({ 1547 type: 'POST', 1548 url: ajax_url, 1549 data: form_data, 1550 success: function(data) { 1551 jQuery('.stage-1').addClass('hidden'); 1552 jQuery('.stage-2').removeClass('hidden'); 1553 window.dispatchEvent(new Event('resize')); 1554 }, 1555 processData: false, 1556 contentType: false 1557 }) 1558 } 1559 1560 }) 1561 1562} 1563 1564function handle_pollution_form_new() { 1565 var form = jQuery('.pollution-map-new form'); 1566 var button = form.find('a.btn'); 1567 var validation = []; 1568 var send = false; 1569 var regions_match = false; 1570 1571 function readURL(input) { 1572 if (input.files && input.files[0]) { 1573 var reader = new FileReader(); 1574 reader.onload = function(e) { 1575 jQuery('#image-preview').removeClass('hidden'); 1576 jQuery('#image-preview').attr('src', e.target.result); 1577 } 1578 reader.readAsDataURL(input.files[0]); 1579 } 1580 } 1581 1582 jQuery('#image-upload').change(function() { readURL(this); }) 1583 1584 button.on('click', function() { 1585 validation = []; 1586 1587 form.find('input').each(function() { 1588 if (jQuery(this).attr('id') != 'image-upload') { 1589 if (jQuery(this).val().length == 0) { 1590 jQuery(this).addClass('failed'); 1591 jQuery(this).on('focus', function() { jQuery(this).removeClass('failed'); }) 1592 validation.push(false); 1593 } else { 1594 validation.push(true); 1595 } 1596 } 1597 1598 if (jQuery(this).attr('id') == 'region') { 1599 var self = jQuery(this); 1600 1601 for (i = 0; i < regions.length; i++) { 1602 if (self.val() == regions[i]) { 1603 regions_match = true; 1604 break; 1605 } else { 1606 regions_match = false; 1607 } 1608 1609 if ((i == (regions.length - 1))) { 1610 if (!regions_match) { 1611 self.addClass('failed'); 1612 self.val(''); 1613 jQuery('#region-tip').removeClass('hidden'); 1614 self.on('focus', function() { 1615 jQuery('#region-tip').addClass('hidden'); 1616 jQuery(this).removeClass('failed'); 1617 }) 1618 } 1619 } 1620 } 1621 } 1622 }) 1623 1624 for (i in validation) { 1625 if (validation[i]) { 1626 send = true; 1627 } else { 1628 send = false;
1629 break; 1630 } 1631 } 1632 1633 1634 if (send && regions_match) { 1635 var form_data = new FormData(); 1636 form_data.append('latitude', form.find('#lat').val()); 1637 form_data.append('longitude', form.find('#lng').val()); 1638 form_data.append('address', form.find('#address').val()); 1639 form_data.append('region', form.find('#region').val()); 1640 form_data.append('description', form.find('#description').val()); 1641 form_data.append('date', form.find('#date').val()); 1642 if (form.find('#image-upload').val() != '') { 1643 form_data.append('image', form.find('#image-upload')[0].files[0]); 1644 } 1645 form_data.append('action', 'store_pollution_data_new'); 1646 1647 1648 1649 jQuery.ajax({ 1650 type: 'POST', 1651 url: ajax_url, 1652 data: form_data, 1653 success: function(data) { 1654 jQuery('.stage-1').addClass('hidden'); 1655 jQuery('.stage-2').removeClass('hidden'); 1656 window.dispatchEvent(new Event('resize')); 1657 }, 1658 processData: false, 1659 contentType: false 1660 }) 1661 } 1662 1663 }) 1664 1665} 1666 1667function handle_volunteer_form() { 1668 var form = jQuery('#volunteer-form'); 1669 var button = form.find('a.btn'); 1670 var validation = []; 1671 var send = false; 1672 1673 button.on('click', function() { 1674 validation = []; 1675 1676 form.find('input').each(function() { 1677 if ((jQuery(this).attr('id') == 'name') || (jQuery(this).attr('id') == 'city')) { 1678 if (jQuery(this).val().length == 0) { 1679 jQuery(this).addClass('failed'); 1680 jQuery(this).on('focus', function() { jQuery(this).removeClass('failed'); }) 1681 validation.push(false); 1682 } else { 1683 validation.push(true); 1684 } 1685 } 1686 }) 1687 1688 for (i in validation) { 1689 if (validation[i]) { 1690 send = true; 1691 } else { 1692 send = false; 1693 break; 1694 } 1695 } 1696 1697 if (send) { 1698 jQuery.ajax({ 1699 type: 'POST', 1700 url: ajax_url, 1701 data: { 1702 action: 'store_volunteer_data', 1703 name: form.find('#name').val(), 1704 email: form.find('#e-mail').val(), 1705 phone_number: form.find('#phone-number').val(), 1706 city: form.find('#city').val(), 1707 note: form.find('#note').val() 1708 }, 1709 success: function(data) { 1710 form.find('input').each(function() { 1711 jQuery(this).attr('value', ''); 1712 jQuery(this).on('focus', function() { 1713 form.find('i.fa.fa-check').addClass('hidden'); 1714 }); 1715 }); 1716 form.find('textarea').attr('value', ''); 1717 form.find('textarea').on('focus', function() { 1718 form.find('i.fa.fa-check').addClass('hidden'); 1719 }) 1720 form.find('i.fa.fa-check').removeClass('hidden'); 1721 } 1722 }) 1723 } 1724 1725 }) 1726} 1727 1728function handle_referendum_form() { 1729 var form = jQuery('#referendum-form'); 1730 var button = form.find('a.btn'); 1731 var validation = []; 1732 var send = false; 1733 form.find('#personal-code').mask('000000-00000'); 1734 1735 button.on('click', function() { 1736 validation = []; 1737 1738 form.find('input').each(function() { 1739 if ((jQuery(this).val().length == 0) && 1740 (form.find('#personal-code').val().length < 12)) { 1741 1742 jQuery(this).addClass('failed'); 1743 jQuery(this).on('focus', function() { 1744 jQuery(this).removeClass('failed'); 1745 jQuery(this).attr('value', ''); 1746 }) 1747 validation.push(false); 1748 } else { 1749 validation.push(true); 1750 } 1751 }) 1752 1753 for (i in validation) { 1754 if (validation[i]) { 1755 send = true; 1756 } else { 1757 send = false;
1758 break; 1759 } 1760 } 1761 1762 if (send) { 1763 jQuery.ajax({ 1764 type: 'POST', 1765 url: ajax_url, 1766 data: { 1767 action: 'store_referendum_voter_data', 1768 name: form.find('#name').val(), 1769 personal_code: form.find('#personal-code').val(), 1770 city: form.find('#city').val() 1771 }, 1772 success: function(data) { 1773 if (data) { 1774 form.find('input').each(function() { 1775 jQuery(this).attr('value', ''); 1776 jQuery(this).on('focus', function() { 1777 form.find('i.fa.fa-check').addClass('hidden'); 1778 }); 1779 }); 1780 form.find('i.fa.fa-check').removeClass('hidden'); 1781 } else { 1782 form.find('#personal-code').addClass('failed'); 1783 form.find('#personal-code').on('focus', function() { 1784 jQuery(this).removeClass('failed'); 1785 jQuery(this).attr('value', ''); 1786 }) 1787 } 1788 } 1789 }) 1790 } 1791 1792 }) 1793} 1794 1795function remove_main_padding() { 1796 if (jQuery('.add-a-point').length > 0) { 1797 jQuery('main').css({ padding: 0 }) 1798 } 1799} 1800 1801function load_more() { 1802 jQuery('#load-more').on('click', function(e) { 1803 e.preventDefault(); 1804 var url = jQuery(this).attr('href'); 1805 jQuery.ajax({ 1806 method: 'GET', 1807 url: url, 1808 success: function(response) { 1809 if (jQuery(response).find('.grid').length > 0) { 1810 var items = jQuery(jQuery(response).find('.grid').get(0)).children(); 1811 var url = jQuery(response).find('#load-more').attr('href'); 1812 jQuery('.grid').append(items); 1813 jQuery('#load-more').attr('href', url); 1814 } else { 1815 jQuery('#load-more').remove(); 1816 } 1817 } 1818 }) 1819 }) 1820} 1821 1822function scroll_to(id) { 1823 jQuery('html, body').animate({ scrollTop: jQuery(id).position().top }, 400); 1824} 1825 1826jQuery(function($) { 1827 $("body").on('click', 'a', function(e) { 1828 if($(this).attr('href') === '#') { 1829 e.preventDefault(); 1830 } 1831 }); 1832}); 1833 1834function load_section(menu_item, page_id, section) { 1835 jQuery.ajax({ 1836 type: 'POST', 1837 url: ajax_url, 1838 data: { action: 'get_section', page_id: page_id, section: section }, 1839 success: function(data) { 1840 var response = JSON.parse(data); 1841 jQuery('#section-container h2').html(response['section_title']); 1842 jQuery('#section-container .content-wrap').html(response['section_content']); 1843 jQuery(menu_item).parent().find('a').removeClass('active'); 1844 jQuery(menu_item).addClass('active'); 1845 } 1846 }); 1847} 1848 1849 1850// In your JavaScript 1851var auth_response_change_callback = function(response) { 1852 // console.log("auth_response_change_callback"); 1853 // console.log(response); 1854} 1855 1856var auth_status_change_callback = function(response) { 1857 // console.log("auth_status_change_callback: " + response.status); 1858} 1859// This is called with the results from from FB.getLoginStatus(). 1860 1861function statusChangeCallback(response) { 1862 // console.log('statusChangeCallback'); 1863 // The response object is returned with a status field that lets the 1864 // app know the current login status of the person. 1865 // Full docs on the response object can be found in the documentation 1866 // for FB.getLoginStatus(). 1867 if (response.status === 'connected') { 1868 // Logged into your app and Facebook. 1869 FB.api('/me', {fields: "id,name,picture,email"},function(response) { 1870 jQuery("#avatar_url").val(response.picture.data.url); 1871 jQuery("#social_type").val('facebook'); 1872 jQuery("#social_id").val(response.id); 1873 jQuery("#email").val(response.email); 1874 jQuery("#full_name").val(response.name); 1875 jQuery("#avatar").attr("src",response.picture.data.url); 1876 jQuery("#image_url").val(response.picture.data.url); 1877 jQuery("#name").html(response.name); 1878 }); 1879 jQuery(".fb-login-button").hide(); 1880 } else { 1881 // The person is not logged into your app or we are unable to tell. 1882 // console.log("not logged in") 1883 // jQuery("#avatar_url").val(""); 1884 // jQuery("#full_name").val(""); 1885 // jQuery("#avatar").attr("src",""); 1886 // jQuery("#name").html(""); 1887 1888 } 1889} 1890 1891// This function is called when someone finishes with the Login 1892// Button. See the onlogin handler attached to it in the sample 1893// code below. 1894function checkLoginState() { 1895 FB.getLoginStatus(function(response) { 1896 statusChangeCallback(response); 1897 }); 1898} 1899 1900jQuery("#share_button").on("click",function() { 1901 // FB.ui({ 1902 // method: 'feed', 1903 // link: jQuery(this).attr("data-link"),
1904 // caption: jQuery(this).attr("data-caption"), 1905 // }, function(response){ 1906 // console.log("shared"); 1907 // console.log(response); 1908 // }); 1909 FB.ui({ 1910 method: 'share', 1911 href: 'https://talkas.lv/laimes-koki?shared=1&novelejums='+encodeURIComponent(jQuery('#description').val()) + '&image=' + jQuery(this).attr("data-link"), 1912 }, function(response){}); 1913 // FB.ui({ 1914 // method: 'share_open_graph', 1915 // action_type: 'og.likes', 1916 // action_properties: JSON.stringify({ 1917 // object:'https://talkas.lv/laimes-koki?shared=1&novelejums='+encodeURIComponent(jQuery('#description').val()) + '&image=' + jQuery(this).attr("data-link"), 1918 // // image: jQuery(this).attr("data-link"), 1919 // scrape:false 1920 // }) 1921 // }, function(response){ 1922 // // Debug response (optional) 1923 // console.log(response); 1924 // }); 1925});
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.