| 1 |
(function () { |
| 2 |
|
| 3 |
window.WPLeafletMapPlugin = window.WPLeafletMapPlugin || []; |
| 4 |
window.WPLeafletMapPlugin.push( initAdminShortcodes ); |
| 5 |
|
| 6 |
function initAdminShortcodes () { |
| 7 |
var map_input = document.getElementById('map-shortcode'), |
| 8 |
marker_input = document.getElementById('marker-shortcode'), |
| 9 |
map_1 = window.WPLeafletMapPlugin.maps[0], |
| 10 |
marker_1 = window.WPLeafletMapPlugin.markers[0]; |
| 11 |
|
| 12 |
function update_marker () { |
| 13 |
var latlng = marker_1.getLatLng(); |
| 14 |
marker_input.value = '[leaflet-marker lat=' + |
| 15 |
latlng.lat + |
| 16 |
' lng=' + |
| 17 |
latlng.lng + |
| 18 |
']'; |
| 19 |
} |
| 20 |
|
| 21 |
function update_map () { |
| 22 |
var bounds = map_1.getBounds(); |
| 23 |
var latlng = bounds.getCenter(); |
| 24 |
map_input.value = '[leaflet-map lat=' + |
| 25 |
latlng.lat + |
| 26 |
' lng=' + |
| 27 |
latlng.lng + |
| 28 |
' zoom=' + |
| 29 |
map_1.getZoom() + |
| 30 |
']'; |
| 31 |
|
| 32 |
// update marker if outside of bounds |
| 33 |
if (!bounds.contains(marker_1.getLatLng())) { |
| 34 |
// move marker to center |
| 35 |
marker_1.setLatLng(latlng); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
marker_1.on('drag', update_marker); |
| 40 |
map_1.on('move', update_map); |
| 41 |
|
| 42 |
update_map(); |
| 43 |
update_marker(); |
| 44 |
|
| 45 |
if (map_input.addEventListener) { |
| 46 |
map_input.addEventListener('click', function () { |
| 47 |
this.select(); |
| 48 |
}); |
| 49 |
|
| 50 |
marker_input.addEventListener('click', function () { |
| 51 |
this.select(); |
| 52 |
}); |
| 53 |
} else { |
| 54 |
// IE 8 |
| 55 |
map_input.attachEvent('onclick', function () { |
| 56 |
map_input.select(); |
| 57 |
}); |
| 58 |
|
| 59 |
marker_input.attachEvent('onclick', function () { |
| 60 |
marker_input.select(); |
| 61 |
}); |
| 62 |
} |
| 63 |
|
| 64 |
}; |
| 65 |
})(); |