[OpenLayers-Commits] r12183 - in trunk/openlayers: lib/OpenLayers tests

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Mon Jul 25 04:46:06 EDT 2011


Author: ahocevar
Date: 2011-07-25 01:46:04 -0700 (Mon, 25 Jul 2011)
New Revision: 12183

Modified:
   trunk/openlayers/lib/OpenLayers/Popup.js
   trunk/openlayers/tests/Popup.html
Log:
Popups can now be cloused on touch devices. p=jorix (closes #3403)

Modified: trunk/openlayers/lib/OpenLayers/Popup.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Popup.js	2011-07-23 21:24:31 UTC (rev 12182)
+++ trunk/openlayers/lib/OpenLayers/Popup.js	2011-07-25 08:46:04 UTC (rev 12183)
@@ -888,6 +888,8 @@
             this.hide();
             OpenLayers.Event.stop(e);
         };
+        OpenLayers.Event.observe(this.closeDiv, "touchend", 
+                OpenLayers.Function.bindAsEventListener(closePopup, this));
         OpenLayers.Event.observe(this.closeDiv, "click", 
                 OpenLayers.Function.bindAsEventListener(closePopup, this));
     },
@@ -944,7 +946,8 @@
      *   Because the user might select the zoom-rectangle option and
      *    then drag it over a popup, we need a safe way to allow the
      *    mousemove and mouseup events to pass through the popup when
-     *    they are initiated from outside.
+     *    they are initiated from outside. The same procedure is needed for
+     *    touchmove and touchend events.
      * 
      *   Otherwise, we want to essentially kill the event propagation
      *    for all other events, though we have to do so carefully, 
@@ -954,6 +957,22 @@
      registerEvents:function() {
         this.events = new OpenLayers.Events(this, this.div, null, true);
 
+        var touchStarted = false;
+        function onTouchstart(evt) {
+            touchStarted = true;
+            OpenLayers.Event.stop(evt, true);
+        }
+        function onTouchmove(evt) {
+            if (touchStarted === true) {
+                OpenLayers.Event.stop(evt, true);
+            }
+        }
+        function onTouchend(evt) {
+            if (touchStarted === true) {
+                touchStarted = false;
+                OpenLayers.Event.stop(evt, true);
+            }
+        }
         this.events.on({
             "mousedown": this.onmousedown,
             "mousemove": this.onmousemove,
@@ -961,6 +980,9 @@
             "click": this.onclick,
             "mouseout": this.onmouseout,
             "dblclick": this.ondblclick,
+            "touchstart": onTouchstart,
+            "touchmove": onTouchmove,
+            "touchsend": onTouchend,
             scope: this
         });
         

Modified: trunk/openlayers/tests/Popup.html
===================================================================
--- trunk/openlayers/tests/Popup.html	2011-07-23 21:24:31 UTC (rev 12182)
+++ trunk/openlayers/tests/Popup.html	2011-07-25 08:46:04 UTC (rev 12183)
@@ -29,7 +29,7 @@
     }
     
     function test_Popup_constructor (t) {
-        t.plan( 8 );
+        t.plan(9);
 
         var id = "chicken";
         var w = 500;
@@ -63,11 +63,17 @@
         for (var i = 0; i < OpenLayers.Event.observers[cacheID].length; i++) {
             var observer = OpenLayers.Event.observers[cacheID][i];
             if (observer.element == closeImgDiv) {
-                t.ok(true, "An event was registered for the close box element");
-                t.eq(observer.name, "click", "A click event was registered for the close box element");
-                //call the registered observer to make sure it's the right one
-                observer.observer();
-                break;
+                if (observer.name == "click") {
+                    t.ok(true, "A click event was registered for the close box element");
+                    //call the registered observer to make sure it's the right one
+                    observer.observer();
+                } else if (observer.name == "touchend") {
+                    t.ok(true, "A touchend event was registered for the close box element");
+                    //call the registered observer to make sure it's the right one
+                    observer.observer();
+                } else {
+                    t.fail("A " + observer.name + " event was registered for the close box element");
+                }
             }
         }
     }



More information about the Commits mailing list