Dragging and dropping a marker on a Google Map inside a modal JQuery dialog isn't working properly using JQuery 1.4.3 and JQuery-UI 1.8.5.
The following snippet is reproducing the issue in Chrome 6.0 and Firefox 3.6.10 (but not Opera 10.63 which surprisingly doesn't have the problem), and this was working before upgrading JQuery (from 1.3.x and JQuery-UI 1.7.x as far as I can remember.)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script language="javascript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js"></script>
<script language="javascript" type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAA7wvJIKWNmIHy1Zz-OBol4hRU04i6YYXAaKMufrGA2zKwYVdFjhQttL37dNm-ct8ZuquPxt-MCn7PIw"></script>
<style type="text/css"> .ui-dialog { border:8px solid #ccc; } .ui-dialog-titlebar { border-bottom: 2px solid #ccc; padding: 4px; } .ui-dialog-titlebar a { display: none; } </style>
</head>
<body onunload="GUnload();">
<a href="#" class="open modal">Open modal</a>
<a href="#" class="open">Open non-modal</a>
<div id="popup" style="display:none;text-align:left;padding: 4px;">
<div id="map" class="map" style="width:400px;height:300px;"></div>
</div>
<script type="text/javascript">
$(function(){
$(".open").click(function(){
$("#popup").dialog({ modal:$(this).hasClass("modal"), // changing to false works ok
title:"Drag marker", width:450, position: "center",
buttons: { "Cancel": function(){ $(this).dialog("close"); } },
open: function() {
var map = new GMap2(document.getElementById("map"));
map.setCenter( new GLatLng(-37.851414,145.052686), 15);
map.addOverlay(new GMarker(new GPoint(145.052686, -37.851414), {draggable:true}));
}
});
}).eq(0).click();
});
</script>
</body>
</html>
Note, the styling is minimal as I couldn't find a quick CDN link to JQuery-UI CSS/image files.
Using the above, when opening the dialog with modal:true
, the marker (and sometimes the map) will get "stuck" to the mouse, i.e. the mouseup event isn't caught. Clicking/moving quickly will sometimes drop it again, but usually you have to press escape to close the dialog.
Opening with modal:false
allows the marker to be dragged normally.
Is there any way to fix this without having to make the dialog non-modal?
I found this, http://forum.jquery.com/topic/modal-dialog-and-google-maps, which seems to be the same problem, but I can't figure out how to apply the answer suggested. I've tried adding z-index:1000
to the div.map
but it didn't help.