git-svn-id: http://svn.openlayers.org/trunk/openlayers@3869 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
169 lines
6.0 KiB
HTML
169 lines
6.0 KiB
HTML
<html>
|
|
<head>
|
|
<script src="../../lib/OpenLayers.js"></script>
|
|
<script type="text/javascript"><!--
|
|
function test_Handler_Drag_constructor(t) {
|
|
t.plan(3);
|
|
var control = new OpenLayers.Control();
|
|
control.id = Math.random();
|
|
var callbacks = {foo: "bar"};
|
|
var options = {bar: "foo"};
|
|
|
|
var oldInit = OpenLayers.Handler.prototype.initialize;
|
|
|
|
OpenLayers.Handler.prototype.initialize = function(con, call, opt) {
|
|
t.eq(con.id, control.id,
|
|
"constructor calls parent with the correct control");
|
|
t.eq(call, callbacks,
|
|
"constructor calls parent with the correct callbacks");
|
|
t.eq(opt, options,
|
|
"constructor calls parent with the correct options");
|
|
}
|
|
var handler = new OpenLayers.Handler.Drag(control, callbacks, options);
|
|
|
|
OpenLayers.Handler.prototype.initialize = oldInit;
|
|
}
|
|
|
|
function test_Handler_Drag_activate(t) {
|
|
t.plan(3);
|
|
var map = new OpenLayers.Map('map');
|
|
var control = new OpenLayers.Control();
|
|
map.addControl(control);
|
|
var handler = new OpenLayers.Handler.Drag(control);
|
|
handler.active = true;
|
|
var activated = handler.activate();
|
|
t.ok(!activated,
|
|
"activate returns false if the handler was already active");
|
|
handler.active = false;
|
|
handler.dragging = true;
|
|
activated = handler.activate();
|
|
t.ok(activated,
|
|
"activate returns true if the handler was not already active");
|
|
t.ok(!handler.dragging,
|
|
"activate sets dragging to false");
|
|
|
|
}
|
|
|
|
function test_Handler_Drag_events(t) {
|
|
t.plan(25);
|
|
|
|
var map = new OpenLayers.Map('map');
|
|
var control = new OpenLayers.Control();
|
|
map.addControl(control);
|
|
var handler = new OpenLayers.Handler.Drag(control);
|
|
|
|
// list below events that should be handled (events) and those
|
|
// that should not be handled (nonevents) by the handler
|
|
var events = ["mousedown", "mouseup", "mousemove", "mouseout", "click"];
|
|
var nonevents = ["dblclick", "resize", "focus", "blur"];
|
|
map.events.registerPriority = function(type, obj, func) {
|
|
t.eq(OpenLayers.Util.indexOf(nonevents, type), -1,
|
|
"registered method is not one of the events " +
|
|
"that should not be handled");
|
|
t.ok(OpenLayers.Util.indexOf(events, type) > -1,
|
|
"activate calls registerPriority with browser event: " + type);
|
|
t.eq(typeof func, "function",
|
|
"activate calls registerPriority with a function");
|
|
t.eq(func(), type,
|
|
"activate calls registerPriority with the correct method");
|
|
t.eq(obj["CLASS_NAME"], "OpenLayers.Handler.Drag",
|
|
"activate calls registerPriority with the handler");
|
|
}
|
|
|
|
// set browser event like properties on the handler
|
|
for(var i=0; i<events.length; ++i) {
|
|
setMethod(events[i]);
|
|
}
|
|
function setMethod(key) {
|
|
handler[key] = function() {return key};
|
|
}
|
|
|
|
var activated = handler.activate();
|
|
|
|
}
|
|
|
|
function test_Handler_Drag_callbacks(t) {
|
|
t.plan(3);
|
|
|
|
var map = new OpenLayers.Map('map', {controls: []});
|
|
|
|
var control = new OpenLayers.Control();
|
|
map.addControl(control);
|
|
|
|
// set callback methods
|
|
var events = ["down", "move", "up", "out", "done"];
|
|
var xys = {};
|
|
var callbacks = {};
|
|
for(var i=0; i<events.length; ++i) {
|
|
var px = new OpenLayers.Pixel(Math.random(), Math.random());
|
|
xys[events[i]] = px;
|
|
setCallback(events[i]);
|
|
}
|
|
function setCallback(key) {
|
|
callbacks[key] = function(evtxy) {
|
|
t.ok(evtxy.x == xys[key].x &&
|
|
evtxy.y == xys[key].y,
|
|
key + " callback called with the proper evt.xy");
|
|
}
|
|
}
|
|
|
|
var handler = new OpenLayers.Handler.Drag(control, callbacks);
|
|
handler.activate();
|
|
|
|
// test mousedown
|
|
var oldIsLeftClick = OpenLayers.Event.isLeftClick;
|
|
var oldStop = OpenLayers.Event.stop;
|
|
var testEvt = {
|
|
xy: xys.down
|
|
}
|
|
handler.checkModifiers = function(evt) {
|
|
t.ok(evt.xy.x == testEvt.xy.x &&
|
|
evt.xy.y == testEvt.xy.y,
|
|
"checkModifiers called with the proper event");
|
|
return true;
|
|
}
|
|
OpenLayers.Event.isLeftClick = function(evt) {
|
|
t.ok(evt.xy.x == testEvt.xy.x &&
|
|
evt.xy.y == testEvt.xy.y,
|
|
"isLeftClick called with the proper event");
|
|
return true;
|
|
}
|
|
//OpenLayers.Event.stop = function(evt) {
|
|
// t.ok(evt.xy.x == testEvt.xy.x &&
|
|
// evt.xy.y == testEvt.xy.y,
|
|
// "mousedown event is stopped");
|
|
//}
|
|
map.events.triggerEvent("mousedown", testEvt);
|
|
|
|
OpenLayers.Event.isLeftClick = oldIsLeftClick;
|
|
OpenLayers.Event.stop = oldStop;
|
|
|
|
}
|
|
|
|
function test_Handler_Drag_deactivate(t) {
|
|
t.plan(3);
|
|
var map = new OpenLayers.Map('map');
|
|
var control = new OpenLayers.Control();
|
|
map.addControl(control);
|
|
var handler = new OpenLayers.Handler.Drag(control);
|
|
handler.active = false;
|
|
var deactivated = handler.deactivate();
|
|
t.ok(!deactivated,
|
|
"deactivate returns false if the handler was not already active");
|
|
handler.active = true;
|
|
handler.dragging = true;
|
|
deactivated = handler.deactivate();
|
|
t.ok(deactivated,
|
|
"deactivate returns true if the handler was active already");
|
|
t.ok(!handler.dragging,
|
|
"deactivate sets dragging to false");
|
|
}
|
|
|
|
// -->
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div id="map" style="width: 300px; height: 150px;"/>
|
|
</body>
|
|
</html>
|