Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wp-map-picker

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wp-map-picker - npm Package Compare versions

Comparing version 0.5.1 to 0.6.0

2

bower.json
{
"name": "wp-map-picker",
"version": "0.5.1",
"version": "0.6.0",
"description": "This jQuery plugin for WordPress can be used to transform an input field into a flexible map field with a location picker.",

@@ -5,0 +5,0 @@ "main": [

{
"name": "wp-map-picker",
"version": "0.5.1",
"version": "0.6.0",
"description": "This jQuery plugin for WordPress can be used to transform an input field into a flexible map field with a location picker.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -20,5 +20,5 @@ # WP Map Picker

The preferred method to install this package is to use Bower.
The preferred method to install this package is to use NPM.
```
bower install wp-map-picker
npm install wp-map-picker
```

@@ -33,4 +33,4 @@

wp_enqueue_script( 'google-maps', $gmaps_url, array(), false, true );
wp_enqueue_script( 'wp-map-picker', 'PATHTOMAPPICKER/wp-map-picker.min.js', array( 'jquery', 'jquery-ui-widget', 'jquery-ui-autocomplete', 'google-maps' ), '0.5.1', true );
wp_enqueue_style( 'wp-map-picker', 'PATHTOMAPPICKER/wp-map-picker.min.css', array(), '0.5.1' );
wp_enqueue_script( 'wp-map-picker', 'PATHTOMAPPICKER/wp-map-picker.min.js', array( 'jquery', 'jquery-ui-widget', 'jquery-ui-autocomplete', 'google-maps' ), '0.6.0', true );
wp_enqueue_style( 'wp-map-picker', 'PATHTOMAPPICKER/wp-map-picker.min.css', array(), '0.6.0' );

@@ -60,2 +60,7 @@ ```

`storeAdditional`:
* Object with additional input element selectors to set their values automatically; these inputs have to exist in the page as they will not be created manually
* Accepts an object where each property is a selector for one input element and the property value is the type of information to store in that element; valid values are 'address', 'coords', 'latitude', 'longitude' or any other field that the Google Geocoder returns in a response
* Default: false
`zoom`:

@@ -76,3 +81,3 @@ * Sets the initial zoom level for the map

`default_location`:
`defaultLocation`:
* Specifies the default location if the input field does not contain any

@@ -82,3 +87,3 @@ * Accepts an object with three properties (`lat` for the latitude default, `lng` for the longitude default and `zoom` for the initial zoom level used when the default location is applied)

`decimal_separator`:
`decimalSeparator`:
* Defines the decimal separator used for coords

@@ -108,12 +113,4 @@ * Accepts '.' or ','

`latlng`:
* Dynamic getter/setter method for the location object (this is _not_ the field value itself!)
* Accepts an Google Maps API latlng object (only for the setter functionality)
`value`:
* Dynamic getter/setter method for the field value
* Accepts a string ("latitude|longitude" or "address", depending on `store` setting) (only for the setter functionality)
## Contribute
I'm always grateful for contributions, whether it is about enhancements or bugfixes, especially since the plugin is at an early stage. If you encounter bugs, compatibility issues or totally missing functionality that must be in this plugin, I would appreciate if you [created an issue](https://github.com/felixarntz/wp-map-picker/issues). Or even better, if you can, do it yourself and [open a pull-request](https://github.com/felixarntz/wp-map-picker/pulls).

@@ -26,6 +26,7 @@ /*

store: 'address',
storeAdditional: false,
zoom: 15,
draggable: true,
mapType: 'roadmap', // roadmap, satellite, terrain or hybrid
default_location: {
defaultLocation: {
lat: '0.0',

@@ -35,3 +36,3 @@ lng: '0.0',

},
decimal_separator: '.',
decimalSeparator: '.',
change: false,

@@ -46,3 +47,3 @@ clear: false

self.default_latlng = self._parseLatLng( self.options.default_location );
self.defaultLatLng = self._parseLatLng( self.options.defaultLocation );
self.is_default = true;

@@ -57,4 +58,4 @@

self.map = new google.maps.Map( self.canvas[0], {
center: self.default_latlng,
zoom: self.options.default_location.zoom,
center: self.defaultLatLng,
zoom: self.options.defaultLocation.zoom,
draggable: self.options.draggable,

@@ -65,4 +66,4 @@ tilt: 0,

});
this.marker = new google.maps.Marker({
position: self.default_latlng,
self.marker = new google.maps.Marker({
position: self.defaultLatLng,
map: self.map,

@@ -72,16 +73,12 @@ draggable: true

self._updateMap();
var value = self.element.val();
if ( 'coords' === self.options.store ) {
self._geocodeLatLng( value, self._initMap );
} else {
self._geocodeAddress( value, self._initMap );
}
self._addListeners();
},
_addListeners: function() {
var self = this;
if ( 'coords' === self.options.store ) {
self.element.on( 'change', function() {
var latlng = self._parseLatLng( self.element.val() );
if ( latlng ) {
self._createMap( latlng );
}
self._geocodeLatLng( self.element.val(), self._updateMap );
});

@@ -91,15 +88,14 @@ } else {

source: function( request, response ) {
self.geocoder.geocode({
address: request.term
}, function( results ) {
if ( null !== results ) {
response( $.map( results, function( item ) {
return {
label: item.formatted_address,
value: item.formatted_address,
latlng: item.geometry.location
};
}) );
self._geocodeAddress( request.term, function( results ) {
if ( results ) {
response([
{
label: results.formatted_address,
value: results.formatted_address,
latlng: results.geometry.location,
geocoded: results
}
]);
} else {
response( [] );
response([]);
}

@@ -109,7 +105,3 @@ });

select: function( e, ui ) {
self.element.val( ui.item.label );
self._createMap( ui.item.latlng );
if ( 'function' === typeof self.options.change ) {
self.options.change.call( self );
}
self._updateMap( ui.item.geocoded );
}

@@ -120,94 +112,143 @@ });

google.maps.event.addListener( self.map, 'click', function( e ) {
self._updateFieldValue( e.latLng );
self._createMap( e.latLng );
self._geocodeLatLng( e.latLng, self._updateField );
});
google.maps.event.addListener( self.marker, 'dragend', function( e ) {
self._updateFieldValue( e.latLng );
self._createMap( e.latLng );
self._geocodeLatLng( e.latLng, self._updateField );
});
},
_updateFieldValue: function( latlng, manual_change ) {
var self = this;
_initMap: function( geocoded ) {
if ( geocoded ) {
this.latlng = geocoded.geometry.location;
if ( 'coords' === self.options.store ) {
self.element.val( self._formatLatLng( latlng ) );
this.marker.setPosition( this.latlng );
this.map.setCenter( this.latlng );
if ( ! manual_change && 'function' === typeof self.options.change ) {
self.options.change.call( self );
if ( this.is_default ) {
this.is_default = false;
this.map.setZoom( this.options.zoom );
}
} else {
self.geocoder.geocode({
location: latlng
}, function( results ) {
if ( null !== results && 'undefined' !== typeof results[0] && 'undefined' !== typeof results[0].formatted_address ) {
self.element.val( results[0].formatted_address );
this.latlng = null;
if ( ! manual_change && 'function' === typeof self.options.change ) {
self.options.change.call( self );
}
}
});
this.marker.setPosition( this.defaultLatLng );
this.map.setCenter( this.defaultLatLng );
if ( ! this.is_default ) {
this.is_default = true;
this.map.setZoom( this.options.defaultLocation.zoom );
}
}
},
_createMap: function( latlng ) {
var self = this;
_updateMap: function( geocoded ) {
this._initMap( geocoded );
self.latlng = latlng;
if ( this.options.storeAdditional ) {
this._updateAdditionalFields( geocoded );
}
self.marker.setPosition( latlng );
self.map.setCenter( latlng );
if ( self.is_default ) {
self.is_default = false;
self.map.setZoom( self.options.zoom );
if ( 'function' === typeof this.options.change ) {
this.options.change.call( this );
}
},
_resetMap: function() {
var self = this;
_updateField: function( geocoded ) {
if ( geocoded ) {
this.latlng = geocoded.geometry.location;
self.latlng = null;
if ( 'coords' === this.options.store ) {
this.element.val( this._formatLatLng( geocoded.geometry.location ) );
} else {
this.element.val( geocoded.formatted_address );
}
} else {
this.latlng = null;
self.marker.setPosition( self.default_latlng );
self.map.setCenter( self.default_latlng );
self.map.setZoom( self.options.default_location.zoom );
self.is_default = true;
this.element.val( null );
}
if ( this.options.storeAdditional ) {
this._updateAdditionalFields( geocoded );
}
if ( 'function' === typeof this.options.change ) {
this.options.change.call( this );
}
},
_updateMap: function() {
var self = this;
var val = self.element.val();
_updateAdditionalFields: function( geocoded ) {
var keys = Object.keys( this.options.storeAdditional );
var store, selector, value, oldValue;
if ( val ) {
if ( 'coords' === self.options.store ) {
var latlng = self._parseLatLng( val );
if ( latlng ) {
self._createMap( latlng );
} else {
self.element.val( null );
self._resetMap();
for ( var i in keys ) {
selector = keys[ i ];
store = this.options.storeAdditional[ selector ];
oldValue = $( selector ).val();
value = null;
if ( geocoded ) {
switch ( store ) {
case 'coords':
value = this._formatLatLng( geocoded.geometry.location );
break;
case 'address':
value = geocoded.formatted_address;
break;
case 'latitude':
value = this._formatLatOrLng( geocoded.geometry.location.lat() );
break;
case 'longitude':
value = this._formatLatOrLng( geocoded.geometry.location.lng() );
break;
default:
if ( 'undefined' !== typeof geocoded[ store ] ) {
value = geocoded[ store ];
}
}
} else {
self.geocoder.geocode({
address: val
}, function( results ) {
if ( null !== results && 'undefined' !== typeof results[0] && 'undefined' !== typeof results[0].geometry && 'undefined' !== typeof results[0].geometry.location ) {
self._createMap( results[0].geometry.location );
} else {
self.element.val( null );
self._resetMap();
}
});
}
} else {
self.element.val( null );
self._resetMap();
if ( value !== oldValue ) {
$( selector ).val( value ).trigger( 'change' );
}
}
},
_parseLatLng: function( val ) {
_geocodeLatLng: function( latlng, callback ) {
if ( ! latlng ) {
callback.apply( this, [ latlng ] );
return;
}
this._geocodeObject({
location: this._parseLatLng( latlng )
}, callback );
},
_geocodeAddress: function( address, callback ) {
if ( ! address ) {
callback.apply( this, [ address ] );
return;
}
this._geocodeObject({
address: address
}, callback );
},
_geocodeObject: function( obj, callback ) {
var self = this;
self.geocoder.geocode( obj, function( results ) {
var value;
if ( null !== results && 'undefined' !== typeof results[0] ) {
value = results[0];
}
callback.apply( self, [ value ] );
});
},
_parseLatLng: function( val ) {
if ( 'object' === typeof val && 'function' !== typeof val.lat ) {

@@ -229,3 +270,3 @@ val = '' + val.lat + '|' + val.lng;

for ( var i = 0; i < 2; i++ ) {
val[ i ] = parseFloat( val[ i ].replace( self.options.decimal_separator, '.' ) );
val[ i ] = this._parseLatOrLng( val[ i ] );
}

@@ -236,5 +277,7 @@

_parseLatOrLng: function( val ) {
return parseFloat( val.replace( this.options.decimalSeparator, '.' ) );
},
_formatLatLng: function( val ) {
var self = this;
if ( 'string' === typeof val ) {

@@ -244,12 +287,15 @@ return val;

return ( '' + val.lat() ).replace( '.', self.options.decimal_separator ) + '|' + ( '' + val.lng() ).replace( '.', self.options.decimal_separator );
return this._formatLatOrLng( val.lat() ) + '|' + this._formatLatOrLng( val.lng() );
},
_formatLatOrLng: function( val ) {
return ( '' + val ).replace( '.', this.options.decimalSeparator );
},
clear: function() {
this.element.val( null );
if ( ! this.is_default ) {
this._resetMap();
if ( 'function' === typeof this.options.clear ) {
this.options.clear.call( this );
}
this._initMap();
this._updateField();
if ( 'function' === typeof this.options.clear ) {
this.options.clear.call( this );
}

@@ -263,30 +309,4 @@ },

} else {
this.map.setCenter( this.default_latlng );
this.map.setCenter( this.defaultLatLng );
}
},
latlng: function( latlng ) {
if ( 'undefined' === typeof latlng ) {
return this.latlng;
}
if ( ! latlng ) {
this.element.val( null );
this._resetMap();
} else {
this._updateFieldValue( latlng, true );
this._createMap( latlng );
}
},
value: function( val ) {
if ( 'undefined' === typeof val ) {
if ( ! this.latlng ) {
return '';
}
return this.element.val();
}
this.element.val( val );
this._updateMap();
}

@@ -293,0 +313,0 @@ };

/*!
* WP Map Picker - version 0.5.0
* WP Map Picker - version 0.6.0
*
* Felix Arntz <felix-arntz@leaves-and-love.net>
*/
!function(a,b){if("undefined"==typeof b||"undefined"==typeof b.maps)return a.fn.wpMapPicker=function(){return this},void console.error("Google Maps not found");var c='<div class="wp-mappicker-container" />',d='<div class="wp-mappicker-map-canvas-wrap" />',e='<div class="wp-mappicker-map-canvas" />',f={options:{store:"address",zoom:15,draggable:!0,mapType:"roadmap",default_location:{lat:"0.0",lng:"0.0",zoom:2},decimal_separator:".",change:!1,clear:!1},_create:function(){var f=this;a.extend(f.options,f.element.data()),f.default_latlng=f._parseLatLng(f.options.default_location),f.is_default=!0,f.element.wrap(c),f.canvas_wrap=a(d).insertAfter(f.element),f.canvas=a(e).appendTo(f.canvas_wrap),f.geocoder=new b.maps.Geocoder,f.map=new b.maps.Map(f.canvas[0],{center:f.default_latlng,zoom:f.options.default_location.zoom,draggable:f.options.draggable,tilt:0,streetViewControl:0,mapTypeId:b.maps.MapTypeId[f.options.mapType.toUpperCase()]}),this.marker=new b.maps.Marker({position:f.default_latlng,map:f.map,draggable:!0}),f._updateMap(),f._addListeners()},_addListeners:function(){var c=this;"coords"===c.options.store?c.element.on("change",function(){var a=c._parseLatLng(c.element.val());a&&c._createMap(a)}):c.element.autocomplete({source:function(b,d){c.geocoder.geocode({address:b.term},function(b){d(null!==b?a.map(b,function(a){return{label:a.formatted_address,value:a.formatted_address,latlng:a.geometry.location}}):[])})},select:function(a,b){c.element.val(b.item.label),c._createMap(b.item.latlng),"function"==typeof c.options.change&&c.options.change.call(c)}}),b.maps.event.addListener(c.map,"click",function(a){c._updateFieldValue(a.latLng),c._createMap(a.latLng)}),b.maps.event.addListener(c.marker,"dragend",function(a){c._updateFieldValue(a.latLng),c._createMap(a.latLng)})},_updateFieldValue:function(a,b){var c=this;"coords"===c.options.store?(c.element.val(c._formatLatLng(a)),b||"function"!=typeof c.options.change||c.options.change.call(c)):c.geocoder.geocode({location:a},function(a){null!==a&&"undefined"!=typeof a[0]&&"undefined"!=typeof a[0].formatted_address&&(c.element.val(a[0].formatted_address),b||"function"!=typeof c.options.change||c.options.change.call(c))})},_createMap:function(a){var b=this;b.latlng=a,b.marker.setPosition(a),b.map.setCenter(a),b.is_default&&(b.is_default=!1,b.map.setZoom(b.options.zoom))},_resetMap:function(){var a=this;a.latlng=null,a.marker.setPosition(a.default_latlng),a.map.setCenter(a.default_latlng),a.map.setZoom(a.options.default_location.zoom),a.is_default=!0},_updateMap:function(){var a=this,b=a.element.val();if(b)if("coords"===a.options.store){var c=a._parseLatLng(b);c?a._createMap(c):(a.element.val(null),a._resetMap())}else a.geocoder.geocode({address:b},function(b){null!==b&&"undefined"!=typeof b[0]&&"undefined"!=typeof b[0].geometry&&"undefined"!=typeof b[0].geometry.location?a._createMap(b[0].geometry.location):(a.element.val(null),a._resetMap())});else a.element.val(null),a._resetMap()},_parseLatLng:function(a){var c=this;if("object"==typeof a&&"function"!=typeof a.lat)a=""+a.lat+"|"+a.lng;else if("object"==typeof a)return a;if("string"!=typeof a)return!1;if(a=a.split("|"),2!==a.length)return!1;for(var d=0;2>d;d++)a[d]=parseFloat(a[d].replace(c.options.decimal_separator,"."));return new b.maps.LatLng(a[0],a[1])},_formatLatLng:function(a){var b=this;return"string"==typeof a?a:(""+a.lat()).replace(".",b.options.decimal_separator)+"|"+(""+a.lng()).replace(".",b.options.decimal_separator)},clear:function(){this.element.val(null),this.is_default||(this._resetMap(),"function"==typeof this.options.clear&&this.options.clear.call(this))},refresh:function(){b.maps.event.trigger(this.map,"resize"),this.latlng?this.map.setCenter(this.latlng):this.map.setCenter(this.default_latlng)},latlng:function(a){return"undefined"==typeof a?this.latlng:void(a?(this._updateFieldValue(a,!0),this._createMap(a)):(this.element.val(null),this._resetMap()))},value:function(a){return"undefined"==typeof a?this.latlng?this.element.val():"":(this.element.val(a),void this._updateMap())}};a.widget("wp.wpMapPicker",f)}(jQuery,google);
!function(a,b){if(void 0===b||void 0===b.maps)return a.fn.wpMapPicker=function(){return this},void console.error("Google Maps not found");var c='<div class="wp-mappicker-container" />',d='<div class="wp-mappicker-map-canvas-wrap" />',e='<div class="wp-mappicker-map-canvas" />',f={options:{store:"address",storeAdditional:!1,zoom:15,draggable:!0,mapType:"roadmap",defaultLocation:{lat:"0.0",lng:"0.0",zoom:2},decimalSeparator:".",change:!1,clear:!1},_create:function(){var f=this;a.extend(f.options,f.element.data()),f.defaultLatLng=f._parseLatLng(f.options.defaultLocation),f.is_default=!0,f.element.wrap(c),f.canvas_wrap=a(d).insertAfter(f.element),f.canvas=a(e).appendTo(f.canvas_wrap),f.geocoder=new b.maps.Geocoder,f.map=new b.maps.Map(f.canvas[0],{center:f.defaultLatLng,zoom:f.options.defaultLocation.zoom,draggable:f.options.draggable,tilt:0,streetViewControl:0,mapTypeId:b.maps.MapTypeId[f.options.mapType.toUpperCase()]}),f.marker=new b.maps.Marker({position:f.defaultLatLng,map:f.map,draggable:!0});var g=f.element.val();"coords"===f.options.store?f._geocodeLatLng(g,f._initMap):f._geocodeAddress(g,f._initMap),"coords"===f.options.store?f.element.on("change",function(){f._geocodeLatLng(f.element.val(),f._updateMap)}):f.element.autocomplete({source:function(a,b){f._geocodeAddress(a.term,function(a){b(a?[{label:a.formatted_address,value:a.formatted_address,latlng:a.geometry.location,geocoded:a}]:[])})},select:function(a,b){f._updateMap(b.item.geocoded)}}),b.maps.event.addListener(f.map,"click",function(a){f._geocodeLatLng(a.latLng,f._updateField)}),b.maps.event.addListener(f.marker,"dragend",function(a){f._geocodeLatLng(a.latLng,f._updateField)})},_initMap:function(a){a?(this.latlng=a.geometry.location,this.marker.setPosition(this.latlng),this.map.setCenter(this.latlng),this.is_default&&(this.is_default=!1,this.map.setZoom(this.options.zoom))):(this.latlng=null,this.marker.setPosition(this.defaultLatLng),this.map.setCenter(this.defaultLatLng),this.is_default||(this.is_default=!0,this.map.setZoom(this.options.defaultLocation.zoom)))},_updateMap:function(a){this._initMap(a),this.options.storeAdditional&&this._updateAdditionalFields(a),"function"==typeof this.options.change&&this.options.change.call(this)},_updateField:function(a){a?(this.latlng=a.geometry.location,"coords"===this.options.store?this.element.val(this._formatLatLng(a.geometry.location)):this.element.val(a.formatted_address)):(this.latlng=null,this.element.val(null)),this.options.storeAdditional&&this._updateAdditionalFields(a),"function"==typeof this.options.change&&this.options.change.call(this)},_updateAdditionalFields:function(b){var c,d,e,f,g=Object.keys(this.options.storeAdditional);for(var h in g){if(d=g[h],c=this.options.storeAdditional[d],f=a(d).val(),e=null,b)switch(c){case"coords":e=this._formatLatLng(b.geometry.location);break;case"address":e=b.formatted_address;break;case"latitude":e=this._formatLatOrLng(b.geometry.location.lat());break;case"longitude":e=this._formatLatOrLng(b.geometry.location.lng());break;default:void 0!==b[c]&&(e=b[c])}e!==f&&a(d).val(e).trigger("change")}},_geocodeLatLng:function(a,b){if(!a)return void b.apply(this,[a]);this._geocodeObject({location:this._parseLatLng(a)},b)},_geocodeAddress:function(a,b){if(!a)return void b.apply(this,[a]);this._geocodeObject({address:a},b)},_geocodeObject:function(a,b){var c=this;c.geocoder.geocode(a,function(a){var d;null!==a&&void 0!==a[0]&&(d=a[0]),b.apply(c,[d])})},_parseLatLng:function(a){if("object"==typeof a&&"function"!=typeof a.lat)a=a.lat+"|"+a.lng;else if("object"==typeof a)return a;if("string"!=typeof a)return!1;if(a=a.split("|"),2!==a.length)return!1;for(var c=0;c<2;c++)a[c]=this._parseLatOrLng(a[c]);return new b.maps.LatLng(a[0],a[1])},_parseLatOrLng:function(a){return parseFloat(a.replace(this.options.decimalSeparator,"."))},_formatLatLng:function(a){return"string"==typeof a?a:this._formatLatOrLng(a.lat())+"|"+this._formatLatOrLng(a.lng())},_formatLatOrLng:function(a){return(""+a).replace(".",this.options.decimalSeparator)},clear:function(){this._initMap(),this._updateField(),"function"==typeof this.options.clear&&this.options.clear.call(this)},refresh:function(){b.maps.event.trigger(this.map,"resize"),this.latlng?this.map.setCenter(this.latlng):this.map.setCenter(this.defaultLatLng)}};a.widget("wp.wpMapPicker",f)}(jQuery,google);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc