badtouch

by Darby Rathbone

HTML

<h3>BadTouch.js</h3>

<br>
<p>BadTouch.js is a multitouch javascript api control for swipes gestures and basic touch controls.</p>
<div id="test" class="tester"></div>
<div id="log"></div>

CSS

body {
    font-family: Arial, sans-serif;
}
div.tester {
    display:inline-block;
    position:relative;
    width:200px;
    height:200px;
    border:raised;
    background-color:#ccc;
}

JavaScript

var Vector = (function () {
    function Vector(x, y) {
        this.x = x !== null ? x : 0;
        this.y = y !== null ? y : 0;
    }
    Vector.add = function (v1, v2) {
        return new Vector(v1.x + v2.x, v1.y + v2.y);
    };
    Vector.sub = function (v1, v2) {
        return new Vector(v1.x - v2.x, v1.y - v2.y);
    };
    Vector.project = function (v1, v2) {
        return v1.clone().scale((v1.dot(v2)) / v1.magSq());
    };
    Vector.prototype.set = function (x, y) {
        this.x = x;
        this.y = y;
        return this;
    };
    Vector.prototype.add = function (v) {
        this.x += v.x;
        this.y += v.y;
        return this;
    };
    Vector.prototype.sub = function (v) {
        this.x -= v.x;
        this.y -= v.y;
        return this;
    };
    Vector.prototype.scale = function (f) {
        this.x *= f;
        this.y *= f;
        return this;
    };
    Vector.prototype.dot = function (v) {
        return this.x * v.x + this.y * v.y;
    };
    Vector.prototype.cross = function (v) {
        return (this.x * v.y) - (this.y * v.x);
    };
    Vector.prototype.mag = function () {
        return Math.sqrt(this.x * this.x + this.y * this.y);
    };
    Vector.prototype.magSq = function () {
        return this.x * this.x + this.y * this.y;
    };
    Vector.prototype.dist = function (v) {
        var dx, dy;
        dx = v.x - this.x;
        dy = v.y - this.y;
        return Math.sqrt(dx * dx + dy * dy);
    };
    Vector.prototype.distSq = function (v) {
        var dx, dy;
        dx = v.x - this.x;
        dy = v.y - this.y;
        return dx * dx + dy * dy;
    };
    Vector.prototype.norm = function () {
        var m;
        m = Math.sqrt(this.x * this.x + this.y * this.y);
        this.x /= m;
        this.y /= m;
        return this;
    };
    Vector.prototype.limit = function (l) {
        var m, mSq;
        mSq = this.x * this.x + this.y * this.y;
        if (mSq > l * l) {
            m = Math.sqrt(mSq);
           ...