Merge b1b342a97e into 49d5cee91e
This commit is contained in:
commit
cecfda1cd0
|
|
@ -486,7 +486,8 @@ function Mouse(defaults) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var that = {}, // Public API methods
|
var that = {}, // Public API methods
|
||||||
conf = {}; // Configuration attributes
|
conf = {}, // Configuration attributes
|
||||||
|
mouseCaptured = false;
|
||||||
|
|
||||||
// Configuration attributes
|
// Configuration attributes
|
||||||
Util.conf_defaults(conf, that, defaults, [
|
Util.conf_defaults(conf, that, defaults, [
|
||||||
|
|
@ -499,7 +500,23 @@ Util.conf_defaults(conf, that, defaults, [
|
||||||
['touchButton', 'rw', 'int', 1, 'Button mask (1, 2, 4) for touch devices (0 means ignore clicks)']
|
['touchButton', 'rw', 'int', 1, 'Button mask (1, 2, 4) for touch devices (0 means ignore clicks)']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
function captureMouse() {
|
||||||
|
// capturing the mouse ensures we get the mouseup event
|
||||||
|
if (conf.target.setCapture) {
|
||||||
|
conf.target.setCapture();
|
||||||
|
}
|
||||||
|
|
||||||
|
// some browsers give us mouseup events regardless,
|
||||||
|
// so if we never captured the mouse, we can disregard the event
|
||||||
|
mouseCaptured = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function releaseMouse() {
|
||||||
|
if (conf.target.releaseCapture) {
|
||||||
|
conf.target.releaseCapture();
|
||||||
|
}
|
||||||
|
mouseCaptured = false;
|
||||||
|
}
|
||||||
//
|
//
|
||||||
// Private functions
|
// Private functions
|
||||||
//
|
//
|
||||||
|
|
@ -536,11 +553,17 @@ function onMouseButton(e, down) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function onMouseDown(e) {
|
function onMouseDown(e) {
|
||||||
|
captureMouse();
|
||||||
onMouseButton(e, 1);
|
onMouseButton(e, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onMouseUp(e) {
|
function onMouseUp(e) {
|
||||||
|
if (!mouseCaptured) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
onMouseButton(e, 0);
|
onMouseButton(e, 0);
|
||||||
|
releaseMouse();
|
||||||
}
|
}
|
||||||
|
|
||||||
function onMouseWheel(e) {
|
function onMouseWheel(e) {
|
||||||
|
|
@ -609,10 +632,12 @@ that.grab = function() {
|
||||||
|
|
||||||
if ('ontouchstart' in document.documentElement) {
|
if ('ontouchstart' in document.documentElement) {
|
||||||
Util.addEvent(c, 'touchstart', onMouseDown);
|
Util.addEvent(c, 'touchstart', onMouseDown);
|
||||||
|
Util.addEvent(window, 'touchend', onMouseUp);
|
||||||
Util.addEvent(c, 'touchend', onMouseUp);
|
Util.addEvent(c, 'touchend', onMouseUp);
|
||||||
Util.addEvent(c, 'touchmove', onMouseMove);
|
Util.addEvent(c, 'touchmove', onMouseMove);
|
||||||
} else {
|
} else {
|
||||||
Util.addEvent(c, 'mousedown', onMouseDown);
|
Util.addEvent(c, 'mousedown', onMouseDown);
|
||||||
|
Util.addEvent(window, 'mouseup', onMouseUp);
|
||||||
Util.addEvent(c, 'mouseup', onMouseUp);
|
Util.addEvent(c, 'mouseup', onMouseUp);
|
||||||
Util.addEvent(c, 'mousemove', onMouseMove);
|
Util.addEvent(c, 'mousemove', onMouseMove);
|
||||||
Util.addEvent(c, (Util.Engine.gecko) ? 'DOMMouseScroll' : 'mousewheel',
|
Util.addEvent(c, (Util.Engine.gecko) ? 'DOMMouseScroll' : 'mousewheel',
|
||||||
|
|
@ -632,10 +657,12 @@ that.ungrab = function() {
|
||||||
|
|
||||||
if ('ontouchstart' in document.documentElement) {
|
if ('ontouchstart' in document.documentElement) {
|
||||||
Util.removeEvent(c, 'touchstart', onMouseDown);
|
Util.removeEvent(c, 'touchstart', onMouseDown);
|
||||||
|
Util.removeEvent(window, 'touchend', onMouseUp);
|
||||||
Util.removeEvent(c, 'touchend', onMouseUp);
|
Util.removeEvent(c, 'touchend', onMouseUp);
|
||||||
Util.removeEvent(c, 'touchmove', onMouseMove);
|
Util.removeEvent(c, 'touchmove', onMouseMove);
|
||||||
} else {
|
} else {
|
||||||
Util.removeEvent(c, 'mousedown', onMouseDown);
|
Util.removeEvent(c, 'mousedown', onMouseDown);
|
||||||
|
Util.removeEvent(window, 'mouseup', onMouseUp);
|
||||||
Util.removeEvent(c, 'mouseup', onMouseUp);
|
Util.removeEvent(c, 'mouseup', onMouseUp);
|
||||||
Util.removeEvent(c, 'mousemove', onMouseMove);
|
Util.removeEvent(c, 'mousemove', onMouseMove);
|
||||||
Util.removeEvent(c, (Util.Engine.gecko) ? 'DOMMouseScroll' : 'mousewheel',
|
Util.removeEvent(c, (Util.Engine.gecko) ? 'DOMMouseScroll' : 'mousewheel',
|
||||||
|
|
|
||||||
|
|
@ -298,7 +298,9 @@ Util.getEventPosition = function (e, obj, scale) {
|
||||||
if (typeof scale === "undefined") {
|
if (typeof scale === "undefined") {
|
||||||
scale = 1;
|
scale = 1;
|
||||||
}
|
}
|
||||||
return {'x': (docX - pos.x) / scale, 'y': (docY - pos.y) / scale};
|
var x = Math.max(Math.min(docX - pos.x, obj.width-1), 0);
|
||||||
|
var y = Math.max(Math.min(docY - pos.y, obj.height-1), 0);
|
||||||
|
return {'x': x / scale, 'y': y / scale};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue