| 30 | | var callbacks = {foo: "bar"}; |
|---|
| 31 | | var handler = new OpenLayers.Handler(control, callbacks); |
|---|
| | 30 | var events = ["mouseover", "mouseout", "mousedown", |
|---|
| | 31 | "mouseup", "mousemove", "click", |
|---|
| | 32 | "dblclick", "resize", "focus", "blur"]; |
|---|
| | 33 | |
|---|
| | 34 | var handler = new OpenLayers.Handler(control); |
|---|
| | 41 | map.events.registerPriority = function(type, obj, func) { |
|---|
| | 42 | t.ok(OpenLayers.Util.indexOf(events, type) > -1, |
|---|
| | 43 | "activate calls registerPriority with browser event: " + type); |
|---|
| | 44 | t.eq(typeof func, "function", |
|---|
| | 45 | "activate calls registerPriority with a function"); |
|---|
| | 46 | t.eq(func(), type, |
|---|
| | 47 | "activate calls registerPriority with the correct method"); |
|---|
| | 48 | t.eq(obj["CLASS_NAME"], "OpenLayers.Handler", |
|---|
| | 49 | "activate calls registerPriority with the handler"); |
|---|
| | 50 | } |
|---|
| | 51 | |
|---|
| | 52 | // set browser event like properties on the handler |
|---|
| | 53 | for(var i=0; i<events.length; ++i) { |
|---|
| | 54 | setMethod(events[i]); |
|---|
| | 55 | } |
|---|
| | 56 | function setMethod(key) { |
|---|
| | 57 | handler[key] = function() {return key}; |
|---|
| | 58 | } |
|---|
| | 59 | activated = handler.activate(); |
|---|
| | 60 | t.ok(activated, |
|---|
| | 61 | "activated returns true if the handler is not already active"); |
|---|
| | 65 | function test_Handler_deactivate(t) { |
|---|
| | 66 | t.plan(42); |
|---|
| | 67 | var map = new OpenLayers.Map('map'); |
|---|
| | 68 | var control = new OpenLayers.Control(); |
|---|
| | 69 | map.addControl(control); |
|---|
| | 70 | |
|---|
| | 71 | var events = ["mouseover", "mouseout", "mousedown", |
|---|
| | 72 | "mouseup", "mousemove", "click", |
|---|
| | 73 | "dblclick", "resize", "focus", "blur"]; |
|---|
| | 74 | |
|---|
| | 75 | var handler = new OpenLayers.Handler(control); |
|---|
| | 76 | handler.active = false; |
|---|
| | 77 | var deactivated = handler.deactivate(); |
|---|
| | 78 | t.ok(!deactivated, |
|---|
| | 79 | "deactivate returns false if the handler is already deactive"); |
|---|
| | 80 | |
|---|
| | 81 | handler.activate(); |
|---|
| | 82 | map.events.unregister = function(type, obj, func) { |
|---|
| | 83 | t.ok(OpenLayers.Util.indexOf(events, type) > -1, |
|---|
| | 84 | "deactivate calls unregister with browser event: " + type); |
|---|
| | 85 | t.eq(typeof func, "function", |
|---|
| | 86 | "activate calls unregister with a function"); |
|---|
| | 87 | t.eq(func(), type, |
|---|
| | 88 | "activate calls unregister with the correct method"); |
|---|
| | 89 | t.eq(obj["CLASS_NAME"], "OpenLayers.Handler", |
|---|
| | 90 | "activate calls unregister with the handler"); |
|---|
| | 91 | } |
|---|
| | 92 | |
|---|
| | 93 | // set browser event like properties on the handler |
|---|
| | 94 | for(var i=0; i<events.length; ++i) { |
|---|
| | 95 | setMethod(events[i]); |
|---|
| | 96 | } |
|---|
| | 97 | function setMethod(key) { |
|---|
| | 98 | handler[key] = function() {return key}; |
|---|
| | 99 | } |
|---|
| | 100 | deactivated = handler.deactivate(); |
|---|
| | 101 | t.ok(deactivated, |
|---|
| | 102 | "deactivated returns true if the handler is already active"); |
|---|
| | 103 | |
|---|
| | 104 | } |
|---|
| | 105 | |
|---|