1var geocoder; 2var map; 3var markers = Array(); 4var results = Array(); 5var infos = Array(); 6var global_radius = 160934; 7var addrMarker; 8var locationTemplate = $('#location_template').html(); 9var locationTemplate_short = $('#location_template_short').html(); 10var locationTemplate_Inside = $('#location_template_inside').html(); 11 12$(".search-by-zipcode").submit(function(e) { 13 e.preventDefault(); 14 var zipcode = $("input[name=zipcode]").val() 15 findAddress(zipcode, 'zipcode'); 16 location.hash = '#zipcode=' + zipcode; 17 console.log("zip"); 18}); 19//home page search 20if ($('.search-by-zipcode-short').length){ 21 bindSubmitForm(); 22} 23function bindSubmitForm(){ 24 $('.search-by-zipcode-short').unbind('submit'); 25 26 $(".active .search-by-zipcode-short, .page-template-template-landing-php .search-by-zipcode-short").validate({ 27 debug: true, 28 onfocusout: function(e){ 29 if($(e).val() === ""){ 30 $('label', $(e).next()).hide() 31 // console.log("empty"); 32 } 33 }, 34 rules: { 35 zipcode: { 36 required: true, 37 minlength: 5 38 } 39 }, 40 wrapper:'span', 41 errorPlacement: function(error,element){ 42 error.addClass('errorbox'); 43 error.insertAfter(element); 44 }, 45 messages: { 46 zipcode: "Please enter a new zip code", 47 }, 48 submitHandler: function(form) { 49 if (geocoder == null) { 50 geocoder = new google.maps.Geocoder(); 51 } 52 53 cake_id = $(form).attr('data-cake-id'); 54 55 if (cake_id!=undefined) { 56 var zipcode = $('#search_for_cake_'+cake_id).val(); 57 findAddressShortByCake(zipcode, 'zipcode',cake_id); 58 } else { 59 var zipcode = $("input[name=zipcode]").val(); 60 findAddressShort(zipcode, 'zipcode'); 61 } 62 63 } 64 }); 65 66 67} 68$(".search_by_state .options .option").click(function(e) { 69 value = $(this).find(".data").text(); 70 label = $(this).find("p:last-child").text(); 71 $(this).closest(".btn_select").find(".state").html(label); 72 $(".btn_select .box").removeClass("active"); 73 $(".btn_select .options").css('visibility', 'hidden'); 74 findAddress(value, 'state'); 75 location.hash = '#state=' + value; 76 e.stopPropagation(); 77}); 78 79function renderClickFeaturesFilter(){ 80 $('.locations_results_short li').click(function(e){ 81 e.preventDefault(); 82 window.location = headJS.blog_url+'/locations/#!'+$(this).attr('data-slug'); 83 }); 84} 85 86//search field arrow animation 87$(".search .field form").hover(function() { 88 $(this).find(".arrow").animate({ 89 "right": "5px" 90 }, { 91 duration: 300 92 }); 93}, function() { 94 $(this).find(".arrow").animate({ 95 "right": "10px" 96 }, { 97 duration: 300 98 }); 99}); 100 101//center a div 102 103 104function CenterItem(theItem) { 105 var winWidth = $(window).width(); 106 var winHeight = $(window).height(); 107 var windowCenter = winWidth / 2; 108 var itemCenter = $(theItem).width() / 2; 109 var theCenter = windowCenter - itemCenter; 110 var windowMiddle = winHeight / 2; 111 var itemMiddle = $(theItem).height() / 2; 112 var theMiddle = windowMiddle - itemMiddle; 113 if (winWidth > $(theItem).width()) { //horizontal 114 $(theItem).css('left', theCenter); 115 } else { 116 $(theItem).css('left', '0'); 117 } 118 if (winHeight > $(theItem).height()) { //vertical 119 $(theItem).css('top', theMiddle); 120 } else { 121 $(theItem).css('top', '0'); 122 } 123} 124 125 126$(window).resize(function() { 127 CenterItem(".msg"); 128}); 129 130// $(document).ajaxStart(function() {x 131// console.log('Ajax loading...') 132// }).ajaxStop(function() { 133// console.log('Ajax stopped...'); 134// }).ajaxError(function(a, b, e) { 135// throw e; 136// }); 137// Distance calc funtions to avoid doing API calls to Google Maps to get the distance 138rad = function(x) { 139 return x * Math.PI / 180; 140} 141 142 143//p1, p2 - google maps locations 144distHaversine = function(p1, p2) { 145 var R = 6371; // earth's mean radius in km 146 var dLat = rad(p2.lat() - p1.lat()); 147 var dLong = rad(p2.lng() - p1.lng()); 148 149 var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(rad(p1.lat())) * Math.cos(rad(p2.lat())) * Math.sin(dLong / 2) * Math.sin(dLong / 2); 150 var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); 151 var d = R * c; 152 153 return (d * 1.60934).toFixed(1); 154} 155 156 157function initialize() { 158 // prepare Geocoder 159 geocoder = new google.maps.Geocoder(); 160 renderDropDownOnTemplate(); // prefill select dropdown 161 resetUI(false); 162 // set initial position (New York) 163 var myLatlng = new google.maps.LatLng(40.7143528, -74.0059731); 164 var myOptions = { // default map options 165 zoom: 11, 166 center: myLatlng, 167 scrollwheel: false, 168 mapTypeId: google.maps.MapTypeId.ROADMAP 169 }; 170 map = new google.maps.Map(document.getElementById('gmap_canvas'), myOptions); 171 if(window.location.hash){ 172 hash = window.location.hash.split('#')[1]; 173 if ( hash.indexOf("zipcode=") > -1 ) { 174 hash = hash.split('zipcode=')[1]; 175 findAddress(hash, 'zipcode'); 176 } else if ( hash.indexOf("state=") > -1 ) { 177 hash = hash.split('state=')[1]; 178 findAddress(hash, 'state'); 179 } else { 180 loadLocationByHash(hash); 181 } 182 } else { 183 //load all 184 findPlacesByField(myLatlng, '', ''); 185 } 186} 187// clear overlays function 188function clearOverlays() { 189 if (markers) { 190 for (i in markers) { 191 markers[i].setMap(null); 192 } 193 markers = []; 194 infos = []; 195 results = []; 196 } 197} 198 199// clear infos function 200function clearInfos() { 201 if (infos) { 202 for (i in infos) { 203 if (infos[i].getMap()) { 204 infos[i].close(); 205 } 206 } 207 } 208} 209 210// find address function 211function findAddress(address, searchType) { 212 // script uses our 'geocoder' in order to find location by address name 213 geocoder.geocode({ 214 'address': address 215 }, function(results, status) { 216 if (status == google.maps.GeocoderStatus.OK) { // and, if everything is ok 217 // we will center map 218 var addrLocation = results[0].geometry.location; 219 // and then - add new custom marker 220 addrMarker = new google.maps.Marker({ 221 position: addrLocation, 222 map: map, 223 title: results[0].formatted_address 224 }); 225 clearOverlays(); 226 // markers.push(addrMarker); 227 findPlacesByField(addrLocation, address, searchType); 228 $("body").addClass('show-search') 229 } else { 230 switch(searchType) 231 { 232 case 'zipcode': 233 alert('Wrong zipcode'); 234 break; 235 case 'state': 236 alert('Wrong state'); 237 break; 238 default: 239 alert('Address Error'); 240 } 241 242 } 243 }); 244} 245
246// find address function short - no google maps 247function findAddressShort(address, searchType) { 248 var features_filter = []; 249 if ($('.location-service-filter .catering.active').length) features_filter.push("catering"); 250 if ($('.location-service-filter .party.active').length) features_filter.push("party_room"); 251 252 // script uses our 'geocoder' in order to find location by address name 253 geocoder.geocode({ 254 'address': address 255 }, function(results, status) { 256 if (status == google.maps.GeocoderStatus.OK) { // and, if everything is ok 257 findPlacesByField(results[0].geometry.location, address, searchType, 'extra_short', features_filter); 258 } else { 259 switch(searchType) 260 { 261 case 'zipcode': 262 alert('Wrong zipcode'); 263 break; 264 case 'state': 265 alert('Wrong state'); 266 break; 267 default: 268 alert('Address Error'); 269 } 270 271 } 272 }); 273} 274 275// find address function short - no google maps 276function findAddressShortByCake(address, searchType,cake) { 277 // script uses our 'geocoder' in order to find location by address name 278 geocoder.geocode({ 279 'address': address 280 }, function(results, status) { 281 if (status == google.maps.GeocoderStatus.OK) { // and, if everything is ok 282 findPlacesByField(results[0].geometry.location, address, searchType, 'extra_short_by_cake', null, cake); 283 } else { 284 switch(searchType) 285 { 286 case 'zipcode': 287 alert('Wrong zipcode'); 288 break; 289 case 'state': 290 alert('Wrong state'); 291 break; 292 default: 293 alert('Address Error'); 294 } 295 296 } 297 }); 298} 299 300function sortLocationByDistance(l1, l2) { 301 var d1 = parseFloat(l1.distance); 302 var d2 = parseFloat(l2.distance); 303 return d1 - d2; 304} 305 306/*create single marker 307return: marker data 308*/ 309function createMarker(location) { 310 311 // prepare new Marker object 312 var mark = new google.maps.Marker({ 313 position: location.position, 314 map: map, 315 title: location.title, 316 icon: headJS.templateurl + "/img/16handles_marker.png" 317 }); 318 markers.push(mark); 319 320 // prepare info window 321 var infowindow = new google.maps.InfoWindow({ 322 content: '<div style="overflow: hidden" class="location-marker"><img src="/wp-content/themes/16handles/img/logo_marker.png" style="float: left; margin-right: 15px;" class="location-marker-image"/><p class="location-marker-title">' + location.title + '</p><p>Address: ' + location.address + '</p></div>' 323 }); 324 325 // add event handler to current marker 326 google.maps.event.addListener(mark, 'click', function() { 327 clearInfos(); 328 infowindow.open(map, mark); 329 }); 330 infos.push(infowindow); 331 return mark; 332} 333 334//render markers on the map 335function createMarkers(locations) { 336 //create empty LatLngBounds object 337 var bounds = new google.maps.LatLngBounds(); 338 339 for (i = 0; i < locations.length; i++) { 340 marker = createMarker(locations[i]); 341 //extend the bounds to include each marker's position 342 bounds.extend(marker.position); 343 } 344 345 //now fit the map to the newly inclusive bounds 346 map.fitBounds(bounds); 347} 348 349/* 350function applyLocationData 351@description: 352add location coordinates, calculate distance and then sort array by distance 353@input: 354var centerLocation - array with coordinates 355var locations - JSON feed 356@return: sorted locations 357*/ 358function applyLocationData(centerLocation, locations) { 359 var NewSortedLocations = Array(); 360 $.each(locations, function(i, location) { 361 location.position = new google.maps.LatLng(location.lat, location.lng); // add GMAP data 362 location.distance = distHaversine(centerLocation, location.position); // get distance from centerLoc 363 NewSortedLocations.push(location); 364 }); NewSortedLocations.sort(sortLocationByDistance); 365 366 return NewSortedLocations; 367} 368 369function renderIndexLocations(InputSortedLocations) { 370 // Destroy and re-create 371 if ($('#locations_results').length > 0) { 372 $('#locations_results').remove(); 373 } 374 $('<div id="locations_results" class="accordion accordion_1" />').appendTo("#locations_results_container"); 375 $('.accordion_head').show(); 376 377 // Fill results using the template. 378 $.each(InputSortedLocations, function(i, location) { 379 location.odd_even = (i % 2 == 0) ? 'odd' : 'even'; 380 output = Mustache.render(locationTemplate, location); 381 $('#locations_results').append(output); 382 }) 383 if (InputSortedLocations.length > 0) { 384 renderAccordion(); 385 resetUI(false); 386 } 387 if(is_touch_device){ 388 $('#datepicker_normal_1, #datepicker_normal_1, #datepicker_normal_2, #datepicker_normal_3').attr('type', 'date'); 389 } 390 391 392} 393 394function renderIndexLocationsExtraShort(InputSortedLocations, number_to_output) { 395 if (number_to_output === undefined ) { 396 number_to_output = 3; 397 } 398 // Destroy and re-create 399 if ($('#locations_results_short').length > 0) { 400 $('#locations_results_short').html(''); 401 } 402 if (InputSortedLocations.length > 0) { 403 $('.locations_short_result_msg').fadeOut(200,function(){ 404 $(this).fadeIn(400).html('<h4>Here are the locations near you</h4>'); 405 }); 406 // $("<div/>", { 407 // id: 'locations_results_short' 408 // }).appendTo("#locations_results_container_short"); 409 410 // Fill results using the template. 411 $.each(InputSortedLocations, function(i, location) { 412 if (i > number_to_output - 1 ) return false;
413 output = Mustache.render(locationTemplate_short, location); 414 $('#locations_results_short').append(output); 415 }); 416 renderClickFeaturesFilter(); 417 } else { 418 $('.locations_short_result_msg').append('<h4 class="none-near">Weâre sorry! None near you</h4>'); 419 } 420} 421 422function renderIndexLocationsExtraShortByCake(InputSortedLocations, number_to_output, cake_id) { 423 if (number_to_output === undefined ) { 424 number_to_output = 3; 425 } 426 // Destroy and re-create 427 if ($('#locations_results_short'+cake_id).length > 0) { 428 $('#locations_results_short'+cake_id).html(''); 429 // console.log('clear section cake_id='+cake_id); 430 } 431 if (InputSortedLocations.length > 0) { 432 $('.cake_id_'+cake_id+'.locations_short_result_msg').fadeOut(200,function(){ 433 $(this).fadeIn(400).html('<h4>Here are the locations near you</h4>'); 434 }); 435 // $("<div/>", { 436 // id: 'locations_results_short' 437 // }).appendTo("#locations_results_container_short"); 438 439 // Fill results using the template. 440 $.each(InputSortedLocations, function(i, location) { 441 if (i > number_to_output - 1 ) return false; 442 output = Mustache.render(locationTemplate_short, location); 443 $('#locations_results_short'+cake_id).append(output); 444 }); 445 renderClickFeaturesFilter(); 446 } else { 447 $('.cake_id_'+cake_id+'.locations_short_result_msg').html('<h4 class="none-near">Weâre sorry! None near you</h4>'); 448 } 449} 450
451function renderSingleLocation(InputLocation) { 452 // Destroy and re-create 453 if ($('#locations_results').length > 0) { 454 $('#locations_results').remove(); 455 } 456 $('<div id="locations_results" class="accordion accordion_1" />').appendTo("#locations_results_container"); 457 $('.accordion_head').show(); 458 459 output = Mustache.render(locationTemplate, InputLocation); 460 content = Mustache.render(locationTemplate_Inside, InputLocation); 461 $('#locations_results').append(output); 462 $('#locations_results .cont').append(content); 463 resetInsideUI($('#locations_results .head')); 464 renderAccordion(); 465 resetUI(true); 466 renderMobileNumbers(); 467 468 //setup location 469 InputLocation.position = new google.maps.LatLng(InputLocation.lat, InputLocation.lng); // add GMAP data 470 createMarker(InputLocation); 471 map.setCenter(InputLocation.position); 472 map.setZoom(15); 473 474 if(is_touch_device){ 475 $('#datepicker_normal_1, #datepicker_normal_2, #datepicker_normal_3').attr('type', 'date'); 476 $('.time input.amount').attr('type', 'time'); 477 478 } 479 480 481} 482 483 484 485function findPlacesByField(centerLocation, address, field, result_type, features_filter,cake_id) { 486 if (result_type === undefined) { result_type = 'short' }; 487 $.ajax({ 488 type: "post", 489 context: this, 490 dataType: "json", 491 url: headJS.ajaxurl, 492 data: { 493 action: "load_locations_info_json", 494 field: field, 495 address: address, 496 features_filter : features_filter, 497 result_type : result_type, 498 centerLocationLat: centerLocation.lat(), 499 centerLocationLng: centerLocation.lng(), 500 cake_id:cake_id 501 }, 502 beforeSend: function() { 503 // console.log(result_type); 504 }, 505 success: function(response) { 506 //debug 507 // console.log(response); 508 if (response) { //if locations found 509 SortedResponse = applyLocationData(centerLocation, response); 510 511 // sort by dist if zip or state 512 if(field === "zipcode" || field === "state"){ 513 SortedResponse = applyLocationData(centerLocation, response); 514 } else { 515 SortedResponse = response; 516 } 517 518 519 520 //switch rendering function based on search type 521 switch (result_type){ 522 case 'extra_short': 523 //console.log('extra_short'); 524 //run different rendering for "extra_short" (form on landing tempalte) 525 renderIndexLocationsExtraShort(SortedResponse); 526 break; 527 case 'extra_short_by_cake': 528 renderIndexLocationsExtraShortByCake(SortedResponse,3,cake_id); 529 break; 530 default: 531 renderIndexLocations(SortedResponse); 532 createMarkers(SortedResponse); 533 } 534 } else { 535 switch (result_type){ 536 case 'extra_short': 537 $('#locations_results_short').html(''); 538 $('.locations_short_result_msg').fadeOut(200,function(){ 539 $(this).html(''); 540 $(this).append('<h4>Here are the locations near you</h4><h4 class="none-near">Weâre sorry! None near you</h4>'); 541 $(this).fadeIn(400); 542 }); 543 break; 544 case 'extra_short_by_cake': 545 $('#locations_results_short'+cake_id).html(''); 546 $('.locations_short_result_msg').fadeOut(200,function(){ 547 $(this).html(''); 548 $(this).append('<h4>Here are the locations near you</h4><h4 class="none-near">Weâre sorry! None near you</h4>'); 549 $(this).fadeIn(400); 550 }); 551 break; 552 default: 553 alert('No stores in that locationsss.'); 554 } 555 } 556 }, 557 error: function(error) { 558 //debug 559 console.log("findPlacesByField") 560 console.log(error); 561 }, 562 ajaxStart: function() { 563 $(".ajax-logo.large").addClass('show'); 564 }, 565 ajaxStop: function() { 566 $(".ajax-logo.large").removeClass('show'); 567 } 568 }) 569}; 570 571// head - jquery element 572function preloadSingleLocation( head ){ 573 loc_id = head.attr('data-locid'); 574 $.ajax({ 575 type: "post", 576 context: this, 577 dataType: "json", 578 url: headJS.ajaxurl, 579 data: { 580 action: "load_single_location_data_json", 581 field: 'id', 582 value: loc_id 583 }, 584 beforeSend: function() { 585 //debug 586 // console.log('loc='+ loc_id); 587 }, 588 success: function(response) { 589 if (response) { //if locations found 590 output = Mustache.render(locationTemplate_Inside, response); 591 head.next().html(output); 592 //TODO improve animation 593 renderDropDownOnTemplate(); 594 renderMobileNumbers(); 595 resetInsideUI(head); 596 resetUI(true); 597 } else { 598 alert('An error occurred while loading a location data'); 599 } 600 }, 601 error: function(error) { 602 //debug 603 console.log("preloadingSingleLocation"); 604 console.log(error); 605 }, 606 ajaxStart: function() { 607 $(".ajax-logo.large").addClass('show'); 608 }, 609 ajaxStop: function() { 610 $(".ajax-logo.large").removeClass('show'); 611 } 612 }) 613 614} 615 616function loadLocationByHash(hash) { 617 $.ajax({ 618 type: "post", 619 context: this, 620 dataType: "json", 621 url: headJS.ajaxurl, 622 data: { 623 action: "load_single_location_data_json", 624 field: 'slug', 625 value: hash, 626 }, 627 success: function(response) { 628 //debug 629 // console.log(response)
630 if (response) { //if locations found 631 renderSingleLocation(response); 632 renderDropDownOnTemplate(); 633 $("body").addClass("show-search"); 634 } else { 635 alert('Sorry... There is no store with the name "'+hash+'". Search may help.'); 636 } 637 }, 638 error: function(error) { 639 //debug 640 console.log("loadLocatonByHash"); 641 console.log(error); 642 } 643 }); 644 resetUI(true); 645 646} 647 648function resetInsideUI(currentHead) { 649 650 var location_id = currentHead.attr('data-locid'); 651 652 currentHead.next().find("#cakes_slider").carouFredSel({ 653 items: 4, 654 direction: "left", 655 prev: { 656 button: "#cake_prev_" + location_id, 657 key: "left" 658 }, 659 next: { 660 button: "#cake_next_" + location_id, 661 key: "right" 662 }, 663 height: "variable", 664 width: "100%", 665 padding: 30, 666 scroll: { 667 items: 1, 668 easing: "easeInOutCubic", 669 duration: 1000, 670 pauseOnHover: true 671 }, 672 auto: { 673 play: false 674 } 675 }); 676 677 currentHead.next().find(".order_cakes_slider").carouFredSel({ 678 items: 4, 679 direction: "left", 680 prev: { 681 button: "#order_cake_prev_" + location_id, 682 key: "left" 683 }, 684 next: { 685 button: "#order_cake_next_" + location_id, 686 key: "right" 687 }, 688 height: "variable", 689 width: "100%", 690 padding: 30, 691 scroll: { 692 items: 1, 693 easing: "easeInOutCubic", 694 duration: 1000, 695 pauseOnHover: true 696 }, 697 auto: { 698 play: false 699 } 700 }); 701 702 currentHead.next().find(".slide_section").carouFredSel({ 703 responsive: true, 704 items: 1, 705 direction: "left", 706 prev: { 707 button: ".prev_slide_section", 708 key: "left" 709 }, 710 next: { 711 button: ".next_slide_section", 712 key: "right" 713 }, 714 width:1000, 715 height: "variable", 716 padding: 30, 717 scroll: { 718 items: 1, 719 easing: "easeInOutCubic", 720 duration: 1000, 721 pauseOnHover: true 722 }, 723 auto: { 724 play: false 725 }, 726 727 }).trigger("linkAnchors", "#links_below"); 728 729 // accordion 730 $('.ui-accordion').accordion('refresh'); 731}; 732 733function renderAccordion(){ 734 // $( ".ui-accordion" ).accordion( "destroy" ); 735 if ($('.accordion .head').length == 1) { 736 active = 0; 737 collapsible = false 738 } else { 739 active = null; 740 collapsible = true 741 } 742 $('.accordion').accordion({ 743 icon: false, 744 active: true, 745 header: '.head', 746 collapsible: collapsible, 747 heightStyle: "content", 748 active : active 749 }); 750} 751 752function goToTop(topPosition){ 753 $('body, html').animate({ scrollTop: topPosition}, 500); 754} 755 756function resetUI(flag) { 757 dateTimeSliderInit(10, 22, 15, 18); 758 Custom.init(); 759 scrollbarInit(); 760 761 if (flag == undefined) { flag = false; } 762 763 // $('.accordion .head').unbind('click'); //trick to run accordion manually 764 if (!flag) { 765 $('.accordion .head').click(function(event) { 766 // event.stopImmediatePropagation(); 767 768 $this = $(this); 769 770 var openAccordions = $this.siblings('.ui-state-active').length, 771 topPos = $this.position().top; 772 773 openAccordions > 0 ? goToTop($this.position().top - 850) : goToTop($this.position().top) 774 775 if ( ! $(this).next().has('.content').length ) { 776 preloadSingleLocation($this); 777 } 778 location.hash = '#!' + $this.attr('data-slug'); 779 780 }); 781 782 } 783 784 if(!is_touch_device){ 785 $('#datepicker_normal_1, #datepicker_normal_2, #datepicker_normal_3').datepicker({ 786 minDate: +3, 787 dayNamesMin: ["S", "M", "T", "W", "T", "F", "S"], 788 firstDay: 1, 789 beforeShow: fixDatePickerPos 790 }); 791 } 792 793 $('.date_icon').click(function(e) { 794 e.preventDefault(); 795 $(this).next().focus(); 796 }); 797 798 //arrows animation in carrousel 799 $(".carrousel .prev").hover(function() { 800 $(this).animate({ 801 "left": "2px" 802 }, { 803 duration: 300 804 }); 805 }, function() { 806 $(this).animate({ 807 "left": "7px" 808 }, { 809 duration: 300 810 }); 811 }); 812 813 $(".carrousel .next").hover(function() { 814 $(this).animate({ 815 "right": "2px" 816 }, { 817 duration: 300 818 }); 819 }, function() { 820 $(this).animate({ 821 "right": "7px" 822 }, { 823 duration: 300 824 }); 825 }); 826 827 //btn_lin_1, btn_link_2 arrow animation 828 $(".btn_left").hover(function() { 829 $(this).find(".arrow").animate({ 830 "left": "-5px" 831 }, { 832 duration: 300 833 }); 834 }, function() { 835 $(this).find(".arrow").animate({ 836 "left": "0px" 837 }, { 838 duration: 300 839 }); 840 }); 841 842 //btn_submit arrow animation 843 $(".btn_submit").hover(function() { 844 $(this).find(".arrow").animate({ 845 "right": "5px" 846 }, { 847 duration: 300 848 }); 849 }, function() { 850 $(this).find(".arrow").animate({ 851 "right": "10px" 852 }, { 853 duration: 300 854 }); 855 }); 856 857 // Update quantity and amount for selected cakes + rush cake + delivery 858 $('.custom_checkbox').click(function(e) { 859 860 e.stopPropagation(); 861 var $this = $(this); 862 863 var total = 0, 864 cnt = 0, 865 tax = 0, 866 grand_total = 0; 867 var parentForm = $this.closest('form.order_cake'); 868 var items_html = '', 869 items_to_submit = ''; 870 parentForm.find('.custom_checkbox input:checked').each(function() { 871 if ($(this).attr('name') == 'cake') { 872 items_html = items_html + '<div class="item"><p>' + $(this).data('name') + '</span></p><p class="clarification">Hand Written Message ″<span class="sync_in order_cake_message"></span>″</p></div>'; 873 items_to_submit = items_to_submit + $(this).data('name') + '\n'; 874 } 875 if ($(this).attr('name') == 'reg_delivery' || $(this).attr('name') == 'rush_cake') { 876 items_html = items_html + '<div class="item"><p>' + $(this).data('name') + '</span></p></div>'; 877 items_to_submit = items_to_submit + '+++' + $(this).data('name') + '\n'; 878 } 879 $('.cake_items').html(items_html); 880 cnt = cnt + parseInt($(this).data('cnt')); 881 }); 882 883 parentForm.find('.qty').html('Qty: ' + cnt ); 884 grand_total = total; 885 886 $('.msg .order_cake_tax').html(tax.toFixed(2)); 887 $('.msg .order_cake_total').html(grand_total.toFixed(2)); 888 $('.input_form.order_cake .order_cake_cakes textarea').html(items_to_submit); 889 }); 890 891 892 //slides extra info carrousel 893 $(".carrousel_items_prod .items_info_extra .slide li").click(function(e) { 894 e.stopPropagation(); 895 var $this = $(this), 896 $liSibs = $('.slide li.active'); 897 898 $(".slide_section").trigger("updateSizes"); 899 900 if ($this.hasClass("active")) { 901 $this.removeClass("active"); 902 $this.closest(".carrousel_items_prod").parent().closest(".caroufredsel_wrapper").animateMinHeight(852, 852); 903 $this.closest(".slide").animateMinHeight(243, 243); 904 $this.closest(".caroufredsel_wrapper").animateMinHeight(215, 215); 905 // $this.find(".txt").animateMinHeight(0, 0); 906 hideTxtArrow($this); 907 908 } else { 909 910 $liSibs.removeClass("active"); 911 $('.txt', $liSibs).fadeOut(); 912 hideTxtArrow($liSibs); 913 914 $this.addClass("active"); 915 showTxtArrow($this); 916 $this.closest(".carrousel_items_prod").parent().closest(".caroufredsel_wrapper").animate({ 917 height: 1200 918 }); 919 $this.closest(".items_info_extra").animateMinHeight(600, 600); 920 $this.closest(".caroufredsel_wrapper").animateMinHeight(600, 600); 921 $this.closest(".slide").animateMinHeight(600, 600); 922 $this.find(".txt").animateMinHeight(160); 923 924 925 } 926 }); 927 // 928 $(".carrousel_items_prod .items_info_extra .prev, .carrousel_items_prod .items_info_extra .next").click(function(e) { 929 e.stopPropagation(); 930 $item = $(".slide li.active"); 931 $item.closest(".caroufredsel_wrapper").parent().closest(".caroufredsel_wrapper").animate({
932 "height": "880px" 933 }, { 934 duration: 300, 935 queue: false 936 }); 937 $item.removeClass("active"); 938 $item.closest(".items_info_extra").animateMinHeight(245, 245); 939 $item.closest(".slide").animateMinHeight(245, 245); 940 $item.closest(".caroufredsel_wrapper").animateMinHeight(245, 245); 941 $item.find(".txt").animateMinHeight(0, 0); 942 hideTxtArrow($item); 943 }); 944 945 //fancy locations inquiry functionality 946 function SubmitForm(form) { 947 $form = $(form); // create jquery form object 948 var form_type = $form.attr('data-gravity-form-type'); // party_inquiry / catering_inquiry / 949 //define gravity form for current operation: 950 $gf_id = $('.' + form_type + '.input_form form').attr('id'); 951 952 switch (form_type) { 953 case '': 954 //do something 955 break; 956 case '': 957 //do something 958 break; 959 default: 960 961 // sync data into gravity forms!!! 962 $form.find('input').each(function() { 963 var field_gf_field = $(this).attr('data-gf-field'), 964 field_gf_val = $(this).val(); 965 $('#' + $gf_id + ' .' + field_gf_field + ' input').val(field_gf_val); 966 967 //filling popup box with data 968 $('.msg.' + form_type + ' .sync_in.' + field_gf_field).html(field_gf_val); 969 }); 970 971 //set location in gravity forms (possibly here need to define id from drop down P.S. use name for now) 972 $('#' + $gf_id + ' .location input').val($form.attr('data-form-loc-name')); 973 CenterItem('.msg.' + form_type); 974 $('.msg.' + form_type).fadeIn('slow', function(){ 975 if(is_touch_device){ 976 $('confirm_gf_action').trigger('click', function(){ 977 alert("Thanks for contacting us"); 978 $('.btn_left').trigger('click'); 979 }) 980 } 981 }); 982 983 984 985 } 986 //show popup box 987 }; 988 989 //submit gf on click + fadeout popup 990 $('.confirm_gf_action').click(function() { 991 var form_type = $(this).attr('data-form-type'); // party_inquiry / catering_inquiry / 992 //define gravity form for current operation:xx 993 var form = $('.' + form_type + '.input_form form'), 994 formAction = form.attr('action'), 995 str = form.serialize(); 996 $.ajax({ 997 type: "POST", 998 url: formAction, 999 data: str, 1000 complete: function() { 1001 //fadeout popup window 1002 //$('.gf_submit input:not(input[type=submit]), .input_form input:not(input[type=submit])').val(''); // reset all fields! 1003 $('.msg.' + form_type).fadeOut('slow', function() { 1004 $('.btn_left').trigger('click'); 1005 }); 1006 1007 } 1008 }); 1009 1010 }); 1011 1012 //validate forms 1013 $("form.party_inquiry").validate({ 1014 rules: { 1015 name: { 1016 required: true 1017 }, 1018 email: { 1019 required: true, 1020 email: true 1021 }, 1022 phone: { 1023 required: true 1024 }, 1025 attendees: { 1026 required: true 1027 }, 1028 party_date: { 1029 required: true 1030 } 1031 }, 1032 messages: { 1033 name: "Please enter your full first name", 1034 email: "Please enter your full first email", 1035 phone: "Please enter your phone", 1036 attendees: "Please enter number of attendees", 1037 party_date: "Please enter party date" 1038 }, 1039 submitHandler: function(form) { 1040 SubmitForm(form); 1041 } 1042 }); 1043 1044 $("form.order_cake").validate({ 1045 rules: { 1046 name: { 1047 required: true 1048 }, 1049 email: { 1050 required: true, 1051 email: true 1052 }, 1053 message: { 1054 required: false 1055 }, 1056 phone: { 1057 required: true 1058 }, 1059 date: { 1060 required: true 1061 } 1062 }, 1063 messages: { 1064 name: "Please enter your full first name", 1065 email: "Please enter your full first email", 1066 city: "Please enter your full first city", 1067 message: "Please enter your full message", 1068 date: "Please enter date", 1069 phone: "Please enter your phone" 1070 }, 1071 submitHandler: function(form) { 1072 SubmitForm(form); 1073 } 1074 }); 1075 1076 $("form.catering_inquiry").validate({ 1077 rules: { 1078 name: { 1079 required: true 1080 }, 1081 email: { 1082 required: true, 1083 email: true 1084 }, 1085 phone: { 1086 required: true 1087 }, 1088 address: { 1089 required: true 1090 }, 1091 city: { 1092 required: true 1093 }, 1094 zipcode: { 1095 required: true 1096 }, 1097 party_date: { 1098 required: true 1099 }, 1100 }, 1101 messages: { 1102 name: "Please enter your full first name", 1103 email: "Please enter your full first email", 1104 phone: "Please enter your phone", 1105 address: "Please enter your address", 1106 city: "Please enter your city", 1107 zipcode: "Please enter your zipcode", 1108 party_date: "Please enter date", 1109 1110 }, 1111 submitHandler: function(form) { 1112 SubmitForm(form); 1113 } 1114 }); 1115 1116 1117 //close message by click putside of the container 1118 $('html').click(function() { 1119 $('.msg').fadeOut(); 1120 }); 1121 $('.msg').click(function(event) { 1122 event.stopPropagation(); 1123 }); 1124}
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.