diff --git a/examples/mobile-jq.js b/examples/mobile-jq.js index 1f61582573..7e487cdfb6 100644 --- a/examples/mobile-jq.js +++ b/examples/mobile-jq.js @@ -3,101 +3,108 @@ window.location.replace(window.location.href.split("#")[0] + "#mappage"); var selectedFeature = null; -$(document).ready(function() { - - // fix height of content - function fixContentHeight() { - var footer = $("div[data-role='footer']:visible"), - content = $("div[data-role='content']:visible:visible"), - viewHeight = $(window).height(), - contentHeight = viewHeight - footer.outerHeight(); - - if ((content.outerHeight() + footer.outerHeight()) !== viewHeight) { - contentHeight -= (content.outerHeight() - content.height() + 1); - content.height(contentHeight); - } +// fix height of content +function fixContentHeight() { + var footer = $("div[data-role='footer']:visible"), + content = $("div[data-role='content']:visible:visible"), + viewHeight = $(window).height(), + contentHeight = viewHeight - footer.outerHeight(); - if (window.map && window.map instanceof OpenLayers.Map) { - map.updateSize(); - } else { - // initialize map - init(function(feature) { - selectedFeature = feature; - $.mobile.changePage("#popup", "pop"); - }); - initLayerList(); - } + if ((content.outerHeight() + footer.outerHeight()) !== viewHeight) { + contentHeight -= (content.outerHeight() - content.height() + 1); + content.height(contentHeight); } - $(window).bind("orientationchange resize pageshow", fixContentHeight); - document.body.onload = fixContentHeight; - // Map zoom - $("#plus").click(function(){ - map.zoomIn(); - }); - $("#minus").click(function(){ - map.zoomOut(); - }); - $("#locate").click(function(){ - var control = map.getControlsBy("id", "locate-control")[0]; - if (control.active) { - control.getCurrentLocation(); - } else { - control.activate(); - } - }); + if (window.map && window.map instanceof OpenLayers.Map) { + map.updateSize(); + } else { + // initialize map + init(function(feature) { + selectedFeature = feature; + $.mobile.changePage("#popup", "pop"); + }); + initLayerList(); + } +} + +// one-time initialisation of button handlers + +$("#plus").live('click', function(){ + map.zoomIn(); +}); + +$("#minus").live('click', function(){ + map.zoomOut(); +}); + +$("#locate").live('click',function(){ + var control = map.getControlsBy("id", "locate-control")[0]; + if (control.active) { + control.getCurrentLocation(); + } else { + control.activate(); + } +}); + +//fix the content height AFTER jQuery Mobile has rendered the map page +$('#mappage').live('pageshow',function (){ + fixContentHeight(); +}); - $('#popup').live('pageshow',function(event, ui){ - var li = ""; - for(var attr in selectedFeature.attributes){ - li += "