Only initialize the various elements if they are in the dom.

This commit is contained in:
Tim Schumacher 2014-07-10 11:48:00 +02:00
parent d64f78dc5e
commit 509a4f501b

View file

@ -9,9 +9,15 @@ function addGeoCoordinates(ev) {
} }
var map = null; var map = null;
$(document).ready(function () { $(document).ready(function () {
if ($('.icon.link').length > 0) {
$('.icon.link').popup(); $('.icon.link').popup();
jQuery('input[type=datetime]').datetimepicker({lang: 'de', format: 'Y-m-d H:i'}); }
if (jQuery('input[type=datetime]').length > 0) {
jQuery('input[type=datetime]').datetimepicker({lang: 'de', format: 'Y-m-d H:i'});
}
if (jQuery('#map').length == 1) {
$('.add_geo').click(addGeoCoordinates); $('.add_geo').click(addGeoCoordinates);
map = L.map('map'); map = L.map('map');
@ -53,8 +59,8 @@ $(document).ready(function () {
var lat = parseFloat($('input[name=location_lat]').val()); var lat = parseFloat($('input[name=location_lat]').val());
var lon = parseFloat($('input[name=location_lon]').val()); var lon = parseFloat($('input[name=location_lon]').val());
if ((lat > 0) && (lon > 0)) { if ((lat > 0) && (lon > 0)) {
map.setView([lat,lon],16); map.setView([lat, lon], 16);
var latlng = new L.LatLng(lat,lon); var latlng = new L.LatLng(lat, lon);
marker.setLatLng(latlng); marker.setLatLng(latlng);
marker.addTo(map); marker.addTo(map);
} else { } else {
@ -62,4 +68,5 @@ $(document).ready(function () {
} }
} }
}).modal('attach events', '.add_geo', 'show'); }).modal('attach events', '.add_geo', 'show');
}
}); });