[OpenLayers-Commits] r11334 - sandbox/camptocamp/mobile/openlayers/examples

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Wed Feb 23 10:32:19 EST 2011


Author: pgiraud
Date: 2011-02-23 07:32:19 -0800 (Wed, 23 Feb 2011)
New Revision: 11334

Modified:
   sandbox/camptocamp/mobile/openlayers/examples/mobile-jq.js
Log:
I need to listen 'pageshow' event to ensure that I can listen on 'change' event on my search input

Modified: sandbox/camptocamp/mobile/openlayers/examples/mobile-jq.js
===================================================================
--- sandbox/camptocamp/mobile/openlayers/examples/mobile-jq.js	2011-02-23 15:23:46 UTC (rev 11333)
+++ sandbox/camptocamp/mobile/openlayers/examples/mobile-jq.js	2011-02-23 15:32:19 UTC (rev 11334)
@@ -40,37 +40,41 @@
             control.activate();
         }
     });
-    $('#query').bind('change', function(e){
-        $.mobile.pageLoading();
+    $('#searchpage').live('pageshow',function(event, ui){
+        $('#query').bind('change', function(e){
+            $.mobile.pageLoading();
 
-        // Prevent form send
-        e.preventDefault();
+            // Prevent form send
+            e.preventDefault();
 
-        $('#search_results').empty();
+            $('#search_results').empty();
 
-        var searchUrl = 'http://ws.geonames.org/searchJSON?featureClass=P&style=full&&maxRows=10';
-        searchUrl += '&name_startsWith=' + $('#query')[0].value;
-        $.getJSON(searchUrl, function(data) {
-            $.each(data.geonames, function() {
-                var place = this;
-                $('<li>')
-                    .hide()
-                    .append($('<h2 />', {
-                        text: place.name
-                    }))
-                    .append($('<p />', {
-                        html: '<b>' + place.countryName + '</b> ' + place.fcodeName
-                    }))
-                    .appendTo('#search_results')
-                    .click(function() {
-                        $.mobile.changePage('mappage');
-                        var lonlat = new OpenLayers.LonLat(place.lng, place.lat);
-                        map.setCenter(lonlat.transform(gg, sm), 10);
-                    })
-                    .show();
+            var searchUrl = 'http://ws.geonames.org/searchJSON?featureClass=P&maxRows=10';
+            searchUrl += '&name_startsWith=' + $('#query')[0].value;
+            $.getJSON(searchUrl, function(data) {
+                $.each(data.geonames, function() {
+                    var place = this;
+                    $('<li>')
+                        .hide()
+                        .append($('<h2 />', {
+                            text: place.name
+                        }))
+                        .append($('<p />', {
+                            html: '<b>' + place.countryName + '</b> ' + place.fcodeName
+                        }))
+                        .appendTo('#search_results')
+                        .click(function() {
+                            $.mobile.changePage('mappage');
+                            var lonlat = new OpenLayers.LonLat(place.lng, place.lat);
+                            map.setCenter(lonlat.transform(gg, sm), 10);
+                        })
+                        .show();
+                });
+                $('#search_results').listview('refresh');
+                $.mobile.pageLoading(true);
             });
-            $('#search_results').listview('refresh');
-            $.mobile.pageLoading(true);
         });
+        // only listen to the first event triggered
+        $('#searchpage').die('pageshow', arguments.callee);
     });
 });



More information about the Commits mailing list