3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
5 function test_Handler_MouseWheel_constructor(t) {
7 var control = new OpenLayers.Control();
8 control.id = Math.random();
9 var callbacks = {foo: "bar"};
10 var options = {bar: "foo"};
12 var oldInit = OpenLayers.Handler.prototype.initialize;
14 OpenLayers.Handler.prototype.initialize = function(con, call, opt) {
15 t.eq(con.id, control.id,
16 "constructor calls parent with the correct control");
18 "constructor calls parent with the correct callbacks");
20 "constructor calls parent with the correct options");
22 var handler = new OpenLayers.Handler.MouseWheel(control, callbacks, options);
24 OpenLayers.Handler.prototype.initialize = oldInit;
27 function test_Handler_MouseWheel_activate(t) {
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();
36 "activate returns false if the handler was already active");
37 handler.active = false;
38 activated = handler.activate();
40 "activate returns true if the handler was not already active");
43 function test_Handler_MouseWheel_mousePosition(t) {
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);
51 var handler = new OpenLayers.Handler.MouseWheel(control, {'up':
53 if (evt.xy) { pass = true; }
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");
64 function test_Handler_MouseWheel_events(t) {
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);
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) {
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");
87 "activate calls registerPriority with the correct method");
88 t.eq(obj["CLASS_NAME"], "OpenLayers.Handler.MouseWheel",
89 "activate calls registerPriority with the handler");
93 // set browser event like properties on the handler
94 for(var i=0; i<events.length; ++i) {
97 function setMethod(key) {
98 handler[key] = function() {return key};
101 var activated = handler.activate();
105 function test_Handler_MouseWheel_deactivate(t) {
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();
114 "deactivate returns false if the handler was not already active");
115 handler.active = true;
116 deactivated = handler.deactivate();
118 "deactivate returns true if the handler was active already");
120 function test_handler_MouseWheel_destroy(t) {
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.");
134 <div id="map" style="width: 300px; height: 150px;"/>