PATH:
home
/
letacommog
/
entrepro
/
wp-content
/
plugins
/
geo-my-wp
/
includes
/
location-form
/
assets
/
js
var GMW_Location_Form_Map_Providers={google_maps:{latLng:function(o,e){return new google.maps.LatLng(o,e)},getPosition:function(o){return o.getPosition()},setMarkerPosition:function(o,e){o.setPosition(e)},resizeMap:function(o){google.maps.event.trigger(o,"resize")},setCenter:function(o,e){e.setCenter(o)},addressAutocomplete:function(){jQuery(".gmw-lf-address-autocomplete").each(function(){autocompleteId=jQuery(this).attr("id"),input=document.getElementById(autocompleteId),options=GMW.apply_filters("gmw_lf_address_autocomplete_options",{},autocompleteId,this_form);var o=new google.maps.places.Autocomplete(input,options);google.maps.event.addListener(o,"place_changed",function(){if(place=o.getPlace(),place.geometry){var e=jQuery("#"+this_form.location_fields.address.id).val();GMW.do_action("gmw_lf_autocomplete_place_changed",place,this_form),jQuery(".group_coordinates, .group_address").val(""),jQuery(".group_coordinates.latitude").val(place.geometry.location.lat()),jQuery(".group_coordinates.longitude").val(place.geometry.location.lng()),jQuery("#gmw_lf_address, #gmw_lf_formatted_address").val(e);var t=GMW_Geocoders.google_maps.getLocationFields(place);t.address=e,this_form.get_address_fields(t,place,!1)}})})},renderMap:function(){this_form.is_location_confirmed?(lat=jQuery("#gmw_lf_latitude").val(),lng=jQuery("#gmw_lf_longitude").val()):(lat=this_form.vars.map_lat,lng=this_form.vars.map_lng),latLng=new google.maps.LatLng(lat,lng),map_options={zoom:parseInt(this_form.vars.map_zoom_level),center:latLng,mapTypeId:google.maps.MapTypeId[this_form.vars.map_type]},map_options=GMW.apply_filters("gmw_lf_render_map_options",map_options,this_form),this_form.map=new google.maps.Map(document.getElementById(this_form.location_fields.map.id),map_options),marker_options={position:latLng,map:this_form.map,draggable:!0},marker_options=GMW.apply_filters("gmw_lf_render_map_marker_options",marker_options,this_form),this_form.map_marker=new google.maps.Marker(marker_options),GMW.do_action("gmw_lf_render_map",this_form),google.maps.event.addListener(this_form.map_marker,"dragend",function(o){this_form.map_updated=!0,this_form.map_coords.lat=o.latLng.lat(),this_form.map_coords.lng=o.latLng.lng(),jQuery(".group_coordinates, .group_address,#"+this_form.location_fields.address.id).val(""),this_form.location_changed(),this_form.reverse_geocode(this_form.map_coords.lat,this_form.map_coords.lng,!1)})}},leaflet:{latLng:function(o,e){return L.latLng(o,e)},getPosition:function(o){return o.getLatLng()},setMarkerPosition:function(o,e){o.setLatLng(e)},resizeMap:function(o){o.invalidateSize()},setCenter:function(o,e){e.setView(o)},renderMap:function(){var o,e;this_form.is_location_confirmed?(o=jQuery("#gmw_lf_latitude").val(),e=jQuery("#gmw_lf_longitude").val()):(o=this_form.vars.map_lat,e=this_form.vars.map_lng);var t=L.latLng(o,e),s={zoom:parseInt(this_form.vars.map_zoom_level),maxZoom:18,minZoom:1};s=GMW.apply_filters("gmw_lf_render_map_options",s,this_form),this_form.map=L.map(this_form.location_fields.map.id,s),this_form.map.setView(t).zoomControl.setPosition("bottomright"),L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{attribution:'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'}).addTo(this_form.map);var i={draggable:!0};i=GMW.apply_filters("gmw_lf_render_map_marker_options",i,this_form),this_form.map_marker=new L.marker(t,i),GMW.do_action("gmw_lf_render_map",this_form),this_form.map_marker.addTo(this_form.map).on("dragend",function(o){this_form.map_updated=!0,this_form.map_coords.lat=this_form.map_marker.getLatLng().lat,this_form.map_coords.lng=this_form.map_marker.getLatLng().lng,jQuery(".group_coordinates, .group_address,#"+this_form.location_fields.address.id).val(""),this_form.location_changed(),this_form.reverse_geocode(this_form.map_coords.lat,this_form.map_coords.lng,!1)})}}},GMW_Location_Form={vars:{},is_location_confirmed:0!=jQuery.trim(jQuery("#gmw_lf_latitude").val()).length&&0!=jQuery.trim(jQuery("#gmw_lf_longitude").val()).length?!0:!1,security:"",fields:!1,messages:!1,wrapper_element:".gmw-location-form-wrapper",location_fields:!1,address_fields:!1,coords_fields:!1,action_fields:!1,map_enabled:jQuery("#gmw-lf-map").length?!0:!1,fields_changed_status:1,map_options:{},map_updated:!1,map_coords:{lat:"",lng:""},autocomplete_options:{},region:"US",proceed_submission:!1,location_exists:!1,auto_confirming:!1,ajaxResponse:{},latLng:function(o,e){},getPosition:function(o){},setMarkerPosition:function(o,e){},resizeMap:function(o){},setCenter:function(o,e){},renderMap:function(){},set_vars:function(){this_form.is_location_confirmed=0!=jQuery.trim(jQuery("#gmw_lf_latitude").val()).length&&0!=jQuery.trim(jQuery("#gmw_lf_longitude").val()).length?!0:!1,this_form.vars=gmw_lf_args.args||{},this_form.security=gmw_lf_args.nonce||"",this_form.fields=gmw_lf_args.fields||!1,this_form.messages=gmw_lf_args.messages||{},!1!==this_form.fields&&(this_form.location_fields=gmw_lf_args.fields.location.fields||!1,this_form.address_fields=gmw_lf_args.fields.address.fields||!1,this_form.coords_fields=gmw_lf_args.fields.coordinates.fields||!1,this_form.action_fields=gmw_lf_args.fields.actions.fields||!1),this_form.map_enabled=jQuery("#gmw-lf-map").length?!0:!1},init:function(){this_form=GMW_Location_Form,this_form.set_vars(),jQuery.extend(this_form,GMW_Location_Form_Map_Providers[gmwVars.mapsProvider]),jQuery("#"+this_form.action_fields.confirm_location.id).fadeOut("fast"),this_form.is_location_confirmed?(this_form.location_exists=!0,this_form.action_message("ok",this_form.messages.location_exists),this_form.is_location_confirmed=location_saved=!0):(this_form.location_exists=!1,jQuery("#"+this_form.action_fields.delete_location.id).fadeOut("fast"),this_form.action_message("error",this_form.messages.location_not_exists)),this_form.init_tabs(),this_form.fields_changed(),this_form.action_buttons(),"undefined"!=typeof this_form.addressAutocomplete&&this_form.vars.address_autocomplete&&jQuery(".gmw-lf-address-autocomplete").length&&this_form.addressAutocomplete(),this_form.map_enabled&&jQuery("#gmw-lf-map").length&&this_form.renderMap(),this_form.vars.geolocation_button&&jQuery(".gmw-lf-locator-button").length?this_form.current_location():jQuery(".gmw-lf-locator-button").remove()},init_actions:function(){jQuery(this_form.vars.form_element).on("submit",function(o){return!this_form.location_exists&&this_form.vars.location_required?(alert(this_form.messages.location_required),!1):void(this_form.proceed_submission||(o.preventDefault(),this_form.vars.auto_confirm?this_form.auto_confirm_submission(!0):this_form.confirm_submission(!0)))})},init_tabs:function(){firstTab=jQuery(".gmw-lf-tabs-wrapper li").first().attr("id"),jQuery("#"+firstTab+"-panel").show().siblings('[id*="-tab-panel"]').hide(),void 0!==typeof this_form.vars.exclude_fields_groups&&this_form.vars.exclude_fields_groups.length&&jQuery.each(this_form.vars.exclude_fields_groups,function(o,e){jQuery("#"+e+"-tab-panel").remove()}),jQuery(".gmw-lf-tabs-wrapper li a").on("click",function(o){o.preventDefault();var e=jQuery(this).data("name");jQuery("#"+e+"-tab-panel").show().siblings('[id*="-tab-panel"]').hide(),jQuery(this).parent("li").addClass("active").siblings().removeClass("active"),this_form.map_enabled&&jQuery("#"+e+"-tab-panel").find(jQuery("#"+this_form.location_fields.map.id)).length&&setTimeout(function(){this_form.resizeMap(this_form.map),this_form.setCenter(this_form.getPosition(this_form.map_marker),this_form.map)},100)})},action_message:function(o,e,t){"updating"==o?(jQuery("#"+this_form.action_fields.message.id).removeClass("changed ok error confirming").addClass("confirming").find("span").html(e),t&&jQuery("#"+this_form.action_fields.message.id).fadeIn("fast")):jQuery("#"+this_form.action_fields.loader.id).fadeOut("fast",function(){jQuery("#"+this_form.action_fields.message.id).removeClass("changed ok error confirming").addClass(o).find("span").html(e),t&&jQuery("#"+this_form.action_fields.message.id).fadeIn("fast")})},action_buttons:function(){jQuery(this_form.wrapper_element+' input[type="text"]').keypress(function(o){return 13==o.which?!1:void 0}),jQuery("#"+this_form.location_fields.address.id).length&&jQuery("#"+this_form.location_fields.address.id).on("keydown",function(o){13==o.which&&(!jQuery(this).hasClass("gmw-lf-address-autocomplete")||jQuery(this).hasClass("gmw-lf-address-autocomplete")&&"none"==jQuery(".pac-container").css("display"))&&(this_form.fields_changed_status=1,this_form.confirm_location())}),jQuery("#"+this_form.action_fields.submit_location.id).length&&jQuery("#"+this_form.action_fields.submit_location.id).on("click",function(){this_form.vars.auto_confirm?this_form.auto_confirm_submission(!1):this_form.confirm_submission(!1)}),jQuery("#"+this_form.action_fields.confirm_location.id).length&&jQuery("#"+this_form.action_fields.confirm_location.id).on("click",function(){this_form.confirm_location()}),jQuery("#"+this_form.action_fields.delete_location.id).length&&jQuery("#"+this_form.action_fields.delete_location.id).on("click",function(){return confirm(this_form.messages.delete_confirmation)?void this_form.delete_location():!1})},fields_changed:function(){jQuery(".gmw-lf-field.address-field, .gmw-lf-field.group_address, .gmw-lf-field.group_coordinates").on("change input",function(o){jQuery(this).hasClass("address-field")?this_form.fields_changed_status=1:jQuery(this).hasClass("group_address")?this_form.fields_changed_status=2:jQuery(this).hasClass("group_coordinates")&&(this_form.fields_changed_status=3),jQuery("#"+jQuery(this).attr("id").replace(/-/g,"_")).val(jQuery(this).val()),jQuery("p.gmw-lf-form-action").hasClass("changed")||this_form.location_changed()})},location_changed:function(){this_form.vars.auto_confirm||jQuery("#"+this_form.action_fields.confirm_location.id).fadeIn("fast"),this_form.location_exists=!0,this_form.action_message("changed",this_form.messages.location_changed),this_form.is_location_confirmed=!1},update_map:function(o,e){var t=this_form.latLng(o,e);this_form.setMarkerPosition(this_form.map_marker,t),this_form.map.panTo(t),GMW.do_action("gmw_lf_update_map",this_form,t)},current_location:function(){jQuery("#gmw-lf-locator-button").on("click",function(){jQuery("#gmw-lf-locator-button").addClass("animate-spin"),navigator.geolocation?(options=GMW.apply_filters("gmw_lf_navigator_options",{timeout:15e3},this_form),navigator.geolocation.getCurrentPosition(this_form.navigator_position,this_form.navigator_error,options)):(alert("Geolocation is not supported by this browser."),jQuery("#gmw-lf-locator-button").removeClass("animate-spin"))})},navigator_position:function(o){jQuery("#gmw-lf-locator-button").removeClass("animate-spin"),this_form.location_changed(),this_form.reverse_geocode(o.coords.latitude,o.coords.longitude,!1)},navigator_error:function(o){switch(o.code){case o.PERMISSION_DENIED:alert("User denied the request for Geolocation.");break;case o.POSITION_UNAVAILABLE:alert("Location information is unavailable.");break;case o.TIMEOUT:alert("The request to get user location timed out.");break;case o.UNKNOWN_ERROR:alert("An unknown error occurred.")}this_form.is_location_confirmed=!1,jQuery("#gmw-lf-locator-button").removeClass("animate-spin")},geocode:function(o){if(jQuery("#"+this_form.action_fields.loader.id).fadeIn("fast"),0==jQuery.trim(o).length)this_form.location_missing_message();else{var e=new GMW_Geocoder(gmwVars.geocodingProvider);e.geocode({q:o},function(e,t){"OK"==t?(1==this_form.fields_changed_status?jQuery(".group_coordinates, .group_address").val(""):2==this_form.fields_changed_status&&jQuery(".group_coordinates, .gmw-lf-submission-field.group_address, #"+this_form.location_fields.address.id).val(""),e.result.address=o,jQuery(".group_coordinates.latitude").val(e.result.lat),jQuery(".group_coordinates.longitude").val(e.result.lng),jQuery("#"+this_form.location_fields.address.id+", #gmw_lf_address").val(o),jQuery("#gmw_lf_formatted_address").val(e.result.formatted_address),this_form.get_address_fields(e.result,e,!0)):this_form.geocoder_failed(e.status,e)})}},reverse_geocode:function(o,e,t){jQuery("#"+this_form.action_fields.loader.id).fadeIn("fast"),jQuery(".group_coordinates.latitude").val(o),jQuery(".group_coordinates.longitude").val(e),data={q:[o,e],region:this_form.region};var s=new GMW_Geocoder(gmwVars.geocodingProvider);s.reverseGeocode(data,function(o,e){"OK"==e?(o.result.address=o.result.formatted_address,jQuery(".group_address,"+this_form.location_fields.address.id).val(""),jQuery("#"+this_form.location_fields.address.id+", #gmw_lf_address, #gmw_lf_formatted_address").val(o.result.formatted_address),this_form.get_address_fields(o.result,o,t)):this_form.geocoder_failed(e)})},geocoder_failed:function(o,e){this_form.is_location_confirmed=!1,alert(this_form.messages.geocoder_failed),console.log(e),jQuery("#"+this_form.action_fields.loader.id).fadeOut("fast")},location_missing_message:function(){this_form.is_location_confirmed=!1,alert(this_form.messages.location_missing),jQuery("#"+this_form.action_fields.loader.id).fadeOut("fast")},get_address_fields:function(o,e,t){o=GMW.apply_filters("gmw_lf_address_component",o,this_form,e),""==o.address&&(o.address=o.formatted_address);for(var s in o)o.result||jQuery(".group_address."+s).length&&jQuery(".group_address."+s).val(o[s]);o.latitude=jQuery("#gmw_lf_latitude").val(),o.longitude=jQuery("#gmw_lf_longitude").val(),o.formatted_address=jQuery("#gmw_lf_formatted_address").val(),jQuery(".group_address.place_id").val(o.place_id),GMW.do_action("gmw_lf_geocoded_location_data",o,e,this_form),this_form.map_enabled&&jQuery("#gmw-lf-map").length&&!this_form.map_updated?this_form.update_map(o.lat,o.lng):this_form.map_updated&&(this_form.map_updated=!1),this_form.location_confirmed()},confirm_location:function(){this_form.is_location_confirmed?this_form.location_confirmed():(jQuery("#"+this_form.action_fields.loader.id).fadeIn("fast"),latVal=lngVal="",0!=typeof this_form.coords_fields&&this_form.coords_fields.length&&(latVal=jQuery("#"+this_form.coords_fields.latitude.id).val(),lngVal=jQuery("#"+this_form.coords_fields.longitude.id).val()),3!=this_form.fields_changed_status||0==jQuery.trim(latVal).length||0==jQuery.trim(lngVal).length?(1==this_form.fields_changed_status&&jQuery.trim(jQuery("#"+this_form.location_fields.address.id).val()).length>0?address=jQuery("#"+this_form.location_fields.address.id).val():(address="",jQuery.each(this_form.address_fields,function(o,e){jQuery("#"+e.id).length&&jQuery.trim(jQuery("#"+e.id).val()).length>0&&(address+=jQuery("#"+e.id).val()+" ")})),0==jQuery.trim(address).length&&0!=jQuery.trim(latVal).length&&0!=jQuery.trim(lngVal).length?this_form.reverse_geocode(latVal,lngVal,!0):this_form.geocode(address)):this_form.reverse_geocode(latVal,lngVal,!0))},auto_confirm_submission:function(o){var e;return this_form.location_exists?(this_form.is_location_confirmed?e=0:(e=3e3,this_form.auto_confirming=!0,jQuery("#"+this_form.action_fields.message.id).fadeOut("fast"),this_form.confirm_location()),void setTimeout(function(){return this_form.is_location_confirmed?void(o||this_form.vars.stand_alone&&!this_form.vars.ajax_enabled?(this_form.proceed_submission=!0,this_form.auto_confirming=!1,jQuery(this_form.vars.form_element).submit()):(this_form.auto_confirming=!1,this_form.save_location())):(this_form.auto_confirming=!1,!1)},e)):this_form.vars.location_required?(this_form.location_missing_message(),!1):(this_form.proceed_submission=!0,jQuery(this_form.vars.form_element).submit(),!1)},confirm_submission:function(o){var e=!1;return this_form.is_location_confirmed?e=!0:this_form.location_exists?this_form.vars.confirm_required?(alert(this_form.messages.confirm_required),e=!1):(lat=jQuery("#gmw_lf_latitude").val(),lng=jQuery("#gmw_lf_longitude").val(),0!=jQuery.trim(lat).length&&0!=jQuery.trim(lng).length&&jQuery.isNumeric(lat)&&jQuery.isNumeric(lng)?e=confirm(this_form.messages.confirm_message)?!0:!1:(alert(this_form.messages.coords_invalid),e=!1)):this_form.vars.location_required?(alert("no location"),e=!1):e=!0,e?void(o||this_form.vars.stand_alone&&!this_form.vars.ajax_enabled?(this_form.proceed_submission=!0,jQuery(this_form.vars.form_element).submit()):this_form.save_location()):!1},location_confirmed:function(){this_form.auto_confirming||(jQuery("#"+this_form.action_fields.confirm_location.id).fadeOut("fast"),jQuery("#"+this_form.action_fields.delete_location.id).fadeIn("fast"),this_form.action_message("ok",this_form.messages.location_exists,!0)),jQuery(".gmw-lf-field.address-field, .gmw-lf-field.group_address, .gmw-lf-field.group_coordinates").off("change"),this_form.is_location_confirmed=!0},save_location:function(){jQuery("#"+this_form.action_fields.message.id).fadeOut("fast",function(){jQuery("#"+this_form.action_fields.loader.id).fadeIn("fast")});var o=jQuery(this_form.vars.form_element).serialize();return this_form.ajaxResponse=jQuery.ajax({type:"POST",dataType:"json",url:gmwVars.ajaxUrl,data:{action:this_form.vars.update_callback,formValues:o,formArgs:this_form.vars,security:this_form.security},success:function(e){e?(jQuery("#gmw_lf_location_id").val(e),GMW.do_action("gmw_lf_location_saved",e,o,this_form.vars),jQuery("#"+this_form.action_fields.confirm_location.id).fadeOut("fast",function(){this_form.action_message("ok",this_form.messages.location_saved,!0),setTimeout(function(){jQuery("#"+this_form.action_fields.message.id+" span").html(this_form.messages.location_exists)},3500)})):this_form.action_message("error",this_form.messages.location_not_saved,!0)}}).fail(function(o,e,t){window.console&&window.console.log&&(console.log(e+": "+t),o.responseText&&console.log(o.responseText)),this_form.action_message("error",this_form.messages.location_not_saved,!0)}).done(function(o){console.log("done saving location"),console.log(o)}),!1},delete_location:function(){jQuery("#"+this_form.action_fields.message.id).fadeOut("fast",function(){jQuery("#"+this_form.action_fields.loader.id).fadeIn("fast"),jQuery("#"+this_form.action_fields.confirm_location.id).fadeOut("fast")}),""!=jQuery("#gmw_lf_location_id").val()&&"0"!=jQuery("#gmw_lf_location_id").val()?this_form.ajax_delete():(jQuery(".group_address, .group_coordinates, .gmw-lf-field.address-field, .gmw-lf-extra-field").val(""),this_form.is_location_confirmed=!1,setTimeout(function(){this_form.location_exists=!1,jQuery("#"+this_form.action_fields.delete_location.id).fadeOut("fast"),this_form.action_message("ok",this_form.messages.location_deleted,!0),setTimeout(function(){this_form.action_message("error",this_form.messages.location_not_exists,!0)},3500)},1500))},ajax_delete:function(){return this_form.ajaxResponse=jQuery.ajax({type:"post",dataType:"json",url:gmwVars.ajaxUrl,data:{action:this_form.vars.delete_callback,formValues:jQuery(this_form.vars.form_element).serialize(),formArgs:this_form.vars,security:this_form.security},success:function(o){o?(jQuery(".group_address, .group_coordinates, .gmw-lf-field.address-field, .gmw-lf-extra-field, #gmw_lf_location_id").val(""),this_form.is_location_confirmed=!1,this_form.location_exists=!1,jQuery("#"+this_form.action_fields.delete_location.id).fadeOut("fast"),this_form.action_message("ok",this_form.messages.location_deleted,!0),setTimeout(function(){this_form.action_message("error",this_form.messages.location_not_exists,!0)},3500)):this_form.action_message("error",this_form.messages.location_not_deleted,!0)}}).fail(function(o,e,t){window.console&&window.console.log&&(console.log(e+": "+t),o.responseText&&console.log(o.responseText)),this_form.action_message("error",this_form.messages.location_not_deleted,!0)}).done(function(o){console.log("done deleting location"),console.log(o)}),!1}};jQuery(document).ready(function(){jQuery(".gmw-location-form-wrapper").length&&(GMW_Location_Form.init(),GMW_Location_Form.init_actions())});
[+]
..
[-] gmw.location.form.js
[edit]
[-] gmw.location.form.min.js
[edit]