/*
 * touchSwipe - jQuery Plugin
 * http://plugins.jquery.com/project/touchSwipe
 * http://labs.skinkers.com/touchSwipe/
 *
 * Copyright (c) 2010 Matt Bryson (www.skinkers.com)
 * Dual licensed under the MIT or GPL Version 2 licenses.
 *
 * $version: 1.2.3
 *
 * This jQuery plugin will only run on devices running Mobile Webkit based browsers (iOS 2.0+, android 2.2+)
 */
(function (a) { a.fn.swipe = function (b) { if (!this) return false; var c = { fingers: 1, threshold: 75, swipe: null, swipeLeft: null, swipeRight: null, swipeUp: null, swipeDown: null, swipeStatus: null, click: null, triggerOnTouchEnd: true, allowPageScroll: "auto" }; var d = "left"; var e = "right"; var f = "up"; var g = "down"; var h = "none"; var i = "horizontal"; var j = "vertical"; var k = "auto"; var l = "start"; var m = "move"; var n = "end"; var o = "cancel"; var p = "start"; if (b.allowPageScroll == undefined && (b.swipe != undefined || b.swipeStatus != undefined)) b.allowPageScroll = h; if (b) a.extend(c, b); return this.each(function () { function D() { var a = C(); if (a <= 45 && a >= 0) return d; else if (a <= 360 && a >= 315) return d; else if (a >= 135 && a <= 225) return e; else if (a > 45 && a < 135) return g; else return f } function C() { var a = s.x - t.x; var b = t.y - s.y; var c = Math.atan2(b, a); var d = Math.round(c * 180 / Math.PI); if (d < 0) d = 360 - Math.abs(d); return d } function B() { return Math.round(Math.sqrt(Math.pow(t.x - s.x, 2) + Math.pow(t.y - s.y, 2))) } function A(a, b) { if (c.allowPageScroll == h) { a.preventDefault() } else { var l = c.allowPageScroll == k; switch (b) { case d: if (c.swipeLeft && l || !l && c.allowPageScroll != i) a.preventDefault(); break; case e: if (c.swipeRight && l || !l && c.allowPageScroll != i) a.preventDefault(); break; case f: if (c.swipeUp && l || !l && c.allowPageScroll != j) a.preventDefault(); break; case g: if (c.swipeDown && l || !l && c.allowPageScroll != j) a.preventDefault(); break } } } function z(a, h) { if (c.swipeStatus) c.swipeStatus.call(b, a, h, direction || null, distance || 0); if (h == o) { if (c.click && r == 1 && (isNaN(distance) || distance == 0)) c.click.call(b, a, a.target) } if (h == n) { if (c.swipe) { c.swipe.call(b, a, direction, distance) } switch (direction) { case d: if (c.swipeLeft) c.swipeLeft.call(b, a, direction, distance); break; case e: if (c.swipeRight) c.swipeRight.call(b, a, direction, distance); break; case f: if (c.swipeUp) c.swipeUp.call(b, a, direction, distance); break; case g: if (c.swipeDown) c.swipeDown.call(b, a, direction, distance); break } } } function y(a) { r = 0; s.x = 0; s.y = 0; t.x = 0; t.y = 0; u.x = 0; u.y = 0 } function x(a) { a.preventDefault(); distance = B(); direction = D(); if (c.triggerOnTouchEnd) { p = n; if (r == c.fingers && t.x != 0) { if (distance >= c.threshold) { z(a, p); y(a) } else { p = o; z(a, p); y(a) } } else { p = o; z(a, p); y(a) } } else if (p == m) { p = o; z(a, p); y(a) } } function w(a) { if (p == n || p == o) return; t.x = a.touches[0].pageX; t.y = a.touches[0].pageY; direction = D(); r = a.touches.length; p = m; A(a, direction); if (r == c.fingers) { distance = B(); if (c.swipeStatus) z(a, p, direction, distance); if (!c.triggerOnTouchEnd) { if (distance >= c.threshold) { p = n; z(a, p); y(a) } } } else { p = o; z(a, p); y(a) } } function v(a) { p = l; r = a.touches.length; distance = 0; direction = null; if (r == c.fingers) { s.x = t.x = a.touches[0].pageX; s.y = t.y = a.touches[0].pageY; if (c.swipeStatus) z(a, p) } else { y(a) } } var b = a(this); var q = null; var r = 0; var s = { x: 0, y: 0 }; var t = { x: 0, y: 0 }; var u = { x: 0, y: 0 }; try { this.addEventListener("touchstart", v, false); this.addEventListener("touchmove", w, false); this.addEventListener("touchend", x, false); this.addEventListener("touchcancel", y, false) } catch (E) { } }) } })(jQuery)
