OpenLayers OpenLayers

Changeset 5523

Show
Ignore:
Timestamp:
12/19/07 22:02:54 (1 year ago)
Author:
tschaub
Message:

stop clicks on the point handler - this means no more clicks sneaking through while editing - if you wanted that behavior, speak up - r=crschmidt (closes #1020)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Handler/Point.js

    r5433 r5523  
    174174 
    175175    /** 
     176     * Method: click 
     177     * Handle clicks.  Clicks are stopped from propagating to other listeners 
     178     *     on map.events or other dom elements. 
     179     *  
     180     * Parameters: 
     181     * evt - {Event} The browser event 
     182     * 
     183     * Returns:  
     184     * {Boolean} Allow event propagation 
     185     */ 
     186    click: function(evt) { 
     187        OpenLayers.Event.stop(evt); 
     188        return false; 
     189    }, 
     190 
     191    /** 
    176192     * Method: dblclick 
    177      * Handle double clicks. 
     193     * Handle double-clicks.  Double-clicks are stopped from propagating to other 
     194     *     listeners on map.events or other dom elements. 
    178195     *  
    179196     * Parameters: 
  • trunk/openlayers/tests/Handler/test_Point.html

    r5085 r5523  
    4343             "deactivate returns true if the handler was active already"); 
    4444    } 
     45 
     46    function test_Handler_Point_events(t) { 
     47        t.plan(29); 
     48         
     49        var map = new OpenLayers.Map('map'); 
     50        var control = { 
     51            map: map 
     52        }; 
     53        var handler = new OpenLayers.Handler.Point(control); 
     54 
     55        // list below events that should be handled (events) and those 
     56        // that should not be handled (nonevents) by the handler 
     57        var events = ["click", "dblclick", "mousedown", "mouseup", "mousemove"]; 
     58        var nonevents = ["mouseout", "resize", "focus", "blur"]; 
     59        map.events.registerPriority = function(type, obj, func) { 
     60            var r = func(); 
     61            if(typeof r == "string") { 
     62                // this is one of the mock handler methods 
     63                t.eq(OpenLayers.Util.indexOf(nonevents, type), -1, 
     64                     "registered method is not one of the events " + 
     65                     "that should not be handled"); 
     66                t.ok(OpenLayers.Util.indexOf(events, type) > -1, 
     67                     "activate calls registerPriority with browser event: " + type); 
     68                t.eq(typeof func, "function", 
     69                     "activate calls registerPriority with a function"); 
     70                t.eq(func(), type, 
     71                     "activate calls registerPriority with the correct method"); 
     72                t.eq(obj["CLASS_NAME"], "OpenLayers.Handler.Point", 
     73                     "activate calls registerPriority with the handler"); 
     74            } 
     75        } 
     76         
     77        // set browser event like properties on the handler 
     78        for(var i=0; i<events.length; ++i) { 
     79            setMethod(events[i]); 
     80        } 
     81        function setMethod(key) { 
     82            handler[key] = function() {return key}; 
     83        } 
     84 
     85        var activated = handler.activate(); 
     86        handler.destroy(); 
     87 
     88        // test that click and dblclick are stopped 
     89        var handler = new OpenLayers.Handler.Point(control); 
     90        var oldStop = OpenLayers.Event.stop; 
     91        OpenLayers.Event.stop = function(evt) { 
     92            t.ok(evt.type == "click" || evt.type == "dblclick", 
     93                 evt.type + " stopped"); 
     94        } 
     95        t.eq(handler.click({type: "click"}), false, "click returns false"); 
     96        t.eq(handler.dblclick({type: "dblclick"}), false, "dblclick returns false"); 
     97        OpenLayers.Event.stop = oldStop; 
     98 
     99    } 
     100 
    45101 
    46102    function test_Handler_Point_deactivation(t) {