| | 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 | |
|---|