| 1 |
<html> |
|---|
| 2 |
<head> |
|---|
| 3 |
<script src="../../lib/OpenLayers.js"></script> |
|---|
| 4 |
<script type="text/javascript"> |
|---|
| 5 |
function test_Handler_MouseWheel_constructor(t) { |
|---|
| 6 |
t.plan(3); |
|---|
| 7 |
var control = new OpenLayers.Control(); |
|---|
| 8 |
control.id = Math.random(); |
|---|
| 9 |
var callbacks = {foo: "bar"}; |
|---|
| 10 |
var options = {bar: "foo"}; |
|---|
| 11 |
|
|---|
| 12 |
var oldInit = OpenLayers.Handler.prototype.initialize; |
|---|
| 13 |
|
|---|
| 14 |
OpenLayers.Handler.prototype.initialize = function(con, call, opt) { |
|---|
| 15 |
t.eq(con.id, control.id, |
|---|
| 16 |
"constructor calls parent with the correct control"); |
|---|
| 17 |
t.eq(call, callbacks, |
|---|
| 18 |
"constructor calls parent with the correct callbacks"); |
|---|
| 19 |
t.eq(opt, options, |
|---|
| 20 |
"constructor calls parent with the correct options"); |
|---|
| 21 |
} |
|---|
| 22 |
var handler = new OpenLayers.Handler.MouseWheel(control, callbacks, options); |
|---|
| 23 |
|
|---|
| 24 |
OpenLayers.Handler.prototype.initialize = oldInit; |
|---|
| 25 |
} |
|---|
| 26 |
|
|---|
| 27 |
function test_Handler_MouseWheel_activate(t) { |
|---|
| 28 |
t.plan(2); |
|---|
| 29 |
var map = new OpenLayers.Map('map'); |
|---|
| 30 |
var control = new OpenLayers.Control(); |
|---|
| 31 |
map.addControl(control); |
|---|
| 32 |
var handler = new OpenLayers.Handler.MouseWheel(control); |
|---|
| 33 |
handler.active = true; |
|---|
| 34 |
var activated = handler.activate(); |
|---|
| 35 |
t.ok(!activated, |
|---|
| 36 |
"activate returns false if the handler was already active"); |
|---|
| 37 |
handler.active = false; |
|---|
| 38 |
activated = handler.activate(); |
|---|
| 39 |
t.ok(activated, |
|---|
| 40 |
"activate returns true if the handler was not already active"); |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
function test_Handler_MouseWheel_mousePosition(t) { |
|---|
| 44 |
t.plan(1); |
|---|
| 45 |
var map = new OpenLayers.Map('map'); |
|---|
| 46 |
map.addLayer(new OpenLayers.Layer.WMS("","",{})); |
|---|
| 47 |
map.zoomToMaxExtent(); |
|---|
| 48 |
var control = new OpenLayers.Control(); |
|---|
| 49 |
map.addControl(control); |
|---|
| 50 |
var pass = false; |
|---|
| 51 |
var handler = new OpenLayers.Handler.MouseWheel(control, {'up': |
|---|
| 52 |
function (evt) { |
|---|
| 53 |
if (evt.xy) { pass = true; } |
|---|
| 54 |
} |
|---|
| 55 |
}); |
|---|
| 56 |
handler.setMap(map); |
|---|
| 57 |
handler.activate(); |
|---|
| 58 |
var delta = 120; |
|---|
| 59 |
if (window.opera && window.opera.version() < 9.2) delta = -delta; |
|---|
| 60 |
handler.onWheelEvent({'target':map.layers[0].div, wheelDelta: delta}); |
|---|
| 61 |
t.ok(pass, "evt.xy was set even without a mouse move"); |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
function test_Handler_MouseWheel_events(t) { |
|---|
| 65 |
t.plan(5); |
|---|
| 66 |
|
|---|
| 67 |
var map = new OpenLayers.Map('map'); |
|---|
| 68 |
var control = new OpenLayers.Control(); |
|---|
| 69 |
map.addControl(control); |
|---|
| 70 |
var handler = new OpenLayers.Handler.MouseWheel(control); |
|---|
| 71 |
|
|---|
| 72 |
// list below events that should be handled (events) and those |
|---|
| 73 |
// that should not be handled (nonevents) by the handler |
|---|
| 74 |
var events = ["mousemove"]; |
|---|
| 75 |
var nonevents = ["dblclick", "resize", "focus", "blur"]; |
|---|
| 76 |
map.events.registerPriority = function(type, obj, func) { |
|---|
| 77 |
var r = func(); |
|---|
| 78 |
if(typeof r == "string") { |
|---|
| 79 |
t.eq(OpenLayers.Util.indexOf(nonevents, type), -1, |
|---|
| 80 |
"registered method is not one of the events " + |
|---|
| 81 |
"that should not be handled"); |
|---|
| 82 |
t.ok(OpenLayers.Util.indexOf(events, type) > -1, |
|---|
| 83 |
"activate calls registerPriority with browser event: " + type); |
|---|
| 84 |
t.eq(typeof func, "function", |
|---|
| 85 |
"activate calls registerPriority with a function"); |
|---|
| 86 |
t.eq(func(), type, |
|---|
| 87 |
"activate calls registerPriority with the correct method"); |
|---|
| 88 |
t.eq(obj["CLASS_NAME"], "OpenLayers.Handler.MouseWheel", |
|---|
| 89 |
"activate calls registerPriority with the handler"); |
|---|
| 90 |
} |
|---|
| 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 |
|
|---|
| 101 |
var activated = handler.activate(); |
|---|
| 102 |
|
|---|
| 103 |
} |
|---|
| 104 |
|
|---|
| 105 |
function test_Handler_MouseWheel_deactivate(t) { |
|---|
| 106 |
t.plan(2); |
|---|
| 107 |
var map = new OpenLayers.Map('map'); |
|---|
| 108 |
var control = new OpenLayers.Control(); |
|---|
| 109 |
map.addControl(control); |
|---|
| 110 |
var handler = new OpenLayers.Handler.MouseWheel(control); |
|---|
| 111 |
handler.active = false; |
|---|
| 112 |
var deactivated = handler.deactivate(); |
|---|
| 113 |
t.ok(!deactivated, |
|---|
| 114 |
"deactivate returns false if the handler was not already active"); |
|---|
| 115 |
handler.active = true; |
|---|
| 116 |
deactivated = handler.deactivate(); |
|---|
| 117 |
t.ok(deactivated, |
|---|
| 118 |
"deactivate returns true if the handler was active already"); |
|---|
| 119 |
} |
|---|
| 120 |
function test_handler_MouseWheel_destroy(t) { |
|---|
| 121 |
t.plan(1); |
|---|
| 122 |
var control = new OpenLayers.Control(); |
|---|
| 123 |
var handler = new OpenLayers.Handler.MouseWheel(control); |
|---|
| 124 |
handler.deactivate = function() { |
|---|
| 125 |
t.ok(true, "Deactivate called one time."); |
|---|
| 126 |
} |
|---|
| 127 |
handler.destroy(); |
|---|
| 128 |
} |
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
</script> |
|---|
| 132 |
</head> |
|---|
| 133 |
<body> |
|---|
| 134 |
<div id="map" style="width: 300px; height: 150px;"/> |
|---|
| 135 |
</body> |
|---|
| 136 |
</html> |
|---|