mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-22 13:16:10 +03:00
f235d7a642
since we are about to create a module for testing utility functions.
56 lines
1.6 KiB
JavaScript
56 lines
1.6 KiB
JavaScript
(function() {
|
|
|
|
// ----------
|
|
window.Util = {
|
|
// ----------
|
|
simulateViewerClick: function(viewer, widthFactor, heightFactor) {
|
|
if (widthFactor === undefined) {
|
|
widthFactor = 0.5;
|
|
}
|
|
|
|
if (heightFactor === undefined) {
|
|
heightFactor = 0.5;
|
|
}
|
|
|
|
widthFactor = Math.min(1, Math.max(0, widthFactor));
|
|
heightFactor = Math.min(1, Math.max(0, heightFactor));
|
|
|
|
var $canvas = $(viewer.element).find('.openseadragon-canvas').not('.navigator .openseadragon-canvas');
|
|
var offset = $canvas.offset();
|
|
var event = {
|
|
clientX: offset.left + Math.floor($canvas.width() * widthFactor),
|
|
clientY: offset.top + Math.floor($canvas.height() * heightFactor)
|
|
};
|
|
|
|
$canvas
|
|
.simulate('mouseover', event)
|
|
.simulate('mousedown', event)
|
|
.simulate('mouseup', event);
|
|
},
|
|
|
|
// ----------
|
|
timeWatcher: function(time) {
|
|
time = time || 2000;
|
|
var finished = false;
|
|
|
|
setTimeout(function() {
|
|
if (!finished) {
|
|
finished = true;
|
|
ok(false, 'finishes in ' + time + 'ms');
|
|
start();
|
|
}
|
|
}, time);
|
|
|
|
return {
|
|
done: function() {
|
|
if (!finished) {
|
|
finished = true;
|
|
start();
|
|
}
|
|
}
|
|
};
|
|
}
|
|
};
|
|
|
|
})();
|