# leaflet-map/2.16.2/scripts/shortcode-helper.js

Leaflet Map, version 2.16.2. 65 lines.

- Page: https://pluginprobe.com/plugins/leaflet-map/2.16.2/code/scripts/shortcode-helper.js
- Raw: https://pluginprobe.com/plugins/leaflet-map/2.16.2/raw/scripts/shortcode-helper.js
- Modified: 2018-09-19T22:32:58+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/leaflet-map/2.16.2/code/scripts/shortcode-helper.js#L10-L20`.

```javascript
(function () {

	window.WPLeafletMapPlugin = window.WPLeafletMapPlugin || [];
	window.WPLeafletMapPlugin.push( initAdminShortcodes );

	function initAdminShortcodes () {
		var map_input = document.getElementById('map-shortcode'),
			marker_input = document.getElementById('marker-shortcode'),
			map_1 = window.WPLeafletMapPlugin.maps[0],
			marker_1 = window.WPLeafletMapPlugin.markers[0];
		
		function update_marker () {
			var latlng = marker_1.getLatLng();
			marker_input.value = '[leaflet-marker lat=' +
				latlng.lat +
				' lng=' + 
				latlng.lng + 
				']';
		}

		function update_map () {
			var bounds = map_1.getBounds();
			var latlng = bounds.getCenter();
			map_input.value = '[leaflet-map lat=' +
				latlng.lat +
				' lng=' + 
				latlng.lng + 
				' zoom=' +
				map_1.getZoom() +
				']';

			// update marker if outside of bounds
			if (!bounds.contains(marker_1.getLatLng())) {
				// move marker to center
				marker_1.setLatLng(latlng);
			}
		}

		marker_1.on('drag', update_marker);
		map_1.on('move', update_map);

		update_map();
		update_marker();

		if (map_input.addEventListener) {
			map_input.addEventListener('click', function () {
				this.select();
			});

			marker_input.addEventListener('click', function () {
				this.select();
			});
		} else {
			// IE 8
			map_input.attachEvent('onclick', function () {
				map_input.select();
			});

			marker_input.attachEvent('onclick', function () {
				marker_input.select();
			});
		}

	};
})();
```
