Skip to content

Commit

Permalink
plugin support. jQuery publication.
Browse files Browse the repository at this point in the history
  • Loading branch information
jairajs89 committed Feb 19, 2012
1 parent eda2127 commit 532e61c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
12 changes: 2 additions & 10 deletions demo.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
<title>Touchy demo - Draw dots</title>
<title>Touchy - Demo</title>

<meta content="yes" name="apple-mobile-web-app-capable">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
Expand All @@ -25,14 +25,6 @@
background: #000;
border-radius: 12px;
}

.line {
z-index: 2;
position: absolute;
width: 25px;
background: #000;
border-radius: 12px;
}
</style>
</head>

Expand All @@ -53,7 +45,7 @@
touchMe.appendChild(elem);
}

Touchy(touchMe, function (hand, finger) {
Touchy(touchMe, true, function (hand, finger) {
finger.on('start', drawPoint);
finger.on('move' , drawPoint);
finger.on('end' , drawPoint);
Expand Down
2 changes: 1 addition & 1 deletion multi_demo.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
<title>Touchy demo - Draw dots</title>
<title>Touchy - Multitouch demo</title>

<meta content="yes" name="apple-mobile-web-app-capable">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
Expand Down
44 changes: 44 additions & 0 deletions touchy.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@


/* Socket-style finger management for multi-touch events */
var plugins = {};

function Touchy (elem, handleMouse, settings) {
if (typeof settings == 'undefined') {
settings = handleMouse;
Expand All @@ -331,6 +333,27 @@
settings = { any: settings };
}

for (var name in plugins) {
if (name in settings) {
var updates = plugins[name]( settings[name] );

for (var handlerType in updates) {
if (handlerType in settings) {
settings[handlerType] = (function (handler1, handler2) {
return function () {
handler1.call(this, arguments);
handler2.call(this, arguments);
};
})(settings[handlerType], updates[handlerType]);
}

else {
settings[handlerType] = updates[handlerType];
}
}
}
}

var mainHand = new Hand(),
multiHand,
mouseID,
Expand Down Expand Up @@ -565,6 +588,15 @@
}
};

/* Plugin support for custom touch handling */
Touchy.plugin = function (name, callback) {
if (name in plugins) {
throw 'Touchy: ' + name + ' plugin already defined';
}

plugins[name] = callback;
};



/* Prevent window movement (iOS fix) */
Expand All @@ -584,4 +616,16 @@

/* Publicise object */
window.Touchy = Touchy;

if (typeof jQuery == 'function') {
jQuery.fn.touchy = function () {
var args = Array.prototype.slice.call(arguments);

this.each(function () {
var thisArgs = args.slice();
thisArgs.unshift(this);
Touchy.apply(window, thisArgs);
});
};
}
})();

0 comments on commit 532e61c

Please sign in to comment.