Преглед на файлове

Fixed mouse event test for element bounds. Attempting to add 'preventDefault' events.

dev-tmpl
Bryan Miller преди 6 години
родител
ревизия
b86d5b939b
променени са 1 файла, в които са добавени 22 реда и са изтрити 5 реда
  1. +22
    -5
      app/js/ui/Input.js

+ 22
- 5
app/js/ui/Input.js Целия файл

var rect = this.__mouseTarget.getBoundingClientRect(); var rect = this.__mouseTarget.getBoundingClientRect();
pos.x -= rect.left; pos.x -= rect.left;
pos.y -= rect.top; pos.y -= rect.top;
pos.inbounds = (pos.x >= 0 && pos.x < rect.right && pos.y >= 0 && pos.y < rect.bottom);
pos.inbounds = (pos.x >= 0 && pos.x < rect.width && pos.y >= 0 && pos.y < rect.height);
} }
pos.x = Math.floor(pos.x);
pos.y = Math.floor(pos.y);
return pos; return pos;
}).bind(this); }).bind(this);


this.__mousePosition = pos; this.__mousePosition = pos;
this.__mouseLastButton = button; this.__mouseLastButton = button;
this.__mouseLastAction = "mouseup"; this.__mouseLastAction = "mouseup";
this.__emitter.emit("mouseup", {
var data = {
source: this, source: this,
lastX: pos.lastX, lastX: pos.lastX,
lastY: pos.lastY, lastY: pos.lastY,
y: pos.y, y: pos.y,
button: button, button: button,
action: "mouseup" action: "mouseup"
});
}
this.__emitter.emit("mouseup", data);
if (diff <= MOUSECLICK_DELAY && this.__mouseButtons.length <= 0){
this.__emitter.emit("mouseclick", data);
}
} }
}).bind(this); }).bind(this);


// TODO: Finish me! // TODO: Finish me!
}).bind(this); }).bind(this);


// This event is purely for preventing Default behaviors on mouse events we're not using.
var handle_mouseprevdef = (function(e){
var pos = mousePosition(e);
if (this.__preventDefaults && pos.inbounds)
e.preventDefault();
}).bind(this);

return (function(enable){ return (function(enable){
enable = (enable !== false); enable = (enable !== false);
if (enable){ if (enable){
window.addEventListener("mousedown", handle_mousedown); window.addEventListener("mousedown", handle_mousedown);
window.addEventListener("mouseup", handle_mouseup); window.addEventListener("mouseup", handle_mouseup);
window.addEventListener("mousewheel", handle_mousewheel); window.addEventListener("mousewheel", handle_mousewheel);
window.addEventListener("click", handle_mouseprevdef);
window.addEventListener("dblclick", handle_mouseprevdef);
} else { } else {
window.removeEventListener("mousemove", handle_mousemove); window.removeEventListener("mousemove", handle_mousemove);
window.removeEventListener("mousedown", handle_mousedown); window.removeEventListener("mousedown", handle_mousedown);
window.removeEventListener("mouseup", handle_mouseup); window.removeEventListener("mouseup", handle_mouseup);
window.removeEventListener("mousewheel", handle_mousewheel); window.removeEventListener("mousewheel", handle_mousewheel);
window.removeEventListener("click", handle_mouseprevdef);
window.removeEventListener("dblclick", handle_mouseprevdef);
} }
}).bind(this); }).bind(this);
}).apply(this); }).apply(this);
} }


listen(ename, func, owner=null, once=false){ listen(ename, func, owner=null, once=false){
if ((["keyup", "keydown", "keypress", "mousemove", "mousedown", "mouseup"]).indexOf(ename) >= 0){
if ((["keyup", "keydown", "keypress", "mousemove", "mousedown", "mouseup", "mouseclick"]).indexOf(ename) >= 0){
this.__emitter.listen(ename, func, owner, once); this.__emitter.listen(ename, func, owner, once);
} else { } else {
ename = ReorderEventName(ename); ename = ReorderEventName(ename);
} }


unlisten(ename, func, owner=null){ unlisten(ename, func, owner=null){
if ((["keyup", "keydown", "keypress", "mousemove", "mousedown", "mouseup"]).indexOf(ename) >= 0){
if ((["keyup", "keydown", "keypress", "mousemove", "mousedown", "mouseup", "mouseclick"]).indexOf(ename) >= 0){
this.__emitter.unlisten(ename, func, owner); this.__emitter.unlisten(ename, func, owner);
} else { } else {
ename = ReorderEventName(ename); ename = ReorderEventName(ename);

Loading…
Отказ
Запис