Skip to content

Commit

Permalink
first
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Furfero committed Oct 28, 2010
0 parents commit 0025018
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
@@ -0,0 +1 @@
Check out some live examples at http://furf.com/exp/touch-punch/
84 changes: 84 additions & 0 deletions jquery.ui.touch-punch.js
@@ -0,0 +1,84 @@
/*!
* jQuery UI Touch Punch 0.1.0
*
* Copyright 2010, Dave Furfero
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* Depends:
* jquery.ui.widget.js
* jquery.ui.mouse.js
*/
(function ($) {

$.support.touch = typeof Touch === 'object';

if (!$.support.touch) {
return;
}

var mouseProto = $.ui.mouse.prototype,
_mouseInit = mouseProto._mouseInit,
_mouseDown = mouseProto._mouseDown,
_mouseUp = mouseProto._mouseUp,

mouseEvents = {
touchstart: 'mousedown',
touchmove: 'mousemove',
touchend: 'mouseup'
};

function makeMouseEvent (event) {

var touch = event.originalEvent.touches[0];

return $.extend(event, {
type: mouseEvents[event.type],
which: 1,
pageX: touch.pageX,
pageY: touch.pageY,
screenX: touch.screenX,
screenY: touch.screenY,
clientX: touch.clientX,
clientY: touch.clientY
});
}

mouseProto._mouseInit = function () {

var self = this;

self.element.bind('touchstart.' + self.widgetName, function (event) {
return self._mouseDown(makeMouseEvent(event));
});

_mouseInit.call(self);
};

mouseProto._mouseDown = function (event) {

var self = this,
ret = _mouseDown.call(self, event);

self._touchMoveDelegate = function (event) {
return self._mouseMove(makeMouseEvent(event));
};

$(document)
.bind('touchmove.' + self.widgetName, self._touchMoveDelegate)
.bind('touchend.' + self.widgetName, self._mouseUpDelegate);

return ret;
};

mouseProto._mouseUp = function (event) {

var self = this;

$(document)
.unbind('touchmove.' + self.widgetName, self._touchMoveDelegate)
.unbind('touchend.' + self.widgetName, self._touchEndDelegate);

return _mouseUp.call(self, event);
};

})(jQuery);
11 changes: 11 additions & 0 deletions jquery.ui.touch-punch.min.js
@@ -0,0 +1,11 @@
/*!
* jQuery UI Touch Punch 0.1.0
*
* Copyright 2010, Dave Furfero
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* Depends:
* jquery.ui.widget.js
* jquery.ui.mouse.js
*/
(function(c){c.support.touch=typeof Touch==="object";if(!c.support.touch){return;}var f=c.ui.mouse.prototype,g=f._mouseInit,a=f._mouseDown,e=f._mouseUp,b={touchstart:"mousedown",touchmove:"mousemove",touchend:"mouseup"};function d(h){var i=h.originalEvent.touches[0];return c.extend(h,{type:b[h.type],which:1,pageX:i.pageX,pageY:i.pageY,screenX:i.screenX,screenY:i.screenY,clientX:i.clientX,clientY:i.clientY});}f._mouseInit=function(){var h=this;h.element.bind("touchstart."+h.widgetName,function(i){return h._mouseDown(d(i));});g.call(h);};f._mouseDown=function(j){var h=this,i=a.call(h,j);h._touchMoveDelegate=function(k){return h._mouseMove(d(k));};c(document).bind("touchmove."+h.widgetName,h._touchMoveDelegate).bind("touchend."+h.widgetName,h._mouseUpDelegate);return i;};f._mouseUp=function(i){var h=this;c(document).unbind("touchmove."+h.widgetName,h._touchMoveDelegate).unbind("touchend."+h.widgetName,h._touchEndDelegate);return e.call(h,i);};})(jQuery);

0 comments on commit 0025018

Please sign in to comment.