event-move-debug.js revision 870b1351b8dad6efd508aacc807cd53dbd43b7c8
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncYUI.add('event-move', function(Y) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync// TODO: Better way to sniff 'n' switch touch support?
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncvar TOUCH = "ontouchstart" in Y.config.win,
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync TOUCH_EVENT_MAP = {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync start: "touchstart",
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync move: "touchmove",
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync end: "touchend"
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync },
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync MOUSE_EVENT_MAP = {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync start: "mousedown",
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync move: "mousemove",
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync end: "mouseup"
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync },
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync EVENT = (TOUCH) ? TOUCH_EVENT_MAP : MOUSE_EVENT_MAP,
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync START = "start",
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync MOVE = "move",
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync END = "end",
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync MOVE_START_HANDLE = "_moveStartHandle",
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync MOVE_HANDLE = "_moveHandle",
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync MOVE_END_HANDLE = "_moveEndHandle",
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync MOVE_START = "_moveStart",
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync _MOVE = "_move",
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync MIN_TIME = "minTime",
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync MIN_DISTANCE = "minDistance",
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync OWNER_DOCUMENT = "ownerDocument";
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncY.Event.define('movestart', {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync init: function (node, subscriber, ce) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync var startHandle = node.on(EVENT[START],
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync Y.bind(this._onStart, this),
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync null,
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync node,
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync subscriber,
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync ce);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync node.setData(MOVE_START_HANDLE, startHandle);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync },
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync destroy: function (node, subscriber, ce) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync var startHandle = node.getData(MOVE_START_HANDLE);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (startHandle) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync startHandle.detach();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync node.setData(MOVE_START_HANDLE, null);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync },
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync processArgs : function(args) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync var params = args[3] ? args.splice(3,1) : {};
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (!(MIN_TIME in params)) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync params.minVelocity = this.MIN_TIME;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (!(MIN_DISTANCE in params)) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync params.minDistance = this.MIN_DISTANCE;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return params;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync },
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync _onStart : function(e, node, subscriber, ce) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync e.preventDefault();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync var start = true, // always true for mouse
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync payload;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync Y.log("_onStart");
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (e.touches) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync start = (e.touches.length === 1);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync e = e.touches[0];
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (start) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync // TODO: Pass through e instead?
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync payload = {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync time : new Date().getTime(),
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync clientX: e.clientX,
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync clientY: e.clientY,
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync pageX: e.pageX,
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync pageY: e.pageY
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync };
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync node.setData(MOVE_START, payload);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync ce.fire(payload);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync },
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync MIN_TIME : 0,
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync MIN_DISTANCE : 3
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync});
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncY.Event.define('move', {
64863d3a0ffadf1ac248b295b78be5d55db6ee13vboxsync
64863d3a0ffadf1ac248b295b78be5d55db6ee13vboxsync init: function (node, subscriber, ce) {
64863d3a0ffadf1ac248b295b78be5d55db6ee13vboxsync
64863d3a0ffadf1ac248b295b78be5d55db6ee13vboxsync var doc = node.get(OWNER_DOCUMENT),
64863d3a0ffadf1ac248b295b78be5d55db6ee13vboxsync
e7c4c205cb0af88b5ef0786be46da94847a9a37bvboxsync moveHandle = doc.on(EVENT[MOVE],
e7c4c205cb0af88b5ef0786be46da94847a9a37bvboxsync Y.bind(this._onMove, this),
64863d3a0ffadf1ac248b295b78be5d55db6ee13vboxsync null,
64863d3a0ffadf1ac248b295b78be5d55db6ee13vboxsync node,
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync subscriber,
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync ce);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync node.setData(MOVE_HANDLE, moveHandle);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync },
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync destroy: function (node, subscriber, ce) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync var moveHandle = node.getData(MOVE_HANDLE);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (moveHandle) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync moveHandle.detach();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync node.setData(MOVE_HANDLE, null);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync Y.log("detaching move handler");
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync },
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync _onMove : function(e, node, subscriber, ce) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync var start = node.getData(MOVE_START),
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync move = !!(start),
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync payload;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync Y.log("_onMove:checkone. e.touches:" + e.touches);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync Y.log("_onMove:checkone. start:" + start);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (move) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (e.touches) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync move = (e.touches.length === 1);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync e = e.touches[0];
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (move) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync e.preventDefault();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync Y.log("_onMove:checktwo");
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync payload = {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync time : new Date().getTime(),
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync clientX: e.clientX,
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync clientY: e.clientY,
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync pageX: e.pageX,
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync pageY: e.pageY
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync };
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync node.setData(_MOVE, payload);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync ce.fire(payload);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync});
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncY.Event.define('moveend', {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync init: function (node, subscriber, ce) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync var doc = node.get(OWNER_DOCUMENT),
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync endHandle = doc.on(EVENT[END],
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync Y.bind(this._onEnd, this),
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync null,
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync node,
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync subscriber,
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync ce);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync node.setData(MOVE_END_HANDLE, endHandle);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync },
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync destroy: function (node, subscriber, ce) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync var endHandle = node.getData(MOVE_END_HANDLE);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
241adddf415cbdf66230864a215b24415f482e72vboxsync if (endHandle) {
241adddf415cbdf66230864a215b24415f482e72vboxsync endHandle.detach();
241adddf415cbdf66230864a215b24415f482e72vboxsync node.setData(MOVE_END_HANDLE, null);
241adddf415cbdf66230864a215b24415f482e72vboxsync }
241adddf415cbdf66230864a215b24415f482e72vboxsync },
241adddf415cbdf66230864a215b24415f482e72vboxsync
241adddf415cbdf66230864a215b24415f482e72vboxsync _onEnd : function(e, node, subscriber, ce) {
241adddf415cbdf66230864a215b24415f482e72vboxsync
241adddf415cbdf66230864a215b24415f482e72vboxsync var moveEnd = !!(node.getData(_MOVE) || node.getData(MOVE_START)),
241adddf415cbdf66230864a215b24415f482e72vboxsync payload;
241adddf415cbdf66230864a215b24415f482e72vboxsync
241adddf415cbdf66230864a215b24415f482e72vboxsync if (moveEnd) {
241adddf415cbdf66230864a215b24415f482e72vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (e.changedTouches) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (e.changedTouches.length === 1) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync e = e.changedTouches[0];
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync } else {
859c9a7cc74066a52cf7e76d54169859e7705c3dvboxsync moveEnd = false;
859c9a7cc74066a52cf7e76d54169859e7705c3dvboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (moveEnd) {
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync e.preventDefault();
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync payload = {
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync time : new Date().getTime(),
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync clientX: e.clientX,
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync clientY: e.clientY,
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync pageX: e.pageX,
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync pageY: e.pageY
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync };
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync node.setData(MOVE_START, null);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync node.setData(_MOVE, null);
241adddf415cbdf66230864a215b24415f482e72vboxsync
241adddf415cbdf66230864a215b24415f482e72vboxsync ce.fire(payload);
241adddf415cbdf66230864a215b24415f482e72vboxsync }
241adddf415cbdf66230864a215b24415f482e72vboxsync }
241adddf415cbdf66230864a215b24415f482e72vboxsync }
241adddf415cbdf66230864a215b24415f482e72vboxsync});
241adddf415cbdf66230864a215b24415f482e72vboxsync
241adddf415cbdf66230864a215b24415f482e72vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync}, '@VERSION@' ,{use:['node-base','event-touch','event-synthetic']});
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync