diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000..5008ddf
Binary files /dev/null and b/.DS_Store differ
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..e227233
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2018 Ben Major
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
index 8854b3d..26599ed 100644
--- a/README.md
+++ b/README.md
@@ -1,31 +1,149 @@
-jQuery Mobile Events
-====================
+# jQuery Touch Events
+
This is a series of plugins that create additional events that can be used in combination with jQuery when developing for mobile devices. The events are also compatible with desktop browsers to ensure ultimate compatibility for your projects. In time, we will update the Repository to include some very basic demonstrations to get you started with using the events, but for now, we've put together a list of the events that are provided, and what they do.
As explained, the events are each triggered by native touch events, or alternatively by click events. The plugin automatically detects whether the user's device is touch compatible, and will use the correct native events whenever required. It is hoped that these events will help to aid single-environment development with jQuery for mobile web app development.
-Utility Functions:
------------------
-In addition to the numerous additional events that are provided, the library also includes a number of utility functions that can be used to further leverage the power of native events within your website or application. These utility functions can be used for unifying basic events, such as `tapstart` or `mousedown`.
+## Table of Contents:
+
+
+1. [Version History](#1-version-history)
+2. [Installation](#2-installation)
+3. [Usage](#3-usage)
+4. [Events](#4-the-events)
+5. [Callback Data](#5-callback-data)
+6. [Defining Thresholds](#6-defining-thresholds)
+7. [Utility Functions](#7-utility-functions)
+8. [Demo](#8-demo)
+9. [Requirements](#9-requirements)
+10. [License](#10-license)
+
+## 1. Version History:
+
+After almost 2 years in public beta, I am pleased to announce that the library is now officially launched as **version 1.0.0**. I'll be updating the version history over time with digests of fixes, features and improvements:
+
++ **Version 2.0.3** (2020-04-23)
+ + Fix for bug [#165](https://github.com/benmajor/jQuery-Touch-Events/issues/165)
++ **Version 2.0.2** (2020-04-21)
+ + Fix for binding events to `document` and `window`.
++ Update NPM repo so that latest releases are detected.
++ **Version 2.0.1** (2019-12-02)
+ + Fix for bug [#156](https://github.com/benmajor/jQuery-Touch-Events/issues/156)
++ **Version 2.0.0** (2018-05-20)
+ + Added two-finger tap event (`tap2`).
+ + Added two-finger taphold event (`taphold2`).
+ + Added setter functions to easily set thresholds globally.
+ + Fixed a bug where the offset position of elements was sometimes incorrect.
+ + Other minor bug fixes.
++ **Version 1.0.9** (2017-06-07)
+ + Fixes a bug where binding to multiple elements with the same selector caused issues with `doubletap`.
++ **Version 1.0.8** (2017-02-01)
+ + Fixes a bug where certain instances of Chrome on touch devices did not correctly fire events.
+ + Added license info to minified script.
++ **Version 1.0.7** (2017-02-01)
+ + Added threshold support for `taphold`
++ **Version 1.0.6** (2016-11-16)
+ + Added slop factor for `singletap`
+ + Fixed a bug where `offset()` was sometimes called on `null` (instead of `window`).
++ **Version 1.0.5** (2015-11-13)
+ + Fixed a major bug where the reported `offset` position of events was incorrect when inside of a parent element.
++ **Version 1.0.4** (2015-11-12)
+ + Regressed from `MSPointerEvent` for compatibility with IE11 and Edge
+ + Removed multi-name event for `tap`.
++ **Version 1.0.3** (2015-11-10)
+ + Numerous minor bug fixes
+ + Fixes a bug where the offset position returned by events relative to the **current target**, not the bound target.
++ **Version 1.0.2** (2015-08-26)
+ + Numerous bug fixes
+ + Added support for `MSPointerEvent`
++ **Version 1.0.1** (2015-08-21)
+ + Added Bower package for easy install
+ + Fixed a bug where Internet Explorer under Windows Mobile did not trigger certain events.
++ **Version 1.0.0** (2015-07-18)
+ + The library officially entered 1.0.0 after minor bug fixes and final adjustments.
+
+## 2. Installation:
+
+
+jQuery Touch Events, as the name suggests, require only the jQuery library (version 1.7+) to run. You should download the latest release from the `src` folder, and include the Javascript file within your project, **after** jQuery has been included. It is recommended to also wrap your code inside the `DOMReady` callback function of jQuery (`$(function() { })`, for example).
+
+**Manual installation:**
+
+Once you have downloaded the JS files from the master branch, you should include them using the following code:
+
+```html
+
+```
+
+The awesome guys over at [cdnjs](https://cdnjs.com/libraries/jquery-touch-events) have kindly added the library to their CDN so you can include it as follows directly into your application:
+
+```html
+
+```
+
+Alternatively, you can also install jQuery-touch-events using Bower as follows:
+
+```
+$ bower install jquery-touch-events
+```
+
+jQuery Touch Events can also be installed using NPM as follows:
+
+```
+$ npm i @benmajor/jquery-touch-events
+```
+
+If you are installing the library via NPM, after running the `npm i` command above, you'll also need to ensure that you import the modules into you project files wherever you wish to use the events. Place the following line alongside your other imports:
+
+```js
+import "@benmajor/jquery-touch-events";
+```
+
+### 3. Usage:
+All of the events outlined above have been written using jQuery's ``event.special`` object, and so can be used in conjunction with jQuery's event handling functions, as well as shortcut wrappers. As a result, all of the events that are supported by this library may be handled using any of jQuery's own event-specific methods, such as `on()` and `one()`.
+
+The following code snippets showcase some basic usage with jQuery:
-The following utility functions are provided (each function is registered to the jQuery namespace, and should be called with `$.funcName()` (or `jQuery.funcName()` for compatibility):
+**Binding a ``tap`` event to an element:**
-+ `isTouchCapable()`:
-Returns `true` or `false` depending upon whether touch events are supported.
-+ `getStartEvent()`:
-Returns `touchstart` for touch-enabled devices, or `mousedown` for standard environments.
-+ `getEndEvent()`:
-Returns `touchend` for touch-enabled devices, or `mouseup` for standard environments.
-+ `getMoveEvent()`:
-Returns `touchmove` for touch-enabled devices, or `mousemove` for standard environments.
-+ `getTapEvent()`:
-Returns `tap` for touch-enabled devices, or `click` for standard environments.
-+ `getScrollEvent()`:
-Returns `touchmove` for touch-enabled devices, or `scroll` for standard environments. **Caution should be exercised when using this function, since some mobile browsers will correctly bind to `scroll` as well as `touchmove`.**
+When binding, you should use jQuery's `on()` function as follows (avoid the use of `live()` and `bind()` as these are now deprecated and will be removed from future versions of jQuery).
+
+```js
+$('#myElement').on('tap', function(e) {
+ console.log('User tapped #myElement');
+});
+```
+
+**Triggering the event:**
+```js
+$('#myElement').trigger('tap');
+```
-Events Provided:
----------------
+**Removing the event:**
+```js
+$('#myElement').off('tap', handler);
+```
+
+**Using method wrapper:**
+```js
+$('#myElement').tap(function(e) {
+ console.log('User tapped #myElement');
+});
+```
+
+**Method chaining:**
+Chaining has also been preserved, so you can easily use these events in conjunction with other jQuery functions, or attach multiple events in a single, chained LOC:
+```js
+$('#myElement').singletap(function() {
+ console.log('singletap');
+}).doubletap(function() {
+ console.log('doubletap');
+});
+```
+
+
+## 4. The Events:
+ **`tapstart`**
Fired as soon as the user begins touching an element (or clicking, for desktop environments).
@@ -34,7 +152,7 @@ Fired after the user releases their finger from the target element (or releases
+ **`tapmove`**
Fired as soon as the user begins moving their finger on an element (or moving their mouse, for desktop environments).
+ **`tap`**
-This event is fired whenever the user taps and releases their finger on the target element. Caution should be observed when using this event in conjunction without tap events, especially ``doubletap``. This event will be fired twice when ``doubletap`` is used, so it is recommended to use ``singletap`` in this case.
+This event is fired whenever the user taps and releases their finger on the target element. Caution should be observed when using this event in conjunction with tap events, especially ``doubletap``. This event will be fired twice when ``doubletap`` is used, so it is recommended to use ``singletap`` in this case.
+ **`singletap`**
Unlike ``tap`` this event is only triggered once we are certain the user has only tapped the target element a single time. This will not be triggered by ``doubletap`` or ``taphold``, unlike ``tap``. Since we need to run some tests to make sure the user isn't double tapping or holding a tap on the target element, this event is fired with a short delay (currently of 500 milliseconds).
+ **`doubletap`**
@@ -60,17 +178,19 @@ Triggered as soon as scrolling is stopped on the target element.
+ **`orientationchange`**
This event is triggered when the orientation of the device is changed. Please note that it uses throttling for non-mobile devices, or devices which do not support the native ``orientationchange`` event. In the latter instance, a detection of the viewport size change occurs.
-Callback Data:
---------------
+
+## 5. Callback Data:
Each event now features a second argument that can be passed to the specified callback function. This argument includes some basic data relating specifically to the event, and can be accessed as a standard JavaScript object. To hook into this parameter, you should use the following code:
-`$(element).swipeend(function(e, touch) { });`
+```js
+$(element).swipeend(function(e, touch) { });
+```
Given the example above, `touch` will now contain some basic data that can be accessed through `touch.`. The first argument will represent the last *native* event that occurred (the names used for these two arguments is irrelevant).
Each event provides different callback data. The following shows the numerous data that are passed back to the callback function inside the second parameter:
-##`tapstart`, `tapend`, `tapmove`, `tap`, `singletap`:
+### `tapstart`, `tapend`, `tapmove`, `tap`, `singletap`:
`offset` - object containing the X and Y positions of the event relative to the element to which is was bound. Accessed through `offset.x` and `offset.y` respectively.
@@ -80,7 +200,7 @@ Each event provides different callback data. The following shows the numerous da
`time` - JavaScript timestamp the event occurred (milliseconds since the Unix Epoch)
-##`taphold`:
+### `taphold`:
`duration`: the time in milliseconds that the user tapped for.
@@ -98,7 +218,7 @@ Each event provides different callback data. The following shows the numerous da
`target` - the jQuery object from which the event was triggered.
-##`doubletap`:
+### `doubletap`:
`firstTap` - Object containing the same data as a `tap` event, but for the first tap to occur.
@@ -106,7 +226,7 @@ Each event provides different callback data. The following shows the numerous da
`interval` - the time in milliseconds between the two tap.
-##`swipe`, `swipeup`, `swiperight`, `swipedown`, `swipeleft`, `swipeend`:
+### `swipe`, `swipeup`, `swiperight`, `swipedown`, `swipeleft`, `swipeend`:
`direction` - string representing the swipe direction (either `up`, `right`, `down` or `left`).
@@ -116,64 +236,63 @@ Each event provides different callback data. The following shows the numerous da
`yAmount` - number of pixels the swipe occupied on the Y-axis (returned regardless of direction).
-`startEvent` - Object containing the same data as a `tap` event, but captured when swiping begins.
+`startEvnt` - Object containing the same data as a `tap` event, but captured when swiping begins.
`endEvent` - Object containing the same data as a `tap` event, but captured when swiping is complete.
-Demo:
------
-I have put together a simple demo application that shows the numerous events in action. The console on the left hand side is used to show information about the events that have been called. You can examine the code easily by viewing the page's source to lear more about how this works. Please click on the below to check out the demo:
+## 6. Defining Thresholds:
-http://ben-major.co.uk/jquery-mobile-events/
+You can also define custom thresholds to be used for ``swipe`` events (``swipeup``, ``swiperight``, ``swipedown`` and ``swipeleft``) to prevent interference with scrolling and other events. To do so, simply assign a `data-xthreshold` or `data-ythreshold` to the target element as follows:
-Please be aware that this demonstration uses Google's hosted jQuery file, and also pulls the latest version of the events library from GitHub. It is a great place to check the status of the library. Since this demo uses the vanilla code, it is a good idea to check the library functionality here for your own reference. If you're running into problems with the library, please check this demonstration using your device in the first instance. You can scan in the QR below to go directly to the web page:
+``
``
+
+The value you define is the difference in pixels that the user must move before the event is triggered on the target element. If no threshold is defined, a default of `50px` will be used.
-
+``data-xthreshold`` defines the horizontal threshold.
-Usage:
-------
-All of the events outlined above have been written using jQuery's ``event.special`` object, and so can be used in conjunction with jQuery's event handling functions, as well as shortcut wrappers.
+``data-ythreshold`` defines the vertical threshold.
-**Binding a ``tap`` event to an element:**
-``$('#myElement').bind('tap', function(e) { console.log('User tapped #myElement'); });``
+**Update as of 1.0.7:**
+Following requests from users and contributors, as of 1.0.7 it is now possible to also define the `doubletap` threshold via jQuery's `data-` attributes as follows:
-**Using with ``.on()`` and ``.live()``:**
-``$('#myElement').live('tap', function(e) { console.log('User tapped #myElement'); });``
-``$('#myElement').on('tap', function(e) { console.log('User tapped #myElement'); });``
+``data-threshold`` defines the amount of time (in milliseconds) after which the `doubletap` event is fired on the target element.
-**Triggering the event:**
-``$('#myElement').trigger('tap');``
+## 7. Utility Functions:
-**Removing the event with ``.off()``, ``.die()`` and ``.unbind()``:**
-``$('#myElement').off('tap', hander);``
-``$('#myElement').die('tap', hander);``
-``$('#myElement').unbind('tap', hander);``
+In addition to the numerous additional events that are provided, the library also includes a number of utility functions that can be used to further leverage the power of native events within your website or application. These utility functions can be used for unifying basic events, such as `tapstart` or `mousedown`.
-**Using method wrapper:**
-``$('#myElement').tap(function(e) { console.log('User tapped #myElement'); });``
+The following utility functions are provided (each function is registered to the jQuery namespace, and should be called with `$.funcName()` (or `jQuery.funcName()` for compatibility):
-**Method chaining:**
-Chaining has also been preserved, so you can easily use these events in conjuction with other jQuery functions, or attach multiple events in a single, chained LOC:
-``$('#myElement').singletap(function() { console.log('singletap'); }).doubletap(function() { console.log('doubletap'); });``
++ `isTouchCapable()`:
+Returns `true` or `false` depending upon whether touch events are supported.
++ `getStartEvent()`:
+Returns `touchstart` for touch-enabled devices, or `mousedown` for standard environments.
++ `getEndEvent()`:
+Returns `touchend` for touch-enabled devices, or `mouseup` for standard environments.
++ `getMoveEvent()`:
+Returns `touchmove` for touch-enabled devices, or `mousemove` for standard environments.
++ `getTapEvent()`:
+Returns `tap` for touch-enabled devices, or `click` for standard environments.
++ `getScrollEvent()`:
+Returns `touchmove` for touch-enabled devices, or `scroll` for standard environments. **Caution should be exercised when using this function, since some mobile browsers will correctly bind to `scroll` as well as `touchmove`.**
-Defining Thresholds:
---------------------
-You can also define custom thresholds to be used for ``swipe`` events (``swipeup``, ``swiperight``, ``swipedown`` and ``swipeleft``) to prevent interference with scrolling and other events. To do so, simply assign a `data-xthreshold` or `date-ythreshold` to the target element as follows:
+## 8. Demo:
-````
+I have put together a simple demo application that shows the numerous events in action. The console on the left hand side is used to show information about the events that have been called. You can examine the code easily by viewing the page's source to lear more about how this works. Please click on the below to check out the demo:
-The value you define is the difference in pixels that the user must move before the event is triggered on the target element. If no threshold is defined, a default of `50px` will be used.
+http://lincweb.co.uk/labs/jquery-touch-events/demo/
-``data-xthreshold`` defines the horizontal threshold.
+Please be aware that this demonstration uses Google's hosted jQuery file, and also pulls the latest version of the events library from GitHub. It is a great place to check the status of the library. Since this demo uses the vanilla code, it is a good idea to check the library functionality here for your own reference. If you're running into problems with the library, please check this demonstration using your device in the first instance. You can scan in the QR below to go directly to the web page:
-``data-ythreshold`` defines the vertical threshold.
+
+
+
+## 9. Requirements:
-Requirements:
--------------
The library works with jQuery 1.7.0+. All major browsers have been tested without problem. The library is not compatible with jQuery < 1.7.
-License:
---------
+## 10. License:
+
Licensed under the MIT License:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
diff --git a/bower.json b/bower.json
new file mode 100644
index 0000000..7d3e959
--- /dev/null
+++ b/bower.json
@@ -0,0 +1,11 @@
+{
+ "name": "jquery-touch-events",
+ "version": "2.0.3",
+ "main": "src/jquery.mobile-events.js",
+ "ignore": [
+ "bower.json"
+ ],
+ "dependencies": {
+ "jquery": ">=1.7.0"
+ }
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..07e77c7
--- /dev/null
+++ b/package.json
@@ -0,0 +1,24 @@
+{
+ "name": "@benmajor/jquery-touch-events",
+ "version": "2.0.3",
+ "description": "Polyfill to remove click delays and unify pointer device events.",
+ "main": "src/jquery.mobile-events.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/benmajor/jQuery-Touch-Events.git"
+ },
+ "keywords": [
+ "jquery",
+ "touch-events",
+ "touch-device"
+ ],
+ "author": "Ben Major",
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/benmajor/jQuery-Touch-Events/issues"
+ },
+ "homepage": "https://github.com/benmajor/jQuery-Touch-Events#readme"
+}
diff --git a/src/1.0.0/bower.json b/src/1.0.0/bower.json
new file mode 100644
index 0000000..48b95cb
--- /dev/null
+++ b/src/1.0.0/bower.json
@@ -0,0 +1,11 @@
+{
+ "name": "jquery-touch-events",
+ "version": "1.0.0",
+ "main": "src/jquery.mobile-events.js",
+ "ignore": [
+ "bower.json"
+ ],
+ "dependencies": {
+ "jquery": ">=1.7.0"
+ }
+}
diff --git a/src/1.0.0/jquery.mobile-events.js b/src/1.0.0/jquery.mobile-events.js
new file mode 100644
index 0000000..f935863
--- /dev/null
+++ b/src/1.0.0/jquery.mobile-events.js
@@ -0,0 +1,875 @@
+/*!
+ * jQuery Mobile Events
+ * by Ben Major (www.ben-major.co.uk)
+ *
+ * Copyright 2011, Ben Major
+ * Licensed under the MIT License:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+(function ($) {
+ $.attrFn = $.attrFn || {};
+
+ // navigator.userAgent.toLowerCase() isn't reliable for Chrome installs
+ // on mobile devices. As such, we will create a boolean isChromeDesktop
+ // The reason that we need to do this is because Chrome annoyingly
+ // purports support for touch events even if the underlying hardware
+ // does not!
+ var agent = navigator.userAgent.toLowerCase(),
+ isChromeDesktop = (agent.indexOf('chrome') > -1 && ((agent.indexOf('windows') > -1) || (agent.indexOf('macintosh') > -1) || (agent.indexOf('linux') > -1)) && agent.indexOf('mobile') < 0 && agent.indexOf('android') < 0),
+
+ settings = {
+ tap_pixel_range: 5,
+ swipe_h_threshold: 50,
+ swipe_v_threshold: 50,
+ taphold_threshold: 750,
+ doubletap_int: 500,
+
+ touch_capable: ('ontouchstart' in window && !isChromeDesktop),
+ orientation_support: ('orientation' in window && 'onorientationchange' in window),
+
+ startevent: ('ontouchstart' in window && !isChromeDesktop) ? 'touchstart' : 'mousedown',
+ endevent: ('ontouchstart' in window && !isChromeDesktop) ? 'touchend' : 'mouseup',
+ moveevent: ('ontouchstart' in window && !isChromeDesktop) ? 'touchmove' : 'mousemove',
+ tapevent: ('ontouchstart' in window && !isChromeDesktop) ? 'tap' : 'click',
+ scrollevent: ('ontouchstart' in window && !isChromeDesktop) ? 'touchmove' : 'scroll',
+
+ hold_timer: null,
+ tap_timer: null
+ };
+
+ // Convenience functions:
+ $.isTouchCapable = function() { return settings.touch_capable; };
+ $.getStartEvent = function() { return settings.startevent; };
+ $.getEndEvent = function() { return settings.endevent; };
+ $.getMoveEvent = function() { return settings.moveevent; };
+ $.getTapEvent = function() { return settings.tapevent; };
+ $.getScrollEvent = function() { return settings.scrollevent; };
+
+ // Add Event shortcuts:
+ $.each(['tapstart', 'tapend', 'tapmove', 'tap', 'tap2', 'tap3', 'tap4', 'singletap', 'doubletap', 'taphold', 'swipe', 'swipeup', 'swiperight', 'swipedown', 'swipeleft', 'swipeend', 'scrollstart', 'scrollend', 'orientationchange'], function (i, name) {
+ $.fn[name] = function (fn) {
+ return fn ? this.on(name, fn) : this.trigger(name);
+ };
+
+ $.attrFn[name] = true;
+ });
+
+ // tapstart Event:
+ $.event.special.tapstart = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.startevent, function (e) {
+ $this.data('callee', arguments.callee);
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapstart', e, touchData);
+ return true;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee);
+ }
+ };
+
+ // tapmove Event:
+ $.event.special.tapmove = {
+ setup: function() {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.moveevent, function(e) {
+ $this.data('callee', arguments.callee);
+
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapmove', e, touchData);
+ return true;
+ });
+ },
+ remove: function() {
+ $(this).off(settings.moveevent, $(this).data.callee);
+ }
+ }
+
+ // tapend Event:
+ $.event.special.tapend = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.endevent, function (e) {
+ // Touch event data:
+ $this.data('callee', arguments.callee);
+
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX - origEvent.changedTouches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY - origEvent.changedTouches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ triggerCustomEvent(thisObject, 'tapend', e, touchData);
+ return true;
+ });
+ },
+ remove: function () {
+ $(this).off(settings.endevent, $(this).data.callee);
+ }
+ };
+
+ // taphold Event:
+ $.event.special.taphold = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ timer,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ end_x = 0,
+ end_y = 0;
+
+ $this.on(settings.startevent, function (e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ $this.data('tapheld', false);
+ origTarget = e.target;
+
+ var origEvent = e.originalEvent;
+ var start_time = Date.now(),
+ startPosition = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ startOffset = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ };
+
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ end_x = start_pos.x;
+ end_y = start_pos.y;
+
+ settings.hold_timer = window.setTimeout(function () {
+
+ var diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y);
+
+ if (e.target == origTarget && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ $this.data('tapheld', true);
+
+ var end_time = Date.now(),
+ endPosition = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ endOffset = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ };
+ duration = end_time - start_time;
+
+ // Build the touch data:
+ var touchData = {
+ 'startTime': start_time,
+ 'endTime': end_time,
+ 'startPosition': startPosition,
+ 'startOffset': startOffset,
+ 'endPosition': endPosition,
+ 'endOffset': endOffset,
+ 'duration': duration,
+ 'target': e.target
+ }
+ $this.data('callee1', arguments.callee);
+ triggerCustomEvent(thisObject, 'taphold', e, touchData);
+ }
+ }, settings.taphold_threshold);
+
+ return true;
+ }
+ }).on(settings.endevent, function () {
+ $this.data('callee2', arguments.callee);
+ $this.data('tapheld', false);
+ window.clearTimeout(settings.hold_timer);
+ })
+ .on(settings.moveevent, function (e) {
+ $this.data('callee3', arguments.callee);
+
+ end_x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2).off(settings.moveevent, $(this).data.callee3);
+ }
+ };
+
+ // doubletap Event:
+ $.event.special.doubletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ action,
+ firstTap,
+ origEvent,
+ cooloff,
+ cooling = false;
+
+ $this.on(settings.startevent, function (e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+ $this.data('doubletapped', false);
+ origTarget = e.target;
+ $this.data('callee1', arguments.callee);
+
+ origEvent = e.originalEvent;
+ firstTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ return true;
+ }).on(settings.endevent, function (e) {
+
+ var now = Date.now();
+ var lastTouch = $this.data('lastTouch') || now + 1;
+ var delta = now - lastTouch;
+ window.clearTimeout(action);
+ $this.data('callee2', arguments.callee);
+
+ if (delta < settings.doubletap_int && (e.target == origTarget) && delta > 100) {
+ $this.data('doubletapped', true);
+ window.clearTimeout(settings.tap_timer);
+
+ // Now get the current event:
+ var lastTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? e.originalEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? e.originalEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? e.originalEvent.changedTouches[0].pageX - e.originalEvent.changedTouches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? e.originalEvent.changedTouches[0].pageY - e.originalEvent.changedTouches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ }
+
+ var touchData = {
+ 'firstTap': firstTap,
+ 'secondTap': lastTap,
+ 'interval': lastTap.time - firstTap.time
+ };
+
+ if (!cooling) {
+ triggerCustomEvent(thisObject, 'doubletap', e, touchData);
+ }
+
+ cooling = true;
+
+ cooloff = window.setTimeout(function (e) {
+ cooling = false;
+ }, settings.doubletap_int);
+
+ } else {
+ $this.data('lastTouch', now);
+ action = window.setTimeout(function (e) {
+ window.clearTimeout(action);
+ }, settings.doubletap_int, [e]);
+ }
+ $this.data('lastTouch', now);
+ });
+ },
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // singletap Event:
+ // This is used in conjuction with doubletap when both events are needed on the same element
+ $.event.special.singletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget = null,
+ startTime = null,
+ start_pos = {
+ x: 0,
+ y: 0
+ };
+
+ $this.on(settings.startevent, function (e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ startTime = Date.now();
+ origTarget = e.target;
+ $this.data('callee1', arguments.callee);
+
+ // Get the start x and y position:
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ return true;
+ }
+ }).on(settings.endevent, function (e) {
+ $this.data('callee2', arguments.callee);
+ if (e.target == origTarget) {
+ // Get the end point:
+ end_pos_x = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX;
+ end_pos_y = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY;
+
+ // We need to check if it was a taphold:
+
+ settings.tap_timer = window.setTimeout(function () {
+ if (!$this.data('doubletapped') && !$this.data('tapheld') && (start_pos.x == end_pos_x) && (start_pos.y == end_pos_y)) {
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX - origEvent.changedTouches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY - origEvent.changedTouches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Was it a taphold?
+ if((touchData.time - startTime) < settings.taphold_threshold)
+ {
+ triggerCustomEvent(thisObject, 'singletap', e, touchData);
+ }
+ }
+ }, settings.doubletap_int);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // tap Event:
+ $.event.special.tap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ origTarget = null,
+ start_time,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ touches;
+
+ $this.on(settings.startevent, function (e) {
+ $this.data('callee1', arguments.callee);
+
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ started = true;
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ start_time = Date.now();
+ origTarget = e.target;
+
+ touches = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches : [ e ];
+ return true;
+ }
+ }).on(settings.endevent, function (e) {
+ $this.data('callee2', arguments.callee);
+
+ // Only trigger if they've started, and the target matches:
+ var end_x = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY,
+ diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y),
+ eventName;
+
+ if (origTarget == e.target && started && ((Date.now() - start_time) < settings.taphold_threshold) && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ var origEvent = e.originalEvent;
+ var touchData = [ ];
+
+ for( var i = 0; i < touches.length; i++)
+ {
+ var touch = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[i].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[i].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[i].pageX - origEvent.changedTouches[i].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[i].pageY - origEvent.changedTouches[i].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ touchData.push( touch );
+ }
+
+ switch( touches.length )
+ {
+ case 1:
+ eventName = 'tap';
+ break;
+
+ case 2:
+ eventName = 'tap2';
+ break;
+
+ case 3:
+ eventName = 'tap3';
+ break;
+
+ case 4:
+ eventName = 'tap4';
+ break;
+ }
+
+ triggerCustomEvent(thisObject, eventName, e, touchData);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // swipe Event (also handles swipeup, swiperight, swipedown and swipeleft):
+ $.event.special.swipe = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ hasSwiped = false,
+ originalCoord = {
+ x: 0,
+ y: 0
+ },
+ finalCoord = {
+ x: 0,
+ y: 0
+ },
+ startEvnt;
+
+ // Screen touched, store the original coordinate
+
+ function touchStart(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee1', arguments.callee);
+ originalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ originalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ finalCoord.x = originalCoord.x;
+ finalCoord.y = originalCoord.y;
+ started = true;
+ var origEvent = e.originalEvent;
+ // Read event data into our startEvt:
+ startEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ }
+
+ // Store coordinates as finger is swiping
+
+ function touchMove(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee2', arguments.callee);
+ finalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ finalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ var swipedir;
+
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = ($this.parent().data('xthreshold')) ? $this.parent().data('xthreshold') : $this.data('xthreshold'),
+ ele_y_threshold = ($this.parent().data('ythreshold')) ? $this.parent().data('ythreshold') : $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ if (originalCoord.y > finalCoord.y && (originalCoord.y - finalCoord.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (originalCoord.x < finalCoord.x && (finalCoord.x - originalCoord.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (originalCoord.y < finalCoord.y && (finalCoord.y - originalCoord.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (originalCoord.x > finalCoord.x && (originalCoord.x - finalCoord.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+ if (swipedir != undefined && started) {
+ originalCoord.x = 0;
+ originalCoord.y = 0;
+ finalCoord.x = 0;
+ finalCoord.y = 0;
+ started = false;
+
+ // Read event data into our endEvnt:
+ var origEvent = e.originalEvent;
+ endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ }
+ hasSwiped = true;
+ $this.trigger('swipe', touchData).trigger(swipedir, touchData);
+ }
+ }
+
+ function touchEnd(e) {
+ $this = $(e.currentTarget);
+ var swipedir = "";
+ $this.data('callee3', arguments.callee);
+ if (hasSwiped) {
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = $this.data('xthreshold'),
+ ele_y_threshold = $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ var origEvent = e.originalEvent;
+ endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX - origEvent.changedTouches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY - origEvent.changedTouches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Read event data into our endEvnt:
+ if (startEvnt.position.y > endEvnt.position.y && (startEvnt.position.y - endEvnt.position.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (startEvnt.position.x < endEvnt.position.x && (endEvnt.position.x - startEvnt.position.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (startEvnt.position.y < endEvnt.position.y && (endEvnt.position.y - startEvnt.position.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (startEvnt.position.x > endEvnt.position.x && (startEvnt.position.x - endEvnt.position.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ }
+ $this.trigger('swipeend', touchData);
+ }
+
+ started = false;
+ hasSwiped = false;
+ }
+
+ $this.on(settings.startevent, touchStart);
+ $this.on(settings.moveevent, touchMove);
+ $this.on(settings.endevent, touchEnd);
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.moveevent, $(this).data.callee2).off(settings.endevent, $(this).data.callee3);
+ }
+ };
+
+ // scrollstart Event (also handles scrollend):
+ $.event.special.scrollstart = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ scrolling,
+ timer;
+
+ function trigger(event, state) {
+ scrolling = state;
+ triggerCustomEvent(thisObject, scrolling ? 'scrollstart' : 'scrollend', event);
+ }
+
+ // iPhone triggers scroll after a small delay; use touchmove instead
+ $this.on(settings.scrollevent, function (event) {
+ $this.data('callee', arguments.callee);
+
+ if (!scrolling) {
+ trigger(event, true);
+ }
+
+ clearTimeout(timer);
+ timer = setTimeout(function () {
+ trigger(event, false);
+ }, 50);
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.scrollevent, $(this).data.callee);
+ }
+ };
+
+ // This is the orientation change (largely borrowed from jQuery Mobile):
+ var win = $(window),
+ special_event,
+ get_orientation,
+ last_orientation,
+ initial_orientation_is_landscape,
+ initial_orientation_is_default,
+ portrait_map = {
+ '0': true,
+ '180': true
+ };
+
+ if (settings.orientation_support) {
+ var ww = window.innerWidth || win.width(),
+ wh = window.innerHeight || win.height(),
+ landscape_threshold = 50;
+
+ initial_orientation_is_landscape = ww > wh && (ww - wh) > landscape_threshold;
+ initial_orientation_is_default = portrait_map[window.orientation];
+
+ if ((initial_orientation_is_landscape && initial_orientation_is_default) || (!initial_orientation_is_landscape && !initial_orientation_is_default)) {
+ portrait_map = {
+ '-90': true,
+ '90': true
+ };
+ }
+ }
+
+ $.event.special.orientationchange = special_event = {
+ setup: function () {
+ // If the event is supported natively, return false so that jQuery
+ // will on to the event using DOM methods.
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ // Get the current orientation to avoid initial double-triggering.
+ last_orientation = get_orientation();
+
+ win.on('throttledresize', handler);
+ return true;
+ },
+ teardown: function () {
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ win.off('throttledresize', handler);
+ return true;
+ },
+ add: function (handleObj) {
+ // Save a reference to the bound event handler.
+ var old_handler = handleObj.handler;
+
+ handleObj.handler = function (event) {
+ event.orientation = get_orientation();
+ return old_handler.apply(this, arguments);
+ };
+ }
+ };
+
+ // If the event is not supported natively, this handler will be bound to
+ // the window resize event to simulate the orientationchange event.
+
+ function handler() {
+ // Get the current orientation.
+ var orientation = get_orientation();
+
+ if (orientation !== last_orientation) {
+ // The orientation has changed, so trigger the orientationchange event.
+ last_orientation = orientation;
+ win.trigger("orientationchange");
+ }
+ }
+
+ $.event.special.orientationchange.orientation = get_orientation = function () {
+ var isPortrait = true,
+ elem = document.documentElement;
+
+ if (settings.orientation_support) {
+ isPortrait = portrait_map[window.orientation];
+ } else {
+ isPortrait = elem && elem.clientWidth / elem.clientHeight < 1.1;
+ }
+
+ return isPortrait ? 'portrait' : 'landscape';
+ };
+
+ // throttle Handler:
+ $.event.special.throttledresize = {
+ setup: function () {
+ $(this).on('resize', throttle_handler);
+ },
+ teardown: function () {
+ $(this).off('resize', throttle_handler);
+ }
+ };
+
+ var throttle = 250,
+ throttle_handler = function () {
+ curr = Date.now();
+ diff = curr - lastCall;
+
+ if (diff >= throttle) {
+ lastCall = curr;
+ $(this).trigger('throttledresize');
+
+ } else {
+ if (heldCall) {
+ window.clearTimeout(heldCall);
+ }
+
+ // Promise a held call will still execute
+ heldCall = window.setTimeout(handler, throttle - diff);
+ }
+ },
+ lastCall = 0,
+ heldCall,
+ curr,
+ diff;
+
+ // Trigger a custom event:
+
+ function triggerCustomEvent(obj, eventType, event, touchData) {
+ var originalType = event.type;
+ event.type = eventType;
+
+ $.event.dispatch.call(obj, event, touchData);
+ event.type = originalType;
+ }
+
+ // Correctly on anything we've overloaded:
+ $.each({
+ scrollend: 'scrollstart',
+ swipeup: 'swipe',
+ swiperight: 'swipe',
+ swipedown: 'swipe',
+ swipeleft: 'swipe',
+ swipeend: 'swipe',
+ tap2: 'tap'
+ }, function (e, srcE, touchData) {
+ $.event.special[e] = {
+ setup: function () {
+ $(this).on(srcE, $.noop);
+ }
+ };
+ });
+
+})(jQuery);
diff --git a/src/1.0.0/jquery.mobile-events.min.js b/src/1.0.0/jquery.mobile-events.min.js
new file mode 100644
index 0000000..63b10c9
--- /dev/null
+++ b/src/1.0.0/jquery.mobile-events.min.js
@@ -0,0 +1 @@
+!function(e){function t(){var e=c();e!==r&&(r=e,l.trigger("orientationchange"))}function a(t,a,n,o){var i=n.type;n.type=a,e.event.dispatch.call(t,n,o),n.type=i}e.attrFn=e.attrFn||{};var n=navigator.userAgent.toLowerCase(),o=n.indexOf("chrome")>-1&&(n.indexOf("windows")>-1||n.indexOf("macintosh")>-1||n.indexOf("linux")>-1)&&n.indexOf("mobile")<0&&n.indexOf("android")<0,i={tap_pixel_range:5,swipe_h_threshold:50,swipe_v_threshold:50,taphold_threshold:750,doubletap_int:500,touch_capable:"ontouchstart"in window&&!o,orientation_support:"orientation"in window&&"onorientationchange"in window,startevent:"ontouchstart"in window&&!o?"touchstart":"mousedown",endevent:"ontouchstart"in window&&!o?"touchend":"mouseup",moveevent:"ontouchstart"in window&&!o?"touchmove":"mousemove",tapevent:"ontouchstart"in window&&!o?"tap":"click",scrollevent:"ontouchstart"in window&&!o?"touchmove":"scroll",hold_timer:null,tap_timer:null};e.isTouchCapable=function(){return i.touch_capable},e.getStartEvent=function(){return i.startevent},e.getEndEvent=function(){return i.endevent},e.getMoveEvent=function(){return i.moveevent},e.getTapEvent=function(){return i.tapevent},e.getScrollEvent=function(){return i.scrollevent},e.each(["tapstart","tapend","tapmove","tap","tap2","tap3","tap4","singletap","doubletap","taphold","swipe","swipeup","swiperight","swipedown","swipeleft","swipeend","scrollstart","scrollend","orientationchange"],function(t,a){e.fn[a]=function(e){return e?this.on(a,e):this.trigger(a)},e.attrFn[a]=!0}),e.event.special.tapstart={setup:function(){var t=this,n=e(t);n.on(i.startevent,function(e){if(n.data("callee",arguments.callee),e.which&&1!==e.which)return!1;var o=e.originalEvent,s={position:{x:i.touch_capable?o.touches[0].screenX:e.screenX,y:i.touch_capable?o.touches[0].screenY:e.screenY},offset:{x:i.touch_capable?o.touches[0].pageX-o.touches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?o.touches[0].pageY-o.touches[0].target.offsetTop:e.offsetY},time:Date.now(),target:e.target};return a(t,"tapstart",e,s),!0})},remove:function(){e(this).off(i.startevent,e(this).data.callee)}},e.event.special.tapmove={setup:function(){var t=this,n=e(t);n.on(i.moveevent,function(e){n.data("callee",arguments.callee);var o=e.originalEvent,s={position:{x:i.touch_capable?o.touches[0].screenX:e.screenX,y:i.touch_capable?o.touches[0].screenY:e.screenY},offset:{x:i.touch_capable?o.touches[0].pageX-o.touches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?o.touches[0].pageY-o.touches[0].target.offsetTop:e.offsetY},time:Date.now(),target:e.target};return a(t,"tapmove",e,s),!0})},remove:function(){e(this).off(i.moveevent,e(this).data.callee)}},e.event.special.tapend={setup:function(){var t=this,n=e(t);n.on(i.endevent,function(e){n.data("callee",arguments.callee);var o=e.originalEvent,s={position:{x:i.touch_capable?o.changedTouches[0].screenX:e.screenX,y:i.touch_capable?o.changedTouches[0].screenY:e.screenY},offset:{x:i.touch_capable?o.changedTouches[0].pageX-o.changedTouches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?o.changedTouches[0].pageY-o.changedTouches[0].target.offsetTop:e.offsetY},time:Date.now(),target:e.target};return a(t,"tapend",e,s),!0})},remove:function(){e(this).off(i.endevent,e(this).data.callee)}},e.event.special.taphold={setup:function(){var t,n=this,o=e(n),s={x:0,y:0},c=0,r=0;o.on(i.startevent,function(e){if(e.which&&1!==e.which)return!1;o.data("tapheld",!1),t=e.target;var h=e.originalEvent,u=Date.now(),l={x:i.touch_capable?h.touches[0].screenX:e.screenX,y:i.touch_capable?h.touches[0].screenY:e.screenY},p={x:i.touch_capable?h.touches[0].pageX-h.touches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?h.touches[0].pageY-h.touches[0].target.offsetTop:e.offsetY};return s.x=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageX:e.pageX,s.y=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageY:e.pageY,c=s.x,r=s.y,i.hold_timer=window.setTimeout(function(){var g=s.x-c,f=s.y-r;if(e.target==t&&(s.x==c&&s.y==r||g>=-i.tap_pixel_range&&g<=i.tap_pixel_range&&f>=-i.tap_pixel_range&&f<=i.tap_pixel_range)){o.data("tapheld",!0);var d=Date.now(),v={x:i.touch_capable?h.touches[0].screenX:e.screenX,y:i.touch_capable?h.touches[0].screenY:e.screenY},w={x:i.touch_capable?h.touches[0].pageX-h.touches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?h.touches[0].pageY-h.touches[0].target.offsetTop:e.offsetY};duration=d-u;var _={startTime:u,endTime:d,startPosition:l,startOffset:p,endPosition:v,endOffset:w,duration:duration,target:e.target};o.data("callee1",arguments.callee),a(n,"taphold",e,_)}},i.taphold_threshold),!0}).on(i.endevent,function(){o.data("callee2",arguments.callee),o.data("tapheld",!1),window.clearTimeout(i.hold_timer)}).on(i.moveevent,function(e){o.data("callee3",arguments.callee),c=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageX:e.pageX,r=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageY:e.pageY})},remove:function(){e(this).off(i.startevent,e(this).data.callee1).off(i.endevent,e(this).data.callee2).off(i.moveevent,e(this).data.callee3)}},e.event.special.doubletap={setup:function(){var t,n,o,s,c,r=this,h=e(r),u=!1;h.on(i.startevent,function(e){return e.which&&1!==e.which?!1:(h.data("doubletapped",!1),t=e.target,h.data("callee1",arguments.callee),s=e.originalEvent,o={position:{x:i.touch_capable?s.touches[0].screenX:e.screenX,y:i.touch_capable?s.touches[0].screenY:e.screenY},offset:{x:i.touch_capable?s.touches[0].pageX-s.touches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?s.touches[0].pageY-s.touches[0].target.offsetTop:e.offsetY},time:Date.now(),target:e.target},!0)}).on(i.endevent,function(e){var s=Date.now(),l=h.data("lastTouch")||s+1,p=s-l;if(window.clearTimeout(n),h.data("callee2",arguments.callee),p100){h.data("doubletapped",!0),window.clearTimeout(i.tap_timer);var g={position:{x:i.touch_capable?e.originalEvent.changedTouches[0].screenX:e.screenX,y:i.touch_capable?e.originalEvent.changedTouches[0].screenY:e.screenY},offset:{x:i.touch_capable?e.originalEvent.changedTouches[0].pageX-e.originalEvent.changedTouches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?e.originalEvent.changedTouches[0].pageY-e.originalEvent.changedTouches[0].target.offsetTop:e.offsetY},time:Date.now(),target:e.target},f={firstTap:o,secondTap:g,interval:g.time-o.time};u||a(r,"doubletap",e,f),u=!0,c=window.setTimeout(function(){u=!1},i.doubletap_int)}else h.data("lastTouch",s),n=window.setTimeout(function(){window.clearTimeout(n)},i.doubletap_int,[e]);h.data("lastTouch",s)})},remove:function(){e(this).off(i.startevent,e(this).data.callee1).off(i.endevent,e(this).data.callee2)}},e.event.special.singletap={setup:function(){var t=this,n=e(t),o=null,s=null,c={x:0,y:0};n.on(i.startevent,function(e){return e.which&&1!==e.which?!1:(s=Date.now(),o=e.target,n.data("callee1",arguments.callee),c.x=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageX:e.pageX,c.y=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageY:e.pageY,!0)}).on(i.endevent,function(e){n.data("callee2",arguments.callee),e.target==o&&(end_pos_x=e.originalEvent.changedTouches?e.originalEvent.changedTouches[0].pageX:e.pageX,end_pos_y=e.originalEvent.changedTouches?e.originalEvent.changedTouches[0].pageY:e.pageY,i.tap_timer=window.setTimeout(function(){if(!n.data("doubletapped")&&!n.data("tapheld")&&c.x==end_pos_x&&c.y==end_pos_y){var o=e.originalEvent,r={position:{x:i.touch_capable?o.changedTouches[0].screenX:e.screenX,y:i.touch_capable?o.changedTouches[0].screenY:e.screenY},offset:{x:i.touch_capable?o.changedTouches[0].pageX-o.changedTouches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?o.changedTouches[0].pageY-o.changedTouches[0].target.offsetTop:e.offsetY},time:Date.now(),target:e.target};r.time-s=-i.tap_pixel_range&&g<=i.tap_pixel_range&&f>=-i.tap_pixel_range&&f<=i.tap_pixel_range)){for(var d=e.originalEvent,v=[],w=0;wl.y&&u.y-l.y>g&&(a="swipeup"),u.xp&&(a="swiperight"),u.yg&&(a="swipedown"),u.x>l.x&&u.x-l.x>p&&(a="swipeleft"),void 0!=a&&r){u.x=0,u.y=0,l.x=0,l.y=0,r=!1;var f=t.originalEvent;endEvnt={position:{x:i.touch_capable?f.touches[0].screenX:t.screenX,y:i.touch_capable?f.touches[0].screenY:t.screenY},offset:{x:i.touch_capable?f.touches[0].pageX-f.touches[0].target.offsetLeft:t.offsetX,y:i.touch_capable?f.touches[0].pageY-f.touches[0].target.offsetTop:t.offsetY},time:Date.now(),target:t.target};var d=Math.abs(o.position.x-endEvnt.position.x),v=Math.abs(o.position.y-endEvnt.position.y),w={startEvnt:o,endEvnt:endEvnt,direction:a.replace("swipe",""),xAmount:d,yAmount:v,duration:endEvnt.time-o.time};h=!0,c.trigger("swipe",w).trigger(a,w)}}function n(t){c=e(t.currentTarget);var a="";if(c.data("callee3",arguments.callee),h){var n=c.data("xthreshold"),s=c.data("ythreshold"),u="undefined"!=typeof n&&n!==!1&&parseInt(n)?parseInt(n):i.swipe_h_threshold,l="undefined"!=typeof s&&s!==!1&&parseInt(s)?parseInt(s):i.swipe_v_threshold,p=t.originalEvent;endEvnt={position:{x:i.touch_capable?p.changedTouches[0].screenX:t.screenX,y:i.touch_capable?p.changedTouches[0].screenY:t.screenY},offset:{x:i.touch_capable?p.changedTouches[0].pageX-p.changedTouches[0].target.offsetLeft:t.offsetX,y:i.touch_capable?p.changedTouches[0].pageY-p.changedTouches[0].target.offsetTop:t.offsetY},time:Date.now(),target:t.target},o.position.y>endEvnt.position.y&&o.position.y-endEvnt.position.y>l&&(a="swipeup"),o.position.xu&&(a="swiperight"),o.position.yl&&(a="swipedown"),o.position.x>endEvnt.position.x&&o.position.x-endEvnt.position.x>u&&(a="swipeleft");var g=Math.abs(o.position.x-endEvnt.position.x),f=Math.abs(o.position.y-endEvnt.position.y),d={startEvnt:o,endEvnt:endEvnt,direction:a.replace("swipe",""),xAmount:g,yAmount:f,duration:endEvnt.time-o.time};c.trigger("swipeend",d)}r=!1,h=!1}var o,s=this,c=e(s),r=!1,h=!1,u={x:0,y:0},l={x:0,y:0};c.on(i.startevent,t),c.on(i.moveevent,a),c.on(i.endevent,n)},remove:function(){e(this).off(i.startevent,e(this).data.callee1).off(i.moveevent,e(this).data.callee2).off(i.endevent,e(this).data.callee3)}},e.event.special.scrollstart={setup:function(){function t(e,t){n=t,a(s,n?"scrollstart":"scrollend",e)}var n,o,s=this,c=e(s);c.on(i.scrollevent,function(e){c.data("callee",arguments.callee),n||t(e,!0),clearTimeout(o),o=setTimeout(function(){t(e,!1)},50)})},remove:function(){e(this).off(i.scrollevent,e(this).data.callee)}};var s,c,r,h,u,l=e(window),p={0:!0,180:!0};if(i.orientation_support){var g=window.innerWidth||l.width(),f=window.innerHeight||l.height(),d=50;h=g>f&&g-f>d,u=p[window.orientation],(h&&u||!h&&!u)&&(p={"-90":!0,90:!0})}e.event.special.orientationchange=s={setup:function(){return i.orientation_support?!1:(r=c(),l.on("throttledresize",t),!0)},teardown:function(){return i.orientation_support?!1:(l.off("throttledresize",t),!0)},add:function(e){var t=e.handler;e.handler=function(e){return e.orientation=c(),t.apply(this,arguments)}}},e.event.special.orientationchange.orientation=c=function(){var e=!0,t=document.documentElement;return e=i.orientation_support?p[window.orientation]:t&&t.clientWidth/t.clientHeight<1.1,e?"portrait":"landscape"},e.event.special.throttledresize={setup:function(){e(this).on("resize",m)},teardown:function(){e(this).off("resize",m)}};var v,w,_,T=250,m=function(){w=Date.now(),_=w-x,_>=T?(x=w,e(this).trigger("throttledresize")):(v&&window.clearTimeout(v),v=window.setTimeout(t,T-_))},x=0;e.each({scrollend:"scrollstart",swipeup:"swipe",swiperight:"swipe",swipedown:"swipe",swipeleft:"swipe",swipeend:"swipe",tap2:"tap"},function(t,a){e.event.special[t]={setup:function(){e(this).on(a,e.noop)}}})}(jQuery);
diff --git a/src/1.0.1/bower.json b/src/1.0.1/bower.json
new file mode 100644
index 0000000..bfd2e4d
--- /dev/null
+++ b/src/1.0.1/bower.json
@@ -0,0 +1,11 @@
+{
+ "name": "jquery-touch-events",
+ "version": "1.0.1",
+ "main": "src/jquery.mobile-events.js",
+ "ignore": [
+ "bower.json"
+ ],
+ "dependencies": {
+ "jquery": ">=1.7.0"
+ }
+}
diff --git a/src/1.0.1/jquery.mobile-events.js b/src/1.0.1/jquery.mobile-events.js
new file mode 100644
index 0000000..ac1b00c
--- /dev/null
+++ b/src/1.0.1/jquery.mobile-events.js
@@ -0,0 +1,882 @@
+/*!
+ * jQuery Mobile Events
+ * by Ben Major (www.ben-major.co.uk)
+ *
+ * Copyright 2011, Ben Major
+ * Licensed under the MIT License:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+(function ($) {
+ $.attrFn = $.attrFn || {};
+
+ // navigator.userAgent.toLowerCase() isn't reliable for Chrome installs
+ // on mobile devices. As such, we will create a boolean isChromeDesktop
+ // The reason that we need to do this is because Chrome annoyingly
+ // purports support for touch events even if the underlying hardware
+ // does not!
+ var agent = navigator.userAgent.toLowerCase(),
+ isChromeDesktop = (agent.indexOf('chrome') > -1 && ((agent.indexOf('windows') > -1) || (agent.indexOf('macintosh') > -1) || (agent.indexOf('linux') > -1)) && agent.indexOf('mobile') < 0 && agent.indexOf('android') < 0),
+
+ settings = {
+ tap_pixel_range: 5,
+ swipe_h_threshold: 50,
+ swipe_v_threshold: 50,
+ taphold_threshold: 750,
+ doubletap_int: 500,
+
+ touch_capable: (window.navigator.msPointerEnabled) ? false : ('ontouchstart' in window && !isChromeDesktop),
+ orientation_support: ('orientation' in window && 'onorientationchange' in window),
+
+ startevent: (window.navigator.msPointerEnabled) ? 'MSPointerDown' : (('ontouchstart' in window && !isChromeDesktop) ? 'touchstart' : 'mousedown'),
+ endevent: (window.navigator.msPointerEnabled) ? 'MSPointerUp' : (('ontouchstart' in window && !isChromeDesktop) ? 'touchend' : 'mouseup'),
+ moveevent: (window.navigator.msPointerEnabled) ? 'MSPointerMove' : (('ontouchstart' in window && !isChromeDesktop) ? 'touchmove' : 'mousemove'),
+ tapevent: ('ontouchstart' in window && !isChromeDesktop) ? 'tap' : 'click',
+ scrollevent: ('ontouchstart' in window && !isChromeDesktop) ? 'touchmove' : 'scroll',
+
+ hold_timer: null,
+ tap_timer: null
+ };
+
+ // Convenience functions:
+ $.isTouchCapable = function() { return settings.touch_capable; };
+ $.getStartEvent = function() { return settings.startevent; };
+ $.getEndEvent = function() { return settings.endevent; };
+ $.getMoveEvent = function() { return settings.moveevent; };
+ $.getTapEvent = function() { return settings.tapevent; };
+ $.getScrollEvent = function() { return settings.scrollevent; };
+
+ // Add Event shortcuts:
+ $.each(['tapstart', 'tapend', 'tapmove', 'tap', 'tap2', 'tap3', 'tap4', 'singletap', 'doubletap', 'taphold', 'swipe', 'swipeup', 'swiperight', 'swipedown', 'swipeleft', 'swipeend', 'scrollstart', 'scrollend', 'orientationchange'], function (i, name) {
+ $.fn[name] = function (fn) {
+ return fn ? this.on(name, fn) : this.trigger(name);
+ };
+
+ $.attrFn[name] = true;
+ });
+
+ // tapstart Event:
+ $.event.special.tapstart = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.startevent, function (e) {
+ $this.data('callee', arguments.callee);
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapstart', e, touchData);
+ return true;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee);
+ }
+ };
+
+ // tapmove Event:
+ $.event.special.tapmove = {
+ setup: function() {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.moveevent, function(e) {
+ $this.data('callee', arguments.callee);
+
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapmove', e, touchData);
+ return true;
+ });
+ },
+ remove: function() {
+ $(this).off(settings.moveevent, $(this).data.callee);
+ }
+ }
+
+ // tapend Event:
+ $.event.special.tapend = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.endevent, function (e) {
+ // Touch event data:
+ $this.data('callee', arguments.callee);
+
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX - origEvent.changedTouches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY - origEvent.changedTouches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ triggerCustomEvent(thisObject, 'tapend', e, touchData);
+ return true;
+ });
+ },
+ remove: function () {
+ $(this).off(settings.endevent, $(this).data.callee);
+ }
+ };
+
+ // taphold Event:
+ $.event.special.taphold = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ timer,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ end_x = 0,
+ end_y = 0;
+
+ $this.on(settings.startevent, function (e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ $this.data('tapheld', false);
+ origTarget = e.target;
+
+ var origEvent = e.originalEvent;
+ var start_time = Date.now(),
+ startPosition = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ startOffset = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ };
+
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ end_x = start_pos.x;
+ end_y = start_pos.y;
+
+ settings.hold_timer = window.setTimeout(function () {
+
+ var diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y);
+
+ if (e.target == origTarget && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ $this.data('tapheld', true);
+
+ var end_time = Date.now(),
+ endPosition = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ endOffset = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ };
+ duration = end_time - start_time;
+
+ // Build the touch data:
+ var touchData = {
+ 'startTime': start_time,
+ 'endTime': end_time,
+ 'startPosition': startPosition,
+ 'startOffset': startOffset,
+ 'endPosition': endPosition,
+ 'endOffset': endOffset,
+ 'duration': duration,
+ 'target': e.target
+ }
+ $this.data('callee1', arguments.callee);
+ triggerCustomEvent(thisObject, 'taphold', e, touchData);
+ }
+ }, settings.taphold_threshold);
+
+ return true;
+ }
+ }).on(settings.endevent, function () {
+ $this.data('callee2', arguments.callee);
+ $this.data('tapheld', false);
+ window.clearTimeout(settings.hold_timer);
+ })
+ .on(settings.moveevent, function (e) {
+ $this.data('callee3', arguments.callee);
+
+ end_x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2).off(settings.moveevent, $(this).data.callee3);
+ }
+ };
+
+ // doubletap Event:
+ $.event.special.doubletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ action,
+ firstTap,
+ origEvent,
+ cooloff,
+ cooling = false;
+
+ $this.on(settings.startevent, function (e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+ $this.data('doubletapped', false);
+ origTarget = e.target;
+ $this.data('callee1', arguments.callee);
+
+ origEvent = e.originalEvent;
+ firstTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ return true;
+ }).on(settings.endevent, function (e) {
+
+ var now = Date.now();
+ var lastTouch = $this.data('lastTouch') || now + 1;
+ var delta = now - lastTouch;
+ window.clearTimeout(action);
+ $this.data('callee2', arguments.callee);
+
+ if (delta < settings.doubletap_int && (e.target == origTarget) && delta > 100) {
+ $this.data('doubletapped', true);
+ window.clearTimeout(settings.tap_timer);
+
+ // Now get the current event:
+ var lastTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? e.originalEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? e.originalEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? e.originalEvent.changedTouches[0].pageX - e.originalEvent.changedTouches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? e.originalEvent.changedTouches[0].pageY - e.originalEvent.changedTouches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ }
+
+ var touchData = {
+ 'firstTap': firstTap,
+ 'secondTap': lastTap,
+ 'interval': lastTap.time - firstTap.time
+ };
+
+ if (!cooling) {
+ triggerCustomEvent(thisObject, 'doubletap', e, touchData);
+ }
+
+ cooling = true;
+
+ cooloff = window.setTimeout(function (e) {
+ cooling = false;
+ }, settings.doubletap_int);
+
+ } else {
+ $this.data('lastTouch', now);
+ action = window.setTimeout(function (e) {
+ window.clearTimeout(action);
+ }, settings.doubletap_int, [e]);
+ }
+ $this.data('lastTouch', now);
+ });
+ },
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // singletap Event:
+ // This is used in conjuction with doubletap when both events are needed on the same element
+ $.event.special.singletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget = null,
+ startTime = null,
+ start_pos = {
+ x: 0,
+ y: 0
+ };
+
+ $this.on(settings.startevent, function (e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ startTime = Date.now();
+ origTarget = e.target;
+ $this.data('callee1', arguments.callee);
+
+ // Get the start x and y position:
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ return true;
+ }
+ }).on(settings.endevent, function (e) {
+ $this.data('callee2', arguments.callee);
+ if (e.target == origTarget) {
+ // Get the end point:
+ end_pos_x = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX;
+ end_pos_y = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY;
+
+ // We need to check if it was a taphold:
+
+ settings.tap_timer = window.setTimeout(function () {
+ if (!$this.data('doubletapped') && !$this.data('tapheld') && (start_pos.x == end_pos_x) && (start_pos.y == end_pos_y)) {
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX - origEvent.changedTouches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY - origEvent.changedTouches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Was it a taphold?
+ if((touchData.time - startTime) < settings.taphold_threshold)
+ {
+ triggerCustomEvent(thisObject, 'singletap', e, touchData);
+ }
+ }
+ }, settings.doubletap_int);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // tap Event:
+ $.event.special.tap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ origTarget = null,
+ start_time,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ touches;
+
+ $this.on(settings.startevent, function (e) {
+ $this.data('callee1', arguments.callee);
+
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ started = true;
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ start_time = Date.now();
+ origTarget = e.target;
+
+ touches = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches : [ e ];
+ return true;
+ }
+ }).on(settings.endevent, function (e) {
+ $this.data('callee2', arguments.callee);
+
+ // Only trigger if they've started, and the target matches:
+ var end_x = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY,
+ diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y),
+ eventName;
+
+ if (origTarget == e.target && started && ((Date.now() - start_time) < settings.taphold_threshold) && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ var origEvent = e.originalEvent;
+ var touchData = [ ];
+
+ for( var i = 0; i < touches.length; i++)
+ {
+ var touch = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[i].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[i].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[i].pageX - origEvent.changedTouches[i].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[i].pageY - origEvent.changedTouches[i].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ touchData.push( touch );
+ }
+
+ switch( touches.length )
+ {
+ case 1:
+ eventName = 'tap';
+ break;
+
+ case 2:
+ eventName = 'tap2';
+ break;
+
+ case 3:
+ eventName = 'tap3';
+ break;
+
+ case 4:
+ eventName = 'tap4';
+ break;
+ }
+
+ triggerCustomEvent(thisObject, eventName, e, touchData);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // swipe Event (also handles swipeup, swiperight, swipedown and swipeleft):
+ $.event.special.swipe = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ hasSwiped = false,
+ originalCoord = {
+ x: 0,
+ y: 0
+ },
+ finalCoord = {
+ x: 0,
+ y: 0
+ },
+ startEvnt;
+
+ // Screen touched, store the original coordinate
+
+ function touchStart(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee1', arguments.callee);
+ originalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ originalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ finalCoord.x = originalCoord.x;
+ finalCoord.y = originalCoord.y;
+ started = true;
+ var origEvent = e.originalEvent;
+ // Read event data into our startEvt:
+ startEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target,
+ 'identifier': origEvent.touches && origEvent.touches[0].identifier
+ };
+ }
+
+ // Store coordinates as finger is swiping
+
+ function touchMove(e) {
+ if (e.originalEvent.changedTouches && e.originalEvent.changedTouches && e.originalEvent.changedTouches[0].identifier !== startEvnt.identifier) {
+ return;
+ }
+ $this = $(e.currentTarget);
+ $this.data('callee2', arguments.callee);
+ finalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ finalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ var swipedir;
+
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = ($this.parent().data('xthreshold')) ? $this.parent().data('xthreshold') : $this.data('xthreshold'),
+ ele_y_threshold = ($this.parent().data('ythreshold')) ? $this.parent().data('ythreshold') : $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ if (originalCoord.y > finalCoord.y && (originalCoord.y - finalCoord.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (originalCoord.x < finalCoord.x && (finalCoord.x - originalCoord.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (originalCoord.y < finalCoord.y && (finalCoord.y - originalCoord.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (originalCoord.x > finalCoord.x && (originalCoord.x - finalCoord.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+ if (swipedir != undefined && started) {
+ originalCoord.x = 0;
+ originalCoord.y = 0;
+ finalCoord.x = 0;
+ finalCoord.y = 0;
+ started = false;
+
+ // Read event data into our endEvnt:
+ var origEvent = e.originalEvent;
+ endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ }
+ hasSwiped = true;
+ $this.trigger('swipe', touchData).trigger(swipedir, touchData);
+ }
+ }
+
+ function touchEnd(e) {
+ if (e.originalEvent.changedTouches && e.originalEvent.changedTouches[0].identifier !== startEvnt.identifier) {
+ return;
+ }
+ $this = $(e.currentTarget);
+ var swipedir = "";
+ $this.data('callee3', arguments.callee);
+ if (hasSwiped) {
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = $this.data('xthreshold'),
+ ele_y_threshold = $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ var origEvent = e.originalEvent;
+ endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX - origEvent.changedTouches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY - origEvent.changedTouches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Read event data into our endEvnt:
+ if (startEvnt.position.y > endEvnt.position.y && (startEvnt.position.y - endEvnt.position.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (startEvnt.position.x < endEvnt.position.x && (endEvnt.position.x - startEvnt.position.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (startEvnt.position.y < endEvnt.position.y && (endEvnt.position.y - startEvnt.position.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (startEvnt.position.x > endEvnt.position.x && (startEvnt.position.x - endEvnt.position.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ }
+ $this.trigger('swipeend', touchData);
+ }
+
+ started = false;
+ hasSwiped = false;
+ }
+
+ $this.on(settings.startevent, touchStart);
+ $this.on(settings.moveevent, touchMove);
+ $this.on(settings.endevent, touchEnd);
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.moveevent, $(this).data.callee2).off(settings.endevent, $(this).data.callee3);
+ }
+ };
+
+ // scrollstart Event (also handles scrollend):
+ $.event.special.scrollstart = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ scrolling,
+ timer;
+
+ function trigger(event, state) {
+ scrolling = state;
+ triggerCustomEvent(thisObject, scrolling ? 'scrollstart' : 'scrollend', event);
+ }
+
+ // iPhone triggers scroll after a small delay; use touchmove instead
+ $this.on(settings.scrollevent, function (event) {
+ $this.data('callee', arguments.callee);
+
+ if (!scrolling) {
+ trigger(event, true);
+ }
+
+ clearTimeout(timer);
+ timer = setTimeout(function () {
+ trigger(event, false);
+ }, 50);
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.scrollevent, $(this).data.callee);
+ }
+ };
+
+ // This is the orientation change (largely borrowed from jQuery Mobile):
+ var win = $(window),
+ special_event,
+ get_orientation,
+ last_orientation,
+ initial_orientation_is_landscape,
+ initial_orientation_is_default,
+ portrait_map = {
+ '0': true,
+ '180': true
+ };
+
+ if (settings.orientation_support) {
+ var ww = window.innerWidth || win.width(),
+ wh = window.innerHeight || win.height(),
+ landscape_threshold = 50;
+
+ initial_orientation_is_landscape = ww > wh && (ww - wh) > landscape_threshold;
+ initial_orientation_is_default = portrait_map[window.orientation];
+
+ if ((initial_orientation_is_landscape && initial_orientation_is_default) || (!initial_orientation_is_landscape && !initial_orientation_is_default)) {
+ portrait_map = {
+ '-90': true,
+ '90': true
+ };
+ }
+ }
+
+ $.event.special.orientationchange = special_event = {
+ setup: function () {
+ // If the event is supported natively, return false so that jQuery
+ // will on to the event using DOM methods.
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ // Get the current orientation to avoid initial double-triggering.
+ last_orientation = get_orientation();
+
+ win.on('throttledresize', handler);
+ return true;
+ },
+ teardown: function () {
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ win.off('throttledresize', handler);
+ return true;
+ },
+ add: function (handleObj) {
+ // Save a reference to the bound event handler.
+ var old_handler = handleObj.handler;
+
+ handleObj.handler = function (event) {
+ event.orientation = get_orientation();
+ return old_handler.apply(this, arguments);
+ };
+ }
+ };
+
+ // If the event is not supported natively, this handler will be bound to
+ // the window resize event to simulate the orientationchange event.
+
+ function handler() {
+ // Get the current orientation.
+ var orientation = get_orientation();
+
+ if (orientation !== last_orientation) {
+ // The orientation has changed, so trigger the orientationchange event.
+ last_orientation = orientation;
+ win.trigger("orientationchange");
+ }
+ }
+
+ $.event.special.orientationchange.orientation = get_orientation = function () {
+ var isPortrait = true,
+ elem = document.documentElement;
+
+ if (settings.orientation_support) {
+ isPortrait = portrait_map[window.orientation];
+ } else {
+ isPortrait = elem && elem.clientWidth / elem.clientHeight < 1.1;
+ }
+
+ return isPortrait ? 'portrait' : 'landscape';
+ };
+
+ // throttle Handler:
+ $.event.special.throttledresize = {
+ setup: function () {
+ $(this).on('resize', throttle_handler);
+ },
+ teardown: function () {
+ $(this).off('resize', throttle_handler);
+ }
+ };
+
+ var throttle = 250,
+ throttle_handler = function () {
+ curr = Date.now();
+ diff = curr - lastCall;
+
+ if (diff >= throttle) {
+ lastCall = curr;
+ $(this).trigger('throttledresize');
+
+ } else {
+ if (heldCall) {
+ window.clearTimeout(heldCall);
+ }
+
+ // Promise a held call will still execute
+ heldCall = window.setTimeout(handler, throttle - diff);
+ }
+ },
+ lastCall = 0,
+ heldCall,
+ curr,
+ diff;
+
+ // Trigger a custom event:
+
+ function triggerCustomEvent(obj, eventType, event, touchData) {
+ var originalType = event.type;
+ event.type = eventType;
+
+ $.event.dispatch.call(obj, event, touchData);
+ event.type = originalType;
+ }
+
+ // Correctly on anything we've overloaded:
+ $.each({
+ scrollend: 'scrollstart',
+ swipeup: 'swipe',
+ swiperight: 'swipe',
+ swipedown: 'swipe',
+ swipeleft: 'swipe',
+ swipeend: 'swipe',
+ tap2: 'tap'
+ }, function (e, srcE, touchData) {
+ $.event.special[e] = {
+ setup: function () {
+ $(this).on(srcE, $.noop);
+ }
+ };
+ });
+
+})(jQuery);
diff --git a/src/1.0.1/jquery.mobile-events.min.js b/src/1.0.1/jquery.mobile-events.min.js
new file mode 100644
index 0000000..24e60d1
--- /dev/null
+++ b/src/1.0.1/jquery.mobile-events.min.js
@@ -0,0 +1 @@
+!function(e){function t(){var e=c();e!==r&&(r=e,l.trigger("orientationchange"))}function a(t,a,n,o){var i=n.type;n.type=a,e.event.dispatch.call(t,n,o),n.type=i}e.attrFn=e.attrFn||{};var n=navigator.userAgent.toLowerCase(),o=n.indexOf("chrome")>-1&&(n.indexOf("windows")>-1||n.indexOf("macintosh")>-1||n.indexOf("linux")>-1)&&n.indexOf("mobile")<0&&n.indexOf("android")<0,i={tap_pixel_range:5,swipe_h_threshold:50,swipe_v_threshold:50,taphold_threshold:750,doubletap_int:500,touch_capable:window.navigator.msPointerEnabled?!1:"ontouchstart"in window&&!o,orientation_support:"orientation"in window&&"onorientationchange"in window,startevent:window.navigator.msPointerEnabled?"MSPointerDown":"ontouchstart"in window&&!o?"touchstart":"mousedown",endevent:window.navigator.msPointerEnabled?"MSPointerUp":"ontouchstart"in window&&!o?"touchend":"mouseup",moveevent:window.navigator.msPointerEnabled?"MSPointerMove":"ontouchstart"in window&&!o?"touchmove":"mousemove",tapevent:"ontouchstart"in window&&!o?"tap":"click",scrollevent:"ontouchstart"in window&&!o?"touchmove":"scroll",hold_timer:null,tap_timer:null};e.isTouchCapable=function(){return i.touch_capable},e.getStartEvent=function(){return i.startevent},e.getEndEvent=function(){return i.endevent},e.getMoveEvent=function(){return i.moveevent},e.getTapEvent=function(){return i.tapevent},e.getScrollEvent=function(){return i.scrollevent},e.each(["tapstart","tapend","tapmove","tap","tap2","tap3","tap4","singletap","doubletap","taphold","swipe","swipeup","swiperight","swipedown","swipeleft","swipeend","scrollstart","scrollend","orientationchange"],function(t,a){e.fn[a]=function(e){return e?this.on(a,e):this.trigger(a)},e.attrFn[a]=!0}),e.event.special.tapstart={setup:function(){var t=this,n=e(t);n.on(i.startevent,function(e){if(n.data("callee",arguments.callee),e.which&&1!==e.which)return!1;var o=e.originalEvent,s={position:{x:i.touch_capable?o.touches[0].screenX:e.screenX,y:i.touch_capable?o.touches[0].screenY:e.screenY},offset:{x:i.touch_capable?o.touches[0].pageX-o.touches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?o.touches[0].pageY-o.touches[0].target.offsetTop:e.offsetY},time:Date.now(),target:e.target};return a(t,"tapstart",e,s),!0})},remove:function(){e(this).off(i.startevent,e(this).data.callee)}},e.event.special.tapmove={setup:function(){var t=this,n=e(t);n.on(i.moveevent,function(e){n.data("callee",arguments.callee);var o=e.originalEvent,s={position:{x:i.touch_capable?o.touches[0].screenX:e.screenX,y:i.touch_capable?o.touches[0].screenY:e.screenY},offset:{x:i.touch_capable?o.touches[0].pageX-o.touches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?o.touches[0].pageY-o.touches[0].target.offsetTop:e.offsetY},time:Date.now(),target:e.target};return a(t,"tapmove",e,s),!0})},remove:function(){e(this).off(i.moveevent,e(this).data.callee)}},e.event.special.tapend={setup:function(){var t=this,n=e(t);n.on(i.endevent,function(e){n.data("callee",arguments.callee);var o=e.originalEvent,s={position:{x:i.touch_capable?o.changedTouches[0].screenX:e.screenX,y:i.touch_capable?o.changedTouches[0].screenY:e.screenY},offset:{x:i.touch_capable?o.changedTouches[0].pageX-o.changedTouches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?o.changedTouches[0].pageY-o.changedTouches[0].target.offsetTop:e.offsetY},time:Date.now(),target:e.target};return a(t,"tapend",e,s),!0})},remove:function(){e(this).off(i.endevent,e(this).data.callee)}},e.event.special.taphold={setup:function(){var t,n=this,o=e(n),s={x:0,y:0},c=0,r=0;o.on(i.startevent,function(e){if(e.which&&1!==e.which)return!1;o.data("tapheld",!1),t=e.target;var h=e.originalEvent,u=Date.now(),l={x:i.touch_capable?h.touches[0].screenX:e.screenX,y:i.touch_capable?h.touches[0].screenY:e.screenY},p={x:i.touch_capable?h.touches[0].pageX-h.touches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?h.touches[0].pageY-h.touches[0].target.offsetTop:e.offsetY};return s.x=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageX:e.pageX,s.y=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageY:e.pageY,c=s.x,r=s.y,i.hold_timer=window.setTimeout(function(){var g=s.x-c,d=s.y-r;if(e.target==t&&(s.x==c&&s.y==r||g>=-i.tap_pixel_range&&g<=i.tap_pixel_range&&d>=-i.tap_pixel_range&&d<=i.tap_pixel_range)){o.data("tapheld",!0);var f=Date.now(),v={x:i.touch_capable?h.touches[0].screenX:e.screenX,y:i.touch_capable?h.touches[0].screenY:e.screenY},w={x:i.touch_capable?h.touches[0].pageX-h.touches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?h.touches[0].pageY-h.touches[0].target.offsetTop:e.offsetY};duration=f-u;var _={startTime:u,endTime:f,startPosition:l,startOffset:p,endPosition:v,endOffset:w,duration:duration,target:e.target};o.data("callee1",arguments.callee),a(n,"taphold",e,_)}},i.taphold_threshold),!0}).on(i.endevent,function(){o.data("callee2",arguments.callee),o.data("tapheld",!1),window.clearTimeout(i.hold_timer)}).on(i.moveevent,function(e){o.data("callee3",arguments.callee),c=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageX:e.pageX,r=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageY:e.pageY})},remove:function(){e(this).off(i.startevent,e(this).data.callee1).off(i.endevent,e(this).data.callee2).off(i.moveevent,e(this).data.callee3)}},e.event.special.doubletap={setup:function(){var t,n,o,s,c,r=this,h=e(r),u=!1;h.on(i.startevent,function(e){return e.which&&1!==e.which?!1:(h.data("doubletapped",!1),t=e.target,h.data("callee1",arguments.callee),s=e.originalEvent,o={position:{x:i.touch_capable?s.touches[0].screenX:e.screenX,y:i.touch_capable?s.touches[0].screenY:e.screenY},offset:{x:i.touch_capable?s.touches[0].pageX-s.touches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?s.touches[0].pageY-s.touches[0].target.offsetTop:e.offsetY},time:Date.now(),target:e.target},!0)}).on(i.endevent,function(e){var s=Date.now(),l=h.data("lastTouch")||s+1,p=s-l;if(window.clearTimeout(n),h.data("callee2",arguments.callee),p100){h.data("doubletapped",!0),window.clearTimeout(i.tap_timer);var g={position:{x:i.touch_capable?e.originalEvent.changedTouches[0].screenX:e.screenX,y:i.touch_capable?e.originalEvent.changedTouches[0].screenY:e.screenY},offset:{x:i.touch_capable?e.originalEvent.changedTouches[0].pageX-e.originalEvent.changedTouches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?e.originalEvent.changedTouches[0].pageY-e.originalEvent.changedTouches[0].target.offsetTop:e.offsetY},time:Date.now(),target:e.target},d={firstTap:o,secondTap:g,interval:g.time-o.time};u||a(r,"doubletap",e,d),u=!0,c=window.setTimeout(function(){u=!1},i.doubletap_int)}else h.data("lastTouch",s),n=window.setTimeout(function(){window.clearTimeout(n)},i.doubletap_int,[e]);h.data("lastTouch",s)})},remove:function(){e(this).off(i.startevent,e(this).data.callee1).off(i.endevent,e(this).data.callee2)}},e.event.special.singletap={setup:function(){var t=this,n=e(t),o=null,s=null,c={x:0,y:0};n.on(i.startevent,function(e){return e.which&&1!==e.which?!1:(s=Date.now(),o=e.target,n.data("callee1",arguments.callee),c.x=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageX:e.pageX,c.y=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageY:e.pageY,!0)}).on(i.endevent,function(e){n.data("callee2",arguments.callee),e.target==o&&(end_pos_x=e.originalEvent.changedTouches?e.originalEvent.changedTouches[0].pageX:e.pageX,end_pos_y=e.originalEvent.changedTouches?e.originalEvent.changedTouches[0].pageY:e.pageY,i.tap_timer=window.setTimeout(function(){if(!n.data("doubletapped")&&!n.data("tapheld")&&c.x==end_pos_x&&c.y==end_pos_y){var o=e.originalEvent,r={position:{x:i.touch_capable?o.changedTouches[0].screenX:e.screenX,y:i.touch_capable?o.changedTouches[0].screenY:e.screenY},offset:{x:i.touch_capable?o.changedTouches[0].pageX-o.changedTouches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?o.changedTouches[0].pageY-o.changedTouches[0].target.offsetTop:e.offsetY},time:Date.now(),target:e.target};r.time-s=-i.tap_pixel_range&&g<=i.tap_pixel_range&&d>=-i.tap_pixel_range&&d<=i.tap_pixel_range)){for(var f=e.originalEvent,v=[],w=0;wl.y&&u.y-l.y>g&&(a="swipeup"),u.xp&&(a="swiperight"),u.yg&&(a="swipedown"),u.x>l.x&&u.x-l.x>p&&(a="swipeleft"),void 0!=a&&r){u.x=0,u.y=0,l.x=0,l.y=0,r=!1;var d=t.originalEvent;endEvnt={position:{x:i.touch_capable?d.touches[0].screenX:t.screenX,y:i.touch_capable?d.touches[0].screenY:t.screenY},offset:{x:i.touch_capable?d.touches[0].pageX-d.touches[0].target.offsetLeft:t.offsetX,y:i.touch_capable?d.touches[0].pageY-d.touches[0].target.offsetTop:t.offsetY},time:Date.now(),target:t.target};var f=Math.abs(o.position.x-endEvnt.position.x),v=Math.abs(o.position.y-endEvnt.position.y),w={startEvnt:o,endEvnt:endEvnt,direction:a.replace("swipe",""),xAmount:f,yAmount:v,duration:endEvnt.time-o.time};h=!0,c.trigger("swipe",w).trigger(a,w)}}function n(t){c=e(t.currentTarget);var a="";if(c.data("callee3",arguments.callee),h){var n=c.data("xthreshold"),s=c.data("ythreshold"),u="undefined"!=typeof n&&n!==!1&&parseInt(n)?parseInt(n):i.swipe_h_threshold,l="undefined"!=typeof s&&s!==!1&&parseInt(s)?parseInt(s):i.swipe_v_threshold,p=t.originalEvent;endEvnt={position:{x:i.touch_capable?p.changedTouches[0].screenX:t.screenX,y:i.touch_capable?p.changedTouches[0].screenY:t.screenY},offset:{x:i.touch_capable?p.changedTouches[0].pageX-p.changedTouches[0].target.offsetLeft:t.offsetX,y:i.touch_capable?p.changedTouches[0].pageY-p.changedTouches[0].target.offsetTop:t.offsetY},time:Date.now(),target:t.target},o.position.y>endEvnt.position.y&&o.position.y-endEvnt.position.y>l&&(a="swipeup"),o.position.xu&&(a="swiperight"),o.position.yl&&(a="swipedown"),o.position.x>endEvnt.position.x&&o.position.x-endEvnt.position.x>u&&(a="swipeleft");var g=Math.abs(o.position.x-endEvnt.position.x),d=Math.abs(o.position.y-endEvnt.position.y),f={startEvnt:o,endEvnt:endEvnt,direction:a.replace("swipe",""),xAmount:g,yAmount:d,duration:endEvnt.time-o.time};c.trigger("swipeend",f)}r=!1,h=!1}var o,s=this,c=e(s),r=!1,h=!1,u={x:0,y:0},l={x:0,y:0};c.on(i.startevent,t),c.on(i.moveevent,a),c.on(i.endevent,n)},remove:function(){e(this).off(i.startevent,e(this).data.callee1).off(i.moveevent,e(this).data.callee2).off(i.endevent,e(this).data.callee3)}},e.event.special.scrollstart={setup:function(){function t(e,t){n=t,a(s,n?"scrollstart":"scrollend",e)}var n,o,s=this,c=e(s);c.on(i.scrollevent,function(e){c.data("callee",arguments.callee),n||t(e,!0),clearTimeout(o),o=setTimeout(function(){t(e,!1)},50)})},remove:function(){e(this).off(i.scrollevent,e(this).data.callee)}};var s,c,r,h,u,l=e(window),p={0:!0,180:!0};if(i.orientation_support){var g=window.innerWidth||l.width(),d=window.innerHeight||l.height(),f=50;h=g>d&&g-d>f,u=p[window.orientation],(h&&u||!h&&!u)&&(p={"-90":!0,90:!0})}e.event.special.orientationchange=s={setup:function(){return i.orientation_support?!1:(r=c(),l.on("throttledresize",t),!0)},teardown:function(){return i.orientation_support?!1:(l.off("throttledresize",t),!0)},add:function(e){var t=e.handler;e.handler=function(e){return e.orientation=c(),t.apply(this,arguments)}}},e.event.special.orientationchange.orientation=c=function(){var e=!0,t=document.documentElement;return e=i.orientation_support?p[window.orientation]:t&&t.clientWidth/t.clientHeight<1.1,e?"portrait":"landscape"},e.event.special.throttledresize={setup:function(){e(this).on("resize",m)},teardown:function(){e(this).off("resize",m)}};var v,w,_,T=250,m=function(){w=Date.now(),_=w-x,_>=T?(x=w,e(this).trigger("throttledresize")):(v&&window.clearTimeout(v),v=window.setTimeout(t,T-_))},x=0;e.each({scrollend:"scrollstart",swipeup:"swipe",swiperight:"swipe",swipedown:"swipe",swipeleft:"swipe",swipeend:"swipe",tap2:"tap"},function(t,a){e.event.special[t]={setup:function(){e(this).on(a,e.noop)}}})}(jQuery);
diff --git a/src/1.0.2/bower.json b/src/1.0.2/bower.json
new file mode 100644
index 0000000..5cea401
--- /dev/null
+++ b/src/1.0.2/bower.json
@@ -0,0 +1,11 @@
+{
+ "name": "jquery-touch-events",
+ "version": "1.0.2",
+ "main": "src/jquery.mobile-events.js",
+ "ignore": [
+ "bower.json"
+ ],
+ "dependencies": {
+ "jquery": ">=1.7.0"
+ }
+}
diff --git a/src/1.0.2/jquery.mobile-events.js b/src/1.0.2/jquery.mobile-events.js
new file mode 100644
index 0000000..b5e867b
--- /dev/null
+++ b/src/1.0.2/jquery.mobile-events.js
@@ -0,0 +1,881 @@
+/*!
+ * jQuery Mobile Events
+ * by Ben Major (www.ben-major.co.uk)
+ *
+ * Copyright 2011, Ben Major
+ * Licensed under the MIT License:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+"use strict";
+
+(function ($) {
+ $.attrFn = $.attrFn || {};
+
+ // navigator.userAgent.toLowerCase() isn't reliable for Chrome installs
+ // on mobile devices. As such, we will create a boolean isChromeDesktop
+ // The reason that we need to do this is because Chrome annoyingly
+ // purports support for touch events even if the underlying hardware
+ // does not!
+ var agent = navigator.userAgent.toLowerCase(),
+ isChromeDesktop = (agent.indexOf('chrome') > -1 && ((agent.indexOf('windows') > -1) || (agent.indexOf('macintosh') > -1) || (agent.indexOf('linux') > -1)) && agent.indexOf('mobile') < 0 && agent.indexOf('android') < 0),
+
+ settings = {
+ tap_pixel_range: 5,
+ swipe_h_threshold: 50,
+ swipe_v_threshold: 50,
+ taphold_threshold: 750,
+ doubletap_int: 500,
+
+ touch_capable: (window.navigator.msPointerEnabled) ? false : ('ontouchstart' in window && !isChromeDesktop),
+ orientation_support: ('orientation' in window && 'onorientationchange' in window),
+
+ startevent: (window.navigator.msPointerEnabled) ? 'MSPointerDown' : (('ontouchstart' in window && !isChromeDesktop) ? 'touchstart' : 'mousedown'),
+ endevent: (window.navigator.msPointerEnabled) ? 'MSPointerUp' : (('ontouchstart' in window && !isChromeDesktop) ? 'touchend' : 'mouseup'),
+ moveevent: (window.navigator.msPointerEnabled) ? 'MSPointerMove' : (('ontouchstart' in window && !isChromeDesktop) ? 'touchmove' : 'mousemove'),
+ tapevent: ('ontouchstart' in window && !isChromeDesktop) ? 'tap' : 'click',
+ scrollevent: ('ontouchstart' in window && !isChromeDesktop) ? 'touchmove' : 'scroll',
+
+ hold_timer: null,
+ tap_timer: null
+ };
+
+ // Convenience functions:
+ $.isTouchCapable = function() { return settings.touch_capable; };
+ $.getStartEvent = function() { return settings.startevent; };
+ $.getEndEvent = function() { return settings.endevent; };
+ $.getMoveEvent = function() { return settings.moveevent; };
+ $.getTapEvent = function() { return settings.tapevent; };
+ $.getScrollEvent = function() { return settings.scrollevent; };
+
+ // Add Event shortcuts:
+ $.each(['tapstart', 'tapend', 'tapmove', 'tap', 'tap2', 'tap3', 'tap4', 'singletap', 'doubletap', 'taphold', 'swipe', 'swipeup', 'swiperight', 'swipedown', 'swipeleft', 'swipeend', 'scrollstart', 'scrollend', 'orientationchange'], function (i, name) {
+ $.fn[name] = function (fn) {
+ return fn ? this.on(name, fn) : this.trigger(name);
+ };
+
+ $.attrFn[name] = true;
+ });
+
+ // tapstart Event:
+ $.event.special.tapstart = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.startevent, function tapStartFunc(e) {
+ $this.data('callee', tapStartFunc);
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapstart', e, touchData);
+ return true;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee);
+ }
+ };
+
+ // tapmove Event:
+ $.event.special.tapmove = {
+ setup: function() {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.moveevent, function tapMoveFunc(e) {
+ $this.data('callee', tapMoveFunc);
+
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapmove', e, touchData);
+ return true;
+ });
+ },
+ remove: function() {
+ $(this).off(settings.moveevent, $(this).data.callee);
+ }
+ };
+
+ // tapend Event:
+ $.event.special.tapend = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.endevent, function tapEndFunc(e) {
+ // Touch event data:
+ $this.data('callee', tapEndFunc);
+
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX - origEvent.changedTouches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY - origEvent.changedTouches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ triggerCustomEvent(thisObject, 'tapend', e, touchData);
+ return true;
+ });
+ },
+ remove: function () {
+ $(this).off(settings.endevent, $(this).data.callee);
+ }
+ };
+
+ // taphold Event:
+ $.event.special.taphold = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ end_x = 0,
+ end_y = 0;
+
+ $this.on(settings.startevent, function tapHoldFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ $this.data('tapheld', false);
+ origTarget = e.target;
+
+ var origEvent = e.originalEvent;
+ var start_time = Date.now(),
+ startPosition = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ startOffset = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ };
+
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ end_x = start_pos.x;
+ end_y = start_pos.y;
+
+ settings.hold_timer = window.setTimeout(function () {
+
+ var diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y);
+
+ if (e.target == origTarget && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ $this.data('tapheld', true);
+
+ var end_time = Date.now(),
+ endPosition = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ endOffset = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ };
+ var duration = end_time - start_time;
+
+ // Build the touch data:
+ var touchData = {
+ 'startTime': start_time,
+ 'endTime': end_time,
+ 'startPosition': startPosition,
+ 'startOffset': startOffset,
+ 'endPosition': endPosition,
+ 'endOffset': endOffset,
+ 'duration': duration,
+ 'target': e.target
+ };
+ $this.data('callee1', tapHoldFunc1);
+ triggerCustomEvent(thisObject, 'taphold', e, touchData);
+ }
+ }, settings.taphold_threshold);
+
+ return true;
+ }
+ }).on(settings.endevent, function tapHoldFunc2() {
+ $this.data('callee2', tapHoldFunc2);
+ $this.data('tapheld', false);
+ window.clearTimeout(settings.hold_timer);
+ })
+ .on(settings.moveevent, function tapHoldFunc3(e) {
+ $this.data('callee3', tapHoldFunc3);
+
+ end_x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2).off(settings.moveevent, $(this).data.callee3);
+ }
+ };
+
+ // doubletap Event:
+ $.event.special.doubletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ action,
+ firstTap = null,
+ origEvent,
+ cooloff,
+ cooling = false;
+
+ $this.on(settings.startevent, function doubleTapFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+ $this.data('doubletapped', false);
+ origTarget = e.target;
+ $this.data('callee1', doubleTapFunc1);
+
+ origEvent = e.originalEvent;
+ if (!firstTap) {
+ firstTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ }
+
+ return true;
+ }).on(settings.endevent, function doubleTapFunc2(e) {
+
+ var now = Date.now();
+ var lastTouch = $this.data('lastTouch') || now + 1;
+ var delta = now - lastTouch;
+ window.clearTimeout(action);
+ $this.data('callee2', doubleTapFunc2);
+
+ if (delta < settings.doubletap_int && (e.target == origTarget) && delta > 100) {
+ $this.data('doubletapped', true);
+ window.clearTimeout(settings.tap_timer);
+
+ // Now get the current event:
+ var lastTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? e.originalEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? e.originalEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? e.originalEvent.changedTouches[0].pageX - e.originalEvent.changedTouches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? e.originalEvent.changedTouches[0].pageY - e.originalEvent.changedTouches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ var touchData = {
+ 'firstTap': firstTap,
+ 'secondTap': lastTap,
+ 'interval': lastTap.time - firstTap.time
+ };
+
+ if (!cooling) {
+ triggerCustomEvent(thisObject, 'doubletap', e, touchData);
+ firstTap = null;
+ }
+
+ cooling = true;
+
+ cooloff = window.setTimeout(function () {
+ cooling = false;
+ }, settings.doubletap_int);
+
+ } else {
+ $this.data('lastTouch', now);
+ action = window.setTimeout(function () {
+ firstTap = null;
+ window.clearTimeout(action);
+ }, settings.doubletap_int, [e]);
+ }
+ $this.data('lastTouch', now);
+ });
+ },
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // singletap Event:
+ // This is used in conjuction with doubletap when both events are needed on the same element
+ $.event.special.singletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget = null,
+ startTime = null,
+ start_pos = {
+ x: 0,
+ y: 0
+ };
+
+ $this.on(settings.startevent, function singleTapFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ startTime = Date.now();
+ origTarget = e.target;
+ $this.data('callee1', singleTapFunc1);
+
+ // Get the start x and y position:
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ return true;
+ }
+ }).on(settings.endevent, function singleTapFunc2(e) {
+ $this.data('callee2', singleTapFunc2);
+ if (e.target == origTarget) {
+ // Get the end point:
+ var end_pos_x = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX;
+ var end_pos_y = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY;
+
+ // We need to check if it was a taphold:
+
+ settings.tap_timer = window.setTimeout(function () {
+ if (!$this.data('doubletapped') && !$this.data('tapheld') && (start_pos.x == end_pos_x) && (start_pos.y == end_pos_y)) {
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX - origEvent.changedTouches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY - origEvent.changedTouches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Was it a taphold?
+ if((touchData.time - startTime) < settings.taphold_threshold)
+ {
+ triggerCustomEvent(thisObject, 'singletap', e, touchData);
+ }
+ }
+ }, settings.doubletap_int);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // tap Event:
+ $.event.special.tap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ origTarget = null,
+ start_time,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ touches;
+
+ $this.on(settings.startevent, function tapFunc1(e) {
+ $this.data('callee1', tapFunc1);
+
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ started = true;
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ start_time = Date.now();
+ origTarget = e.target;
+
+ touches = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches : [ e ];
+ return true;
+ }
+ }).on(settings.endevent, function tapFunc2(e) {
+ $this.data('callee2', tapFunc2);
+
+ // Only trigger if they've started, and the target matches:
+ var end_x = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY,
+ diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y),
+ eventName;
+
+ if (origTarget == e.target && started && ((Date.now() - start_time) < settings.taphold_threshold) && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ var origEvent = e.originalEvent;
+ var touchData = [ ];
+
+ for( var i = 0; i < touches.length; i++)
+ {
+ var touch = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[i].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[i].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[i].pageX - origEvent.changedTouches[i].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[i].pageY - origEvent.changedTouches[i].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ touchData.push( touch );
+ }
+
+ switch( touches.length )
+ {
+ case 1:
+ eventName = 'tap';
+ break;
+
+ case 2:
+ eventName = 'tap2';
+ break;
+
+ case 3:
+ eventName = 'tap3';
+ break;
+
+ case 4:
+ eventName = 'tap4';
+ break;
+ }
+
+ triggerCustomEvent(thisObject, eventName, e, touchData);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // swipe Event (also handles swipeup, swiperight, swipedown and swipeleft):
+ $.event.special.swipe = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ hasSwiped = false,
+ originalCoord = {
+ x: 0,
+ y: 0
+ },
+ finalCoord = {
+ x: 0,
+ y: 0
+ },
+ startEvnt;
+
+ // Screen touched, store the original coordinate
+
+ function touchStart(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee1', touchStart);
+ originalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ originalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ finalCoord.x = originalCoord.x;
+ finalCoord.y = originalCoord.y;
+ started = true;
+ var origEvent = e.originalEvent;
+ // Read event data into our startEvt:
+ startEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ }
+
+ // Store coordinates as finger is swiping
+
+ function touchMove(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee2', touchMove);
+ finalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ finalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ var swipedir;
+
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = ($this.parent().data('xthreshold')) ? $this.parent().data('xthreshold') : $this.data('xthreshold'),
+ ele_y_threshold = ($this.parent().data('ythreshold')) ? $this.parent().data('ythreshold') : $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ if (originalCoord.y > finalCoord.y && (originalCoord.y - finalCoord.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (originalCoord.x < finalCoord.x && (finalCoord.x - originalCoord.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (originalCoord.y < finalCoord.y && (finalCoord.y - originalCoord.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (originalCoord.x > finalCoord.x && (originalCoord.x - finalCoord.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+ if (swipedir != undefined && started) {
+ originalCoord.x = 0;
+ originalCoord.y = 0;
+ finalCoord.x = 0;
+ finalCoord.y = 0;
+ started = false;
+
+ // Read event data into our endEvnt:
+ var origEvent = e.originalEvent;
+ var endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ };
+ hasSwiped = true;
+ $this.trigger('swipe', touchData).trigger(swipedir, touchData);
+ }
+ }
+
+ function touchEnd(e) {
+ $this = $(e.currentTarget);
+ var swipedir = "";
+ $this.data('callee3', touchEnd);
+ if (hasSwiped) {
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = $this.data('xthreshold'),
+ ele_y_threshold = $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ var origEvent = e.originalEvent;
+ var endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX - origEvent.changedTouches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY - origEvent.changedTouches[0].target.offsetTop : e.offsetY
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Read event data into our endEvnt:
+ if (startEvnt.position.y > endEvnt.position.y && (startEvnt.position.y - endEvnt.position.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (startEvnt.position.x < endEvnt.position.x && (endEvnt.position.x - startEvnt.position.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (startEvnt.position.y < endEvnt.position.y && (endEvnt.position.y - startEvnt.position.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (startEvnt.position.x > endEvnt.position.x && (startEvnt.position.x - endEvnt.position.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ };
+ $this.trigger('swipeend', touchData);
+ }
+
+ started = false;
+ hasSwiped = false;
+ }
+
+ $this.on(settings.startevent, touchStart);
+ $this.on(settings.moveevent, touchMove);
+ $this.on(settings.endevent, touchEnd);
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.moveevent, $(this).data.callee2).off(settings.endevent, $(this).data.callee3);
+ }
+ };
+
+ // scrollstart Event (also handles scrollend):
+ $.event.special.scrollstart = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ scrolling,
+ timer;
+
+ function trigger(event, state) {
+ scrolling = state;
+ triggerCustomEvent(thisObject, scrolling ? 'scrollstart' : 'scrollend', event);
+ }
+
+ // iPhone triggers scroll after a small delay; use touchmove instead
+ $this.on(settings.scrollevent, function scrollFunc(event) {
+ $this.data('callee', scrollFunc);
+
+ if (!scrolling) {
+ trigger(event, true);
+ }
+
+ clearTimeout(timer);
+ timer = setTimeout(function () {
+ trigger(event, false);
+ }, 50);
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.scrollevent, $(this).data.callee);
+ }
+ };
+
+ // This is the orientation change (largely borrowed from jQuery Mobile):
+ var win = $(window),
+ special_event,
+ get_orientation,
+ last_orientation,
+ initial_orientation_is_landscape,
+ initial_orientation_is_default,
+ portrait_map = {
+ '0': true,
+ '180': true
+ };
+
+ if (settings.orientation_support) {
+ var ww = window.innerWidth || win.width(),
+ wh = window.innerHeight || win.height(),
+ landscape_threshold = 50;
+
+ initial_orientation_is_landscape = ww > wh && (ww - wh) > landscape_threshold;
+ initial_orientation_is_default = portrait_map[window.orientation];
+
+ if ((initial_orientation_is_landscape && initial_orientation_is_default) || (!initial_orientation_is_landscape && !initial_orientation_is_default)) {
+ portrait_map = {
+ '-90': true,
+ '90': true
+ };
+ }
+ }
+
+ $.event.special.orientationchange = special_event = {
+ setup: function () {
+ // If the event is supported natively, return false so that jQuery
+ // will on to the event using DOM methods.
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ // Get the current orientation to avoid initial double-triggering.
+ last_orientation = get_orientation();
+
+ win.on('throttledresize', handler);
+ return true;
+ },
+ teardown: function () {
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ win.off('throttledresize', handler);
+ return true;
+ },
+ add: function (handleObj) {
+ // Save a reference to the bound event handler.
+ var old_handler = handleObj.handler;
+
+ handleObj.handler = function (event) {
+ event.orientation = get_orientation();
+ return old_handler.apply(this, arguments);
+ };
+ }
+ };
+
+ // If the event is not supported natively, this handler will be bound to
+ // the window resize event to simulate the orientationchange event.
+
+ function handler() {
+ // Get the current orientation.
+ var orientation = get_orientation();
+
+ if (orientation !== last_orientation) {
+ // The orientation has changed, so trigger the orientationchange event.
+ last_orientation = orientation;
+ win.trigger("orientationchange");
+ }
+ }
+
+ $.event.special.orientationchange.orientation = get_orientation = function () {
+ var isPortrait = true,
+ elem = document.documentElement;
+
+ if (settings.orientation_support) {
+ isPortrait = portrait_map[window.orientation];
+ } else {
+ isPortrait = elem && elem.clientWidth / elem.clientHeight < 1.1;
+ }
+
+ return isPortrait ? 'portrait' : 'landscape';
+ };
+
+ // throttle Handler:
+ $.event.special.throttledresize = {
+ setup: function () {
+ $(this).on('resize', throttle_handler);
+ },
+ teardown: function () {
+ $(this).off('resize', throttle_handler);
+ }
+ };
+
+ var throttle = 250,
+ throttle_handler = function () {
+ curr = Date.now();
+ diff = curr - lastCall;
+
+ if (diff >= throttle) {
+ lastCall = curr;
+ $(this).trigger('throttledresize');
+
+ } else {
+ if (heldCall) {
+ window.clearTimeout(heldCall);
+ }
+
+ // Promise a held call will still execute
+ heldCall = window.setTimeout(handler, throttle - diff);
+ }
+ },
+ lastCall = 0,
+ heldCall,
+ curr,
+ diff;
+
+ // Trigger a custom event:
+
+ function triggerCustomEvent(obj, eventType, event, touchData) {
+ var originalType = event.type;
+ event.type = eventType;
+
+ $.event.dispatch.call(obj, event, touchData);
+ event.type = originalType;
+ }
+
+ // Correctly on anything we've overloaded:
+ $.each({
+ scrollend: 'scrollstart',
+ swipeup: 'swipe',
+ swiperight: 'swipe',
+ swipedown: 'swipe',
+ swipeleft: 'swipe',
+ swipeend: 'swipe',
+ tap2: 'tap'
+ }, function (e, srcE) {
+ $.event.special[e] = {
+ setup: function () {
+ $(this).on(srcE, $.noop);
+ }
+ };
+ });
+
+}(jQuery));
diff --git a/src/1.0.2/jquery.mobile-events.min.js b/src/1.0.2/jquery.mobile-events.min.js
new file mode 100644
index 0000000..3d981e7
--- /dev/null
+++ b/src/1.0.2/jquery.mobile-events.min.js
@@ -0,0 +1 @@
+"use strict";!function(e){function t(){var e=c();e!==r&&(r=e,u.trigger("orientationchange"))}function a(t,a,o,n){var i=o.type;o.type=a,e.event.dispatch.call(t,o,n),o.type=i}e.attrFn=e.attrFn||{};var o=navigator.userAgent.toLowerCase(),n=o.indexOf("chrome")>-1&&(o.indexOf("windows")>-1||o.indexOf("macintosh")>-1||o.indexOf("linux")>-1)&&o.indexOf("mobile")<0&&o.indexOf("android")<0,i={tap_pixel_range:5,swipe_h_threshold:50,swipe_v_threshold:50,taphold_threshold:750,doubletap_int:500,touch_capable:window.navigator.msPointerEnabled?!1:"ontouchstart"in window&&!n,orientation_support:"orientation"in window&&"onorientationchange"in window,startevent:window.navigator.msPointerEnabled?"MSPointerDown":"ontouchstart"in window&&!n?"touchstart":"mousedown",endevent:window.navigator.msPointerEnabled?"MSPointerUp":"ontouchstart"in window&&!n?"touchend":"mouseup",moveevent:window.navigator.msPointerEnabled?"MSPointerMove":"ontouchstart"in window&&!n?"touchmove":"mousemove",tapevent:"ontouchstart"in window&&!n?"tap":"click",scrollevent:"ontouchstart"in window&&!n?"touchmove":"scroll",hold_timer:null,tap_timer:null};e.isTouchCapable=function(){return i.touch_capable},e.getStartEvent=function(){return i.startevent},e.getEndEvent=function(){return i.endevent},e.getMoveEvent=function(){return i.moveevent},e.getTapEvent=function(){return i.tapevent},e.getScrollEvent=function(){return i.scrollevent},e.each(["tapstart","tapend","tapmove","tap","tap2","tap3","tap4","singletap","doubletap","taphold","swipe","swipeup","swiperight","swipedown","swipeleft","swipeend","scrollstart","scrollend","orientationchange"],function(t,a){e.fn[a]=function(e){return e?this.on(a,e):this.trigger(a)},e.attrFn[a]=!0}),e.event.special.tapstart={setup:function(){var t=this,o=e(t);o.on(i.startevent,function n(e){if(o.data("callee",n),e.which&&1!==e.which)return!1;var s=e.originalEvent,c={position:{x:i.touch_capable?s.touches[0].screenX:e.screenX,y:i.touch_capable?s.touches[0].screenY:e.screenY},offset:{x:i.touch_capable?s.touches[0].pageX-s.touches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?s.touches[0].pageY-s.touches[0].target.offsetTop:e.offsetY},time:Date.now(),target:e.target};return a(t,"tapstart",e,c),!0})},remove:function(){e(this).off(i.startevent,e(this).data.callee)}},e.event.special.tapmove={setup:function(){var t=this,o=e(t);o.on(i.moveevent,function n(e){o.data("callee",n);var s=e.originalEvent,c={position:{x:i.touch_capable?s.touches[0].screenX:e.screenX,y:i.touch_capable?s.touches[0].screenY:e.screenY},offset:{x:i.touch_capable?s.touches[0].pageX-s.touches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?s.touches[0].pageY-s.touches[0].target.offsetTop:e.offsetY},time:Date.now(),target:e.target};return a(t,"tapmove",e,c),!0})},remove:function(){e(this).off(i.moveevent,e(this).data.callee)}},e.event.special.tapend={setup:function(){var t=this,o=e(t);o.on(i.endevent,function n(e){o.data("callee",n);var s=e.originalEvent,c={position:{x:i.touch_capable?s.changedTouches[0].screenX:e.screenX,y:i.touch_capable?s.changedTouches[0].screenY:e.screenY},offset:{x:i.touch_capable?s.changedTouches[0].pageX-s.changedTouches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?s.changedTouches[0].pageY-s.changedTouches[0].target.offsetTop:e.offsetY},time:Date.now(),target:e.target};return a(t,"tapend",e,c),!0})},remove:function(){e(this).off(i.endevent,e(this).data.callee)}},e.event.special.taphold={setup:function(){var t,o=this,n=e(o),s={x:0,y:0},c=0,r=0;n.on(i.startevent,function h(e){if(e.which&&1!==e.which)return!1;n.data("tapheld",!1),t=e.target;var p=e.originalEvent,u=Date.now(),l={x:i.touch_capable?p.touches[0].screenX:e.screenX,y:i.touch_capable?p.touches[0].screenY:e.screenY},g={x:i.touch_capable?p.touches[0].pageX-p.touches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?p.touches[0].pageY-p.touches[0].target.offsetTop:e.offsetY};return s.x=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageX:e.pageX,s.y=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageY:e.pageY,c=s.x,r=s.y,i.hold_timer=window.setTimeout(function(){var f=s.x-c,d=s.y-r;if(e.target==t&&(s.x==c&&s.y==r||f>=-i.tap_pixel_range&&f<=i.tap_pixel_range&&d>=-i.tap_pixel_range&&d<=i.tap_pixel_range)){n.data("tapheld",!0);var v=Date.now(),w={x:i.touch_capable?p.touches[0].screenX:e.screenX,y:i.touch_capable?p.touches[0].screenY:e.screenY},T={x:i.touch_capable?p.touches[0].pageX-p.touches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?p.touches[0].pageY-p.touches[0].target.offsetTop:e.offsetY},_=v-u,x={startTime:u,endTime:v,startPosition:l,startOffset:g,endPosition:w,endOffset:T,duration:_,target:e.target};n.data("callee1",h),a(o,"taphold",e,x)}},i.taphold_threshold),!0}).on(i.endevent,function p(){n.data("callee2",p),n.data("tapheld",!1),window.clearTimeout(i.hold_timer)}).on(i.moveevent,function u(e){n.data("callee3",u),c=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageX:e.pageX,r=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageY:e.pageY})},remove:function(){e(this).off(i.startevent,e(this).data.callee1).off(i.endevent,e(this).data.callee2).off(i.moveevent,e(this).data.callee3)}},e.event.special.doubletap={setup:function(){var t,o,n,s,c=this,r=e(c),h=null,p=!1;r.on(i.startevent,function u(e){return e.which&&1!==e.which?!1:(r.data("doubletapped",!1),t=e.target,r.data("callee1",u),n=e.originalEvent,h||(h={position:{x:i.touch_capable?n.touches[0].screenX:e.screenX,y:i.touch_capable?n.touches[0].screenY:e.screenY},offset:{x:i.touch_capable?n.touches[0].pageX-n.touches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?n.touches[0].pageY-n.touches[0].target.offsetTop:e.offsetY},time:Date.now(),target:e.target}),!0)}).on(i.endevent,function l(e){var n=Date.now(),u=r.data("lastTouch")||n+1,g=n-u;if(window.clearTimeout(o),r.data("callee2",l),g100){r.data("doubletapped",!0),window.clearTimeout(i.tap_timer);var f={position:{x:i.touch_capable?e.originalEvent.changedTouches[0].screenX:e.screenX,y:i.touch_capable?e.originalEvent.changedTouches[0].screenY:e.screenY},offset:{x:i.touch_capable?e.originalEvent.changedTouches[0].pageX-e.originalEvent.changedTouches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?e.originalEvent.changedTouches[0].pageY-e.originalEvent.changedTouches[0].target.offsetTop:e.offsetY},time:Date.now(),target:e.target},d={firstTap:h,secondTap:f,interval:f.time-h.time};p||(a(c,"doubletap",e,d),h=null),p=!0,s=window.setTimeout(function(){p=!1},i.doubletap_int)}else r.data("lastTouch",n),o=window.setTimeout(function(){h=null,window.clearTimeout(o)},i.doubletap_int,[e]);r.data("lastTouch",n)})},remove:function(){e(this).off(i.startevent,e(this).data.callee1).off(i.endevent,e(this).data.callee2)}},e.event.special.singletap={setup:function(){var t=this,o=e(t),n=null,s=null,c={x:0,y:0};o.on(i.startevent,function r(e){return e.which&&1!==e.which?!1:(s=Date.now(),n=e.target,o.data("callee1",r),c.x=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageX:e.pageX,c.y=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageY:e.pageY,!0)}).on(i.endevent,function h(e){if(o.data("callee2",h),e.target==n){var r=e.originalEvent.changedTouches?e.originalEvent.changedTouches[0].pageX:e.pageX,p=e.originalEvent.changedTouches?e.originalEvent.changedTouches[0].pageY:e.pageY;i.tap_timer=window.setTimeout(function(){if(!o.data("doubletapped")&&!o.data("tapheld")&&c.x==r&&c.y==p){var n=e.originalEvent,h={position:{x:i.touch_capable?n.changedTouches[0].screenX:e.screenX,y:i.touch_capable?n.changedTouches[0].screenY:e.screenY},offset:{x:i.touch_capable?n.changedTouches[0].pageX-n.changedTouches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?n.changedTouches[0].pageY-n.changedTouches[0].target.offsetTop:e.offsetY},time:Date.now(),target:e.target};h.time-s=-i.tap_pixel_range&&f<=i.tap_pixel_range&&d>=-i.tap_pixel_range&&d<=i.tap_pixel_range)){for(var v=e.originalEvent,w=[],T=0;Tu.y&&p.y-u.y>f&&(o="swipeup"),p.xg&&(o="swiperight"),p.yf&&(o="swipedown"),p.x>u.x&&p.x-u.x>g&&(o="swipeleft"),void 0!=o&&r){p.x=0,p.y=0,u.x=0,u.y=0,r=!1;var d=t.originalEvent,v={position:{x:i.touch_capable?d.touches[0].screenX:t.screenX,y:i.touch_capable?d.touches[0].screenY:t.screenY},offset:{x:i.touch_capable?d.touches[0].pageX-d.touches[0].target.offsetLeft:t.offsetX,y:i.touch_capable?d.touches[0].pageY-d.touches[0].target.offsetTop:t.offsetY},time:Date.now(),target:t.target},w=Math.abs(n.position.x-v.position.x),T=Math.abs(n.position.y-v.position.y),_={startEvnt:n,endEvnt:v,direction:o.replace("swipe",""),xAmount:w,yAmount:T,duration:v.time-n.time};h=!0,c.trigger("swipe",_).trigger(o,_)}}function o(t){c=e(t.currentTarget);var a="";if(c.data("callee3",o),h){var s=c.data("xthreshold"),p=c.data("ythreshold"),u="undefined"!=typeof s&&s!==!1&&parseInt(s)?parseInt(s):i.swipe_h_threshold,l="undefined"!=typeof p&&p!==!1&&parseInt(p)?parseInt(p):i.swipe_v_threshold,g=t.originalEvent,f={position:{x:i.touch_capable?g.changedTouches[0].screenX:t.screenX,y:i.touch_capable?g.changedTouches[0].screenY:t.screenY},offset:{x:i.touch_capable?g.changedTouches[0].pageX-g.changedTouches[0].target.offsetLeft:t.offsetX,y:i.touch_capable?g.changedTouches[0].pageY-g.changedTouches[0].target.offsetTop:t.offsetY},time:Date.now(),target:t.target};n.position.y>f.position.y&&n.position.y-f.position.y>l&&(a="swipeup"),n.position.xu&&(a="swiperight"),n.position.yl&&(a="swipedown"),n.position.x>f.position.x&&n.position.x-f.position.x>u&&(a="swipeleft");var d=Math.abs(n.position.x-f.position.x),v=Math.abs(n.position.y-f.position.y),w={startEvnt:n,endEvnt:f,direction:a.replace("swipe",""),xAmount:d,yAmount:v,duration:f.time-n.time};c.trigger("swipeend",w)}r=!1,h=!1}var n,s=this,c=e(s),r=!1,h=!1,p={x:0,y:0},u={x:0,y:0};c.on(i.startevent,t),c.on(i.moveevent,a),c.on(i.endevent,o)},remove:function(){e(this).off(i.startevent,e(this).data.callee1).off(i.moveevent,e(this).data.callee2).off(i.endevent,e(this).data.callee3)}},e.event.special.scrollstart={setup:function(){function t(e,t){o=t,a(s,o?"scrollstart":"scrollend",e)}var o,n,s=this,c=e(s);c.on(i.scrollevent,function r(e){c.data("callee",r),o||t(e,!0),clearTimeout(n),n=setTimeout(function(){t(e,!1)},50)})},remove:function(){e(this).off(i.scrollevent,e(this).data.callee)}};var s,c,r,h,p,u=e(window),l={0:!0,180:!0};if(i.orientation_support){var g=window.innerWidth||u.width(),f=window.innerHeight||u.height(),d=50;h=g>f&&g-f>d,p=l[window.orientation],(h&&p||!h&&!p)&&(l={"-90":!0,90:!0})}e.event.special.orientationchange=s={setup:function(){return i.orientation_support?!1:(r=c(),u.on("throttledresize",t),!0)},teardown:function(){return i.orientation_support?!1:(u.off("throttledresize",t),!0)},add:function(e){var t=e.handler;e.handler=function(e){return e.orientation=c(),t.apply(this,arguments)}}},e.event.special.orientationchange.orientation=c=function(){var e=!0,t=document.documentElement;return e=i.orientation_support?l[window.orientation]:t&&t.clientWidth/t.clientHeight<1.1,e?"portrait":"landscape"},e.event.special.throttledresize={setup:function(){e(this).on("resize",x)},teardown:function(){e(this).off("resize",x)}};var v,w,T,_=250,x=function(){w=Date.now(),T=w-y,T>=_?(y=w,e(this).trigger("throttledresize")):(v&&window.clearTimeout(v),v=window.setTimeout(t,_-T))},y=0;e.each({scrollend:"scrollstart",swipeup:"swipe",swiperight:"swipe",swipedown:"swipe",swipeleft:"swipe",swipeend:"swipe",tap2:"tap"},function(t,a){e.event.special[t]={setup:function(){e(this).on(a,e.noop)}}})}(jQuery);
diff --git a/src/1.0.3/bower.json b/src/1.0.3/bower.json
new file mode 100644
index 0000000..5986df8
--- /dev/null
+++ b/src/1.0.3/bower.json
@@ -0,0 +1,11 @@
+{
+ "name": "jquery-touch-events",
+ "version": "1.0.3",
+ "main": "src/jquery.mobile-events.js",
+ "ignore": [
+ "bower.json"
+ ],
+ "dependencies": {
+ "jquery": ">=1.7.0"
+ }
+}
diff --git a/src/1.0.3/jquery.mobile-events.js b/src/1.0.3/jquery.mobile-events.js
new file mode 100644
index 0000000..1c054d8
--- /dev/null
+++ b/src/1.0.3/jquery.mobile-events.js
@@ -0,0 +1,884 @@
+/*!
+ * jQuery Mobile Events
+ * by Ben Major (www.ben-major.co.uk)
+ *
+ * Copyright 2011, Ben Major
+ * Licensed under the MIT License:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+"use strict";
+
+(function ($) {
+ $.attrFn = $.attrFn || {};
+
+ // navigator.userAgent.toLowerCase() isn't reliable for Chrome installs
+ // on mobile devices. As such, we will create a boolean isChromeDesktop
+ // The reason that we need to do this is because Chrome annoyingly
+ // purports support for touch events even if the underlying hardware
+ // does not!
+ var agent = navigator.userAgent.toLowerCase(),
+ isChromeDesktop = (agent.indexOf('chrome') > -1 && ((agent.indexOf('windows') > -1) || (agent.indexOf('macintosh') > -1) || (agent.indexOf('linux') > -1)) && agent.indexOf('mobile') < 0 && agent.indexOf('android') < 0),
+
+ settings = {
+ tap_pixel_range: 5,
+ swipe_h_threshold: 50,
+ swipe_v_threshold: 50,
+ taphold_threshold: 750,
+ doubletap_int: 500,
+
+ touch_capable: (window.navigator.msPointerEnabled) ? false : ('ontouchstart' in window && !isChromeDesktop),
+ orientation_support: ('orientation' in window && 'onorientationchange' in window),
+
+ startevent: (window.navigator.msPointerEnabled) ? 'MSPointerDown' : (('ontouchstart' in window && !isChromeDesktop) ? 'touchstart' : 'mousedown'),
+ endevent: (window.navigator.msPointerEnabled) ? 'MSPointerUp' : (('ontouchstart' in window && !isChromeDesktop) ? 'touchend' : 'mouseup'),
+ moveevent: (window.navigator.msPointerEnabled) ? 'MSPointerMove' : (('ontouchstart' in window && !isChromeDesktop) ? 'touchmove' : 'mousemove'),
+ tapevent: ('ontouchstart' in window && !isChromeDesktop) ? 'tap' : 'click',
+ scrollevent: ('ontouchstart' in window && !isChromeDesktop) ? 'touchmove' : 'scroll',
+
+ hold_timer: null,
+ tap_timer: null
+ };
+
+ // Convenience functions:
+ $.isTouchCapable = function() { return settings.touch_capable; };
+ $.getStartEvent = function() { return settings.startevent; };
+ $.getEndEvent = function() { return settings.endevent; };
+ $.getMoveEvent = function() { return settings.moveevent; };
+ $.getTapEvent = function() { return settings.tapevent; };
+ $.getScrollEvent = function() { return settings.scrollevent; };
+
+ // Add Event shortcuts:
+ $.each(['tapstart', 'tapend', 'tapmove', 'tap', 'tap2', 'tap3', 'tap4', 'singletap', 'doubletap', 'taphold', 'swipe', 'swipeup', 'swiperight', 'swipedown', 'swipeleft', 'swipeend', 'scrollstart', 'scrollend', 'orientationchange'], function (i, name) {
+ $.fn[name] = function (fn) {
+ return fn ? this.on(name, fn) : this.trigger(name);
+ };
+
+ $.attrFn[name] = true;
+ });
+
+ // tapstart Event:
+ $.event.special.tapstart = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.startevent, function tapStartFunc(e) {
+ $this.data('callee', tapStartFunc);
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.position().left) : Math.round(e.pageX - $this.position().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.position().top) : Math.round(e.pageY - $this.position().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapstart', e, touchData);
+ return true;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee);
+ }
+ };
+
+ // tapmove Event:
+ $.event.special.tapmove = {
+ setup: function() {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.moveevent, function tapMoveFunc(e) {
+ $this.data('callee', tapMoveFunc);
+
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.position().left) : Math.round(e.pageX - $this.position().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.position().top) : Math.round(e.pageY - $this.position().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapmove', e, touchData);
+ return true;
+ });
+ },
+ remove: function() {
+ $(this).off(settings.moveevent, $(this).data.callee);
+ }
+ };
+
+ // tapend Event:
+ $.event.special.tapend = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.endevent, function tapEndFunc(e) {
+ // Touch event data:
+ $this.data('callee', tapEndFunc);
+
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.position().left) : Math.round(e.pageX - $this.position().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.position().top) : Math.round(e.pageY - $this.position().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ triggerCustomEvent(thisObject, 'tapend', e, touchData);
+ return true;
+ });
+ },
+ remove: function () {
+ $(this).off(settings.endevent, $(this).data.callee);
+ }
+ };
+
+ // taphold Event:
+ $.event.special.taphold = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ end_x = 0,
+ end_y = 0;
+
+ $this.on(settings.startevent, function tapHoldFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ $this.data('tapheld', false);
+ origTarget = e.target;
+
+ var origEvent = e.originalEvent;
+ var start_time = Date.now(),
+ startPosition = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ startOffset = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ };
+
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ end_x = start_pos.x;
+ end_y = start_pos.y;
+
+ settings.hold_timer = window.setTimeout(function () {
+
+ var diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y);
+
+ if (e.target == origTarget && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ $this.data('tapheld', true);
+
+ var end_time = Date.now(),
+ endPosition = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ endOffset = {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.position().left) : Math.round(e.pageX - $this.position().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.position().top) : Math.round(e.pageY - $this.position().top)
+ };
+ var duration = end_time - start_time;
+
+ // Build the touch data:
+ var touchData = {
+ 'startTime': start_time,
+ 'endTime': end_time,
+ 'startPosition': startPosition,
+ 'startOffset': startOffset,
+ 'endPosition': endPosition,
+ 'endOffset': endOffset,
+ 'duration': duration,
+ 'target': e.target
+ };
+ $this.data('callee1', tapHoldFunc1);
+ triggerCustomEvent(thisObject, 'taphold', e, touchData);
+ }
+ }, settings.taphold_threshold);
+
+ return true;
+ }
+ }).on(settings.endevent, function tapHoldFunc2() {
+ $this.data('callee2', tapHoldFunc2);
+ $this.data('tapheld', false);
+ window.clearTimeout(settings.hold_timer);
+ })
+ .on(settings.moveevent, function tapHoldFunc3(e) {
+ $this.data('callee3', tapHoldFunc3);
+
+ end_x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2).off(settings.moveevent, $(this).data.callee3);
+ }
+ };
+
+ // doubletap Event:
+ $.event.special.doubletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ action,
+ firstTap = null,
+ origEvent,
+ cooloff,
+ cooling = false;
+
+ $this.on(settings.startevent, function doubleTapFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+ $this.data('doubletapped', false);
+ origTarget = e.target;
+ $this.data('callee1', doubleTapFunc1);
+
+ origEvent = e.originalEvent;
+ if (!firstTap) {
+ firstTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.position().left) : Math.round(e.pageX - $this.position().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.position().top) : Math.round(e.pageY - $this.position().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ }
+
+ return true;
+ }).on(settings.endevent, function doubleTapFunc2(e) {
+
+ var now = Date.now();
+ var lastTouch = $this.data('lastTouch') || now + 1;
+ var delta = now - lastTouch;
+ window.clearTimeout(action);
+ $this.data('callee2', doubleTapFunc2);
+
+ if (delta < settings.doubletap_int && (e.target == origTarget) && delta > 100) {
+ $this.data('doubletapped', true);
+ window.clearTimeout(settings.tap_timer);
+
+ // Now get the current event:
+ var lastTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? e.originalEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? e.originalEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.position().left) : Math.round(e.pageX - $this.position().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.position().top) : Math.round(e.pageY - $this.position().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ var touchData = {
+ 'firstTap': firstTap,
+ 'secondTap': lastTap,
+ 'interval': lastTap.time - firstTap.time
+ };
+
+ if (!cooling) {
+ triggerCustomEvent(thisObject, 'doubletap', e, touchData);
+ firstTap = null;
+ }
+
+ cooling = true;
+
+ cooloff = window.setTimeout(function () {
+ cooling = false;
+ }, settings.doubletap_int);
+
+ } else {
+ $this.data('lastTouch', now);
+ action = window.setTimeout(function () {
+ firstTap = null;
+ window.clearTimeout(action);
+ }, settings.doubletap_int, [e]);
+ }
+ $this.data('lastTouch', now);
+ });
+ },
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // singletap Event:
+ // This is used in conjuction with doubletap when both events are needed on the same element
+ $.event.special.singletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget = null,
+ startTime = null,
+ start_pos = {
+ x: 0,
+ y: 0
+ };
+
+ $this.on(settings.startevent, function singleTapFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ startTime = Date.now();
+ origTarget = e.target;
+ $this.data('callee1', singleTapFunc1);
+
+ // Get the start x and y position:
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ return true;
+ }
+ }).on(settings.endevent, function singleTapFunc2(e) {
+ $this.data('callee2', singleTapFunc2);
+ if (e.target == origTarget) {
+ // Get the end point:
+ var end_pos_x = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX;
+ var end_pos_y = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY;
+
+ // We need to check if it was a taphold:
+
+ settings.tap_timer = window.setTimeout(function () {
+ if (!$this.data('doubletapped') && !$this.data('tapheld') && (start_pos.x == end_pos_x) && (start_pos.y == end_pos_y)) {
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.position().left) : Math.round(e.pageX - $this.position().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.position().top) : Math.round(e.pageY - $this.position().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Was it a taphold?
+ if((touchData.time - startTime) < settings.taphold_threshold)
+ {
+ triggerCustomEvent(thisObject, 'singletap', e, touchData);
+ }
+ }
+ }, settings.doubletap_int);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // tap Event:
+ $.event.special.tap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ origTarget = null,
+ start_time,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ touches;
+
+ $this.on(settings.startevent, function tapFunc1(e) {
+ $this.data('callee1', tapFunc1);
+
+ if( e.which && e.which !== 1 )
+ {
+ return false;
+ }
+ else
+ {
+ started = true;
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ start_time = Date.now();
+ origTarget = e.target;
+
+ touches = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches : [ e ];
+ return true;
+ }
+ }).on(settings.endevent, function tapFunc2(e) {
+ $this.data('callee2', tapFunc2);
+
+ // Only trigger if they've started, and the target matches:
+ var end_x = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY,
+ diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y),
+ eventName;
+
+ if (origTarget == e.target && started && ((Date.now() - start_time) < settings.taphold_threshold) && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ var origEvent = e.originalEvent;
+ var touchData = [ ];
+
+ for( var i = 0; i < touches.length; i++)
+ {
+ var touch = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[i].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[i].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageX - $this.position().left) : Math.round(e.pageX - $this.position().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageY - $this.position().top) : Math.round(e.pageY - $this.position().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ touchData.push( touch );
+ }
+
+ switch( touches.length )
+ {
+ case 1:
+ eventName = 'tap';
+ break;
+
+ case 2:
+ eventName = 'tap2';
+ break;
+
+ case 3:
+ eventName = 'tap3';
+ break;
+
+ case 4:
+ eventName = 'tap4';
+ break;
+ }
+
+ triggerCustomEvent(thisObject, eventName, e, touchData);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // swipe Event (also handles swipeup, swiperight, swipedown and swipeleft):
+ $.event.special.swipe = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ hasSwiped = false,
+ originalCoord = {
+ x: 0,
+ y: 0
+ },
+ finalCoord = {
+ x: 0,
+ y: 0
+ },
+ startEvnt;
+
+ // Screen touched, store the original coordinate
+
+ function touchStart(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee1', touchStart);
+ originalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ originalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ finalCoord.x = originalCoord.x;
+ finalCoord.y = originalCoord.y;
+ started = true;
+ var origEvent = e.originalEvent;
+ // Read event data into our startEvt:
+ startEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.position().left) : Math.round(e.pageX - $this.position().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.position().top) : Math.round(e.pageY - $this.position().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ }
+
+ // Store coordinates as finger is swiping
+
+ function touchMove(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee2', touchMove);
+ finalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ finalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ var swipedir;
+
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = ($this.parent().data('xthreshold')) ? $this.parent().data('xthreshold') : $this.data('xthreshold'),
+ ele_y_threshold = ($this.parent().data('ythreshold')) ? $this.parent().data('ythreshold') : $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ if (originalCoord.y > finalCoord.y && (originalCoord.y - finalCoord.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (originalCoord.x < finalCoord.x && (finalCoord.x - originalCoord.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (originalCoord.y < finalCoord.y && (finalCoord.y - originalCoord.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (originalCoord.x > finalCoord.x && (originalCoord.x - finalCoord.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+ if (swipedir != undefined && started) {
+ originalCoord.x = 0;
+ originalCoord.y = 0;
+ finalCoord.x = 0;
+ finalCoord.y = 0;
+ started = false;
+
+ // Read event data into our endEvnt:
+ var origEvent = e.originalEvent;
+ var endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.position().left) : Math.round(e.pageX - $this.position().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.position().top) : Math.round(e.pageY - $this.position().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ };
+ hasSwiped = true;
+ $this.trigger('swipe', touchData).trigger(swipedir, touchData);
+ }
+ }
+
+ function touchEnd(e) {
+ $this = $(e.currentTarget);
+ var swipedir = "";
+ $this.data('callee3', touchEnd);
+ if (hasSwiped) {
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = $this.data('xthreshold'),
+ ele_y_threshold = $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ var origEvent = e.originalEvent;
+ var endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.position().left) : Math.round(e.pageX - $this.position().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.position().top) : Math.round(e.pageY - $this.position().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Read event data into our endEvnt:
+ if (startEvnt.position.y > endEvnt.position.y && (startEvnt.position.y - endEvnt.position.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (startEvnt.position.x < endEvnt.position.x && (endEvnt.position.x - startEvnt.position.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (startEvnt.position.y < endEvnt.position.y && (endEvnt.position.y - startEvnt.position.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (startEvnt.position.x > endEvnt.position.x && (startEvnt.position.x - endEvnt.position.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ };
+ $this.trigger('swipeend', touchData);
+ }
+
+ started = false;
+ hasSwiped = false;
+ }
+
+ $this.on(settings.startevent, touchStart);
+ $this.on(settings.moveevent, touchMove);
+ $this.on(settings.endevent, touchEnd);
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.moveevent, $(this).data.callee2).off(settings.endevent, $(this).data.callee3);
+ }
+ };
+
+ // scrollstart Event (also handles scrollend):
+ $.event.special.scrollstart = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ scrolling,
+ timer;
+
+ function trigger(event, state) {
+ scrolling = state;
+ triggerCustomEvent(thisObject, scrolling ? 'scrollstart' : 'scrollend', event);
+ }
+
+ // iPhone triggers scroll after a small delay; use touchmove instead
+ $this.on(settings.scrollevent, function scrollFunc(event) {
+ $this.data('callee', scrollFunc);
+
+ if (!scrolling) {
+ trigger(event, true);
+ }
+
+ clearTimeout(timer);
+ timer = setTimeout(function () {
+ trigger(event, false);
+ }, 50);
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.scrollevent, $(this).data.callee);
+ }
+ };
+
+ // This is the orientation change (largely borrowed from jQuery Mobile):
+ var win = $(window),
+ special_event,
+ get_orientation,
+ last_orientation,
+ initial_orientation_is_landscape,
+ initial_orientation_is_default,
+ portrait_map = {
+ '0': true,
+ '180': true
+ };
+
+ if (settings.orientation_support) {
+ var ww = window.innerWidth || win.width(),
+ wh = window.innerHeight || win.height(),
+ landscape_threshold = 50;
+
+ initial_orientation_is_landscape = ww > wh && (ww - wh) > landscape_threshold;
+ initial_orientation_is_default = portrait_map[window.orientation];
+
+ if ((initial_orientation_is_landscape && initial_orientation_is_default) || (!initial_orientation_is_landscape && !initial_orientation_is_default)) {
+ portrait_map = {
+ '-90': true,
+ '90': true
+ };
+ }
+ }
+
+ $.event.special.orientationchange = special_event = {
+ setup: function () {
+ // If the event is supported natively, return false so that jQuery
+ // will on to the event using DOM methods.
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ // Get the current orientation to avoid initial double-triggering.
+ last_orientation = get_orientation();
+
+ win.on('throttledresize', handler);
+ return true;
+ },
+ teardown: function () {
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ win.off('throttledresize', handler);
+ return true;
+ },
+ add: function (handleObj) {
+ // Save a reference to the bound event handler.
+ var old_handler = handleObj.handler;
+
+ handleObj.handler = function (event) {
+ event.orientation = get_orientation();
+ return old_handler.apply(this, arguments);
+ };
+ }
+ };
+
+ // If the event is not supported natively, this handler will be bound to
+ // the window resize event to simulate the orientationchange event.
+
+ function handler() {
+ // Get the current orientation.
+ var orientation = get_orientation();
+
+ if (orientation !== last_orientation) {
+ // The orientation has changed, so trigger the orientationchange event.
+ last_orientation = orientation;
+ win.trigger("orientationchange");
+ }
+ }
+
+ $.event.special.orientationchange.orientation = get_orientation = function () {
+ var isPortrait = true,
+ elem = document.documentElement;
+
+ if (settings.orientation_support) {
+ isPortrait = portrait_map[window.orientation];
+ } else {
+ isPortrait = elem && elem.clientWidth / elem.clientHeight < 1.1;
+ }
+
+ return isPortrait ? 'portrait' : 'landscape';
+ };
+
+ // throttle Handler:
+ $.event.special.throttledresize = {
+ setup: function () {
+ $(this).on('resize', throttle_handler);
+ },
+ teardown: function () {
+ $(this).off('resize', throttle_handler);
+ }
+ };
+
+ var throttle = 250,
+ throttle_handler = function () {
+ curr = Date.now();
+ diff = curr - lastCall;
+
+ if (diff >= throttle) {
+ lastCall = curr;
+ $(this).trigger('throttledresize');
+
+ } else {
+ if (heldCall) {
+ window.clearTimeout(heldCall);
+ }
+
+ // Promise a held call will still execute
+ heldCall = window.setTimeout(handler, throttle - diff);
+ }
+ },
+ lastCall = 0,
+ heldCall,
+ curr,
+ diff;
+
+ // Trigger a custom event:
+
+ function triggerCustomEvent(obj, eventType, event, touchData) {
+ var originalType = event.type;
+ event.type = eventType;
+
+ $.event.dispatch.call(obj, event, touchData);
+ event.type = originalType;
+ }
+
+ // Correctly on anything we've overloaded:
+ $.each({
+ scrollend: 'scrollstart',
+ swipeup: 'swipe',
+ swiperight: 'swipe',
+ swipedown: 'swipe',
+ swipeleft: 'swipe',
+ swipeend: 'swipe',
+ tap2: 'tap'
+ }, function (e, srcE) {
+ $.event.special[e] = {
+ setup: function () {
+ $(this).on(srcE, $.noop);
+ }
+ };
+ });
+
+}(jQuery));
diff --git a/src/1.0.3/jquery.mobile-events.min.js b/src/1.0.3/jquery.mobile-events.min.js
new file mode 100644
index 0000000..f5f7c1f
--- /dev/null
+++ b/src/1.0.3/jquery.mobile-events.min.js
@@ -0,0 +1 @@
+"use strict";!function(e){function t(){var e=s();e!==c&&(c=e,l.trigger("orientationchange"))}function a(t,a,n,o){var i=n.type;n.type=a,e.event.dispatch.call(t,n,o),n.type=i}e.attrFn=e.attrFn||{};var n=navigator.userAgent.toLowerCase(),o=n.indexOf("chrome")>-1&&(n.indexOf("windows")>-1||n.indexOf("macintosh")>-1||n.indexOf("linux")>-1)&&n.indexOf("mobile")<0&&n.indexOf("android")<0,i={tap_pixel_range:5,swipe_h_threshold:50,swipe_v_threshold:50,taphold_threshold:750,doubletap_int:500,touch_capable:window.navigator.msPointerEnabled?!1:"ontouchstart"in window&&!o,orientation_support:"orientation"in window&&"onorientationchange"in window,startevent:window.navigator.msPointerEnabled?"MSPointerDown":"ontouchstart"in window&&!o?"touchstart":"mousedown",endevent:window.navigator.msPointerEnabled?"MSPointerUp":"ontouchstart"in window&&!o?"touchend":"mouseup",moveevent:window.navigator.msPointerEnabled?"MSPointerMove":"ontouchstart"in window&&!o?"touchmove":"mousemove",tapevent:"ontouchstart"in window&&!o?"tap":"click",scrollevent:"ontouchstart"in window&&!o?"touchmove":"scroll",hold_timer:null,tap_timer:null};e.isTouchCapable=function(){return i.touch_capable},e.getStartEvent=function(){return i.startevent},e.getEndEvent=function(){return i.endevent},e.getMoveEvent=function(){return i.moveevent},e.getTapEvent=function(){return i.tapevent},e.getScrollEvent=function(){return i.scrollevent},e.each(["tapstart","tapend","tapmove","tap","tap2","tap3","tap4","singletap","doubletap","taphold","swipe","swipeup","swiperight","swipedown","swipeleft","swipeend","scrollstart","scrollend","orientationchange"],function(t,a){e.fn[a]=function(e){return e?this.on(a,e):this.trigger(a)},e.attrFn[a]=!0}),e.event.special.tapstart={setup:function(){var t=this,n=e(t);n.on(i.startevent,function o(e){if(n.data("callee",o),e.which&&1!==e.which)return!1;var r=e.originalEvent,s={position:{x:i.touch_capable?r.touches[0].screenX:e.screenX,y:i.touch_capable?r.touches[0].screenY:e.screenY},offset:{x:Math.round(i.touch_capable?r.changedTouches[0].pageX-n.position().left:e.pageX-n.position().left),y:Math.round(i.touch_capable?r.changedTouches[0].pageY-n.position().top:e.pageY-n.position().top)},time:Date.now(),target:e.target};return a(t,"tapstart",e,s),!0})},remove:function(){e(this).off(i.startevent,e(this).data.callee)}},e.event.special.tapmove={setup:function(){var t=this,n=e(t);n.on(i.moveevent,function o(e){n.data("callee",o);var r=e.originalEvent,s={position:{x:i.touch_capable?r.touches[0].screenX:e.screenX,y:i.touch_capable?r.touches[0].screenY:e.screenY},offset:{x:Math.round(i.touch_capable?r.changedTouches[0].pageX-n.position().left:e.pageX-n.position().left),y:Math.round(i.touch_capable?r.changedTouches[0].pageY-n.position().top:e.pageY-n.position().top)},time:Date.now(),target:e.target};return a(t,"tapmove",e,s),!0})},remove:function(){e(this).off(i.moveevent,e(this).data.callee)}},e.event.special.tapend={setup:function(){var t=this,n=e(t);n.on(i.endevent,function o(e){n.data("callee",o);var r=e.originalEvent,s={position:{x:i.touch_capable?r.changedTouches[0].screenX:e.screenX,y:i.touch_capable?r.changedTouches[0].screenY:e.screenY},offset:{x:Math.round(i.touch_capable?r.changedTouches[0].pageX-n.position().left:e.pageX-n.position().left),y:Math.round(i.touch_capable?r.changedTouches[0].pageY-n.position().top:e.pageY-n.position().top)},time:Date.now(),target:e.target};return a(t,"tapend",e,s),!0})},remove:function(){e(this).off(i.endevent,e(this).data.callee)}},e.event.special.taphold={setup:function(){var t,n=this,o=e(n),r={x:0,y:0},s=0,c=0;o.on(i.startevent,function p(e){if(e.which&&1!==e.which)return!1;o.data("tapheld",!1),t=e.target;var h=e.originalEvent,l=Date.now(),u={x:i.touch_capable?h.touches[0].screenX:e.screenX,y:i.touch_capable?h.touches[0].screenY:e.screenY},g={x:i.touch_capable?h.touches[0].pageX-h.touches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?h.touches[0].pageY-h.touches[0].target.offsetTop:e.offsetY};return r.x=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageX:e.pageX,r.y=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageY:e.pageY,s=r.x,c=r.y,i.hold_timer=window.setTimeout(function(){var d=r.x-s,f=r.y-c;if(e.target==t&&(r.x==s&&r.y==c||d>=-i.tap_pixel_range&&d<=i.tap_pixel_range&&f>=-i.tap_pixel_range&&f<=i.tap_pixel_range)){o.data("tapheld",!0);var v=Date.now(),w={x:i.touch_capable?h.touches[0].screenX:e.screenX,y:i.touch_capable?h.touches[0].screenY:e.screenY},_={x:Math.round(i.touch_capable?h.changedTouches[0].pageX-o.position().left:e.pageX-o.position().left),y:Math.round(i.touch_capable?h.changedTouches[0].pageY-o.position().top:e.pageY-o.position().top)},T=v-l,x={startTime:l,endTime:v,startPosition:u,startOffset:g,endPosition:w,endOffset:_,duration:T,target:e.target};o.data("callee1",p),a(n,"taphold",e,x)}},i.taphold_threshold),!0}).on(i.endevent,function h(){o.data("callee2",h),o.data("tapheld",!1),window.clearTimeout(i.hold_timer)}).on(i.moveevent,function l(e){o.data("callee3",l),s=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageX:e.pageX,c=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageY:e.pageY})},remove:function(){e(this).off(i.startevent,e(this).data.callee1).off(i.endevent,e(this).data.callee2).off(i.moveevent,e(this).data.callee3)}},e.event.special.doubletap={setup:function(){var t,n,o,r,s=this,c=e(s),p=null,h=!1;c.on(i.startevent,function l(e){return e.which&&1!==e.which?!1:(c.data("doubletapped",!1),t=e.target,c.data("callee1",l),o=e.originalEvent,p||(p={position:{x:i.touch_capable?o.touches[0].screenX:e.screenX,y:i.touch_capable?o.touches[0].screenY:e.screenY},offset:{x:Math.round(i.touch_capable?o.changedTouches[0].pageX-c.position().left:e.pageX-c.position().left),y:Math.round(i.touch_capable?o.changedTouches[0].pageY-c.position().top:e.pageY-c.position().top)},time:Date.now(),target:e.target}),!0)}).on(i.endevent,function u(e){var l=Date.now(),g=c.data("lastTouch")||l+1,d=l-g;if(window.clearTimeout(n),c.data("callee2",u),d100){c.data("doubletapped",!0),window.clearTimeout(i.tap_timer);var f={position:{x:i.touch_capable?e.originalEvent.changedTouches[0].screenX:e.screenX,y:i.touch_capable?e.originalEvent.changedTouches[0].screenY:e.screenY},offset:{x:Math.round(i.touch_capable?o.changedTouches[0].pageX-c.position().left:e.pageX-c.position().left),y:Math.round(i.touch_capable?o.changedTouches[0].pageY-c.position().top:e.pageY-c.position().top)},time:Date.now(),target:e.target},v={firstTap:p,secondTap:f,interval:f.time-p.time};h||(a(s,"doubletap",e,v),p=null),h=!0,r=window.setTimeout(function(){h=!1},i.doubletap_int)}else c.data("lastTouch",l),n=window.setTimeout(function(){p=null,window.clearTimeout(n)},i.doubletap_int,[e]);c.data("lastTouch",l)})},remove:function(){e(this).off(i.startevent,e(this).data.callee1).off(i.endevent,e(this).data.callee2)}},e.event.special.singletap={setup:function(){var t=this,n=e(t),o=null,r=null,s={x:0,y:0};n.on(i.startevent,function c(e){return e.which&&1!==e.which?!1:(r=Date.now(),o=e.target,n.data("callee1",c),s.x=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageX:e.pageX,s.y=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageY:e.pageY,!0)}).on(i.endevent,function p(e){if(n.data("callee2",p),e.target==o){var c=e.originalEvent.changedTouches?e.originalEvent.changedTouches[0].pageX:e.pageX,h=e.originalEvent.changedTouches?e.originalEvent.changedTouches[0].pageY:e.pageY;i.tap_timer=window.setTimeout(function(){if(!n.data("doubletapped")&&!n.data("tapheld")&&s.x==c&&s.y==h){var o=e.originalEvent,p={position:{x:i.touch_capable?o.changedTouches[0].screenX:e.screenX,y:i.touch_capable?o.changedTouches[0].screenY:e.screenY},offset:{x:Math.round(i.touch_capable?o.changedTouches[0].pageX-n.position().left:e.pageX-n.position().left),y:Math.round(i.touch_capable?o.changedTouches[0].pageY-n.position().top:e.pageY-n.position().top)},time:Date.now(),target:e.target};p.time-r=-i.tap_pixel_range&&d<=i.tap_pixel_range&&f>=-i.tap_pixel_range&&f<=i.tap_pixel_range)){for(var v=e.originalEvent,w=[],_=0;_l.y&&h.y-l.y>d&&(n="swipeup"),h.xg&&(n="swiperight"),h.yd&&(n="swipedown"),h.x>l.x&&h.x-l.x>g&&(n="swipeleft"),void 0!=n&&c){h.x=0,h.y=0,l.x=0,l.y=0,c=!1;var f=t.originalEvent,v={position:{x:i.touch_capable?f.touches[0].screenX:t.screenX,y:i.touch_capable?f.touches[0].screenY:t.screenY},offset:{x:Math.round(i.touch_capable?f.changedTouches[0].pageX-s.position().left:t.pageX-s.position().left),y:Math.round(i.touch_capable?f.changedTouches[0].pageY-s.position().top:t.pageY-s.position().top)},time:Date.now(),target:t.target},w=Math.abs(o.position.x-v.position.x),_=Math.abs(o.position.y-v.position.y),T={startEvnt:o,endEvnt:v,direction:n.replace("swipe",""),xAmount:w,yAmount:_,duration:v.time-o.time};p=!0,s.trigger("swipe",T).trigger(n,T)}}function n(t){s=e(t.currentTarget);var a="";if(s.data("callee3",n),p){var r=s.data("xthreshold"),h=s.data("ythreshold"),l="undefined"!=typeof r&&r!==!1&&parseInt(r)?parseInt(r):i.swipe_h_threshold,u="undefined"!=typeof h&&h!==!1&&parseInt(h)?parseInt(h):i.swipe_v_threshold,g=t.originalEvent,d={position:{x:i.touch_capable?g.changedTouches[0].screenX:t.screenX,y:i.touch_capable?g.changedTouches[0].screenY:t.screenY},offset:{x:Math.round(i.touch_capable?g.changedTouches[0].pageX-s.position().left:t.pageX-s.position().left),y:Math.round(i.touch_capable?g.changedTouches[0].pageY-s.position().top:t.pageY-s.position().top)},time:Date.now(),target:t.target};o.position.y>d.position.y&&o.position.y-d.position.y>u&&(a="swipeup"),o.position.xl&&(a="swiperight"),o.position.yu&&(a="swipedown"),o.position.x>d.position.x&&o.position.x-d.position.x>l&&(a="swipeleft");var f=Math.abs(o.position.x-d.position.x),v=Math.abs(o.position.y-d.position.y),w={startEvnt:o,endEvnt:d,direction:a.replace("swipe",""),xAmount:f,yAmount:v,duration:d.time-o.time};s.trigger("swipeend",w)}c=!1,p=!1}var o,r=this,s=e(r),c=!1,p=!1,h={x:0,y:0},l={x:0,y:0};s.on(i.startevent,t),s.on(i.moveevent,a),s.on(i.endevent,n)},remove:function(){e(this).off(i.startevent,e(this).data.callee1).off(i.moveevent,e(this).data.callee2).off(i.endevent,e(this).data.callee3)}},e.event.special.scrollstart={setup:function(){function t(e,t){n=t,a(r,n?"scrollstart":"scrollend",e)}var n,o,r=this,s=e(r);s.on(i.scrollevent,function c(e){s.data("callee",c),n||t(e,!0),clearTimeout(o),o=setTimeout(function(){t(e,!1)},50)})},remove:function(){e(this).off(i.scrollevent,e(this).data.callee)}};var r,s,c,p,h,l=e(window),u={0:!0,180:!0};if(i.orientation_support){var g=window.innerWidth||l.width(),d=window.innerHeight||l.height(),f=50;p=g>d&&g-d>f,h=u[window.orientation],(p&&h||!p&&!h)&&(u={"-90":!0,90:!0})}e.event.special.orientationchange=r={setup:function(){return i.orientation_support?!1:(c=s(),l.on("throttledresize",t),!0)},teardown:function(){return i.orientation_support?!1:(l.off("throttledresize",t),!0)},add:function(e){var t=e.handler;e.handler=function(e){return e.orientation=s(),t.apply(this,arguments)}}},e.event.special.orientationchange.orientation=s=function(){var e=!0,t=document.documentElement;return e=i.orientation_support?u[window.orientation]:t&&t.clientWidth/t.clientHeight<1.1,e?"portrait":"landscape"},e.event.special.throttledresize={setup:function(){e(this).on("resize",x)},teardown:function(){e(this).off("resize",x)}};var v,w,_,T=250,x=function(){w=Date.now(),_=w-y,_>=T?(y=w,e(this).trigger("throttledresize")):(v&&window.clearTimeout(v),v=window.setTimeout(t,T-_))},y=0;e.each({scrollend:"scrollstart",swipeup:"swipe",swiperight:"swipe",swipedown:"swipe",swipeleft:"swipe",swipeend:"swipe",tap2:"tap"},function(t,a){e.event.special[t]={setup:function(){e(this).on(a,e.noop)}}})}(jQuery);
diff --git a/src/1.0.4/bower.json b/src/1.0.4/bower.json
new file mode 100644
index 0000000..9ef7b56
--- /dev/null
+++ b/src/1.0.4/bower.json
@@ -0,0 +1,11 @@
+{
+ "name": "jquery-touch-events",
+ "version": "1.0.4",
+ "main": "src/jquery.mobile-events.js",
+ "ignore": [
+ "bower.json"
+ ],
+ "dependencies": {
+ "jquery": ">=1.7.0"
+ }
+}
diff --git a/src/1.0.4/jquery.mobile-events.js b/src/1.0.4/jquery.mobile-events.js
new file mode 100644
index 0000000..c60f769
--- /dev/null
+++ b/src/1.0.4/jquery.mobile-events.js
@@ -0,0 +1,867 @@
+/*!
+ * jQuery Mobile Events
+ * by Ben Major (lincweb - www.lincweb.co.uk)
+ *
+ * Copyright 2011-2015, Ben Major
+ * Licensed under the MIT License:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+"use strict";
+
+(function ($) {
+ $.attrFn = $.attrFn || {};
+
+ // navigator.userAgent.toLowerCase() isn't reliable for Chrome installs
+ // on mobile devices. As such, we will create a boolean isChromeDesktop
+ // The reason that we need to do this is because Chrome annoyingly
+ // purports support for touch events even if the underlying hardware
+ // does not!
+ var agent = navigator.userAgent.toLowerCase(),
+ isChromeDesktop = (agent.indexOf('chrome') > -1 && ((agent.indexOf('windows') > -1) || (agent.indexOf('macintosh') > -1) || (agent.indexOf('linux') > -1)) && agent.indexOf('mobile') < 0 && agent.indexOf('android') < 0),
+
+ settings = {
+ tap_pixel_range: 5,
+ swipe_h_threshold: 50,
+ swipe_v_threshold: 50,
+ taphold_threshold: 750,
+ doubletap_int: 500,
+
+ touch_capable: ('ontouchstart' in window && !isChromeDesktop),
+ orientation_support: ('orientation' in window && 'onorientationchange' in window),
+
+ startevent: (('ontouchstart' in window && !isChromeDesktop) ? 'touchstart' : 'mousedown'),
+ endevent: (('ontouchstart' in window && !isChromeDesktop) ? 'touchend' : 'mouseup'),
+ moveevent: (('ontouchstart' in window && !isChromeDesktop) ? 'touchmove' : 'mousemove'),
+ tapevent: ('ontouchstart' in window && !isChromeDesktop) ? 'tap' : 'click',
+ scrollevent: ('ontouchstart' in window && !isChromeDesktop) ? 'touchmove' : 'scroll',
+
+ hold_timer: null,
+ tap_timer: null
+ };
+
+ // Convenience functions:
+ $.isTouchCapable = function() { return settings.touch_capable; };
+ $.getStartEvent = function() { return settings.startevent; };
+ $.getEndEvent = function() { return settings.endevent; };
+ $.getMoveEvent = function() { return settings.moveevent; };
+ $.getTapEvent = function() { return settings.tapevent; };
+ $.getScrollEvent = function() { return settings.scrollevent; };
+
+ // Add Event shortcuts:
+ $.each(['tapstart', 'tapend', 'tapmove', 'tap', 'tap2', 'tap3', 'tap4', 'singletap', 'doubletap', 'taphold', 'swipe', 'swipeup', 'swiperight', 'swipedown', 'swipeleft', 'swipeend', 'scrollstart', 'scrollend', 'orientationchange'], function (i, name) {
+ $.fn[name] = function (fn) {
+ return fn ? this.on(name, fn) : this.trigger(name);
+ };
+
+ $.attrFn[name] = true;
+ });
+
+ // tapstart Event:
+ $.event.special.tapstart = {
+ setup: function () {
+
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.startevent, function tapStartFunc(e) {
+
+ $this.data('callee', tapStartFunc);
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.position().left) : Math.round(e.pageX - $this.position().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.position().top) : Math.round(e.pageY - $this.position().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapstart', e, touchData);
+ return true;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee);
+ }
+ };
+
+ // tapmove Event:
+ $.event.special.tapmove = {
+ setup: function() {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.moveevent, function tapMoveFunc(e) {
+ $this.data('callee', tapMoveFunc);
+
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.position().left) : Math.round(e.pageX - $this.position().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.position().top) : Math.round(e.pageY - $this.position().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapmove', e, touchData);
+ return true;
+ });
+ },
+ remove: function() {
+ $(this).off(settings.moveevent, $(this).data.callee);
+ }
+ };
+
+ // tapend Event:
+ $.event.special.tapend = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.endevent, function tapEndFunc(e) {
+ // Touch event data:
+ $this.data('callee', tapEndFunc);
+
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.position().left) : Math.round(e.pageX - $this.position().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.position().top) : Math.round(e.pageY - $this.position().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ triggerCustomEvent(thisObject, 'tapend', e, touchData);
+ return true;
+ });
+ },
+ remove: function () {
+ $(this).off(settings.endevent, $(this).data.callee);
+ }
+ };
+
+ // taphold Event:
+ $.event.special.taphold = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ end_x = 0,
+ end_y = 0;
+
+ $this.on(settings.startevent, function tapHoldFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ $this.data('tapheld', false);
+ origTarget = e.target;
+
+ var origEvent = e.originalEvent;
+ var start_time = Date.now(),
+ startPosition = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ startOffset = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ };
+
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ end_x = start_pos.x;
+ end_y = start_pos.y;
+
+ settings.hold_timer = window.setTimeout(function () {
+
+ var diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y);
+
+ if (e.target == origTarget && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ $this.data('tapheld', true);
+
+ var end_time = Date.now(),
+ endPosition = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ endOffset = {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.position().left) : Math.round(e.pageX - $this.position().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.position().top) : Math.round(e.pageY - $this.position().top)
+ };
+ var duration = end_time - start_time;
+
+ // Build the touch data:
+ var touchData = {
+ 'startTime': start_time,
+ 'endTime': end_time,
+ 'startPosition': startPosition,
+ 'startOffset': startOffset,
+ 'endPosition': endPosition,
+ 'endOffset': endOffset,
+ 'duration': duration,
+ 'target': e.target
+ };
+ $this.data('callee1', tapHoldFunc1);
+ triggerCustomEvent(thisObject, 'taphold', e, touchData);
+ }
+ }, settings.taphold_threshold);
+
+ return true;
+ }
+ }).on(settings.endevent, function tapHoldFunc2() {
+ $this.data('callee2', tapHoldFunc2);
+ $this.data('tapheld', false);
+ window.clearTimeout(settings.hold_timer);
+ })
+ .on(settings.moveevent, function tapHoldFunc3(e) {
+ $this.data('callee3', tapHoldFunc3);
+
+ end_x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2).off(settings.moveevent, $(this).data.callee3);
+ }
+ };
+
+ // doubletap Event:
+ $.event.special.doubletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ action,
+ firstTap = null,
+ origEvent,
+ cooloff,
+ cooling = false;
+
+ $this.on(settings.startevent, function doubleTapFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+ $this.data('doubletapped', false);
+ origTarget = e.target;
+ $this.data('callee1', doubleTapFunc1);
+
+ origEvent = e.originalEvent;
+ if (!firstTap) {
+ firstTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.position().left) : Math.round(e.pageX - $this.position().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.position().top) : Math.round(e.pageY - $this.position().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ }
+
+ return true;
+ }).on(settings.endevent, function doubleTapFunc2(e) {
+
+ var now = Date.now();
+ var lastTouch = $this.data('lastTouch') || now + 1;
+ var delta = now - lastTouch;
+ window.clearTimeout(action);
+ $this.data('callee2', doubleTapFunc2);
+
+ if (delta < settings.doubletap_int && (e.target == origTarget) && delta > 100) {
+ $this.data('doubletapped', true);
+ window.clearTimeout(settings.tap_timer);
+
+ // Now get the current event:
+ var lastTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? e.originalEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? e.originalEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.position().left) : Math.round(e.pageX - $this.position().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.position().top) : Math.round(e.pageY - $this.position().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ var touchData = {
+ 'firstTap': firstTap,
+ 'secondTap': lastTap,
+ 'interval': lastTap.time - firstTap.time
+ };
+
+ if (!cooling) {
+ triggerCustomEvent(thisObject, 'doubletap', e, touchData);
+ firstTap = null;
+ }
+
+ cooling = true;
+
+ cooloff = window.setTimeout(function () {
+ cooling = false;
+ }, settings.doubletap_int);
+
+ } else {
+ $this.data('lastTouch', now);
+ action = window.setTimeout(function () {
+ firstTap = null;
+ window.clearTimeout(action);
+ }, settings.doubletap_int, [e]);
+ }
+ $this.data('lastTouch', now);
+ });
+ },
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // singletap Event:
+ // This is used in conjuction with doubletap when both events are needed on the same element
+ $.event.special.singletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget = null,
+ startTime = null,
+ start_pos = {
+ x: 0,
+ y: 0
+ };
+
+ $this.on(settings.startevent, function singleTapFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ startTime = Date.now();
+ origTarget = e.target;
+ $this.data('callee1', singleTapFunc1);
+
+ // Get the start x and y position:
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ return true;
+ }
+ }).on(settings.endevent, function singleTapFunc2(e) {
+ $this.data('callee2', singleTapFunc2);
+ if (e.target == origTarget) {
+ // Get the end point:
+ var end_pos_x = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX;
+ var end_pos_y = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY;
+
+ // We need to check if it was a taphold:
+
+ settings.tap_timer = window.setTimeout(function () {
+ if (!$this.data('doubletapped') && !$this.data('tapheld') && (start_pos.x == end_pos_x) && (start_pos.y == end_pos_y)) {
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.position().left) : Math.round(e.pageX - $this.position().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.position().top) : Math.round(e.pageY - $this.position().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Was it a taphold?
+ if((touchData.time - startTime) < settings.taphold_threshold)
+ {
+ triggerCustomEvent(thisObject, 'singletap', e, touchData);
+ }
+ }
+ }, settings.doubletap_int);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // tap Event:
+ $.event.special.tap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ origTarget = null,
+ start_time,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ touches;
+
+ $this.on(settings.startevent, function tapFunc1(e) {
+ $this.data('callee1', tapFunc1);
+
+ if( e.which && e.which !== 1 )
+ {
+ return false;
+ }
+ else
+ {
+ started = true;
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ start_time = Date.now();
+ origTarget = e.target;
+
+ touches = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches : [ e ];
+ return true;
+ }
+ }).on(settings.endevent, function tapFunc2(e) {
+ $this.data('callee2', tapFunc2);
+
+ // Only trigger if they've started, and the target matches:
+ var end_x = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY,
+ diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y),
+ eventName;
+
+ if (origTarget == e.target && started && ((Date.now() - start_time) < settings.taphold_threshold) && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ var origEvent = e.originalEvent;
+ var touchData = [ ];
+
+ for( var i = 0; i < touches.length; i++)
+ {
+ var touch = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[i].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[i].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageX - $this.position().left) : Math.round(e.pageX - $this.position().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageY - $this.position().top) : Math.round(e.pageY - $this.position().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ touchData.push( touch );
+ }
+
+ triggerCustomEvent(thisObject, 'tap', e, touchData);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // swipe Event (also handles swipeup, swiperight, swipedown and swipeleft):
+ $.event.special.swipe = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ hasSwiped = false,
+ originalCoord = {
+ x: 0,
+ y: 0
+ },
+ finalCoord = {
+ x: 0,
+ y: 0
+ },
+ startEvnt;
+
+ // Screen touched, store the original coordinate
+
+ function touchStart(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee1', touchStart);
+ originalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ originalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ finalCoord.x = originalCoord.x;
+ finalCoord.y = originalCoord.y;
+ started = true;
+ var origEvent = e.originalEvent;
+ // Read event data into our startEvt:
+ startEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.position().left) : Math.round(e.pageX - $this.position().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.position().top) : Math.round(e.pageY - $this.position().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ }
+
+ // Store coordinates as finger is swiping
+
+ function touchMove(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee2', touchMove);
+ finalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ finalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ var swipedir;
+
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = ($this.parent().data('xthreshold')) ? $this.parent().data('xthreshold') : $this.data('xthreshold'),
+ ele_y_threshold = ($this.parent().data('ythreshold')) ? $this.parent().data('ythreshold') : $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ if (originalCoord.y > finalCoord.y && (originalCoord.y - finalCoord.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (originalCoord.x < finalCoord.x && (finalCoord.x - originalCoord.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (originalCoord.y < finalCoord.y && (finalCoord.y - originalCoord.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (originalCoord.x > finalCoord.x && (originalCoord.x - finalCoord.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+ if (swipedir != undefined && started) {
+ originalCoord.x = 0;
+ originalCoord.y = 0;
+ finalCoord.x = 0;
+ finalCoord.y = 0;
+ started = false;
+
+ // Read event data into our endEvnt:
+ var origEvent = e.originalEvent;
+ var endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.position().left) : Math.round(e.pageX - $this.position().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.position().top) : Math.round(e.pageY - $this.position().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ };
+ hasSwiped = true;
+ $this.trigger('swipe', touchData).trigger(swipedir, touchData);
+ }
+ }
+
+ function touchEnd(e) {
+ $this = $(e.currentTarget);
+ var swipedir = "";
+ $this.data('callee3', touchEnd);
+ if (hasSwiped) {
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = $this.data('xthreshold'),
+ ele_y_threshold = $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ var origEvent = e.originalEvent;
+ var endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.position().left) : Math.round(e.pageX - $this.position().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.position().top) : Math.round(e.pageY - $this.position().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Read event data into our endEvnt:
+ if (startEvnt.position.y > endEvnt.position.y && (startEvnt.position.y - endEvnt.position.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (startEvnt.position.x < endEvnt.position.x && (endEvnt.position.x - startEvnt.position.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (startEvnt.position.y < endEvnt.position.y && (endEvnt.position.y - startEvnt.position.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (startEvnt.position.x > endEvnt.position.x && (startEvnt.position.x - endEvnt.position.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ };
+ $this.trigger('swipeend', touchData);
+ }
+
+ started = false;
+ hasSwiped = false;
+ }
+
+ $this.on(settings.startevent, touchStart);
+ $this.on(settings.moveevent, touchMove);
+ $this.on(settings.endevent, touchEnd);
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.moveevent, $(this).data.callee2).off(settings.endevent, $(this).data.callee3);
+ }
+ };
+
+ // scrollstart Event (also handles scrollend):
+ $.event.special.scrollstart = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ scrolling,
+ timer;
+
+ function trigger(event, state) {
+ scrolling = state;
+ triggerCustomEvent(thisObject, scrolling ? 'scrollstart' : 'scrollend', event);
+ }
+
+ // iPhone triggers scroll after a small delay; use touchmove instead
+ $this.on(settings.scrollevent, function scrollFunc(event) {
+ $this.data('callee', scrollFunc);
+
+ if (!scrolling) {
+ trigger(event, true);
+ }
+
+ clearTimeout(timer);
+ timer = setTimeout(function () {
+ trigger(event, false);
+ }, 50);
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.scrollevent, $(this).data.callee);
+ }
+ };
+
+ // This is the orientation change (largely borrowed from jQuery Mobile):
+ var win = $(window),
+ special_event,
+ get_orientation,
+ last_orientation,
+ initial_orientation_is_landscape,
+ initial_orientation_is_default,
+ portrait_map = {
+ '0': true,
+ '180': true
+ };
+
+ if (settings.orientation_support) {
+ var ww = window.innerWidth || win.width(),
+ wh = window.innerHeight || win.height(),
+ landscape_threshold = 50;
+
+ initial_orientation_is_landscape = ww > wh && (ww - wh) > landscape_threshold;
+ initial_orientation_is_default = portrait_map[window.orientation];
+
+ if ((initial_orientation_is_landscape && initial_orientation_is_default) || (!initial_orientation_is_landscape && !initial_orientation_is_default)) {
+ portrait_map = {
+ '-90': true,
+ '90': true
+ };
+ }
+ }
+
+ $.event.special.orientationchange = special_event = {
+ setup: function () {
+ // If the event is supported natively, return false so that jQuery
+ // will on to the event using DOM methods.
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ // Get the current orientation to avoid initial double-triggering.
+ last_orientation = get_orientation();
+
+ win.on('throttledresize', handler);
+ return true;
+ },
+ teardown: function () {
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ win.off('throttledresize', handler);
+ return true;
+ },
+ add: function (handleObj) {
+ // Save a reference to the bound event handler.
+ var old_handler = handleObj.handler;
+
+ handleObj.handler = function (event) {
+ event.orientation = get_orientation();
+ return old_handler.apply(this, arguments);
+ };
+ }
+ };
+
+ // If the event is not supported natively, this handler will be bound to
+ // the window resize event to simulate the orientationchange event.
+
+ function handler() {
+ // Get the current orientation.
+ var orientation = get_orientation();
+
+ if (orientation !== last_orientation) {
+ // The orientation has changed, so trigger the orientationchange event.
+ last_orientation = orientation;
+ win.trigger("orientationchange");
+ }
+ }
+
+ $.event.special.orientationchange.orientation = get_orientation = function () {
+ var isPortrait = true,
+ elem = document.documentElement;
+
+ if (settings.orientation_support) {
+ isPortrait = portrait_map[window.orientation];
+ } else {
+ isPortrait = elem && elem.clientWidth / elem.clientHeight < 1.1;
+ }
+
+ return isPortrait ? 'portrait' : 'landscape';
+ };
+
+ // throttle Handler:
+ $.event.special.throttledresize = {
+ setup: function () {
+ $(this).on('resize', throttle_handler);
+ },
+ teardown: function () {
+ $(this).off('resize', throttle_handler);
+ }
+ };
+
+ var throttle = 250,
+ throttle_handler = function () {
+ curr = Date.now();
+ diff = curr - lastCall;
+
+ if (diff >= throttle) {
+ lastCall = curr;
+ $(this).trigger('throttledresize');
+
+ } else {
+ if (heldCall) {
+ window.clearTimeout(heldCall);
+ }
+
+ // Promise a held call will still execute
+ heldCall = window.setTimeout(handler, throttle - diff);
+ }
+ },
+ lastCall = 0,
+ heldCall,
+ curr,
+ diff;
+
+ // Trigger a custom event:
+
+ function triggerCustomEvent(obj, eventType, event, touchData) {
+ var originalType = event.type;
+ event.type = eventType;
+
+ $.event.dispatch.call(obj, event, touchData);
+ event.type = originalType;
+ }
+
+ // Correctly on anything we've overloaded:
+ $.each({
+ scrollend: 'scrollstart',
+ swipeup: 'swipe',
+ swiperight: 'swipe',
+ swipedown: 'swipe',
+ swipeleft: 'swipe',
+ swipeend: 'swipe',
+ tap2: 'tap'
+ }, function (e, srcE) {
+ $.event.special[e] = {
+ setup: function () {
+ $(this).on(srcE, $.noop);
+ }
+ };
+ });
+
+}(jQuery));
diff --git a/src/1.0.4/jquery.mobile-events.min.js b/src/1.0.4/jquery.mobile-events.min.js
new file mode 100644
index 0000000..5db6423
--- /dev/null
+++ b/src/1.0.4/jquery.mobile-events.min.js
@@ -0,0 +1 @@
+"use strict";!function(e){function t(){var e=s();e!==r&&(r=e,u.trigger("orientationchange"))}function a(t,a,o,n){var i=o.type;o.type=a,e.event.dispatch.call(t,o,n),o.type=i}e.attrFn=e.attrFn||{};var o=navigator.userAgent.toLowerCase(),n=o.indexOf("chrome")>-1&&(o.indexOf("windows")>-1||o.indexOf("macintosh")>-1||o.indexOf("linux")>-1)&&o.indexOf("mobile")<0&&o.indexOf("android")<0,i={tap_pixel_range:5,swipe_h_threshold:50,swipe_v_threshold:50,taphold_threshold:750,doubletap_int:500,touch_capable:"ontouchstart"in window&&!n,orientation_support:"orientation"in window&&"onorientationchange"in window,startevent:"ontouchstart"in window&&!n?"touchstart":"mousedown",endevent:"ontouchstart"in window&&!n?"touchend":"mouseup",moveevent:"ontouchstart"in window&&!n?"touchmove":"mousemove",tapevent:"ontouchstart"in window&&!n?"tap":"click",scrollevent:"ontouchstart"in window&&!n?"touchmove":"scroll",hold_timer:null,tap_timer:null};e.isTouchCapable=function(){return i.touch_capable},e.getStartEvent=function(){return i.startevent},e.getEndEvent=function(){return i.endevent},e.getMoveEvent=function(){return i.moveevent},e.getTapEvent=function(){return i.tapevent},e.getScrollEvent=function(){return i.scrollevent},e.each(["tapstart","tapend","tapmove","tap","tap2","tap3","tap4","singletap","doubletap","taphold","swipe","swipeup","swiperight","swipedown","swipeleft","swipeend","scrollstart","scrollend","orientationchange"],function(t,a){e.fn[a]=function(e){return e?this.on(a,e):this.trigger(a)},e.attrFn[a]=!0}),e.event.special.tapstart={setup:function(){var t=this,o=e(t);o.on(i.startevent,function n(e){if(o.data("callee",n),e.which&&1!==e.which)return!1;var c=e.originalEvent,s={position:{x:i.touch_capable?c.touches[0].screenX:e.screenX,y:i.touch_capable?c.touches[0].screenY:e.screenY},offset:{x:Math.round(i.touch_capable?c.changedTouches[0].pageX-o.position().left:e.pageX-o.position().left),y:Math.round(i.touch_capable?c.changedTouches[0].pageY-o.position().top:e.pageY-o.position().top)},time:Date.now(),target:e.target};return a(t,"tapstart",e,s),!0})},remove:function(){e(this).off(i.startevent,e(this).data.callee)}},e.event.special.tapmove={setup:function(){var t=this,o=e(t);o.on(i.moveevent,function n(e){o.data("callee",n);var c=e.originalEvent,s={position:{x:i.touch_capable?c.touches[0].screenX:e.screenX,y:i.touch_capable?c.touches[0].screenY:e.screenY},offset:{x:Math.round(i.touch_capable?c.changedTouches[0].pageX-o.position().left:e.pageX-o.position().left),y:Math.round(i.touch_capable?c.changedTouches[0].pageY-o.position().top:e.pageY-o.position().top)},time:Date.now(),target:e.target};return a(t,"tapmove",e,s),!0})},remove:function(){e(this).off(i.moveevent,e(this).data.callee)}},e.event.special.tapend={setup:function(){var t=this,o=e(t);o.on(i.endevent,function n(e){o.data("callee",n);var c=e.originalEvent,s={position:{x:i.touch_capable?c.changedTouches[0].screenX:e.screenX,y:i.touch_capable?c.changedTouches[0].screenY:e.screenY},offset:{x:Math.round(i.touch_capable?c.changedTouches[0].pageX-o.position().left:e.pageX-o.position().left),y:Math.round(i.touch_capable?c.changedTouches[0].pageY-o.position().top:e.pageY-o.position().top)},time:Date.now(),target:e.target};return a(t,"tapend",e,s),!0})},remove:function(){e(this).off(i.endevent,e(this).data.callee)}},e.event.special.taphold={setup:function(){var t,o=this,n=e(o),c={x:0,y:0},s=0,r=0;n.on(i.startevent,function p(e){if(e.which&&1!==e.which)return!1;n.data("tapheld",!1),t=e.target;var h=e.originalEvent,u=Date.now(),l={x:i.touch_capable?h.touches[0].screenX:e.screenX,y:i.touch_capable?h.touches[0].screenY:e.screenY},g={x:i.touch_capable?h.touches[0].pageX-h.touches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?h.touches[0].pageY-h.touches[0].target.offsetTop:e.offsetY};return c.x=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageX:e.pageX,c.y=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageY:e.pageY,s=c.x,r=c.y,i.hold_timer=window.setTimeout(function(){var d=c.x-s,f=c.y-r;if(e.target==t&&(c.x==s&&c.y==r||d>=-i.tap_pixel_range&&d<=i.tap_pixel_range&&f>=-i.tap_pixel_range&&f<=i.tap_pixel_range)){n.data("tapheld",!0);var v=Date.now(),w={x:i.touch_capable?h.touches[0].screenX:e.screenX,y:i.touch_capable?h.touches[0].screenY:e.screenY},_={x:Math.round(i.touch_capable?h.changedTouches[0].pageX-n.position().left:e.pageX-n.position().left),y:Math.round(i.touch_capable?h.changedTouches[0].pageY-n.position().top:e.pageY-n.position().top)},T=v-u,x={startTime:u,endTime:v,startPosition:l,startOffset:g,endPosition:w,endOffset:_,duration:T,target:e.target};n.data("callee1",p),a(o,"taphold",e,x)}},i.taphold_threshold),!0}).on(i.endevent,function h(){n.data("callee2",h),n.data("tapheld",!1),window.clearTimeout(i.hold_timer)}).on(i.moveevent,function u(e){n.data("callee3",u),s=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageX:e.pageX,r=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageY:e.pageY})},remove:function(){e(this).off(i.startevent,e(this).data.callee1).off(i.endevent,e(this).data.callee2).off(i.moveevent,e(this).data.callee3)}},e.event.special.doubletap={setup:function(){var t,o,n,c,s=this,r=e(s),p=null,h=!1;r.on(i.startevent,function u(e){return e.which&&1!==e.which?!1:(r.data("doubletapped",!1),t=e.target,r.data("callee1",u),n=e.originalEvent,p||(p={position:{x:i.touch_capable?n.touches[0].screenX:e.screenX,y:i.touch_capable?n.touches[0].screenY:e.screenY},offset:{x:Math.round(i.touch_capable?n.changedTouches[0].pageX-r.position().left:e.pageX-r.position().left),y:Math.round(i.touch_capable?n.changedTouches[0].pageY-r.position().top:e.pageY-r.position().top)},time:Date.now(),target:e.target}),!0)}).on(i.endevent,function l(e){var u=Date.now(),g=r.data("lastTouch")||u+1,d=u-g;if(window.clearTimeout(o),r.data("callee2",l),d100){r.data("doubletapped",!0),window.clearTimeout(i.tap_timer);var f={position:{x:i.touch_capable?e.originalEvent.changedTouches[0].screenX:e.screenX,y:i.touch_capable?e.originalEvent.changedTouches[0].screenY:e.screenY},offset:{x:Math.round(i.touch_capable?n.changedTouches[0].pageX-r.position().left:e.pageX-r.position().left),y:Math.round(i.touch_capable?n.changedTouches[0].pageY-r.position().top:e.pageY-r.position().top)},time:Date.now(),target:e.target},v={firstTap:p,secondTap:f,interval:f.time-p.time};h||(a(s,"doubletap",e,v),p=null),h=!0,c=window.setTimeout(function(){h=!1},i.doubletap_int)}else r.data("lastTouch",u),o=window.setTimeout(function(){p=null,window.clearTimeout(o)},i.doubletap_int,[e]);r.data("lastTouch",u)})},remove:function(){e(this).off(i.startevent,e(this).data.callee1).off(i.endevent,e(this).data.callee2)}},e.event.special.singletap={setup:function(){var t=this,o=e(t),n=null,c=null,s={x:0,y:0};o.on(i.startevent,function r(e){return e.which&&1!==e.which?!1:(c=Date.now(),n=e.target,o.data("callee1",r),s.x=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageX:e.pageX,s.y=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageY:e.pageY,!0)}).on(i.endevent,function p(e){if(o.data("callee2",p),e.target==n){var r=e.originalEvent.changedTouches?e.originalEvent.changedTouches[0].pageX:e.pageX,h=e.originalEvent.changedTouches?e.originalEvent.changedTouches[0].pageY:e.pageY;i.tap_timer=window.setTimeout(function(){if(!o.data("doubletapped")&&!o.data("tapheld")&&s.x==r&&s.y==h){var n=e.originalEvent,p={position:{x:i.touch_capable?n.changedTouches[0].screenX:e.screenX,y:i.touch_capable?n.changedTouches[0].screenY:e.screenY},offset:{x:Math.round(i.touch_capable?n.changedTouches[0].pageX-o.position().left:e.pageX-o.position().left),y:Math.round(i.touch_capable?n.changedTouches[0].pageY-o.position().top:e.pageY-o.position().top)},time:Date.now(),target:e.target};p.time-c=-i.tap_pixel_range&&g<=i.tap_pixel_range&&d>=-i.tap_pixel_range&&d<=i.tap_pixel_range)){for(var f=e.originalEvent,v=[],w=0;wu.y&&h.y-u.y>d&&(o="swipeup"),h.xg&&(o="swiperight"),h.yd&&(o="swipedown"),h.x>u.x&&h.x-u.x>g&&(o="swipeleft"),void 0!=o&&r){h.x=0,h.y=0,u.x=0,u.y=0,r=!1;var f=t.originalEvent,v={position:{x:i.touch_capable?f.touches[0].screenX:t.screenX,y:i.touch_capable?f.touches[0].screenY:t.screenY},offset:{x:Math.round(i.touch_capable?f.changedTouches[0].pageX-s.position().left:t.pageX-s.position().left),y:Math.round(i.touch_capable?f.changedTouches[0].pageY-s.position().top:t.pageY-s.position().top)},time:Date.now(),target:t.target},w=Math.abs(n.position.x-v.position.x),_=Math.abs(n.position.y-v.position.y),T={startEvnt:n,endEvnt:v,direction:o.replace("swipe",""),xAmount:w,yAmount:_,duration:v.time-n.time};p=!0,s.trigger("swipe",T).trigger(o,T)}}function o(t){s=e(t.currentTarget);var a="";if(s.data("callee3",o),p){var c=s.data("xthreshold"),h=s.data("ythreshold"),u="undefined"!=typeof c&&c!==!1&&parseInt(c)?parseInt(c):i.swipe_h_threshold,l="undefined"!=typeof h&&h!==!1&&parseInt(h)?parseInt(h):i.swipe_v_threshold,g=t.originalEvent,d={position:{x:i.touch_capable?g.changedTouches[0].screenX:t.screenX,y:i.touch_capable?g.changedTouches[0].screenY:t.screenY},offset:{x:Math.round(i.touch_capable?g.changedTouches[0].pageX-s.position().left:t.pageX-s.position().left),y:Math.round(i.touch_capable?g.changedTouches[0].pageY-s.position().top:t.pageY-s.position().top)},time:Date.now(),target:t.target};n.position.y>d.position.y&&n.position.y-d.position.y>l&&(a="swipeup"),n.position.xu&&(a="swiperight"),n.position.yl&&(a="swipedown"),n.position.x>d.position.x&&n.position.x-d.position.x>u&&(a="swipeleft");var f=Math.abs(n.position.x-d.position.x),v=Math.abs(n.position.y-d.position.y),w={startEvnt:n,endEvnt:d,direction:a.replace("swipe",""),xAmount:f,yAmount:v,duration:d.time-n.time};s.trigger("swipeend",w)}r=!1,p=!1}var n,c=this,s=e(c),r=!1,p=!1,h={x:0,y:0},u={x:0,y:0};s.on(i.startevent,t),s.on(i.moveevent,a),s.on(i.endevent,o)},remove:function(){e(this).off(i.startevent,e(this).data.callee1).off(i.moveevent,e(this).data.callee2).off(i.endevent,e(this).data.callee3)}},e.event.special.scrollstart={setup:function(){function t(e,t){o=t,a(c,o?"scrollstart":"scrollend",e)}var o,n,c=this,s=e(c);s.on(i.scrollevent,function r(e){s.data("callee",r),o||t(e,!0),clearTimeout(n),n=setTimeout(function(){t(e,!1)},50)})},remove:function(){e(this).off(i.scrollevent,e(this).data.callee)}};var c,s,r,p,h,u=e(window),l={0:!0,180:!0};if(i.orientation_support){var g=window.innerWidth||u.width(),d=window.innerHeight||u.height(),f=50;p=g>d&&g-d>f,h=l[window.orientation],(p&&h||!p&&!h)&&(l={"-90":!0,90:!0})}e.event.special.orientationchange=c={setup:function(){return i.orientation_support?!1:(r=s(),u.on("throttledresize",t),!0)},teardown:function(){return i.orientation_support?!1:(u.off("throttledresize",t),!0)},add:function(e){var t=e.handler;e.handler=function(e){return e.orientation=s(),t.apply(this,arguments)}}},e.event.special.orientationchange.orientation=s=function(){var e=!0,t=document.documentElement;return e=i.orientation_support?l[window.orientation]:t&&t.clientWidth/t.clientHeight<1.1,e?"portrait":"landscape"},e.event.special.throttledresize={setup:function(){e(this).on("resize",x)},teardown:function(){e(this).off("resize",x)}};var v,w,_,T=250,x=function(){w=Date.now(),_=w-y,_>=T?(y=w,e(this).trigger("throttledresize")):(v&&window.clearTimeout(v),v=window.setTimeout(t,T-_))},y=0;e.each({scrollend:"scrollstart",swipeup:"swipe",swiperight:"swipe",swipedown:"swipe",swipeleft:"swipe",swipeend:"swipe",tap2:"tap"},function(t,a){e.event.special[t]={setup:function(){e(this).on(a,e.noop)}}})}(jQuery);
diff --git a/src/1.0.5/jquery.mobile-events.js b/src/1.0.5/jquery.mobile-events.js
new file mode 100644
index 0000000..c453f62
--- /dev/null
+++ b/src/1.0.5/jquery.mobile-events.js
@@ -0,0 +1,867 @@
+/*!
+ * jQuery Mobile Events
+ * by Ben Major (lincweb - www.lincweb.co.uk)
+ *
+ * Copyright 2011-2015, Ben Major
+ * Licensed under the MIT License:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+"use strict";
+
+(function ($) {
+ $.attrFn = $.attrFn || {};
+
+ // navigator.userAgent.toLowerCase() isn't reliable for Chrome installs
+ // on mobile devices. As such, we will create a boolean isChromeDesktop
+ // The reason that we need to do this is because Chrome annoyingly
+ // purports support for touch events even if the underlying hardware
+ // does not!
+ var agent = navigator.userAgent.toLowerCase(),
+ isChromeDesktop = (agent.indexOf('chrome') > -1 && ((agent.indexOf('windows') > -1) || (agent.indexOf('macintosh') > -1) || (agent.indexOf('linux') > -1)) && agent.indexOf('mobile') < 0 && agent.indexOf('android') < 0),
+
+ settings = {
+ tap_pixel_range: 5,
+ swipe_h_threshold: 50,
+ swipe_v_threshold: 50,
+ taphold_threshold: 750,
+ doubletap_int: 500,
+
+ touch_capable: ('ontouchstart' in window && !isChromeDesktop),
+ orientation_support: ('orientation' in window && 'onorientationchange' in window),
+
+ startevent: (('ontouchstart' in window && !isChromeDesktop) ? 'touchstart' : 'mousedown'),
+ endevent: (('ontouchstart' in window && !isChromeDesktop) ? 'touchend' : 'mouseup'),
+ moveevent: (('ontouchstart' in window && !isChromeDesktop) ? 'touchmove' : 'mousemove'),
+ tapevent: ('ontouchstart' in window && !isChromeDesktop) ? 'tap' : 'click',
+ scrollevent: ('ontouchstart' in window && !isChromeDesktop) ? 'touchmove' : 'scroll',
+
+ hold_timer: null,
+ tap_timer: null
+ };
+
+ // Convenience functions:
+ $.isTouchCapable = function() { return settings.touch_capable; };
+ $.getStartEvent = function() { return settings.startevent; };
+ $.getEndEvent = function() { return settings.endevent; };
+ $.getMoveEvent = function() { return settings.moveevent; };
+ $.getTapEvent = function() { return settings.tapevent; };
+ $.getScrollEvent = function() { return settings.scrollevent; };
+
+ // Add Event shortcuts:
+ $.each(['tapstart', 'tapend', 'tapmove', 'tap', 'tap2', 'tap3', 'tap4', 'singletap', 'doubletap', 'taphold', 'swipe', 'swipeup', 'swiperight', 'swipedown', 'swipeleft', 'swipeend', 'scrollstart', 'scrollend', 'orientationchange'], function (i, name) {
+ $.fn[name] = function (fn) {
+ return fn ? this.on(name, fn) : this.trigger(name);
+ };
+
+ $.attrFn[name] = true;
+ });
+
+ // tapstart Event:
+ $.event.special.tapstart = {
+ setup: function () {
+
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.startevent, function tapStartFunc(e) {
+
+ $this.data('callee', tapStartFunc);
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.offset().left) : Math.round(e.pageX - $this.offset().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.offset().top) : Math.round(e.pageY - $this.offset().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapstart', e, touchData);
+ return true;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee);
+ }
+ };
+
+ // tapmove Event:
+ $.event.special.tapmove = {
+ setup: function() {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.moveevent, function tapMoveFunc(e) {
+ $this.data('callee', tapMoveFunc);
+
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.offset().left) : Math.round(e.pageX - $this.offset().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.offset().top) : Math.round(e.pageY - $this.offset().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapmove', e, touchData);
+ return true;
+ });
+ },
+ remove: function() {
+ $(this).off(settings.moveevent, $(this).data.callee);
+ }
+ };
+
+ // tapend Event:
+ $.event.special.tapend = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.endevent, function tapEndFunc(e) {
+ // Touch event data:
+ $this.data('callee', tapEndFunc);
+
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.offset().left) : Math.round(e.pageX - $this.offset().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.offset().top) : Math.round(e.pageY - $this.offset().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ triggerCustomEvent(thisObject, 'tapend', e, touchData);
+ return true;
+ });
+ },
+ remove: function () {
+ $(this).off(settings.endevent, $(this).data.callee);
+ }
+ };
+
+ // taphold Event:
+ $.event.special.taphold = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ end_x = 0,
+ end_y = 0;
+
+ $this.on(settings.startevent, function tapHoldFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ $this.data('tapheld', false);
+ origTarget = e.target;
+
+ var origEvent = e.originalEvent;
+ var start_time = Date.now(),
+ startPosition = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ startOffset = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ };
+
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ end_x = start_pos.x;
+ end_y = start_pos.y;
+
+ settings.hold_timer = window.setTimeout(function () {
+
+ var diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y);
+
+ if (e.target == origTarget && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ $this.data('tapheld', true);
+
+ var end_time = Date.now(),
+ endPosition = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ endOffset = {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.offset().left) : Math.round(e.pageX - $this.offset().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.offset().top) : Math.round(e.pageY - $this.offset().top)
+ };
+ var duration = end_time - start_time;
+
+ // Build the touch data:
+ var touchData = {
+ 'startTime': start_time,
+ 'endTime': end_time,
+ 'startPosition': startPosition,
+ 'startOffset': startOffset,
+ 'endPosition': endPosition,
+ 'endOffset': endOffset,
+ 'duration': duration,
+ 'target': e.target
+ };
+ $this.data('callee1', tapHoldFunc1);
+ triggerCustomEvent(thisObject, 'taphold', e, touchData);
+ }
+ }, settings.taphold_threshold);
+
+ return true;
+ }
+ }).on(settings.endevent, function tapHoldFunc2() {
+ $this.data('callee2', tapHoldFunc2);
+ $this.data('tapheld', false);
+ window.clearTimeout(settings.hold_timer);
+ })
+ .on(settings.moveevent, function tapHoldFunc3(e) {
+ $this.data('callee3', tapHoldFunc3);
+
+ end_x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2).off(settings.moveevent, $(this).data.callee3);
+ }
+ };
+
+ // doubletap Event:
+ $.event.special.doubletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ action,
+ firstTap = null,
+ origEvent,
+ cooloff,
+ cooling = false;
+
+ $this.on(settings.startevent, function doubleTapFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+ $this.data('doubletapped', false);
+ origTarget = e.target;
+ $this.data('callee1', doubleTapFunc1);
+
+ origEvent = e.originalEvent;
+ if (!firstTap) {
+ firstTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.offset().left) : Math.round(e.pageX - $this.offset().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.offset().top) : Math.round(e.pageY - $this.offset().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ }
+
+ return true;
+ }).on(settings.endevent, function doubleTapFunc2(e) {
+
+ var now = Date.now();
+ var lastTouch = $this.data('lastTouch') || now + 1;
+ var delta = now - lastTouch;
+ window.clearTimeout(action);
+ $this.data('callee2', doubleTapFunc2);
+
+ if (delta < settings.doubletap_int && (e.target == origTarget) && delta > 100) {
+ $this.data('doubletapped', true);
+ window.clearTimeout(settings.tap_timer);
+
+ // Now get the current event:
+ var lastTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? e.originalEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? e.originalEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.offset().left) : Math.round(e.pageX - $this.offset().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.offset().top) : Math.round(e.pageY - $this.offset().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ var touchData = {
+ 'firstTap': firstTap,
+ 'secondTap': lastTap,
+ 'interval': lastTap.time - firstTap.time
+ };
+
+ if (!cooling) {
+ triggerCustomEvent(thisObject, 'doubletap', e, touchData);
+ firstTap = null;
+ }
+
+ cooling = true;
+
+ cooloff = window.setTimeout(function () {
+ cooling = false;
+ }, settings.doubletap_int);
+
+ } else {
+ $this.data('lastTouch', now);
+ action = window.setTimeout(function () {
+ firstTap = null;
+ window.clearTimeout(action);
+ }, settings.doubletap_int, [e]);
+ }
+ $this.data('lastTouch', now);
+ });
+ },
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // singletap Event:
+ // This is used in conjuction with doubletap when both events are needed on the same element
+ $.event.special.singletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget = null,
+ startTime = null,
+ start_pos = {
+ x: 0,
+ y: 0
+ };
+
+ $this.on(settings.startevent, function singleTapFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ startTime = Date.now();
+ origTarget = e.target;
+ $this.data('callee1', singleTapFunc1);
+
+ // Get the start x and y position:
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ return true;
+ }
+ }).on(settings.endevent, function singleTapFunc2(e) {
+ $this.data('callee2', singleTapFunc2);
+ if (e.target == origTarget) {
+ // Get the end point:
+ var end_pos_x = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX;
+ var end_pos_y = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY;
+
+ // We need to check if it was a taphold:
+
+ settings.tap_timer = window.setTimeout(function () {
+ if (!$this.data('doubletapped') && !$this.data('tapheld') && (start_pos.x == end_pos_x) && (start_pos.y == end_pos_y)) {
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.offset().left) : Math.round(e.pageX - $this.offset().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.offset().top) : Math.round(e.pageY - $this.offset().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Was it a taphold?
+ if((touchData.time - startTime) < settings.taphold_threshold)
+ {
+ triggerCustomEvent(thisObject, 'singletap', e, touchData);
+ }
+ }
+ }, settings.doubletap_int);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // tap Event:
+ $.event.special.tap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ origTarget = null,
+ start_time,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ touches;
+
+ $this.on(settings.startevent, function tapFunc1(e) {
+ $this.data('callee1', tapFunc1);
+
+ if( e.which && e.which !== 1 )
+ {
+ return false;
+ }
+ else
+ {
+ started = true;
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ start_time = Date.now();
+ origTarget = e.target;
+
+ touches = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches : [ e ];
+ return true;
+ }
+ }).on(settings.endevent, function tapFunc2(e) {
+ $this.data('callee2', tapFunc2);
+
+ // Only trigger if they've started, and the target matches:
+ var end_x = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY,
+ diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y),
+ eventName;
+
+ if (origTarget == e.target && started && ((Date.now() - start_time) < settings.taphold_threshold) && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ var origEvent = e.originalEvent;
+ var touchData = [ ];
+
+ for( var i = 0; i < touches.length; i++)
+ {
+ var touch = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[i].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[i].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageX - $this.offset().left) : Math.round(e.pageX - $this.offset().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageY - $this.offset().top) : Math.round(e.pageY - $this.offset().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ touchData.push( touch );
+ }
+
+ triggerCustomEvent(thisObject, 'tap', e, touchData);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // swipe Event (also handles swipeup, swiperight, swipedown and swipeleft):
+ $.event.special.swipe = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ hasSwiped = false,
+ originalCoord = {
+ x: 0,
+ y: 0
+ },
+ finalCoord = {
+ x: 0,
+ y: 0
+ },
+ startEvnt;
+
+ // Screen touched, store the original coordinate
+
+ function touchStart(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee1', touchStart);
+ originalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ originalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ finalCoord.x = originalCoord.x;
+ finalCoord.y = originalCoord.y;
+ started = true;
+ var origEvent = e.originalEvent;
+ // Read event data into our startEvt:
+ startEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.offset().left) : Math.round(e.pageX - $this.offset().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.offset().top) : Math.round(e.pageY - $this.offset().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ }
+
+ // Store coordinates as finger is swiping
+
+ function touchMove(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee2', touchMove);
+ finalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ finalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ var swipedir;
+
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = ($this.parent().data('xthreshold')) ? $this.parent().data('xthreshold') : $this.data('xthreshold'),
+ ele_y_threshold = ($this.parent().data('ythreshold')) ? $this.parent().data('ythreshold') : $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ if (originalCoord.y > finalCoord.y && (originalCoord.y - finalCoord.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (originalCoord.x < finalCoord.x && (finalCoord.x - originalCoord.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (originalCoord.y < finalCoord.y && (finalCoord.y - originalCoord.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (originalCoord.x > finalCoord.x && (originalCoord.x - finalCoord.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+ if (swipedir != undefined && started) {
+ originalCoord.x = 0;
+ originalCoord.y = 0;
+ finalCoord.x = 0;
+ finalCoord.y = 0;
+ started = false;
+
+ // Read event data into our endEvnt:
+ var origEvent = e.originalEvent;
+ var endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.offset().left) : Math.round(e.pageX - $this.offset().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.offset().top) : Math.round(e.pageY - $this.offset().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ };
+ hasSwiped = true;
+ $this.trigger('swipe', touchData).trigger(swipedir, touchData);
+ }
+ }
+
+ function touchEnd(e) {
+ $this = $(e.currentTarget);
+ var swipedir = "";
+ $this.data('callee3', touchEnd);
+ if (hasSwiped) {
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = $this.data('xthreshold'),
+ ele_y_threshold = $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ var origEvent = e.originalEvent;
+ var endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - $this.offset().left) : Math.round(e.pageX - $this.offset().left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - $this.offset().top) : Math.round(e.pageY - $this.offset().top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Read event data into our endEvnt:
+ if (startEvnt.position.y > endEvnt.position.y && (startEvnt.position.y - endEvnt.position.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (startEvnt.position.x < endEvnt.position.x && (endEvnt.position.x - startEvnt.position.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (startEvnt.position.y < endEvnt.position.y && (endEvnt.position.y - startEvnt.position.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (startEvnt.position.x > endEvnt.position.x && (startEvnt.position.x - endEvnt.position.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ };
+ $this.trigger('swipeend', touchData);
+ }
+
+ started = false;
+ hasSwiped = false;
+ }
+
+ $this.on(settings.startevent, touchStart);
+ $this.on(settings.moveevent, touchMove);
+ $this.on(settings.endevent, touchEnd);
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.moveevent, $(this).data.callee2).off(settings.endevent, $(this).data.callee3);
+ }
+ };
+
+ // scrollstart Event (also handles scrollend):
+ $.event.special.scrollstart = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ scrolling,
+ timer;
+
+ function trigger(event, state) {
+ scrolling = state;
+ triggerCustomEvent(thisObject, scrolling ? 'scrollstart' : 'scrollend', event);
+ }
+
+ // iPhone triggers scroll after a small delay; use touchmove instead
+ $this.on(settings.scrollevent, function scrollFunc(event) {
+ $this.data('callee', scrollFunc);
+
+ if (!scrolling) {
+ trigger(event, true);
+ }
+
+ clearTimeout(timer);
+ timer = setTimeout(function () {
+ trigger(event, false);
+ }, 50);
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.scrollevent, $(this).data.callee);
+ }
+ };
+
+ // This is the orientation change (largely borrowed from jQuery Mobile):
+ var win = $(window),
+ special_event,
+ get_orientation,
+ last_orientation,
+ initial_orientation_is_landscape,
+ initial_orientation_is_default,
+ portrait_map = {
+ '0': true,
+ '180': true
+ };
+
+ if (settings.orientation_support) {
+ var ww = window.innerWidth || win.width(),
+ wh = window.innerHeight || win.height(),
+ landscape_threshold = 50;
+
+ initial_orientation_is_landscape = ww > wh && (ww - wh) > landscape_threshold;
+ initial_orientation_is_default = portrait_map[window.orientation];
+
+ if ((initial_orientation_is_landscape && initial_orientation_is_default) || (!initial_orientation_is_landscape && !initial_orientation_is_default)) {
+ portrait_map = {
+ '-90': true,
+ '90': true
+ };
+ }
+ }
+
+ $.event.special.orientationchange = special_event = {
+ setup: function () {
+ // If the event is supported natively, return false so that jQuery
+ // will on to the event using DOM methods.
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ // Get the current orientation to avoid initial double-triggering.
+ last_orientation = get_orientation();
+
+ win.on('throttledresize', handler);
+ return true;
+ },
+ teardown: function () {
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ win.off('throttledresize', handler);
+ return true;
+ },
+ add: function (handleObj) {
+ // Save a reference to the bound event handler.
+ var old_handler = handleObj.handler;
+
+ handleObj.handler = function (event) {
+ event.orientation = get_orientation();
+ return old_handler.apply(this, arguments);
+ };
+ }
+ };
+
+ // If the event is not supported natively, this handler will be bound to
+ // the window resize event to simulate the orientationchange event.
+
+ function handler() {
+ // Get the current orientation.
+ var orientation = get_orientation();
+
+ if (orientation !== last_orientation) {
+ // The orientation has changed, so trigger the orientationchange event.
+ last_orientation = orientation;
+ win.trigger("orientationchange");
+ }
+ }
+
+ $.event.special.orientationchange.orientation = get_orientation = function () {
+ var isPortrait = true,
+ elem = document.documentElement;
+
+ if (settings.orientation_support) {
+ isPortrait = portrait_map[window.orientation];
+ } else {
+ isPortrait = elem && elem.clientWidth / elem.clientHeight < 1.1;
+ }
+
+ return isPortrait ? 'portrait' : 'landscape';
+ };
+
+ // throttle Handler:
+ $.event.special.throttledresize = {
+ setup: function () {
+ $(this).on('resize', throttle_handler);
+ },
+ teardown: function () {
+ $(this).off('resize', throttle_handler);
+ }
+ };
+
+ var throttle = 250,
+ throttle_handler = function () {
+ curr = Date.now();
+ diff = curr - lastCall;
+
+ if (diff >= throttle) {
+ lastCall = curr;
+ $(this).trigger('throttledresize');
+
+ } else {
+ if (heldCall) {
+ window.clearTimeout(heldCall);
+ }
+
+ // Promise a held call will still execute
+ heldCall = window.setTimeout(handler, throttle - diff);
+ }
+ },
+ lastCall = 0,
+ heldCall,
+ curr,
+ diff;
+
+ // Trigger a custom event:
+
+ function triggerCustomEvent(obj, eventType, event, touchData) {
+ var originalType = event.type;
+ event.type = eventType;
+
+ $.event.dispatch.call(obj, event, touchData);
+ event.type = originalType;
+ }
+
+ // Correctly on anything we've overloaded:
+ $.each({
+ scrollend: 'scrollstart',
+ swipeup: 'swipe',
+ swiperight: 'swipe',
+ swipedown: 'swipe',
+ swipeleft: 'swipe',
+ swipeend: 'swipe',
+ tap2: 'tap'
+ }, function (e, srcE) {
+ $.event.special[e] = {
+ setup: function () {
+ $(this).on(srcE, $.noop);
+ }
+ };
+ });
+
+}(jQuery));
diff --git a/src/1.0.5/jquery.mobile-events.min.js b/src/1.0.5/jquery.mobile-events.min.js
new file mode 100644
index 0000000..6176530
--- /dev/null
+++ b/src/1.0.5/jquery.mobile-events.min.js
@@ -0,0 +1 @@
+"use strict";!function(e){function t(){var e=s();e!==r&&(r=e,u.trigger("orientationchange"))}function a(t,a,o,n){var i=o.type;o.type=a,e.event.dispatch.call(t,o,n),o.type=i}e.attrFn=e.attrFn||{};var o=navigator.userAgent.toLowerCase(),n=o.indexOf("chrome")>-1&&(o.indexOf("windows")>-1||o.indexOf("macintosh")>-1||o.indexOf("linux")>-1)&&o.indexOf("mobile")<0&&o.indexOf("android")<0,i={tap_pixel_range:5,swipe_h_threshold:50,swipe_v_threshold:50,taphold_threshold:750,doubletap_int:500,touch_capable:"ontouchstart"in window&&!n,orientation_support:"orientation"in window&&"onorientationchange"in window,startevent:"ontouchstart"in window&&!n?"touchstart":"mousedown",endevent:"ontouchstart"in window&&!n?"touchend":"mouseup",moveevent:"ontouchstart"in window&&!n?"touchmove":"mousemove",tapevent:"ontouchstart"in window&&!n?"tap":"click",scrollevent:"ontouchstart"in window&&!n?"touchmove":"scroll",hold_timer:null,tap_timer:null};e.isTouchCapable=function(){return i.touch_capable},e.getStartEvent=function(){return i.startevent},e.getEndEvent=function(){return i.endevent},e.getMoveEvent=function(){return i.moveevent},e.getTapEvent=function(){return i.tapevent},e.getScrollEvent=function(){return i.scrollevent},e.each(["tapstart","tapend","tapmove","tap","tap2","tap3","tap4","singletap","doubletap","taphold","swipe","swipeup","swiperight","swipedown","swipeleft","swipeend","scrollstart","scrollend","orientationchange"],function(t,a){e.fn[a]=function(e){return e?this.on(a,e):this.trigger(a)},e.attrFn[a]=!0}),e.event.special.tapstart={setup:function(){var t=this,o=e(t);o.on(i.startevent,function n(e){if(o.data("callee",n),e.which&&1!==e.which)return!1;var c=e.originalEvent,s={position:{x:i.touch_capable?c.touches[0].screenX:e.screenX,y:i.touch_capable?c.touches[0].screenY:e.screenY},offset:{x:Math.round(i.touch_capable?c.changedTouches[0].pageX-o.offset().left:e.pageX-o.offset().left),y:Math.round(i.touch_capable?c.changedTouches[0].pageY-o.offset().top:e.pageY-o.offset().top)},time:Date.now(),target:e.target};return a(t,"tapstart",e,s),!0})},remove:function(){e(this).off(i.startevent,e(this).data.callee)}},e.event.special.tapmove={setup:function(){var t=this,o=e(t);o.on(i.moveevent,function n(e){o.data("callee",n);var c=e.originalEvent,s={position:{x:i.touch_capable?c.touches[0].screenX:e.screenX,y:i.touch_capable?c.touches[0].screenY:e.screenY},offset:{x:Math.round(i.touch_capable?c.changedTouches[0].pageX-o.offset().left:e.pageX-o.offset().left),y:Math.round(i.touch_capable?c.changedTouches[0].pageY-o.offset().top:e.pageY-o.offset().top)},time:Date.now(),target:e.target};return a(t,"tapmove",e,s),!0})},remove:function(){e(this).off(i.moveevent,e(this).data.callee)}},e.event.special.tapend={setup:function(){var t=this,o=e(t);o.on(i.endevent,function n(e){o.data("callee",n);var c=e.originalEvent,s={position:{x:i.touch_capable?c.changedTouches[0].screenX:e.screenX,y:i.touch_capable?c.changedTouches[0].screenY:e.screenY},offset:{x:Math.round(i.touch_capable?c.changedTouches[0].pageX-o.offset().left:e.pageX-o.offset().left),y:Math.round(i.touch_capable?c.changedTouches[0].pageY-o.offset().top:e.pageY-o.offset().top)},time:Date.now(),target:e.target};return a(t,"tapend",e,s),!0})},remove:function(){e(this).off(i.endevent,e(this).data.callee)}},e.event.special.taphold={setup:function(){var t,o=this,n=e(o),c={x:0,y:0},s=0,r=0;n.on(i.startevent,function p(e){if(e.which&&1!==e.which)return!1;n.data("tapheld",!1),t=e.target;var h=e.originalEvent,u=Date.now(),l={x:i.touch_capable?h.touches[0].screenX:e.screenX,y:i.touch_capable?h.touches[0].screenY:e.screenY},f={x:i.touch_capable?h.touches[0].pageX-h.touches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?h.touches[0].pageY-h.touches[0].target.offsetTop:e.offsetY};return c.x=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageX:e.pageX,c.y=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageY:e.pageY,s=c.x,r=c.y,i.hold_timer=window.setTimeout(function(){var g=c.x-s,d=c.y-r;if(e.target==t&&(c.x==s&&c.y==r||g>=-i.tap_pixel_range&&g<=i.tap_pixel_range&&d>=-i.tap_pixel_range&&d<=i.tap_pixel_range)){n.data("tapheld",!0);var v=Date.now(),w={x:i.touch_capable?h.touches[0].screenX:e.screenX,y:i.touch_capable?h.touches[0].screenY:e.screenY},_={x:Math.round(i.touch_capable?h.changedTouches[0].pageX-n.offset().left:e.pageX-n.offset().left),y:Math.round(i.touch_capable?h.changedTouches[0].pageY-n.offset().top:e.pageY-n.offset().top)},T=v-u,x={startTime:u,endTime:v,startPosition:l,startOffset:f,endPosition:w,endOffset:_,duration:T,target:e.target};n.data("callee1",p),a(o,"taphold",e,x)}},i.taphold_threshold),!0}).on(i.endevent,function h(){n.data("callee2",h),n.data("tapheld",!1),window.clearTimeout(i.hold_timer)}).on(i.moveevent,function u(e){n.data("callee3",u),s=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageX:e.pageX,r=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageY:e.pageY})},remove:function(){e(this).off(i.startevent,e(this).data.callee1).off(i.endevent,e(this).data.callee2).off(i.moveevent,e(this).data.callee3)}},e.event.special.doubletap={setup:function(){var t,o,n,c,s=this,r=e(s),p=null,h=!1;r.on(i.startevent,function u(e){return e.which&&1!==e.which?!1:(r.data("doubletapped",!1),t=e.target,r.data("callee1",u),n=e.originalEvent,p||(p={position:{x:i.touch_capable?n.touches[0].screenX:e.screenX,y:i.touch_capable?n.touches[0].screenY:e.screenY},offset:{x:Math.round(i.touch_capable?n.changedTouches[0].pageX-r.offset().left:e.pageX-r.offset().left),y:Math.round(i.touch_capable?n.changedTouches[0].pageY-r.offset().top:e.pageY-r.offset().top)},time:Date.now(),target:e.target}),!0)}).on(i.endevent,function l(e){var u=Date.now(),f=r.data("lastTouch")||u+1,g=u-f;if(window.clearTimeout(o),r.data("callee2",l),g100){r.data("doubletapped",!0),window.clearTimeout(i.tap_timer);var d={position:{x:i.touch_capable?e.originalEvent.changedTouches[0].screenX:e.screenX,y:i.touch_capable?e.originalEvent.changedTouches[0].screenY:e.screenY},offset:{x:Math.round(i.touch_capable?n.changedTouches[0].pageX-r.offset().left:e.pageX-r.offset().left),y:Math.round(i.touch_capable?n.changedTouches[0].pageY-r.offset().top:e.pageY-r.offset().top)},time:Date.now(),target:e.target},v={firstTap:p,secondTap:d,interval:d.time-p.time};h||(a(s,"doubletap",e,v),p=null),h=!0,c=window.setTimeout(function(){h=!1},i.doubletap_int)}else r.data("lastTouch",u),o=window.setTimeout(function(){p=null,window.clearTimeout(o)},i.doubletap_int,[e]);r.data("lastTouch",u)})},remove:function(){e(this).off(i.startevent,e(this).data.callee1).off(i.endevent,e(this).data.callee2)}},e.event.special.singletap={setup:function(){var t=this,o=e(t),n=null,c=null,s={x:0,y:0};o.on(i.startevent,function r(e){return e.which&&1!==e.which?!1:(c=Date.now(),n=e.target,o.data("callee1",r),s.x=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageX:e.pageX,s.y=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageY:e.pageY,!0)}).on(i.endevent,function p(e){if(o.data("callee2",p),e.target==n){var r=e.originalEvent.changedTouches?e.originalEvent.changedTouches[0].pageX:e.pageX,h=e.originalEvent.changedTouches?e.originalEvent.changedTouches[0].pageY:e.pageY;i.tap_timer=window.setTimeout(function(){if(!o.data("doubletapped")&&!o.data("tapheld")&&s.x==r&&s.y==h){var n=e.originalEvent,p={position:{x:i.touch_capable?n.changedTouches[0].screenX:e.screenX,y:i.touch_capable?n.changedTouches[0].screenY:e.screenY},offset:{x:Math.round(i.touch_capable?n.changedTouches[0].pageX-o.offset().left:e.pageX-o.offset().left),y:Math.round(i.touch_capable?n.changedTouches[0].pageY-o.offset().top:e.pageY-o.offset().top)},time:Date.now(),target:e.target};p.time-c=-i.tap_pixel_range&&f<=i.tap_pixel_range&&g>=-i.tap_pixel_range&&g<=i.tap_pixel_range)){for(var d=e.originalEvent,v=[],w=0;wu.y&&h.y-u.y>g&&(o="swipeup"),h.xf&&(o="swiperight"),h.yg&&(o="swipedown"),h.x>u.x&&h.x-u.x>f&&(o="swipeleft"),void 0!=o&&r){h.x=0,h.y=0,u.x=0,u.y=0,r=!1;var d=t.originalEvent,v={position:{x:i.touch_capable?d.touches[0].screenX:t.screenX,y:i.touch_capable?d.touches[0].screenY:t.screenY},offset:{x:Math.round(i.touch_capable?d.changedTouches[0].pageX-s.offset().left:t.pageX-s.offset().left),y:Math.round(i.touch_capable?d.changedTouches[0].pageY-s.offset().top:t.pageY-s.offset().top)},time:Date.now(),target:t.target},w=Math.abs(n.position.x-v.position.x),_=Math.abs(n.position.y-v.position.y),T={startEvnt:n,endEvnt:v,direction:o.replace("swipe",""),xAmount:w,yAmount:_,duration:v.time-n.time};p=!0,s.trigger("swipe",T).trigger(o,T)}}function o(t){s=e(t.currentTarget);var a="";if(s.data("callee3",o),p){var c=s.data("xthreshold"),h=s.data("ythreshold"),u="undefined"!=typeof c&&c!==!1&&parseInt(c)?parseInt(c):i.swipe_h_threshold,l="undefined"!=typeof h&&h!==!1&&parseInt(h)?parseInt(h):i.swipe_v_threshold,f=t.originalEvent,g={position:{x:i.touch_capable?f.changedTouches[0].screenX:t.screenX,y:i.touch_capable?f.changedTouches[0].screenY:t.screenY},offset:{x:Math.round(i.touch_capable?f.changedTouches[0].pageX-s.offset().left:t.pageX-s.offset().left),y:Math.round(i.touch_capable?f.changedTouches[0].pageY-s.offset().top:t.pageY-s.offset().top)},time:Date.now(),target:t.target};n.position.y>g.position.y&&n.position.y-g.position.y>l&&(a="swipeup"),n.position.xu&&(a="swiperight"),n.position.yl&&(a="swipedown"),n.position.x>g.position.x&&n.position.x-g.position.x>u&&(a="swipeleft");var d=Math.abs(n.position.x-g.position.x),v=Math.abs(n.position.y-g.position.y),w={startEvnt:n,endEvnt:g,direction:a.replace("swipe",""),xAmount:d,yAmount:v,duration:g.time-n.time};s.trigger("swipeend",w)}r=!1,p=!1}var n,c=this,s=e(c),r=!1,p=!1,h={x:0,y:0},u={x:0,y:0};s.on(i.startevent,t),s.on(i.moveevent,a),s.on(i.endevent,o)},remove:function(){e(this).off(i.startevent,e(this).data.callee1).off(i.moveevent,e(this).data.callee2).off(i.endevent,e(this).data.callee3)}},e.event.special.scrollstart={setup:function(){function t(e,t){o=t,a(c,o?"scrollstart":"scrollend",e)}var o,n,c=this,s=e(c);s.on(i.scrollevent,function r(e){s.data("callee",r),o||t(e,!0),clearTimeout(n),n=setTimeout(function(){t(e,!1)},50)})},remove:function(){e(this).off(i.scrollevent,e(this).data.callee)}};var c,s,r,p,h,u=e(window),l={0:!0,180:!0};if(i.orientation_support){var f=window.innerWidth||u.width(),g=window.innerHeight||u.height(),d=50;p=f>g&&f-g>d,h=l[window.orientation],(p&&h||!p&&!h)&&(l={"-90":!0,90:!0})}e.event.special.orientationchange=c={setup:function(){return i.orientation_support?!1:(r=s(),u.on("throttledresize",t),!0)},teardown:function(){return i.orientation_support?!1:(u.off("throttledresize",t),!0)},add:function(e){var t=e.handler;e.handler=function(e){return e.orientation=s(),t.apply(this,arguments)}}},e.event.special.orientationchange.orientation=s=function(){var e=!0,t=document.documentElement;return e=i.orientation_support?l[window.orientation]:t&&t.clientWidth/t.clientHeight<1.1,e?"portrait":"landscape"},e.event.special.throttledresize={setup:function(){e(this).on("resize",x)},teardown:function(){e(this).off("resize",x)}};var v,w,_,T=250,x=function(){w=Date.now(),_=w-y,_>=T?(y=w,e(this).trigger("throttledresize")):(v&&window.clearTimeout(v),v=window.setTimeout(t,T-_))},y=0;e.each({scrollend:"scrollstart",swipeup:"swipe",swiperight:"swipe",swipedown:"swipe",swipeleft:"swipe",swipeend:"swipe",tap2:"tap"},function(t,a){e.event.special[t]={setup:function(){e(this).on(a,e.noop)}}})}(jQuery);
diff --git a/src/1.0.6/jquery.mobile-events.js b/src/1.0.6/jquery.mobile-events.js
new file mode 100644
index 0000000..21143ff
--- /dev/null
+++ b/src/1.0.6/jquery.mobile-events.js
@@ -0,0 +1,873 @@
+/*!
+ * jQuery Mobile Events
+ * by Ben Major
+ *
+ * Copyright 2011-2015, Ben Major
+ * Licensed under the MIT License:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+"use strict";
+
+(function ($) {
+ $.attrFn = $.attrFn || {};
+
+ // navigator.userAgent.toLowerCase() isn't reliable for Chrome installs
+ // on mobile devices. As such, we will create a boolean isChromeDesktop
+ // The reason that we need to do this is because Chrome annoyingly
+ // purports support for touch events even if the underlying hardware
+ // does not!
+ var agent = navigator.userAgent.toLowerCase(),
+ isChromeDesktop = (agent.indexOf('chrome') > -1 && ((agent.indexOf('windows') > -1) || (agent.indexOf('macintosh') > -1) || (agent.indexOf('linux') > -1)) && agent.indexOf('mobile') < 0 && agent.indexOf('android') < 0),
+
+ settings = {
+ tap_pixel_range: 5,
+ swipe_h_threshold: 50,
+ swipe_v_threshold: 50,
+ taphold_threshold: 750,
+ doubletap_int: 500,
+
+ touch_capable: ('ontouchstart' in window && !isChromeDesktop),
+ orientation_support: ('orientation' in window && 'onorientationchange' in window),
+
+ startevent: (('ontouchstart' in window && !isChromeDesktop) ? 'touchstart' : 'mousedown'),
+ endevent: (('ontouchstart' in window && !isChromeDesktop) ? 'touchend' : 'mouseup'),
+ moveevent: (('ontouchstart' in window && !isChromeDesktop) ? 'touchmove' : 'mousemove'),
+ tapevent: ('ontouchstart' in window && !isChromeDesktop) ? 'tap' : 'click',
+ scrollevent: ('ontouchstart' in window && !isChromeDesktop) ? 'touchmove' : 'scroll',
+
+ hold_timer: null,
+ tap_timer: null
+ };
+
+ // Convenience functions:
+ $.isTouchCapable = function() { return settings.touch_capable; };
+ $.getStartEvent = function() { return settings.startevent; };
+ $.getEndEvent = function() { return settings.endevent; };
+ $.getMoveEvent = function() { return settings.moveevent; };
+ $.getTapEvent = function() { return settings.tapevent; };
+ $.getScrollEvent = function() { return settings.scrollevent; };
+
+ // Add Event shortcuts:
+ $.each(['tapstart', 'tapend', 'tapmove', 'tap', 'tap2', 'tap3', 'tap4', 'singletap', 'doubletap', 'taphold', 'swipe', 'swipeup', 'swiperight', 'swipedown', 'swipeleft', 'swipeend', 'scrollstart', 'scrollend', 'orientationchange'], function (i, name) {
+ $.fn[name] = function (fn) {
+ return fn ? this.on(name, fn) : this.trigger(name);
+ };
+
+ $.attrFn[name] = true;
+ });
+
+ // tapstart Event:
+ $.event.special.tapstart = {
+ setup: function () {
+
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.startevent, function tapStartFunc(e) {
+
+ $this.data('callee', tapStartFunc);
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapstart', e, touchData);
+ return true;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee);
+ }
+ };
+
+ // tapmove Event:
+ $.event.special.tapmove = {
+ setup: function() {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.moveevent, function tapMoveFunc(e) {
+ $this.data('callee', tapMoveFunc);
+
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapmove', e, touchData);
+ return true;
+ });
+ },
+ remove: function() {
+ $(this).off(settings.moveevent, $(this).data.callee);
+ }
+ };
+
+ // tapend Event:
+ $.event.special.tapend = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.endevent, function tapEndFunc(e) {
+ // Touch event data:
+ $this.data('callee', tapEndFunc);
+
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ triggerCustomEvent(thisObject, 'tapend', e, touchData);
+ return true;
+ });
+ },
+ remove: function () {
+ $(this).off(settings.endevent, $(this).data.callee);
+ }
+ };
+
+ // taphold Event:
+ $.event.special.taphold = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ end_x = 0,
+ end_y = 0;
+
+ $this.on(settings.startevent, function tapHoldFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ $this.data('tapheld', false);
+ origTarget = e.target;
+
+ var origEvent = e.originalEvent;
+ var start_time = Date.now(),
+ startPosition = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ startOffset = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ };
+
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ end_x = start_pos.x;
+ end_y = start_pos.y;
+
+ settings.hold_timer = window.setTimeout(function () {
+
+ var diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y);
+
+ if (e.target == origTarget && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ $this.data('tapheld', true);
+
+ var end_time = Date.now(),
+ endPosition = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ endOffset = {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ };
+ var duration = end_time - start_time;
+
+ // Build the touch data:
+ var touchData = {
+ 'startTime': start_time,
+ 'endTime': end_time,
+ 'startPosition': startPosition,
+ 'startOffset': startOffset,
+ 'endPosition': endPosition,
+ 'endOffset': endOffset,
+ 'duration': duration,
+ 'target': e.target
+ };
+ $this.data('callee1', tapHoldFunc1);
+ triggerCustomEvent(thisObject, 'taphold', e, touchData);
+ }
+ }, settings.taphold_threshold);
+
+ return true;
+ }
+ }).on(settings.endevent, function tapHoldFunc2() {
+ $this.data('callee2', tapHoldFunc2);
+ $this.data('tapheld', false);
+ window.clearTimeout(settings.hold_timer);
+ })
+ .on(settings.moveevent, function tapHoldFunc3(e) {
+ $this.data('callee3', tapHoldFunc3);
+
+ end_x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2).off(settings.moveevent, $(this).data.callee3);
+ }
+ };
+
+ // doubletap Event:
+ $.event.special.doubletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ action,
+ firstTap = null,
+ origEvent,
+ cooloff,
+ cooling = false;
+
+ $this.on(settings.startevent, function doubleTapFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+ $this.data('doubletapped', false);
+ origTarget = e.target;
+ $this.data('callee1', doubleTapFunc1);
+
+ origEvent = e.originalEvent;
+ if (!firstTap) {
+ firstTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ }
+
+ return true;
+ }).on(settings.endevent, function doubleTapFunc2(e) {
+
+ var now = Date.now();
+ var lastTouch = $this.data('lastTouch') || now + 1;
+ var delta = now - lastTouch;
+ window.clearTimeout(action);
+ $this.data('callee2', doubleTapFunc2);
+
+ if (delta < settings.doubletap_int && (e.target == origTarget) && delta > 100) {
+ $this.data('doubletapped', true);
+ window.clearTimeout(settings.tap_timer);
+
+ // Now get the current event:
+ var lastTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? e.originalEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? e.originalEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ var touchData = {
+ 'firstTap': firstTap,
+ 'secondTap': lastTap,
+ 'interval': lastTap.time - firstTap.time
+ };
+
+ if (!cooling) {
+ triggerCustomEvent(thisObject, 'doubletap', e, touchData);
+ firstTap = null;
+ }
+
+ cooling = true;
+
+ cooloff = window.setTimeout(function () {
+ cooling = false;
+ }, settings.doubletap_int);
+
+ } else {
+ $this.data('lastTouch', now);
+ action = window.setTimeout(function () {
+ firstTap = null;
+ window.clearTimeout(action);
+ }, settings.doubletap_int, [e]);
+ }
+ $this.data('lastTouch', now);
+ });
+ },
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // singletap Event:
+ // This is used in conjuction with doubletap when both events are needed on the same element
+ $.event.special.singletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget = null,
+ startTime = null,
+ start_pos = {
+ x: 0,
+ y: 0
+ };
+
+ $this.on(settings.startevent, function singleTapFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ startTime = Date.now();
+ origTarget = e.target;
+ $this.data('callee1', singleTapFunc1);
+
+ // Get the start x and y position:
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ return true;
+ }
+ }).on(settings.endevent, function singleTapFunc2(e) {
+ $this.data('callee2', singleTapFunc2);
+ if (e.target == origTarget) {
+
+ // Get the end point:
+ var end_pos_x = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ end_pos_y = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY;
+
+ // We need to check if it was a taphold:
+
+ settings.tap_timer = window.setTimeout(function () {
+
+ var diff_x = (start_pos.x - end_pos_x), diff_y = (start_pos.y - end_pos_y);
+
+ if(!$this.data('doubletapped') && !$this.data('tapheld') && (((start_pos.x == end_pos_x) && (start_pos.y == end_pos_y)) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Was it a taphold?
+ if((touchData.time - startTime) < settings.taphold_threshold)
+ {
+ triggerCustomEvent(thisObject, 'singletap', e, touchData);
+ }
+ }
+ }, settings.doubletap_int);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // tap Event:
+ $.event.special.tap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ origTarget = null,
+ start_time,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ touches;
+
+ $this.on(settings.startevent, function tapFunc1(e) {
+ $this.data('callee1', tapFunc1);
+
+ if( e.which && e.which !== 1 )
+ {
+ return false;
+ }
+ else
+ {
+ started = true;
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ start_time = Date.now();
+ origTarget = e.target;
+
+ touches = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches : [ e ];
+ return true;
+ }
+ }).on(settings.endevent, function tapFunc2(e) {
+ $this.data('callee2', tapFunc2);
+
+ // Only trigger if they've started, and the target matches:
+ var end_x = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY,
+ diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y),
+ eventName;
+
+ if (origTarget == e.target && started && ((Date.now() - start_time) < settings.taphold_threshold) && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ var origEvent = e.originalEvent;
+ var touchData = [ ];
+
+ for( var i = 0; i < touches.length; i++)
+ {
+ var touch = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[i].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[i].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ touchData.push( touch );
+ }
+
+ triggerCustomEvent(thisObject, 'tap', e, touchData);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // swipe Event (also handles swipeup, swiperight, swipedown and swipeleft):
+ $.event.special.swipe = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ hasSwiped = false,
+ originalCoord = {
+ x: 0,
+ y: 0
+ },
+ finalCoord = {
+ x: 0,
+ y: 0
+ },
+ startEvnt;
+
+ // Screen touched, store the original coordinate
+
+ function touchStart(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee1', touchStart);
+ originalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ originalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ finalCoord.x = originalCoord.x;
+ finalCoord.y = originalCoord.y;
+ started = true;
+ var origEvent = e.originalEvent;
+ // Read event data into our startEvt:
+ startEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ }
+
+ // Store coordinates as finger is swiping
+
+ function touchMove(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee2', touchMove);
+ finalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ finalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ var swipedir;
+
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = ($this.parent().data('xthreshold')) ? $this.parent().data('xthreshold') : $this.data('xthreshold'),
+ ele_y_threshold = ($this.parent().data('ythreshold')) ? $this.parent().data('ythreshold') : $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ if (originalCoord.y > finalCoord.y && (originalCoord.y - finalCoord.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (originalCoord.x < finalCoord.x && (finalCoord.x - originalCoord.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (originalCoord.y < finalCoord.y && (finalCoord.y - originalCoord.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (originalCoord.x > finalCoord.x && (originalCoord.x - finalCoord.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+ if (swipedir != undefined && started) {
+ originalCoord.x = 0;
+ originalCoord.y = 0;
+ finalCoord.x = 0;
+ finalCoord.y = 0;
+ started = false;
+
+ // Read event data into our endEvnt:
+ var origEvent = e.originalEvent;
+ var endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ };
+ hasSwiped = true;
+ $this.trigger('swipe', touchData).trigger(swipedir, touchData);
+ }
+ }
+
+ function touchEnd(e) {
+ $this = $(e.currentTarget);
+ var swipedir = "";
+ $this.data('callee3', touchEnd);
+ if (hasSwiped) {
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = $this.data('xthreshold'),
+ ele_y_threshold = $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ var origEvent = e.originalEvent;
+ var endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Read event data into our endEvnt:
+ if (startEvnt.position.y > endEvnt.position.y && (startEvnt.position.y - endEvnt.position.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (startEvnt.position.x < endEvnt.position.x && (endEvnt.position.x - startEvnt.position.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (startEvnt.position.y < endEvnt.position.y && (endEvnt.position.y - startEvnt.position.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (startEvnt.position.x > endEvnt.position.x && (startEvnt.position.x - endEvnt.position.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ };
+ $this.trigger('swipeend', touchData);
+ }
+
+ started = false;
+ hasSwiped = false;
+ }
+
+ $this.on(settings.startevent, touchStart);
+ $this.on(settings.moveevent, touchMove);
+ $this.on(settings.endevent, touchEnd);
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.moveevent, $(this).data.callee2).off(settings.endevent, $(this).data.callee3);
+ }
+ };
+
+ // scrollstart Event (also handles scrollend):
+ $.event.special.scrollstart = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ scrolling,
+ timer;
+
+ function trigger(event, state) {
+ scrolling = state;
+ triggerCustomEvent(thisObject, scrolling ? 'scrollstart' : 'scrollend', event);
+ }
+
+ // iPhone triggers scroll after a small delay; use touchmove instead
+ $this.on(settings.scrollevent, function scrollFunc(event) {
+ $this.data('callee', scrollFunc);
+
+ if (!scrolling) {
+ trigger(event, true);
+ }
+
+ clearTimeout(timer);
+ timer = setTimeout(function () {
+ trigger(event, false);
+ }, 50);
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.scrollevent, $(this).data.callee);
+ }
+ };
+
+ // This is the orientation change (largely borrowed from jQuery Mobile):
+ var win = $(window),
+ special_event,
+ get_orientation,
+ last_orientation,
+ initial_orientation_is_landscape,
+ initial_orientation_is_default,
+ portrait_map = {
+ '0': true,
+ '180': true
+ };
+
+ if (settings.orientation_support) {
+ var ww = window.innerWidth || win.width(),
+ wh = window.innerHeight || win.height(),
+ landscape_threshold = 50;
+
+ initial_orientation_is_landscape = ww > wh && (ww - wh) > landscape_threshold;
+ initial_orientation_is_default = portrait_map[window.orientation];
+
+ if ((initial_orientation_is_landscape && initial_orientation_is_default) || (!initial_orientation_is_landscape && !initial_orientation_is_default)) {
+ portrait_map = {
+ '-90': true,
+ '90': true
+ };
+ }
+ }
+
+ $.event.special.orientationchange = special_event = {
+ setup: function () {
+ // If the event is supported natively, return false so that jQuery
+ // will on to the event using DOM methods.
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ // Get the current orientation to avoid initial double-triggering.
+ last_orientation = get_orientation();
+
+ win.on('throttledresize', handler);
+ return true;
+ },
+ teardown: function () {
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ win.off('throttledresize', handler);
+ return true;
+ },
+ add: function (handleObj) {
+ // Save a reference to the bound event handler.
+ var old_handler = handleObj.handler;
+
+ handleObj.handler = function (event) {
+ event.orientation = get_orientation();
+ return old_handler.apply(this, arguments);
+ };
+ }
+ };
+
+ // If the event is not supported natively, this handler will be bound to
+ // the window resize event to simulate the orientationchange event.
+
+ function handler() {
+ // Get the current orientation.
+ var orientation = get_orientation();
+
+ if (orientation !== last_orientation) {
+ // The orientation has changed, so trigger the orientationchange event.
+ last_orientation = orientation;
+ win.trigger("orientationchange");
+ }
+ }
+
+ $.event.special.orientationchange.orientation = get_orientation = function () {
+ var isPortrait = true,
+ elem = document.documentElement;
+
+ if (settings.orientation_support) {
+ isPortrait = portrait_map[window.orientation];
+ } else {
+ isPortrait = elem && elem.clientWidth / elem.clientHeight < 1.1;
+ }
+
+ return isPortrait ? 'portrait' : 'landscape';
+ };
+
+ // throttle Handler:
+ $.event.special.throttledresize = {
+ setup: function () {
+ $(this).on('resize', throttle_handler);
+ },
+ teardown: function () {
+ $(this).off('resize', throttle_handler);
+ }
+ };
+
+ var throttle = 250,
+ throttle_handler = function () {
+ curr = Date.now();
+ diff = curr - lastCall;
+
+ if (diff >= throttle) {
+ lastCall = curr;
+ $(this).trigger('throttledresize');
+
+ } else {
+ if (heldCall) {
+ window.clearTimeout(heldCall);
+ }
+
+ // Promise a held call will still execute
+ heldCall = window.setTimeout(handler, throttle - diff);
+ }
+ },
+ lastCall = 0,
+ heldCall,
+ curr,
+ diff;
+
+ // Trigger a custom event:
+
+ function triggerCustomEvent(obj, eventType, event, touchData) {
+ var originalType = event.type;
+ event.type = eventType;
+
+ $.event.dispatch.call(obj, event, touchData);
+ event.type = originalType;
+ }
+
+ // Correctly on anything we've overloaded:
+ $.each({
+ scrollend: 'scrollstart',
+ swipeup: 'swipe',
+ swiperight: 'swipe',
+ swipedown: 'swipe',
+ swipeleft: 'swipe',
+ swipeend: 'swipe',
+ tap2: 'tap'
+ }, function (e, srcE) {
+ $.event.special[e] = {
+ setup: function () {
+ $(this).on(srcE, $.noop);
+ }
+ };
+ });
+
+}(jQuery));
diff --git a/src/1.0.6/jquery.mobile-events.min.js b/src/1.0.6/jquery.mobile-events.min.js
new file mode 100644
index 0000000..0e19f41
--- /dev/null
+++ b/src/1.0.6/jquery.mobile-events.min.js
@@ -0,0 +1 @@
+"use strict";!function(a){function o(){var a=g();a!==h&&(h=a,e.trigger("orientationchange"))}function v(b,c,d,e){var f=d.type;d.type=c,a.event.dispatch.call(b,d,e),d.type=f}a.attrFn=a.attrFn||{};var b=navigator.userAgent.toLowerCase(),c=b.indexOf("chrome")>-1&&(b.indexOf("windows")>-1||b.indexOf("macintosh")>-1||b.indexOf("linux")>-1)&&b.indexOf("mobile")<0&&b.indexOf("android")<0,d={tap_pixel_range:5,swipe_h_threshold:50,swipe_v_threshold:50,taphold_threshold:750,doubletap_int:500,touch_capable:"ontouchstart"in window&&!c,orientation_support:"orientation"in window&&"onorientationchange"in window,startevent:"ontouchstart"in window&&!c?"touchstart":"mousedown",endevent:"ontouchstart"in window&&!c?"touchend":"mouseup",moveevent:"ontouchstart"in window&&!c?"touchmove":"mousemove",tapevent:"ontouchstart"in window&&!c?"tap":"click",scrollevent:"ontouchstart"in window&&!c?"touchmove":"scroll",hold_timer:null,tap_timer:null};a.isTouchCapable=function(){return d.touch_capable},a.getStartEvent=function(){return d.startevent},a.getEndEvent=function(){return d.endevent},a.getMoveEvent=function(){return d.moveevent},a.getTapEvent=function(){return d.tapevent},a.getScrollEvent=function(){return d.scrollevent},a.each(["tapstart","tapend","tapmove","tap","tap2","tap3","tap4","singletap","doubletap","taphold","swipe","swipeup","swiperight","swipedown","swipeleft","swipeend","scrollstart","scrollend","orientationchange"],function(b,c){a.fn[c]=function(a){return a?this.on(c,a):this.trigger(c)},a.attrFn[c]=!0}),a.event.special.tapstart={setup:function(){var b=this,c=a(b);c.on(d.startevent,function a(e){if(c.data("callee",a),e.which&&1!==e.which)return!1;var f=e.originalEvent,g={position:{x:d.touch_capable?f.touches[0].screenX:e.screenX,y:d.touch_capable?f.touches[0].screenY:e.screenY},offset:{x:d.touch_capable?Math.round(f.changedTouches[0].pageX-(c.offset()?c.offset().left:0)):Math.round(e.pageX-(c.offset()?c.offset().left:0)),y:d.touch_capable?Math.round(f.changedTouches[0].pageY-(c.offset()?c.offset().top:0)):Math.round(e.pageY-(c.offset()?c.offset().top:0))},time:Date.now(),target:e.target};return v(b,"tapstart",e,g),!0})},remove:function(){a(this).off(d.startevent,a(this).data.callee)}},a.event.special.tapmove={setup:function(){var b=this,c=a(b);c.on(d.moveevent,function a(e){c.data("callee",a);var f=e.originalEvent,g={position:{x:d.touch_capable?f.touches[0].screenX:e.screenX,y:d.touch_capable?f.touches[0].screenY:e.screenY},offset:{x:d.touch_capable?Math.round(f.changedTouches[0].pageX-(c.offset()?c.offset().left:0)):Math.round(e.pageX-(c.offset()?c.offset().left:0)),y:d.touch_capable?Math.round(f.changedTouches[0].pageY-(c.offset()?c.offset().top:0)):Math.round(e.pageY-(c.offset()?c.offset().top:0))},time:Date.now(),target:e.target};return v(b,"tapmove",e,g),!0})},remove:function(){a(this).off(d.moveevent,a(this).data.callee)}},a.event.special.tapend={setup:function(){var b=this,c=a(b);c.on(d.endevent,function a(e){c.data("callee",a);var f=e.originalEvent,g={position:{x:d.touch_capable?f.changedTouches[0].screenX:e.screenX,y:d.touch_capable?f.changedTouches[0].screenY:e.screenY},offset:{x:d.touch_capable?Math.round(f.changedTouches[0].pageX-(c.offset()?c.offset().left:0)):Math.round(e.pageX-(c.offset()?c.offset().left:0)),y:d.touch_capable?Math.round(f.changedTouches[0].pageY-(c.offset()?c.offset().top:0)):Math.round(e.pageY-(c.offset()?c.offset().top:0))},time:Date.now(),target:e.target};return v(b,"tapend",e,g),!0})},remove:function(){a(this).off(d.endevent,a(this).data.callee)}},a.event.special.taphold={setup:function(){var e,b=this,c=a(b),f={x:0,y:0},g=0,h=0;c.on(d.startevent,function a(i){if(i.which&&1!==i.which)return!1;c.data("tapheld",!1),e=i.target;var j=i.originalEvent,k=Date.now(),l={x:d.touch_capable?j.touches[0].screenX:i.screenX,y:d.touch_capable?j.touches[0].screenY:i.screenY},m={x:d.touch_capable?j.touches[0].pageX-j.touches[0].target.offsetLeft:i.offsetX,y:d.touch_capable?j.touches[0].pageY-j.touches[0].target.offsetTop:i.offsetY};return f.x=i.originalEvent.targetTouches?i.originalEvent.targetTouches[0].pageX:i.pageX,f.y=i.originalEvent.targetTouches?i.originalEvent.targetTouches[0].pageY:i.pageY,g=f.x,h=f.y,d.hold_timer=window.setTimeout(function(){var n=f.x-g,o=f.y-h;if(i.target==e&&(f.x==g&&f.y==h||n>=-d.tap_pixel_range&&n<=d.tap_pixel_range&&o>=-d.tap_pixel_range&&o<=d.tap_pixel_range)){c.data("tapheld",!0);var p=Date.now(),q={x:d.touch_capable?j.touches[0].screenX:i.screenX,y:d.touch_capable?j.touches[0].screenY:i.screenY},r={x:d.touch_capable?Math.round(j.changedTouches[0].pageX-(c.offset()?c.offset().left:0)):Math.round(i.pageX-(c.offset()?c.offset().left:0)),y:d.touch_capable?Math.round(j.changedTouches[0].pageY-(c.offset()?c.offset().top:0)):Math.round(i.pageY-(c.offset()?c.offset().top:0))},s=p-k,t={startTime:k,endTime:p,startPosition:l,startOffset:m,endPosition:q,endOffset:r,duration:s,target:i.target};c.data("callee1",a),v(b,"taphold",i,t)}},d.taphold_threshold),!0}).on(d.endevent,function a(){c.data("callee2",a),c.data("tapheld",!1),window.clearTimeout(d.hold_timer)}).on(d.moveevent,function a(b){c.data("callee3",a),g=b.originalEvent.targetTouches?b.originalEvent.targetTouches[0].pageX:b.pageX,h=b.originalEvent.targetTouches?b.originalEvent.targetTouches[0].pageY:b.pageY})},remove:function(){a(this).off(d.startevent,a(this).data.callee1).off(d.endevent,a(this).data.callee2).off(d.moveevent,a(this).data.callee3)}},a.event.special.doubletap={setup:function(){var e,f,h,i,b=this,c=a(b),g=null,j=!1;c.on(d.startevent,function a(b){return(!b.which||1===b.which)&&(c.data("doubletapped",!1),e=b.target,c.data("callee1",a),h=b.originalEvent,g||(g={position:{x:d.touch_capable?h.touches[0].screenX:b.screenX,y:d.touch_capable?h.touches[0].screenY:b.screenY},offset:{x:d.touch_capable?Math.round(h.changedTouches[0].pageX-(c.offset()?c.offset().left:0)):Math.round(b.pageX-(c.offset()?c.offset().left:0)),y:d.touch_capable?Math.round(h.changedTouches[0].pageY-(c.offset()?c.offset().top:0)):Math.round(b.pageY-(c.offset()?c.offset().top:0))},time:Date.now(),target:b.target}),!0)}).on(d.endevent,function a(k){var l=Date.now(),m=c.data("lastTouch")||l+1,n=l-m;if(window.clearTimeout(f),c.data("callee2",a),n100){c.data("doubletapped",!0),window.clearTimeout(d.tap_timer);var o={position:{x:d.touch_capable?k.originalEvent.changedTouches[0].screenX:k.screenX,y:d.touch_capable?k.originalEvent.changedTouches[0].screenY:k.screenY},offset:{x:d.touch_capable?Math.round(h.changedTouches[0].pageX-(c.offset()?c.offset().left:0)):Math.round(k.pageX-(c.offset()?c.offset().left:0)),y:d.touch_capable?Math.round(h.changedTouches[0].pageY-(c.offset()?c.offset().top:0)):Math.round(k.pageY-(c.offset()?c.offset().top:0))},time:Date.now(),target:k.target},p={firstTap:g,secondTap:o,interval:o.time-g.time};j||(v(b,"doubletap",k,p),g=null),j=!0,i=window.setTimeout(function(){j=!1},d.doubletap_int)}else c.data("lastTouch",l),f=window.setTimeout(function(){g=null,window.clearTimeout(f)},d.doubletap_int,[k]);c.data("lastTouch",l)})},remove:function(){a(this).off(d.startevent,a(this).data.callee1).off(d.endevent,a(this).data.callee2)}},a.event.special.singletap={setup:function(){var b=this,c=a(b),e=null,f=null,g={x:0,y:0};c.on(d.startevent,function a(b){return(!b.which||1===b.which)&&(f=Date.now(),e=b.target,c.data("callee1",a),g.x=b.originalEvent.targetTouches?b.originalEvent.targetTouches[0].pageX:b.pageX,g.y=b.originalEvent.targetTouches?b.originalEvent.targetTouches[0].pageY:b.pageY,!0)}).on(d.endevent,function a(h){if(c.data("callee2",a),h.target==e){var i=h.originalEvent.changedTouches?h.originalEvent.changedTouches[0].pageX:h.pageX,j=h.originalEvent.changedTouches?h.originalEvent.changedTouches[0].pageY:h.pageY;d.tap_timer=window.setTimeout(function(){var a=g.x-i,e=g.y-j;if(!c.data("doubletapped")&&!c.data("tapheld")&&(g.x==i&&g.y==j||a>=-d.tap_pixel_range&&a<=d.tap_pixel_range&&e>=-d.tap_pixel_range&&e<=d.tap_pixel_range)){var k=h.originalEvent,l={position:{x:d.touch_capable?k.changedTouches[0].screenX:h.screenX,y:d.touch_capable?k.changedTouches[0].screenY:h.screenY},offset:{x:d.touch_capable?Math.round(k.changedTouches[0].pageX-(c.offset()?c.offset().left:0)):Math.round(h.pageX-(c.offset()?c.offset().left:0)),y:d.touch_capable?Math.round(k.changedTouches[0].pageY-(c.offset()?c.offset().top:0)):Math.round(h.pageY-(c.offset()?c.offset().top:0))},time:Date.now(),target:h.target};l.time-f=-d.tap_pixel_range&&m<=d.tap_pixel_range&&n>=-d.tap_pixel_range&&n<=d.tap_pixel_range)){for(var p=j.originalEvent,q=[],r=0;rh.y&&g.y-h.y>o&&(j="swipeup"),g.xn&&(j="swiperight"),g.yo&&(j="swipedown"),g.x>h.x&&g.x-h.x>n&&(j="swipeleft"),void 0!=j&&e){g.x=0,g.y=0,h.x=0,h.y=0,e=!1;var p=b.originalEvent,q={position:{x:d.touch_capable?p.touches[0].screenX:b.screenX,y:d.touch_capable?p.touches[0].screenY:b.screenY},offset:{x:d.touch_capable?Math.round(p.changedTouches[0].pageX-(c.offset()?c.offset().left:0)):Math.round(b.pageX-(c.offset()?c.offset().left:0)),y:d.touch_capable?Math.round(p.changedTouches[0].pageY-(c.offset()?c.offset().top:0)):Math.round(b.pageY-(c.offset()?c.offset().top:0))},time:Date.now(),target:b.target},r=Math.abs(i.position.x-q.position.x),s=Math.abs(i.position.y-q.position.y),t={startEvnt:i,endEvnt:q,direction:j.replace("swipe",""),xAmount:r,yAmount:s,duration:q.time-i.time};f=!0,c.trigger("swipe",t).trigger(j,t)}}function l(b){c=a(b.currentTarget);var g="";if(c.data("callee3",l),f){var h=c.data("xthreshold"),j=c.data("ythreshold"),k="undefined"!=typeof h&&h!==!1&&parseInt(h)?parseInt(h):d.swipe_h_threshold,m="undefined"!=typeof j&&j!==!1&&parseInt(j)?parseInt(j):d.swipe_v_threshold,n=b.originalEvent,o={position:{x:d.touch_capable?n.changedTouches[0].screenX:b.screenX,y:d.touch_capable?n.changedTouches[0].screenY:b.screenY},offset:{x:d.touch_capable?Math.round(n.changedTouches[0].pageX-(c.offset()?c.offset().left:0)):Math.round(b.pageX-(c.offset()?c.offset().left:0)),y:d.touch_capable?Math.round(n.changedTouches[0].pageY-(c.offset()?c.offset().top:0)):Math.round(b.pageY-(c.offset()?c.offset().top:0))},time:Date.now(),target:b.target};i.position.y>o.position.y&&i.position.y-o.position.y>m&&(g="swipeup"),i.position.xk&&(g="swiperight"),i.position.ym&&(g="swipedown"),i.position.x>o.position.x&&i.position.x-o.position.x>k&&(g="swipeleft");var p=Math.abs(i.position.x-o.position.x),q=Math.abs(i.position.y-o.position.y),r={startEvnt:i,endEvnt:o,direction:g.replace("swipe",""),xAmount:p,yAmount:q,duration:o.time-i.time};c.trigger("swipeend",r)}e=!1,f=!1}var i,b=this,c=a(b),e=!1,f=!1,g={x:0,y:0},h={x:0,y:0};c.on(d.startevent,j),c.on(d.moveevent,k),c.on(d.endevent,l)},remove:function(){a(this).off(d.startevent,a(this).data.callee1).off(d.moveevent,a(this).data.callee2).off(d.endevent,a(this).data.callee3)}},a.event.special.scrollstart={setup:function(){function g(a,c){e=c,v(b,e?"scrollstart":"scrollend",a)}var e,f,b=this,c=a(b);c.on(d.scrollevent,function a(b){c.data("callee",a),e||g(b,!0),clearTimeout(f),f=setTimeout(function(){g(b,!1)},50)})},remove:function(){a(this).off(d.scrollevent,a(this).data.callee)}};var f,g,h,i,j,e=a(window),k={0:!0,180:!0};if(d.orientation_support){var l=window.innerWidth||e.width(),m=window.innerHeight||e.height(),n=50;i=l>m&&l-m>n,j=k[window.orientation],(i&&j||!i&&!j)&&(k={"-90":!0,90:!0})}a.event.special.orientationchange=f={setup:function(){return!d.orientation_support&&(h=g(),e.on("throttledresize",o),!0)},teardown:function(){return!d.orientation_support&&(e.off("throttledresize",o),!0)},add:function(a){var b=a.handler;a.handler=function(a){return a.orientation=g(),b.apply(this,arguments)}}},a.event.special.orientationchange.orientation=g=function(){var a=!0,b=document.documentElement;return a=d.orientation_support?k[window.orientation]:b&&b.clientWidth/b.clientHeight<1.1,a?"portrait":"landscape"},a.event.special.throttledresize={setup:function(){a(this).on("resize",q)},teardown:function(){a(this).off("resize",q)}};var s,t,u,p=250,q=function(){t=Date.now(),u=t-r,u>=p?(r=t,a(this).trigger("throttledresize")):(s&&window.clearTimeout(s),s=window.setTimeout(o,p-u))},r=0;a.each({scrollend:"scrollstart",swipeup:"swipe",swiperight:"swipe",swipedown:"swipe",swipeleft:"swipe",swipeend:"swipe",tap2:"tap"},function(b,c){a.event.special[b]={setup:function(){a(this).on(c,a.noop)}}})}(jQuery);
diff --git a/src/1.0.7/jquery.mobile-events.js b/src/1.0.7/jquery.mobile-events.js
new file mode 100644
index 0000000..25d4f85
--- /dev/null
+++ b/src/1.0.7/jquery.mobile-events.js
@@ -0,0 +1,878 @@
+/*!
+ * jQuery Mobile Events
+ * by Ben Major
+ *
+ * Copyright 2011-2015, Ben Major
+ * Licensed under the MIT License:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+"use strict";
+
+(function ($) {
+ $.attrFn = $.attrFn || {};
+
+ // navigator.userAgent.toLowerCase() isn't reliable for Chrome installs
+ // on mobile devices. As such, we will create a boolean isChromeDesktop
+ // The reason that we need to do this is because Chrome annoyingly
+ // purports support for touch events even if the underlying hardware
+ // does not!
+ var agent = navigator.userAgent.toLowerCase(),
+ isChromeDesktop = (agent.indexOf('chrome') > -1 && ((agent.indexOf('windows') > -1) || (agent.indexOf('macintosh') > -1) || (agent.indexOf('linux') > -1)) && agent.indexOf('mobile') < 0 && agent.indexOf('android') < 0),
+
+ settings = {
+ tap_pixel_range: 5,
+ swipe_h_threshold: 50,
+ swipe_v_threshold: 50,
+ taphold_threshold: 750,
+ doubletap_int: 500,
+
+ touch_capable: ('ontouchstart' in window && !isChromeDesktop),
+ orientation_support: ('orientation' in window && 'onorientationchange' in window),
+
+ startevent: (('ontouchstart' in window && !isChromeDesktop) ? 'touchstart' : 'mousedown'),
+ endevent: (('ontouchstart' in window && !isChromeDesktop) ? 'touchend' : 'mouseup'),
+ moveevent: (('ontouchstart' in window && !isChromeDesktop) ? 'touchmove' : 'mousemove'),
+ tapevent: ('ontouchstart' in window && !isChromeDesktop) ? 'tap' : 'click',
+ scrollevent: ('ontouchstart' in window && !isChromeDesktop) ? 'touchmove' : 'scroll',
+
+ hold_timer: null,
+ tap_timer: null
+ };
+
+ // Convenience functions:
+ $.isTouchCapable = function() { return settings.touch_capable; };
+ $.getStartEvent = function() { return settings.startevent; };
+ $.getEndEvent = function() { return settings.endevent; };
+ $.getMoveEvent = function() { return settings.moveevent; };
+ $.getTapEvent = function() { return settings.tapevent; };
+ $.getScrollEvent = function() { return settings.scrollevent; };
+
+ // Add Event shortcuts:
+ $.each(['tapstart', 'tapend', 'tapmove', 'tap', 'tap2', 'tap3', 'tap4', 'singletap', 'doubletap', 'taphold', 'swipe', 'swipeup', 'swiperight', 'swipedown', 'swipeleft', 'swipeend', 'scrollstart', 'scrollend', 'orientationchange'], function (i, name) {
+ $.fn[name] = function (fn) {
+ return fn ? this.on(name, fn) : this.trigger(name);
+ };
+
+ $.attrFn[name] = true;
+ });
+
+ // tapstart Event:
+ $.event.special.tapstart = {
+ setup: function () {
+
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.startevent, function tapStartFunc(e) {
+
+ $this.data('callee', tapStartFunc);
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapstart', e, touchData);
+ return true;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee);
+ }
+ };
+
+ // tapmove Event:
+ $.event.special.tapmove = {
+ setup: function() {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.moveevent, function tapMoveFunc(e) {
+ $this.data('callee', tapMoveFunc);
+
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapmove', e, touchData);
+ return true;
+ });
+ },
+ remove: function() {
+ $(this).off(settings.moveevent, $(this).data.callee);
+ }
+ };
+
+ // tapend Event:
+ $.event.special.tapend = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.endevent, function tapEndFunc(e) {
+ // Touch event data:
+ $this.data('callee', tapEndFunc);
+
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ triggerCustomEvent(thisObject, 'tapend', e, touchData);
+ return true;
+ });
+ },
+ remove: function () {
+ $(this).off(settings.endevent, $(this).data.callee);
+ }
+ };
+
+ // taphold Event:
+ $.event.special.taphold = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ end_x = 0,
+ end_y = 0;
+
+ $this.on(settings.startevent, function tapHoldFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ $this.data('tapheld', false);
+ origTarget = e.target;
+
+ var origEvent = e.originalEvent;
+ var start_time = Date.now(),
+ startPosition = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ startOffset = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ };
+
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ end_x = start_pos.x;
+ end_y = start_pos.y;
+
+ // Get the element's threshold:
+
+ var ele_threshold = ($this.parent().data('threshold')) ? $this.parent().data('threshold') : $this.data('threshold'),
+ threshold = (typeof ele_threshold !== 'undefined' && ele_threshold !== false && parseInt(ele_threshold)) ? parseInt(ele_threshold) : settings.taphold_threshold;
+
+ settings.hold_timer = window.setTimeout(function () {
+
+ var diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y);
+
+ if (e.target == origTarget && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ $this.data('tapheld', true);
+
+ var end_time = Date.now(),
+ endPosition = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ endOffset = {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ };
+ var duration = end_time - start_time;
+
+ // Build the touch data:
+ var touchData = {
+ 'startTime': start_time,
+ 'endTime': end_time,
+ 'startPosition': startPosition,
+ 'startOffset': startOffset,
+ 'endPosition': endPosition,
+ 'endOffset': endOffset,
+ 'duration': duration,
+ 'target': e.target
+ };
+ $this.data('callee1', tapHoldFunc1);
+ triggerCustomEvent(thisObject, 'taphold', e, touchData);
+ }
+ }, threshold);
+
+ return true;
+ }
+ }).on(settings.endevent, function tapHoldFunc2() {
+ $this.data('callee2', tapHoldFunc2);
+ $this.data('tapheld', false);
+ window.clearTimeout(settings.hold_timer);
+ })
+ .on(settings.moveevent, function tapHoldFunc3(e) {
+ $this.data('callee3', tapHoldFunc3);
+
+ end_x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2).off(settings.moveevent, $(this).data.callee3);
+ }
+ };
+
+ // doubletap Event:
+ $.event.special.doubletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ action,
+ firstTap = null,
+ origEvent,
+ cooloff,
+ cooling = false;
+
+ $this.on(settings.startevent, function doubleTapFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+ $this.data('doubletapped', false);
+ origTarget = e.target;
+ $this.data('callee1', doubleTapFunc1);
+
+ origEvent = e.originalEvent;
+ if (!firstTap) {
+ firstTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ }
+
+ return true;
+ }).on(settings.endevent, function doubleTapFunc2(e) {
+
+ var now = Date.now();
+ var lastTouch = $this.data('lastTouch') || now + 1;
+ var delta = now - lastTouch;
+ window.clearTimeout(action);
+ $this.data('callee2', doubleTapFunc2);
+
+ if (delta < settings.doubletap_int && (e.target == origTarget) && delta > 100) {
+ $this.data('doubletapped', true);
+ window.clearTimeout(settings.tap_timer);
+
+ // Now get the current event:
+ var lastTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? e.originalEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? e.originalEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ var touchData = {
+ 'firstTap': firstTap,
+ 'secondTap': lastTap,
+ 'interval': lastTap.time - firstTap.time
+ };
+
+ if (!cooling) {
+ triggerCustomEvent(thisObject, 'doubletap', e, touchData);
+ firstTap = null;
+ }
+
+ cooling = true;
+
+ cooloff = window.setTimeout(function () {
+ cooling = false;
+ }, settings.doubletap_int);
+
+ } else {
+ $this.data('lastTouch', now);
+ action = window.setTimeout(function () {
+ firstTap = null;
+ window.clearTimeout(action);
+ }, settings.doubletap_int, [e]);
+ }
+ $this.data('lastTouch', now);
+ });
+ },
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // singletap Event:
+ // This is used in conjuction with doubletap when both events are needed on the same element
+ $.event.special.singletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget = null,
+ startTime = null,
+ start_pos = {
+ x: 0,
+ y: 0
+ };
+
+ $this.on(settings.startevent, function singleTapFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ startTime = Date.now();
+ origTarget = e.target;
+ $this.data('callee1', singleTapFunc1);
+
+ // Get the start x and y position:
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ return true;
+ }
+ }).on(settings.endevent, function singleTapFunc2(e) {
+ $this.data('callee2', singleTapFunc2);
+ if (e.target == origTarget) {
+
+ // Get the end point:
+ var end_pos_x = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ end_pos_y = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY;
+
+ // We need to check if it was a taphold:
+
+ settings.tap_timer = window.setTimeout(function () {
+
+ var diff_x = (start_pos.x - end_pos_x), diff_y = (start_pos.y - end_pos_y);
+
+ if(!$this.data('doubletapped') && !$this.data('tapheld') && (((start_pos.x == end_pos_x) && (start_pos.y == end_pos_y)) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Was it a taphold?
+ if((touchData.time - startTime) < settings.taphold_threshold)
+ {
+ triggerCustomEvent(thisObject, 'singletap', e, touchData);
+ }
+ }
+ }, settings.doubletap_int);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // tap Event:
+ $.event.special.tap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ origTarget = null,
+ start_time,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ touches;
+
+ $this.on(settings.startevent, function tapFunc1(e) {
+ $this.data('callee1', tapFunc1);
+
+ if( e.which && e.which !== 1 )
+ {
+ return false;
+ }
+ else
+ {
+ started = true;
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ start_time = Date.now();
+ origTarget = e.target;
+
+ touches = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches : [ e ];
+ return true;
+ }
+ }).on(settings.endevent, function tapFunc2(e) {
+ $this.data('callee2', tapFunc2);
+
+ // Only trigger if they've started, and the target matches:
+ var end_x = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY,
+ diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y),
+ eventName;
+
+ if (origTarget == e.target && started && ((Date.now() - start_time) < settings.taphold_threshold) && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ var origEvent = e.originalEvent;
+ var touchData = [ ];
+
+ for( var i = 0; i < touches.length; i++)
+ {
+ var touch = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[i].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[i].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ touchData.push( touch );
+ }
+
+ triggerCustomEvent(thisObject, 'tap', e, touchData);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // swipe Event (also handles swipeup, swiperight, swipedown and swipeleft):
+ $.event.special.swipe = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ hasSwiped = false,
+ originalCoord = {
+ x: 0,
+ y: 0
+ },
+ finalCoord = {
+ x: 0,
+ y: 0
+ },
+ startEvnt;
+
+ // Screen touched, store the original coordinate
+
+ function touchStart(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee1', touchStart);
+ originalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ originalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ finalCoord.x = originalCoord.x;
+ finalCoord.y = originalCoord.y;
+ started = true;
+ var origEvent = e.originalEvent;
+ // Read event data into our startEvt:
+ startEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ }
+
+ // Store coordinates as finger is swiping
+
+ function touchMove(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee2', touchMove);
+ finalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ finalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ var swipedir;
+
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = ($this.parent().data('xthreshold')) ? $this.parent().data('xthreshold') : $this.data('xthreshold'),
+ ele_y_threshold = ($this.parent().data('ythreshold')) ? $this.parent().data('ythreshold') : $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ if (originalCoord.y > finalCoord.y && (originalCoord.y - finalCoord.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (originalCoord.x < finalCoord.x && (finalCoord.x - originalCoord.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (originalCoord.y < finalCoord.y && (finalCoord.y - originalCoord.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (originalCoord.x > finalCoord.x && (originalCoord.x - finalCoord.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+ if (swipedir != undefined && started) {
+ originalCoord.x = 0;
+ originalCoord.y = 0;
+ finalCoord.x = 0;
+ finalCoord.y = 0;
+ started = false;
+
+ // Read event data into our endEvnt:
+ var origEvent = e.originalEvent;
+ var endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ };
+ hasSwiped = true;
+ $this.trigger('swipe', touchData).trigger(swipedir, touchData);
+ }
+ }
+
+ function touchEnd(e) {
+ $this = $(e.currentTarget);
+ var swipedir = "";
+ $this.data('callee3', touchEnd);
+ if (hasSwiped) {
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = $this.data('xthreshold'),
+ ele_y_threshold = $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ var origEvent = e.originalEvent;
+ var endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Read event data into our endEvnt:
+ if (startEvnt.position.y > endEvnt.position.y && (startEvnt.position.y - endEvnt.position.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (startEvnt.position.x < endEvnt.position.x && (endEvnt.position.x - startEvnt.position.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (startEvnt.position.y < endEvnt.position.y && (endEvnt.position.y - startEvnt.position.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (startEvnt.position.x > endEvnt.position.x && (startEvnt.position.x - endEvnt.position.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ };
+ $this.trigger('swipeend', touchData);
+ }
+
+ started = false;
+ hasSwiped = false;
+ }
+
+ $this.on(settings.startevent, touchStart);
+ $this.on(settings.moveevent, touchMove);
+ $this.on(settings.endevent, touchEnd);
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.moveevent, $(this).data.callee2).off(settings.endevent, $(this).data.callee3);
+ }
+ };
+
+ // scrollstart Event (also handles scrollend):
+ $.event.special.scrollstart = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ scrolling,
+ timer;
+
+ function trigger(event, state) {
+ scrolling = state;
+ triggerCustomEvent(thisObject, scrolling ? 'scrollstart' : 'scrollend', event);
+ }
+
+ // iPhone triggers scroll after a small delay; use touchmove instead
+ $this.on(settings.scrollevent, function scrollFunc(event) {
+ $this.data('callee', scrollFunc);
+
+ if (!scrolling) {
+ trigger(event, true);
+ }
+
+ clearTimeout(timer);
+ timer = setTimeout(function () {
+ trigger(event, false);
+ }, 50);
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.scrollevent, $(this).data.callee);
+ }
+ };
+
+ // This is the orientation change (largely borrowed from jQuery Mobile):
+ var win = $(window),
+ special_event,
+ get_orientation,
+ last_orientation,
+ initial_orientation_is_landscape,
+ initial_orientation_is_default,
+ portrait_map = {
+ '0': true,
+ '180': true
+ };
+
+ if (settings.orientation_support) {
+ var ww = window.innerWidth || win.width(),
+ wh = window.innerHeight || win.height(),
+ landscape_threshold = 50;
+
+ initial_orientation_is_landscape = ww > wh && (ww - wh) > landscape_threshold;
+ initial_orientation_is_default = portrait_map[window.orientation];
+
+ if ((initial_orientation_is_landscape && initial_orientation_is_default) || (!initial_orientation_is_landscape && !initial_orientation_is_default)) {
+ portrait_map = {
+ '-90': true,
+ '90': true
+ };
+ }
+ }
+
+ $.event.special.orientationchange = special_event = {
+ setup: function () {
+ // If the event is supported natively, return false so that jQuery
+ // will on to the event using DOM methods.
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ // Get the current orientation to avoid initial double-triggering.
+ last_orientation = get_orientation();
+
+ win.on('throttledresize', handler);
+ return true;
+ },
+ teardown: function () {
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ win.off('throttledresize', handler);
+ return true;
+ },
+ add: function (handleObj) {
+ // Save a reference to the bound event handler.
+ var old_handler = handleObj.handler;
+
+ handleObj.handler = function (event) {
+ event.orientation = get_orientation();
+ return old_handler.apply(this, arguments);
+ };
+ }
+ };
+
+ // If the event is not supported natively, this handler will be bound to
+ // the window resize event to simulate the orientationchange event.
+
+ function handler() {
+ // Get the current orientation.
+ var orientation = get_orientation();
+
+ if (orientation !== last_orientation) {
+ // The orientation has changed, so trigger the orientationchange event.
+ last_orientation = orientation;
+ win.trigger("orientationchange");
+ }
+ }
+
+ $.event.special.orientationchange.orientation = get_orientation = function () {
+ var isPortrait = true,
+ elem = document.documentElement;
+
+ if (settings.orientation_support) {
+ isPortrait = portrait_map[window.orientation];
+ } else {
+ isPortrait = elem && elem.clientWidth / elem.clientHeight < 1.1;
+ }
+
+ return isPortrait ? 'portrait' : 'landscape';
+ };
+
+ // throttle Handler:
+ $.event.special.throttledresize = {
+ setup: function () {
+ $(this).on('resize', throttle_handler);
+ },
+ teardown: function () {
+ $(this).off('resize', throttle_handler);
+ }
+ };
+
+ var throttle = 250,
+ throttle_handler = function () {
+ curr = Date.now();
+ diff = curr - lastCall;
+
+ if (diff >= throttle) {
+ lastCall = curr;
+ $(this).trigger('throttledresize');
+
+ } else {
+ if (heldCall) {
+ window.clearTimeout(heldCall);
+ }
+
+ // Promise a held call will still execute
+ heldCall = window.setTimeout(handler, throttle - diff);
+ }
+ },
+ lastCall = 0,
+ heldCall,
+ curr,
+ diff;
+
+ // Trigger a custom event:
+
+ function triggerCustomEvent(obj, eventType, event, touchData) {
+ var originalType = event.type;
+ event.type = eventType;
+
+ $.event.dispatch.call(obj, event, touchData);
+ event.type = originalType;
+ }
+
+ // Correctly on anything we've overloaded:
+ $.each({
+ scrollend: 'scrollstart',
+ swipeup: 'swipe',
+ swiperight: 'swipe',
+ swipedown: 'swipe',
+ swipeleft: 'swipe',
+ swipeend: 'swipe',
+ tap2: 'tap'
+ }, function (e, srcE) {
+ $.event.special[e] = {
+ setup: function () {
+ $(this).on(srcE, $.noop);
+ }
+ };
+ });
+
+}(jQuery));
diff --git a/src/1.0.7/jquery.mobile-events.min.js b/src/1.0.7/jquery.mobile-events.min.js
new file mode 100644
index 0000000..959b843
--- /dev/null
+++ b/src/1.0.7/jquery.mobile-events.min.js
@@ -0,0 +1 @@
+"use strict";!function(a){function o(){var a=g();a!==h&&(h=a,e.trigger("orientationchange"))}function v(b,c,d,e){var f=d.type;d.type=c,a.event.dispatch.call(b,d,e),d.type=f}a.attrFn=a.attrFn||{};var b=navigator.userAgent.toLowerCase(),c=b.indexOf("chrome")>-1&&(b.indexOf("windows")>-1||b.indexOf("macintosh")>-1||b.indexOf("linux")>-1)&&b.indexOf("mobile")<0&&b.indexOf("android")<0,d={tap_pixel_range:5,swipe_h_threshold:50,swipe_v_threshold:50,taphold_threshold:750,doubletap_int:500,touch_capable:"ontouchstart"in window&&!c,orientation_support:"orientation"in window&&"onorientationchange"in window,startevent:"ontouchstart"in window&&!c?"touchstart":"mousedown",endevent:"ontouchstart"in window&&!c?"touchend":"mouseup",moveevent:"ontouchstart"in window&&!c?"touchmove":"mousemove",tapevent:"ontouchstart"in window&&!c?"tap":"click",scrollevent:"ontouchstart"in window&&!c?"touchmove":"scroll",hold_timer:null,tap_timer:null};a.isTouchCapable=function(){return d.touch_capable},a.getStartEvent=function(){return d.startevent},a.getEndEvent=function(){return d.endevent},a.getMoveEvent=function(){return d.moveevent},a.getTapEvent=function(){return d.tapevent},a.getScrollEvent=function(){return d.scrollevent},a.each(["tapstart","tapend","tapmove","tap","tap2","tap3","tap4","singletap","doubletap","taphold","swipe","swipeup","swiperight","swipedown","swipeleft","swipeend","scrollstart","scrollend","orientationchange"],function(b,c){a.fn[c]=function(a){return a?this.on(c,a):this.trigger(c)},a.attrFn[c]=!0}),a.event.special.tapstart={setup:function(){var b=this,c=a(b);c.on(d.startevent,function a(e){if(c.data("callee",a),e.which&&1!==e.which)return!1;var f=e.originalEvent,g={position:{x:d.touch_capable?f.touches[0].screenX:e.screenX,y:d.touch_capable?f.touches[0].screenY:e.screenY},offset:{x:d.touch_capable?Math.round(f.changedTouches[0].pageX-(c.offset()?c.offset().left:0)):Math.round(e.pageX-(c.offset()?c.offset().left:0)),y:d.touch_capable?Math.round(f.changedTouches[0].pageY-(c.offset()?c.offset().top:0)):Math.round(e.pageY-(c.offset()?c.offset().top:0))},time:Date.now(),target:e.target};return v(b,"tapstart",e,g),!0})},remove:function(){a(this).off(d.startevent,a(this).data.callee)}},a.event.special.tapmove={setup:function(){var b=this,c=a(b);c.on(d.moveevent,function a(e){c.data("callee",a);var f=e.originalEvent,g={position:{x:d.touch_capable?f.touches[0].screenX:e.screenX,y:d.touch_capable?f.touches[0].screenY:e.screenY},offset:{x:d.touch_capable?Math.round(f.changedTouches[0].pageX-(c.offset()?c.offset().left:0)):Math.round(e.pageX-(c.offset()?c.offset().left:0)),y:d.touch_capable?Math.round(f.changedTouches[0].pageY-(c.offset()?c.offset().top:0)):Math.round(e.pageY-(c.offset()?c.offset().top:0))},time:Date.now(),target:e.target};return v(b,"tapmove",e,g),!0})},remove:function(){a(this).off(d.moveevent,a(this).data.callee)}},a.event.special.tapend={setup:function(){var b=this,c=a(b);c.on(d.endevent,function a(e){c.data("callee",a);var f=e.originalEvent,g={position:{x:d.touch_capable?f.changedTouches[0].screenX:e.screenX,y:d.touch_capable?f.changedTouches[0].screenY:e.screenY},offset:{x:d.touch_capable?Math.round(f.changedTouches[0].pageX-(c.offset()?c.offset().left:0)):Math.round(e.pageX-(c.offset()?c.offset().left:0)),y:d.touch_capable?Math.round(f.changedTouches[0].pageY-(c.offset()?c.offset().top:0)):Math.round(e.pageY-(c.offset()?c.offset().top:0))},time:Date.now(),target:e.target};return v(b,"tapend",e,g),!0})},remove:function(){a(this).off(d.endevent,a(this).data.callee)}},a.event.special.taphold={setup:function(){var e,b=this,c=a(b),f={x:0,y:0},g=0,h=0;c.on(d.startevent,function a(i){if(i.which&&1!==i.which)return!1;c.data("tapheld",!1),e=i.target;var j=i.originalEvent,k=Date.now(),l={x:d.touch_capable?j.touches[0].screenX:i.screenX,y:d.touch_capable?j.touches[0].screenY:i.screenY},m={x:d.touch_capable?j.touches[0].pageX-j.touches[0].target.offsetLeft:i.offsetX,y:d.touch_capable?j.touches[0].pageY-j.touches[0].target.offsetTop:i.offsetY};f.x=i.originalEvent.targetTouches?i.originalEvent.targetTouches[0].pageX:i.pageX,f.y=i.originalEvent.targetTouches?i.originalEvent.targetTouches[0].pageY:i.pageY,g=f.x,h=f.y;var n=c.parent().data("threshold")?c.parent().data("threshold"):c.data("threshold"),o="undefined"!=typeof n&&n!==!1&&parseInt(n)?parseInt(n):d.taphold_threshold;return d.hold_timer=window.setTimeout(function(){var n=f.x-g,o=f.y-h;if(i.target==e&&(f.x==g&&f.y==h||n>=-d.tap_pixel_range&&n<=d.tap_pixel_range&&o>=-d.tap_pixel_range&&o<=d.tap_pixel_range)){c.data("tapheld",!0);var p=Date.now(),q={x:d.touch_capable?j.touches[0].screenX:i.screenX,y:d.touch_capable?j.touches[0].screenY:i.screenY},r={x:d.touch_capable?Math.round(j.changedTouches[0].pageX-(c.offset()?c.offset().left:0)):Math.round(i.pageX-(c.offset()?c.offset().left:0)),y:d.touch_capable?Math.round(j.changedTouches[0].pageY-(c.offset()?c.offset().top:0)):Math.round(i.pageY-(c.offset()?c.offset().top:0))},s=p-k,t={startTime:k,endTime:p,startPosition:l,startOffset:m,endPosition:q,endOffset:r,duration:s,target:i.target};c.data("callee1",a),v(b,"taphold",i,t)}},o),!0}).on(d.endevent,function a(){c.data("callee2",a),c.data("tapheld",!1),window.clearTimeout(d.hold_timer)}).on(d.moveevent,function a(b){c.data("callee3",a),g=b.originalEvent.targetTouches?b.originalEvent.targetTouches[0].pageX:b.pageX,h=b.originalEvent.targetTouches?b.originalEvent.targetTouches[0].pageY:b.pageY})},remove:function(){a(this).off(d.startevent,a(this).data.callee1).off(d.endevent,a(this).data.callee2).off(d.moveevent,a(this).data.callee3)}},a.event.special.doubletap={setup:function(){var e,f,h,i,b=this,c=a(b),g=null,j=!1;c.on(d.startevent,function a(b){return(!b.which||1===b.which)&&(c.data("doubletapped",!1),e=b.target,c.data("callee1",a),h=b.originalEvent,g||(g={position:{x:d.touch_capable?h.touches[0].screenX:b.screenX,y:d.touch_capable?h.touches[0].screenY:b.screenY},offset:{x:d.touch_capable?Math.round(h.changedTouches[0].pageX-(c.offset()?c.offset().left:0)):Math.round(b.pageX-(c.offset()?c.offset().left:0)),y:d.touch_capable?Math.round(h.changedTouches[0].pageY-(c.offset()?c.offset().top:0)):Math.round(b.pageY-(c.offset()?c.offset().top:0))},time:Date.now(),target:b.target}),!0)}).on(d.endevent,function a(k){var l=Date.now(),m=c.data("lastTouch")||l+1,n=l-m;if(window.clearTimeout(f),c.data("callee2",a),n100){c.data("doubletapped",!0),window.clearTimeout(d.tap_timer);var o={position:{x:d.touch_capable?k.originalEvent.changedTouches[0].screenX:k.screenX,y:d.touch_capable?k.originalEvent.changedTouches[0].screenY:k.screenY},offset:{x:d.touch_capable?Math.round(h.changedTouches[0].pageX-(c.offset()?c.offset().left:0)):Math.round(k.pageX-(c.offset()?c.offset().left:0)),y:d.touch_capable?Math.round(h.changedTouches[0].pageY-(c.offset()?c.offset().top:0)):Math.round(k.pageY-(c.offset()?c.offset().top:0))},time:Date.now(),target:k.target},p={firstTap:g,secondTap:o,interval:o.time-g.time};j||(v(b,"doubletap",k,p),g=null),j=!0,i=window.setTimeout(function(){j=!1},d.doubletap_int)}else c.data("lastTouch",l),f=window.setTimeout(function(){g=null,window.clearTimeout(f)},d.doubletap_int,[k]);c.data("lastTouch",l)})},remove:function(){a(this).off(d.startevent,a(this).data.callee1).off(d.endevent,a(this).data.callee2)}},a.event.special.singletap={setup:function(){var b=this,c=a(b),e=null,f=null,g={x:0,y:0};c.on(d.startevent,function a(b){return(!b.which||1===b.which)&&(f=Date.now(),e=b.target,c.data("callee1",a),g.x=b.originalEvent.targetTouches?b.originalEvent.targetTouches[0].pageX:b.pageX,g.y=b.originalEvent.targetTouches?b.originalEvent.targetTouches[0].pageY:b.pageY,!0)}).on(d.endevent,function a(h){if(c.data("callee2",a),h.target==e){var i=h.originalEvent.changedTouches?h.originalEvent.changedTouches[0].pageX:h.pageX,j=h.originalEvent.changedTouches?h.originalEvent.changedTouches[0].pageY:h.pageY;d.tap_timer=window.setTimeout(function(){var a=g.x-i,e=g.y-j;if(!c.data("doubletapped")&&!c.data("tapheld")&&(g.x==i&&g.y==j||a>=-d.tap_pixel_range&&a<=d.tap_pixel_range&&e>=-d.tap_pixel_range&&e<=d.tap_pixel_range)){var k=h.originalEvent,l={position:{x:d.touch_capable?k.changedTouches[0].screenX:h.screenX,y:d.touch_capable?k.changedTouches[0].screenY:h.screenY},offset:{x:d.touch_capable?Math.round(k.changedTouches[0].pageX-(c.offset()?c.offset().left:0)):Math.round(h.pageX-(c.offset()?c.offset().left:0)),y:d.touch_capable?Math.round(k.changedTouches[0].pageY-(c.offset()?c.offset().top:0)):Math.round(h.pageY-(c.offset()?c.offset().top:0))},time:Date.now(),target:h.target};l.time-f=-d.tap_pixel_range&&m<=d.tap_pixel_range&&n>=-d.tap_pixel_range&&n<=d.tap_pixel_range)){for(var p=j.originalEvent,q=[],r=0;rh.y&&g.y-h.y>o&&(j="swipeup"),g.xn&&(j="swiperight"),g.yo&&(j="swipedown"),g.x>h.x&&g.x-h.x>n&&(j="swipeleft"),void 0!=j&&e){g.x=0,g.y=0,h.x=0,h.y=0,e=!1;var p=b.originalEvent,q={position:{x:d.touch_capable?p.touches[0].screenX:b.screenX,y:d.touch_capable?p.touches[0].screenY:b.screenY},offset:{x:d.touch_capable?Math.round(p.changedTouches[0].pageX-(c.offset()?c.offset().left:0)):Math.round(b.pageX-(c.offset()?c.offset().left:0)),y:d.touch_capable?Math.round(p.changedTouches[0].pageY-(c.offset()?c.offset().top:0)):Math.round(b.pageY-(c.offset()?c.offset().top:0))},time:Date.now(),target:b.target},r=Math.abs(i.position.x-q.position.x),s=Math.abs(i.position.y-q.position.y),t={startEvnt:i,endEvnt:q,direction:j.replace("swipe",""),xAmount:r,yAmount:s,duration:q.time-i.time};f=!0,c.trigger("swipe",t).trigger(j,t)}}function l(b){c=a(b.currentTarget);var g="";if(c.data("callee3",l),f){var h=c.data("xthreshold"),j=c.data("ythreshold"),k="undefined"!=typeof h&&h!==!1&&parseInt(h)?parseInt(h):d.swipe_h_threshold,m="undefined"!=typeof j&&j!==!1&&parseInt(j)?parseInt(j):d.swipe_v_threshold,n=b.originalEvent,o={position:{x:d.touch_capable?n.changedTouches[0].screenX:b.screenX,y:d.touch_capable?n.changedTouches[0].screenY:b.screenY},offset:{x:d.touch_capable?Math.round(n.changedTouches[0].pageX-(c.offset()?c.offset().left:0)):Math.round(b.pageX-(c.offset()?c.offset().left:0)),y:d.touch_capable?Math.round(n.changedTouches[0].pageY-(c.offset()?c.offset().top:0)):Math.round(b.pageY-(c.offset()?c.offset().top:0))},time:Date.now(),target:b.target};i.position.y>o.position.y&&i.position.y-o.position.y>m&&(g="swipeup"),i.position.xk&&(g="swiperight"),i.position.ym&&(g="swipedown"),i.position.x>o.position.x&&i.position.x-o.position.x>k&&(g="swipeleft");var p=Math.abs(i.position.x-o.position.x),q=Math.abs(i.position.y-o.position.y),r={startEvnt:i,endEvnt:o,direction:g.replace("swipe",""),xAmount:p,yAmount:q,duration:o.time-i.time};c.trigger("swipeend",r)}e=!1,f=!1}var i,b=this,c=a(b),e=!1,f=!1,g={x:0,y:0},h={x:0,y:0};c.on(d.startevent,j),c.on(d.moveevent,k),c.on(d.endevent,l)},remove:function(){a(this).off(d.startevent,a(this).data.callee1).off(d.moveevent,a(this).data.callee2).off(d.endevent,a(this).data.callee3)}},a.event.special.scrollstart={setup:function(){function g(a,c){e=c,v(b,e?"scrollstart":"scrollend",a)}var e,f,b=this,c=a(b);c.on(d.scrollevent,function a(b){c.data("callee",a),e||g(b,!0),clearTimeout(f),f=setTimeout(function(){g(b,!1)},50)})},remove:function(){a(this).off(d.scrollevent,a(this).data.callee)}};var f,g,h,i,j,e=a(window),k={0:!0,180:!0};if(d.orientation_support){var l=window.innerWidth||e.width(),m=window.innerHeight||e.height(),n=50;i=l>m&&l-m>n,j=k[window.orientation],(i&&j||!i&&!j)&&(k={"-90":!0,90:!0})}a.event.special.orientationchange=f={setup:function(){return!d.orientation_support&&(h=g(),e.on("throttledresize",o),!0)},teardown:function(){return!d.orientation_support&&(e.off("throttledresize",o),!0)},add:function(a){var b=a.handler;a.handler=function(a){return a.orientation=g(),b.apply(this,arguments)}}},a.event.special.orientationchange.orientation=g=function(){var a=!0,b=document.documentElement;return a=d.orientation_support?k[window.orientation]:b&&b.clientWidth/b.clientHeight<1.1,a?"portrait":"landscape"},a.event.special.throttledresize={setup:function(){a(this).on("resize",q)},teardown:function(){a(this).off("resize",q)}};var s,t,u,p=250,q=function(){t=Date.now(),u=t-r,u>=p?(r=t,a(this).trigger("throttledresize")):(s&&window.clearTimeout(s),s=window.setTimeout(o,p-u))},r=0;a.each({scrollend:"scrollstart",swipeup:"swipe",swiperight:"swipe",swipedown:"swipe",swipeleft:"swipe",swipeend:"swipe",tap2:"tap"},function(b,c){a.event.special[b]={setup:function(){a(this).on(c,a.noop)}}})}(jQuery);
diff --git a/src/1.0.8/jquery.mobile-events.js b/src/1.0.8/jquery.mobile-events.js
new file mode 100644
index 0000000..65fb4f6
--- /dev/null
+++ b/src/1.0.8/jquery.mobile-events.js
@@ -0,0 +1,877 @@
+/*!
+ * jQuery Mobile Events
+ * by Ben Major
+ *
+ * Copyright 2011-2017, Ben Major
+ * Licensed under the MIT License:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+"use strict";
+
+(function ($) {
+ $.attrFn = $.attrFn || {};
+
+ // navigator.userAgent.toLowerCase() isn't reliable for Chrome installs
+ // on mobile devices. As such, we will create a boolean isChromeDesktop
+ // The reason that we need to do this is because Chrome annoyingly
+ // purports support for touch events even if the underlying hardware
+ // does not!
+ var touchCapable = ('ontouchstart' in window),
+
+ settings = {
+ tap_pixel_range: 5,
+ swipe_h_threshold: 50,
+ swipe_v_threshold: 50,
+ taphold_threshold: 750,
+ doubletap_int: 500,
+
+ touch_capable: touchCapable,
+ orientation_support: ('orientation' in window && 'onorientationchange' in window),
+
+ startevent: (touchCapable) ? 'touchstart' : 'mousedown',
+ endevent: (touchCapable) ? 'touchend' : 'mouseup',
+ moveevent: (touchCapable) ? 'touchmove' : 'mousemove',
+ tapevent: (touchCapable) ? 'tap' : 'click',
+ scrollevent: (touchCapable) ? 'touchmove' : 'scroll',
+
+ hold_timer: null,
+ tap_timer: null
+ };
+
+ // Convenience functions:
+ $.isTouchCapable = function() { return settings.touch_capable; };
+ $.getStartEvent = function() { return settings.startevent; };
+ $.getEndEvent = function() { return settings.endevent; };
+ $.getMoveEvent = function() { return settings.moveevent; };
+ $.getTapEvent = function() { return settings.tapevent; };
+ $.getScrollEvent = function() { return settings.scrollevent; };
+
+ // Add Event shortcuts:
+ $.each(['tapstart', 'tapend', 'tapmove', 'tap', 'tap2', 'tap3', 'tap4', 'singletap', 'doubletap', 'taphold', 'swipe', 'swipeup', 'swiperight', 'swipedown', 'swipeleft', 'swipeend', 'scrollstart', 'scrollend', 'orientationchange'], function (i, name) {
+ $.fn[name] = function (fn) {
+ return fn ? this.on(name, fn) : this.trigger(name);
+ };
+
+ $.attrFn[name] = true;
+ });
+
+ // tapstart Event:
+ $.event.special.tapstart = {
+ setup: function () {
+
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.startevent, function tapStartFunc(e) {
+
+ $this.data('callee', tapStartFunc);
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapstart', e, touchData);
+ return true;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee);
+ }
+ };
+
+ // tapmove Event:
+ $.event.special.tapmove = {
+ setup: function() {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.moveevent, function tapMoveFunc(e) {
+ $this.data('callee', tapMoveFunc);
+
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapmove', e, touchData);
+ return true;
+ });
+ },
+ remove: function() {
+ $(this).off(settings.moveevent, $(this).data.callee);
+ }
+ };
+
+ // tapend Event:
+ $.event.special.tapend = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.endevent, function tapEndFunc(e) {
+ // Touch event data:
+ $this.data('callee', tapEndFunc);
+
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ triggerCustomEvent(thisObject, 'tapend', e, touchData);
+ return true;
+ });
+ },
+ remove: function () {
+ $(this).off(settings.endevent, $(this).data.callee);
+ }
+ };
+
+ // taphold Event:
+ $.event.special.taphold = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ end_x = 0,
+ end_y = 0;
+
+ $this.on(settings.startevent, function tapHoldFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ $this.data('tapheld', false);
+ origTarget = e.target;
+
+ var origEvent = e.originalEvent;
+ var start_time = Date.now(),
+ startPosition = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ startOffset = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ };
+
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ end_x = start_pos.x;
+ end_y = start_pos.y;
+
+ // Get the element's threshold:
+
+ var ele_threshold = ($this.parent().data('threshold')) ? $this.parent().data('threshold') : $this.data('threshold'),
+ threshold = (typeof ele_threshold !== 'undefined' && ele_threshold !== false && parseInt(ele_threshold)) ? parseInt(ele_threshold) : settings.taphold_threshold;
+
+ settings.hold_timer = window.setTimeout(function () {
+
+ var diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y);
+
+ if (e.target == origTarget && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ $this.data('tapheld', true);
+
+ var end_time = Date.now(),
+ endPosition = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ endOffset = {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ };
+ var duration = end_time - start_time;
+
+ // Build the touch data:
+ var touchData = {
+ 'startTime': start_time,
+ 'endTime': end_time,
+ 'startPosition': startPosition,
+ 'startOffset': startOffset,
+ 'endPosition': endPosition,
+ 'endOffset': endOffset,
+ 'duration': duration,
+ 'target': e.target
+ };
+ $this.data('callee1', tapHoldFunc1);
+ triggerCustomEvent(thisObject, 'taphold', e, touchData);
+ }
+ }, threshold);
+
+ return true;
+ }
+ }).on(settings.endevent, function tapHoldFunc2() {
+ $this.data('callee2', tapHoldFunc2);
+ $this.data('tapheld', false);
+ window.clearTimeout(settings.hold_timer);
+ })
+ .on(settings.moveevent, function tapHoldFunc3(e) {
+ $this.data('callee3', tapHoldFunc3);
+
+ end_x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2).off(settings.moveevent, $(this).data.callee3);
+ }
+ };
+
+ // doubletap Event:
+ $.event.special.doubletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ action,
+ firstTap = null,
+ origEvent,
+ cooloff,
+ cooling = false;
+
+ $this.on(settings.startevent, function doubleTapFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+ $this.data('doubletapped', false);
+ origTarget = e.target;
+ $this.data('callee1', doubleTapFunc1);
+
+ origEvent = e.originalEvent;
+ if (!firstTap) {
+ firstTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ }
+
+ return true;
+ }).on(settings.endevent, function doubleTapFunc2(e) {
+
+ var now = Date.now();
+ var lastTouch = $this.data('lastTouch') || now + 1;
+ var delta = now - lastTouch;
+ window.clearTimeout(action);
+ $this.data('callee2', doubleTapFunc2);
+
+ if (delta < settings.doubletap_int && (e.target == origTarget) && delta > 100) {
+ $this.data('doubletapped', true);
+ window.clearTimeout(settings.tap_timer);
+
+ // Now get the current event:
+ var lastTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? e.originalEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? e.originalEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ var touchData = {
+ 'firstTap': firstTap,
+ 'secondTap': lastTap,
+ 'interval': lastTap.time - firstTap.time
+ };
+
+ if (!cooling) {
+ triggerCustomEvent(thisObject, 'doubletap', e, touchData);
+ firstTap = null;
+ }
+
+ cooling = true;
+
+ cooloff = window.setTimeout(function () {
+ cooling = false;
+ }, settings.doubletap_int);
+
+ } else {
+ $this.data('lastTouch', now);
+ action = window.setTimeout(function () {
+ firstTap = null;
+ window.clearTimeout(action);
+ }, settings.doubletap_int, [e]);
+ }
+ $this.data('lastTouch', now);
+ });
+ },
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // singletap Event:
+ // This is used in conjuction with doubletap when both events are needed on the same element
+ $.event.special.singletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget = null,
+ startTime = null,
+ start_pos = {
+ x: 0,
+ y: 0
+ };
+
+ $this.on(settings.startevent, function singleTapFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ startTime = Date.now();
+ origTarget = e.target;
+ $this.data('callee1', singleTapFunc1);
+
+ // Get the start x and y position:
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ return true;
+ }
+ }).on(settings.endevent, function singleTapFunc2(e) {
+ $this.data('callee2', singleTapFunc2);
+ if (e.target == origTarget) {
+
+ // Get the end point:
+ var end_pos_x = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ end_pos_y = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY;
+
+ // We need to check if it was a taphold:
+
+ settings.tap_timer = window.setTimeout(function () {
+
+ var diff_x = (start_pos.x - end_pos_x), diff_y = (start_pos.y - end_pos_y);
+
+ if(!$this.data('doubletapped') && !$this.data('tapheld') && (((start_pos.x == end_pos_x) && (start_pos.y == end_pos_y)) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Was it a taphold?
+ if((touchData.time - startTime) < settings.taphold_threshold)
+ {
+ triggerCustomEvent(thisObject, 'singletap', e, touchData);
+ }
+ }
+ }, settings.doubletap_int);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // tap Event:
+ $.event.special.tap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ origTarget = null,
+ start_time,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ touches;
+
+ $this.on(settings.startevent, function tapFunc1(e) {
+ $this.data('callee1', tapFunc1);
+
+ if( e.which && e.which !== 1 )
+ {
+ return false;
+ }
+ else
+ {
+ started = true;
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ start_time = Date.now();
+ origTarget = e.target;
+
+ touches = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches : [ e ];
+ return true;
+ }
+ }).on(settings.endevent, function tapFunc2(e) {
+ $this.data('callee2', tapFunc2);
+
+ // Only trigger if they've started, and the target matches:
+ var end_x = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY,
+ diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y),
+ eventName;
+
+ if (origTarget == e.target && started && ((Date.now() - start_time) < settings.taphold_threshold) && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ var origEvent = e.originalEvent;
+ var touchData = [ ];
+
+ for( var i = 0; i < touches.length; i++)
+ {
+ var touch = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[i].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[i].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ touchData.push( touch );
+ }
+
+ triggerCustomEvent(thisObject, 'tap', e, touchData);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // swipe Event (also handles swipeup, swiperight, swipedown and swipeleft):
+ $.event.special.swipe = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ hasSwiped = false,
+ originalCoord = {
+ x: 0,
+ y: 0
+ },
+ finalCoord = {
+ x: 0,
+ y: 0
+ },
+ startEvnt;
+
+ // Screen touched, store the original coordinate
+
+ function touchStart(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee1', touchStart);
+ originalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ originalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ finalCoord.x = originalCoord.x;
+ finalCoord.y = originalCoord.y;
+ started = true;
+ var origEvent = e.originalEvent;
+ // Read event data into our startEvt:
+ startEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ }
+
+ // Store coordinates as finger is swiping
+
+ function touchMove(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee2', touchMove);
+ finalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ finalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ var swipedir;
+
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = ($this.parent().data('xthreshold')) ? $this.parent().data('xthreshold') : $this.data('xthreshold'),
+ ele_y_threshold = ($this.parent().data('ythreshold')) ? $this.parent().data('ythreshold') : $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ if (originalCoord.y > finalCoord.y && (originalCoord.y - finalCoord.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (originalCoord.x < finalCoord.x && (finalCoord.x - originalCoord.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (originalCoord.y < finalCoord.y && (finalCoord.y - originalCoord.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (originalCoord.x > finalCoord.x && (originalCoord.x - finalCoord.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+ if (swipedir != undefined && started) {
+ originalCoord.x = 0;
+ originalCoord.y = 0;
+ finalCoord.x = 0;
+ finalCoord.y = 0;
+ started = false;
+
+ // Read event data into our endEvnt:
+ var origEvent = e.originalEvent;
+ var endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ };
+ hasSwiped = true;
+ $this.trigger('swipe', touchData).trigger(swipedir, touchData);
+ }
+ }
+
+ function touchEnd(e) {
+ $this = $(e.currentTarget);
+ var swipedir = "";
+ $this.data('callee3', touchEnd);
+ if (hasSwiped) {
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = $this.data('xthreshold'),
+ ele_y_threshold = $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ var origEvent = e.originalEvent;
+ var endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Read event data into our endEvnt:
+ if (startEvnt.position.y > endEvnt.position.y && (startEvnt.position.y - endEvnt.position.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (startEvnt.position.x < endEvnt.position.x && (endEvnt.position.x - startEvnt.position.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (startEvnt.position.y < endEvnt.position.y && (endEvnt.position.y - startEvnt.position.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (startEvnt.position.x > endEvnt.position.x && (startEvnt.position.x - endEvnt.position.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ };
+ $this.trigger('swipeend', touchData);
+ }
+
+ started = false;
+ hasSwiped = false;
+ }
+
+ $this.on(settings.startevent, touchStart);
+ $this.on(settings.moveevent, touchMove);
+ $this.on(settings.endevent, touchEnd);
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.moveevent, $(this).data.callee2).off(settings.endevent, $(this).data.callee3);
+ }
+ };
+
+ // scrollstart Event (also handles scrollend):
+ $.event.special.scrollstart = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ scrolling,
+ timer;
+
+ function trigger(event, state) {
+ scrolling = state;
+ triggerCustomEvent(thisObject, scrolling ? 'scrollstart' : 'scrollend', event);
+ }
+
+ // iPhone triggers scroll after a small delay; use touchmove instead
+ $this.on(settings.scrollevent, function scrollFunc(event) {
+ $this.data('callee', scrollFunc);
+
+ if (!scrolling) {
+ trigger(event, true);
+ }
+
+ clearTimeout(timer);
+ timer = setTimeout(function () {
+ trigger(event, false);
+ }, 50);
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.scrollevent, $(this).data.callee);
+ }
+ };
+
+ // This is the orientation change (largely borrowed from jQuery Mobile):
+ var win = $(window),
+ special_event,
+ get_orientation,
+ last_orientation,
+ initial_orientation_is_landscape,
+ initial_orientation_is_default,
+ portrait_map = {
+ '0': true,
+ '180': true
+ };
+
+ if (settings.orientation_support) {
+ var ww = window.innerWidth || win.width(),
+ wh = window.innerHeight || win.height(),
+ landscape_threshold = 50;
+
+ initial_orientation_is_landscape = ww > wh && (ww - wh) > landscape_threshold;
+ initial_orientation_is_default = portrait_map[window.orientation];
+
+ if ((initial_orientation_is_landscape && initial_orientation_is_default) || (!initial_orientation_is_landscape && !initial_orientation_is_default)) {
+ portrait_map = {
+ '-90': true,
+ '90': true
+ };
+ }
+ }
+
+ $.event.special.orientationchange = special_event = {
+ setup: function () {
+ // If the event is supported natively, return false so that jQuery
+ // will on to the event using DOM methods.
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ // Get the current orientation to avoid initial double-triggering.
+ last_orientation = get_orientation();
+
+ win.on('throttledresize', handler);
+ return true;
+ },
+ teardown: function () {
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ win.off('throttledresize', handler);
+ return true;
+ },
+ add: function (handleObj) {
+ // Save a reference to the bound event handler.
+ var old_handler = handleObj.handler;
+
+ handleObj.handler = function (event) {
+ event.orientation = get_orientation();
+ return old_handler.apply(this, arguments);
+ };
+ }
+ };
+
+ // If the event is not supported natively, this handler will be bound to
+ // the window resize event to simulate the orientationchange event.
+
+ function handler() {
+ // Get the current orientation.
+ var orientation = get_orientation();
+
+ if (orientation !== last_orientation) {
+ // The orientation has changed, so trigger the orientationchange event.
+ last_orientation = orientation;
+ win.trigger("orientationchange");
+ }
+ }
+
+ $.event.special.orientationchange.orientation = get_orientation = function () {
+ var isPortrait = true,
+ elem = document.documentElement;
+
+ if (settings.orientation_support) {
+ isPortrait = portrait_map[window.orientation];
+ } else {
+ isPortrait = elem && elem.clientWidth / elem.clientHeight < 1.1;
+ }
+
+ return isPortrait ? 'portrait' : 'landscape';
+ };
+
+ // throttle Handler:
+ $.event.special.throttledresize = {
+ setup: function () {
+ $(this).on('resize', throttle_handler);
+ },
+ teardown: function () {
+ $(this).off('resize', throttle_handler);
+ }
+ };
+
+ var throttle = 250,
+ throttle_handler = function () {
+ curr = Date.now();
+ diff = curr - lastCall;
+
+ if (diff >= throttle) {
+ lastCall = curr;
+ $(this).trigger('throttledresize');
+
+ } else {
+ if (heldCall) {
+ window.clearTimeout(heldCall);
+ }
+
+ // Promise a held call will still execute
+ heldCall = window.setTimeout(handler, throttle - diff);
+ }
+ },
+ lastCall = 0,
+ heldCall,
+ curr,
+ diff;
+
+ // Trigger a custom event:
+
+ function triggerCustomEvent(obj, eventType, event, touchData) {
+ var originalType = event.type;
+ event.type = eventType;
+
+ $.event.dispatch.call(obj, event, touchData);
+ event.type = originalType;
+ }
+
+ // Correctly on anything we've overloaded:
+ $.each({
+ scrollend: 'scrollstart',
+ swipeup: 'swipe',
+ swiperight: 'swipe',
+ swipedown: 'swipe',
+ swipeleft: 'swipe',
+ swipeend: 'swipe',
+ tap2: 'tap'
+ }, function (e, srcE) {
+ $.event.special[e] = {
+ setup: function () {
+ $(this).on(srcE, $.noop);
+ }
+ };
+ });
+
+}(jQuery));
diff --git a/src/1.0.8/jquery.mobile-events.min.js b/src/1.0.8/jquery.mobile-events.min.js
new file mode 100644
index 0000000..c72b49f
--- /dev/null
+++ b/src/1.0.8/jquery.mobile-events.min.js
@@ -0,0 +1,27 @@
+/*!
+ * jQuery Mobile Events
+ * by Ben Major
+ *
+ * Copyright 2011-2017, Ben Major
+ * Licensed under the MIT License:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+"use strict";!function(a){function n(){var a=f();a!==g&&(g=a,d.trigger("orientationchange"))}function u(b,c,d,e){var f=d.type;d.type=c,a.event.dispatch.call(b,d,e),d.type=f}a.attrFn=a.attrFn||{};var b="ontouchstart"in window,c={tap_pixel_range:5,swipe_h_threshold:50,swipe_v_threshold:50,taphold_threshold:750,doubletap_int:500,touch_capable:b,orientation_support:"orientation"in window&&"onorientationchange"in window,startevent:b?"touchstart":"mousedown",endevent:b?"touchend":"mouseup",moveevent:b?"touchmove":"mousemove",tapevent:b?"tap":"click",scrollevent:b?"touchmove":"scroll",hold_timer:null,tap_timer:null};a.isTouchCapable=function(){return c.touch_capable},a.getStartEvent=function(){return c.startevent},a.getEndEvent=function(){return c.endevent},a.getMoveEvent=function(){return c.moveevent},a.getTapEvent=function(){return c.tapevent},a.getScrollEvent=function(){return c.scrollevent},a.each(["tapstart","tapend","tapmove","tap","tap2","tap3","tap4","singletap","doubletap","taphold","swipe","swipeup","swiperight","swipedown","swipeleft","swipeend","scrollstart","scrollend","orientationchange"],function(b,c){a.fn[c]=function(a){return a?this.on(c,a):this.trigger(c)},a.attrFn[c]=!0}),a.event.special.tapstart={setup:function(){var b=this,d=a(b);d.on(c.startevent,function a(e){if(d.data("callee",a),e.which&&1!==e.which)return!1;var f=e.originalEvent,g={position:{x:c.touch_capable?f.touches[0].screenX:e.screenX,y:c.touch_capable?f.touches[0].screenY:e.screenY},offset:{x:c.touch_capable?Math.round(f.changedTouches[0].pageX-(d.offset()?d.offset().left:0)):Math.round(e.pageX-(d.offset()?d.offset().left:0)),y:c.touch_capable?Math.round(f.changedTouches[0].pageY-(d.offset()?d.offset().top:0)):Math.round(e.pageY-(d.offset()?d.offset().top:0))},time:Date.now(),target:e.target};return u(b,"tapstart",e,g),!0})},remove:function(){a(this).off(c.startevent,a(this).data.callee)}},a.event.special.tapmove={setup:function(){var b=this,d=a(b);d.on(c.moveevent,function a(e){d.data("callee",a);var f=e.originalEvent,g={position:{x:c.touch_capable?f.touches[0].screenX:e.screenX,y:c.touch_capable?f.touches[0].screenY:e.screenY},offset:{x:c.touch_capable?Math.round(f.changedTouches[0].pageX-(d.offset()?d.offset().left:0)):Math.round(e.pageX-(d.offset()?d.offset().left:0)),y:c.touch_capable?Math.round(f.changedTouches[0].pageY-(d.offset()?d.offset().top:0)):Math.round(e.pageY-(d.offset()?d.offset().top:0))},time:Date.now(),target:e.target};return u(b,"tapmove",e,g),!0})},remove:function(){a(this).off(c.moveevent,a(this).data.callee)}},a.event.special.tapend={setup:function(){var b=this,d=a(b);d.on(c.endevent,function a(e){d.data("callee",a);var f=e.originalEvent,g={position:{x:c.touch_capable?f.changedTouches[0].screenX:e.screenX,y:c.touch_capable?f.changedTouches[0].screenY:e.screenY},offset:{x:c.touch_capable?Math.round(f.changedTouches[0].pageX-(d.offset()?d.offset().left:0)):Math.round(e.pageX-(d.offset()?d.offset().left:0)),y:c.touch_capable?Math.round(f.changedTouches[0].pageY-(d.offset()?d.offset().top:0)):Math.round(e.pageY-(d.offset()?d.offset().top:0))},time:Date.now(),target:e.target};return u(b,"tapend",e,g),!0})},remove:function(){a(this).off(c.endevent,a(this).data.callee)}},a.event.special.taphold={setup:function(){var e,b=this,d=a(b),f={x:0,y:0},g=0,h=0;d.on(c.startevent,function a(i){if(i.which&&1!==i.which)return!1;d.data("tapheld",!1),e=i.target;var j=i.originalEvent,k=Date.now(),l={x:c.touch_capable?j.touches[0].screenX:i.screenX,y:c.touch_capable?j.touches[0].screenY:i.screenY},m={x:c.touch_capable?j.touches[0].pageX-j.touches[0].target.offsetLeft:i.offsetX,y:c.touch_capable?j.touches[0].pageY-j.touches[0].target.offsetTop:i.offsetY};f.x=i.originalEvent.targetTouches?i.originalEvent.targetTouches[0].pageX:i.pageX,f.y=i.originalEvent.targetTouches?i.originalEvent.targetTouches[0].pageY:i.pageY,g=f.x,h=f.y;var n=d.parent().data("threshold")?d.parent().data("threshold"):d.data("threshold"),o="undefined"!=typeof n&&n!==!1&&parseInt(n)?parseInt(n):c.taphold_threshold;return c.hold_timer=window.setTimeout(function(){var n=f.x-g,o=f.y-h;if(i.target==e&&(f.x==g&&f.y==h||n>=-c.tap_pixel_range&&n<=c.tap_pixel_range&&o>=-c.tap_pixel_range&&o<=c.tap_pixel_range)){d.data("tapheld",!0);var p=Date.now(),q={x:c.touch_capable?j.touches[0].screenX:i.screenX,y:c.touch_capable?j.touches[0].screenY:i.screenY},r={x:c.touch_capable?Math.round(j.changedTouches[0].pageX-(d.offset()?d.offset().left:0)):Math.round(i.pageX-(d.offset()?d.offset().left:0)),y:c.touch_capable?Math.round(j.changedTouches[0].pageY-(d.offset()?d.offset().top:0)):Math.round(i.pageY-(d.offset()?d.offset().top:0))},s=p-k,t={startTime:k,endTime:p,startPosition:l,startOffset:m,endPosition:q,endOffset:r,duration:s,target:i.target};d.data("callee1",a),u(b,"taphold",i,t)}},o),!0}).on(c.endevent,function a(){d.data("callee2",a),d.data("tapheld",!1),window.clearTimeout(c.hold_timer)}).on(c.moveevent,function a(b){d.data("callee3",a),g=b.originalEvent.targetTouches?b.originalEvent.targetTouches[0].pageX:b.pageX,h=b.originalEvent.targetTouches?b.originalEvent.targetTouches[0].pageY:b.pageY})},remove:function(){a(this).off(c.startevent,a(this).data.callee1).off(c.endevent,a(this).data.callee2).off(c.moveevent,a(this).data.callee3)}},a.event.special.doubletap={setup:function(){var e,f,h,i,b=this,d=a(b),g=null,j=!1;d.on(c.startevent,function a(b){return(!b.which||1===b.which)&&(d.data("doubletapped",!1),e=b.target,d.data("callee1",a),h=b.originalEvent,g||(g={position:{x:c.touch_capable?h.touches[0].screenX:b.screenX,y:c.touch_capable?h.touches[0].screenY:b.screenY},offset:{x:c.touch_capable?Math.round(h.changedTouches[0].pageX-(d.offset()?d.offset().left:0)):Math.round(b.pageX-(d.offset()?d.offset().left:0)),y:c.touch_capable?Math.round(h.changedTouches[0].pageY-(d.offset()?d.offset().top:0)):Math.round(b.pageY-(d.offset()?d.offset().top:0))},time:Date.now(),target:b.target}),!0)}).on(c.endevent,function a(k){var l=Date.now(),m=d.data("lastTouch")||l+1,n=l-m;if(window.clearTimeout(f),d.data("callee2",a),n100){d.data("doubletapped",!0),window.clearTimeout(c.tap_timer);var o={position:{x:c.touch_capable?k.originalEvent.changedTouches[0].screenX:k.screenX,y:c.touch_capable?k.originalEvent.changedTouches[0].screenY:k.screenY},offset:{x:c.touch_capable?Math.round(h.changedTouches[0].pageX-(d.offset()?d.offset().left:0)):Math.round(k.pageX-(d.offset()?d.offset().left:0)),y:c.touch_capable?Math.round(h.changedTouches[0].pageY-(d.offset()?d.offset().top:0)):Math.round(k.pageY-(d.offset()?d.offset().top:0))},time:Date.now(),target:k.target},p={firstTap:g,secondTap:o,interval:o.time-g.time};j||(u(b,"doubletap",k,p),g=null),j=!0,i=window.setTimeout(function(){j=!1},c.doubletap_int)}else d.data("lastTouch",l),f=window.setTimeout(function(){g=null,window.clearTimeout(f)},c.doubletap_int,[k]);d.data("lastTouch",l)})},remove:function(){a(this).off(c.startevent,a(this).data.callee1).off(c.endevent,a(this).data.callee2)}},a.event.special.singletap={setup:function(){var b=this,d=a(b),e=null,f=null,g={x:0,y:0};d.on(c.startevent,function a(b){return(!b.which||1===b.which)&&(f=Date.now(),e=b.target,d.data("callee1",a),g.x=b.originalEvent.targetTouches?b.originalEvent.targetTouches[0].pageX:b.pageX,g.y=b.originalEvent.targetTouches?b.originalEvent.targetTouches[0].pageY:b.pageY,!0)}).on(c.endevent,function a(h){if(d.data("callee2",a),h.target==e){var i=h.originalEvent.changedTouches?h.originalEvent.changedTouches[0].pageX:h.pageX,j=h.originalEvent.changedTouches?h.originalEvent.changedTouches[0].pageY:h.pageY;c.tap_timer=window.setTimeout(function(){var a=g.x-i,e=g.y-j;if(!d.data("doubletapped")&&!d.data("tapheld")&&(g.x==i&&g.y==j||a>=-c.tap_pixel_range&&a<=c.tap_pixel_range&&e>=-c.tap_pixel_range&&e<=c.tap_pixel_range)){var k=h.originalEvent,l={position:{x:c.touch_capable?k.changedTouches[0].screenX:h.screenX,y:c.touch_capable?k.changedTouches[0].screenY:h.screenY},offset:{x:c.touch_capable?Math.round(k.changedTouches[0].pageX-(d.offset()?d.offset().left:0)):Math.round(h.pageX-(d.offset()?d.offset().left:0)),y:c.touch_capable?Math.round(k.changedTouches[0].pageY-(d.offset()?d.offset().top:0)):Math.round(h.pageY-(d.offset()?d.offset().top:0))},time:Date.now(),target:h.target};l.time-f=-c.tap_pixel_range&&m<=c.tap_pixel_range&&n>=-c.tap_pixel_range&&n<=c.tap_pixel_range)){for(var p=j.originalEvent,q=[],r=0;rh.y&&g.y-h.y>o&&(j="swipeup"),g.xn&&(j="swiperight"),g.yo&&(j="swipedown"),g.x>h.x&&g.x-h.x>n&&(j="swipeleft"),void 0!=j&&e){g.x=0,g.y=0,h.x=0,h.y=0,e=!1;var p=b.originalEvent,q={position:{x:c.touch_capable?p.touches[0].screenX:b.screenX,y:c.touch_capable?p.touches[0].screenY:b.screenY},offset:{x:c.touch_capable?Math.round(p.changedTouches[0].pageX-(d.offset()?d.offset().left:0)):Math.round(b.pageX-(d.offset()?d.offset().left:0)),y:c.touch_capable?Math.round(p.changedTouches[0].pageY-(d.offset()?d.offset().top:0)):Math.round(b.pageY-(d.offset()?d.offset().top:0))},time:Date.now(),target:b.target},r=Math.abs(i.position.x-q.position.x),s=Math.abs(i.position.y-q.position.y),t={startEvnt:i,endEvnt:q,direction:j.replace("swipe",""),xAmount:r,yAmount:s,duration:q.time-i.time};f=!0,d.trigger("swipe",t).trigger(j,t)}}function l(b){d=a(b.currentTarget);var g="";if(d.data("callee3",l),f){var h=d.data("xthreshold"),j=d.data("ythreshold"),k="undefined"!=typeof h&&h!==!1&&parseInt(h)?parseInt(h):c.swipe_h_threshold,m="undefined"!=typeof j&&j!==!1&&parseInt(j)?parseInt(j):c.swipe_v_threshold,n=b.originalEvent,o={position:{x:c.touch_capable?n.changedTouches[0].screenX:b.screenX,y:c.touch_capable?n.changedTouches[0].screenY:b.screenY},offset:{x:c.touch_capable?Math.round(n.changedTouches[0].pageX-(d.offset()?d.offset().left:0)):Math.round(b.pageX-(d.offset()?d.offset().left:0)),y:c.touch_capable?Math.round(n.changedTouches[0].pageY-(d.offset()?d.offset().top:0)):Math.round(b.pageY-(d.offset()?d.offset().top:0))},time:Date.now(),target:b.target};i.position.y>o.position.y&&i.position.y-o.position.y>m&&(g="swipeup"),i.position.xk&&(g="swiperight"),i.position.ym&&(g="swipedown"),i.position.x>o.position.x&&i.position.x-o.position.x>k&&(g="swipeleft");var p=Math.abs(i.position.x-o.position.x),q=Math.abs(i.position.y-o.position.y),r={startEvnt:i,endEvnt:o,direction:g.replace("swipe",""),xAmount:p,yAmount:q,duration:o.time-i.time};d.trigger("swipeend",r)}e=!1,f=!1}var i,b=this,d=a(b),e=!1,f=!1,g={x:0,y:0},h={x:0,y:0};d.on(c.startevent,j),d.on(c.moveevent,k),d.on(c.endevent,l)},remove:function(){a(this).off(c.startevent,a(this).data.callee1).off(c.moveevent,a(this).data.callee2).off(c.endevent,a(this).data.callee3)}},a.event.special.scrollstart={setup:function(){function g(a,c){e=c,u(b,e?"scrollstart":"scrollend",a)}var e,f,b=this,d=a(b);d.on(c.scrollevent,function a(b){d.data("callee",a),e||g(b,!0),clearTimeout(f),f=setTimeout(function(){g(b,!1)},50)})},remove:function(){a(this).off(c.scrollevent,a(this).data.callee)}};var e,f,g,h,i,d=a(window),j={0:!0,180:!0};if(c.orientation_support){var k=window.innerWidth||d.width(),l=window.innerHeight||d.height(),m=50;h=k>l&&k-l>m,i=j[window.orientation],(h&&i||!h&&!i)&&(j={"-90":!0,90:!0})}a.event.special.orientationchange=e={setup:function(){return!c.orientation_support&&(g=f(),d.on("throttledresize",n),!0)},teardown:function(){return!c.orientation_support&&(d.off("throttledresize",n),!0)},add:function(a){var b=a.handler;a.handler=function(a){return a.orientation=f(),b.apply(this,arguments)}}},a.event.special.orientationchange.orientation=f=function(){var a=!0,b=document.documentElement;return a=c.orientation_support?j[window.orientation]:b&&b.clientWidth/b.clientHeight<1.1,a?"portrait":"landscape"},a.event.special.throttledresize={setup:function(){a(this).on("resize",p)},teardown:function(){a(this).off("resize",p)}};var r,s,t,o=250,p=function(){s=Date.now(),t=s-q,t>=o?(q=s,a(this).trigger("throttledresize")):(r&&window.clearTimeout(r),r=window.setTimeout(n,o-t))},q=0;a.each({scrollend:"scrollstart",swipeup:"swipe",swiperight:"swipe",swipedown:"swipe",swipeleft:"swipe",swipeend:"swipe",tap2:"tap"},function(b,c){a.event.special[b]={setup:function(){a(this).on(c,a.noop)}}})}(jQuery);
diff --git a/src/1.0.9/jquery.mobile-events.js b/src/1.0.9/jquery.mobile-events.js
new file mode 100644
index 0000000..6976761
--- /dev/null
+++ b/src/1.0.9/jquery.mobile-events.js
@@ -0,0 +1,882 @@
+/*!
+ * jQuery Mobile Events
+ * by Ben Major
+ *
+ * Copyright 2011-2017, Ben Major
+ * Licensed under the MIT License:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+"use strict";
+
+(function ($) {
+ $.attrFn = $.attrFn || {};
+
+ // navigator.userAgent.toLowerCase() isn't reliable for Chrome installs
+ // on mobile devices. As such, we will create a boolean isChromeDesktop
+ // The reason that we need to do this is because Chrome annoyingly
+ // purports support for touch events even if the underlying hardware
+ // does not!
+ var touchCapable = ('ontouchstart' in window),
+
+ settings = {
+ tap_pixel_range: 5,
+ swipe_h_threshold: 50,
+ swipe_v_threshold: 50,
+ taphold_threshold: 750,
+ doubletap_int: 500,
+
+ touch_capable: touchCapable,
+ orientation_support: ('orientation' in window && 'onorientationchange' in window),
+
+ startevent: (touchCapable) ? 'touchstart' : 'mousedown',
+ endevent: (touchCapable) ? 'touchend' : 'mouseup',
+ moveevent: (touchCapable) ? 'touchmove' : 'mousemove',
+ tapevent: (touchCapable) ? 'tap' : 'click',
+ scrollevent: (touchCapable) ? 'touchmove' : 'scroll',
+
+ hold_timer: null,
+ tap_timer: null
+ };
+
+ // Convenience functions:
+ $.isTouchCapable = function() { return settings.touch_capable; };
+ $.getStartEvent = function() { return settings.startevent; };
+ $.getEndEvent = function() { return settings.endevent; };
+ $.getMoveEvent = function() { return settings.moveevent; };
+ $.getTapEvent = function() { return settings.tapevent; };
+ $.getScrollEvent = function() { return settings.scrollevent; };
+
+ // Add Event shortcuts:
+ $.each(['tapstart', 'tapend', 'tapmove', 'tap', 'tap2', 'tap3', 'tap4', 'singletap', 'doubletap', 'taphold', 'swipe', 'swipeup', 'swiperight', 'swipedown', 'swipeleft', 'swipeend', 'scrollstart', 'scrollend', 'orientationchange'], function (i, name) {
+ $.fn[name] = function (fn) {
+ return fn ? this.on(name, fn) : this.trigger(name);
+ };
+
+ $.attrFn[name] = true;
+ });
+
+ // tapstart Event:
+ $.event.special.tapstart = {
+ setup: function () {
+
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.startevent, function tapStartFunc(e) {
+
+ $this.data('callee', tapStartFunc);
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapstart', e, touchData);
+ return true;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee);
+ }
+ };
+
+ // tapmove Event:
+ $.event.special.tapmove = {
+ setup: function() {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.moveevent, function tapMoveFunc(e) {
+ $this.data('callee', tapMoveFunc);
+
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapmove', e, touchData);
+ return true;
+ });
+ },
+ remove: function() {
+ $(this).off(settings.moveevent, $(this).data.callee);
+ }
+ };
+
+ // tapend Event:
+ $.event.special.tapend = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.endevent, function tapEndFunc(e) {
+ // Touch event data:
+ $this.data('callee', tapEndFunc);
+
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ triggerCustomEvent(thisObject, 'tapend', e, touchData);
+ return true;
+ });
+ },
+ remove: function () {
+ $(this).off(settings.endevent, $(this).data.callee);
+ }
+ };
+
+ // taphold Event:
+ $.event.special.taphold = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ end_x = 0,
+ end_y = 0;
+
+ $this.on(settings.startevent, function tapHoldFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ $this.data('tapheld', false);
+ origTarget = e.target;
+
+ var origEvent = e.originalEvent;
+ var start_time = Date.now(),
+ startPosition = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ startOffset = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ };
+
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ end_x = start_pos.x;
+ end_y = start_pos.y;
+
+ // Get the element's threshold:
+
+ var ele_threshold = ($this.parent().data('threshold')) ? $this.parent().data('threshold') : $this.data('threshold'),
+ threshold = (typeof ele_threshold !== 'undefined' && ele_threshold !== false && parseInt(ele_threshold)) ? parseInt(ele_threshold) : settings.taphold_threshold;
+
+ settings.hold_timer = window.setTimeout(function () {
+
+ var diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y);
+
+ if (e.target == origTarget && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ $this.data('tapheld', true);
+
+ var end_time = Date.now(),
+ endPosition = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ endOffset = {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ };
+ var duration = end_time - start_time;
+
+ // Build the touch data:
+ var touchData = {
+ 'startTime': start_time,
+ 'endTime': end_time,
+ 'startPosition': startPosition,
+ 'startOffset': startOffset,
+ 'endPosition': endPosition,
+ 'endOffset': endOffset,
+ 'duration': duration,
+ 'target': e.target
+ };
+ $this.data('callee1', tapHoldFunc1);
+ triggerCustomEvent(thisObject, 'taphold', e, touchData);
+ }
+ }, threshold);
+
+ return true;
+ }
+ }).on(settings.endevent, function tapHoldFunc2() {
+ $this.data('callee2', tapHoldFunc2);
+ $this.data('tapheld', false);
+ window.clearTimeout(settings.hold_timer);
+ })
+ .on(settings.moveevent, function tapHoldFunc3(e) {
+ $this.data('callee3', tapHoldFunc3);
+
+ end_x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2).off(settings.moveevent, $(this).data.callee3);
+ }
+ };
+
+ // doubletap Event:
+ $.event.special.doubletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ action,
+ firstTap = null,
+ origEvent,
+ cooloff,
+ cooling = false;
+
+ $this.on(settings.startevent, function doubleTapFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+
+ $this.data('doubletapped', false);
+ origTarget = e.target;
+ $this.data('callee1', doubleTapFunc1);
+
+ origEvent = e.originalEvent;
+ if (!firstTap) {
+ firstTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target,
+ 'element': e.originalEvent.srcElement,
+ 'index': $(e.target).index()
+ };
+ }
+
+ return true;
+ }).on(settings.endevent, function doubleTapFunc2(e) {
+
+ var now = Date.now();
+ var lastTouch = $this.data('lastTouch') || now + 1;
+ var delta = now - lastTouch;
+ window.clearTimeout(action);
+ $this.data('callee2', doubleTapFunc2);
+
+ if (delta < settings.doubletap_int && ($(e.target).index() == firstTap.index) && delta > 100) {
+ $this.data('doubletapped', true);
+ window.clearTimeout(settings.tap_timer);
+
+ // Now get the current event:
+ var lastTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? e.originalEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? e.originalEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target,
+ 'element': e.originalEvent.srcElement,
+ 'index': $(e.target).index()
+ };
+
+ var touchData = {
+ 'firstTap': firstTap,
+ 'secondTap': lastTap,
+ 'interval': lastTap.time - firstTap.time
+ };
+
+ if (!cooling) {
+ triggerCustomEvent(thisObject, 'doubletap', e, touchData);
+ firstTap = null;
+ }
+
+ cooling = true;
+
+ cooloff = window.setTimeout(function () {
+ cooling = false;
+ }, settings.doubletap_int);
+
+ } else {
+ $this.data('lastTouch', now);
+ action = window.setTimeout(function () {
+ firstTap = null;
+ window.clearTimeout(action);
+ }, settings.doubletap_int, [e]);
+ }
+ $this.data('lastTouch', now);
+ });
+ },
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // singletap Event:
+ // This is used in conjuction with doubletap when both events are needed on the same element
+ $.event.special.singletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget = null,
+ startTime = null,
+ start_pos = {
+ x: 0,
+ y: 0
+ };
+
+ $this.on(settings.startevent, function singleTapFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ startTime = Date.now();
+ origTarget = e.target;
+ $this.data('callee1', singleTapFunc1);
+
+ // Get the start x and y position:
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ return true;
+ }
+ }).on(settings.endevent, function singleTapFunc2(e) {
+ $this.data('callee2', singleTapFunc2);
+ if (e.target == origTarget) {
+
+ // Get the end point:
+ var end_pos_x = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ end_pos_y = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY;
+
+ // We need to check if it was a taphold:
+
+ settings.tap_timer = window.setTimeout(function () {
+
+ var diff_x = (start_pos.x - end_pos_x), diff_y = (start_pos.y - end_pos_y);
+
+ if(!$this.data('doubletapped') && !$this.data('tapheld') && (((start_pos.x == end_pos_x) && (start_pos.y == end_pos_y)) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Was it a taphold?
+ if((touchData.time - startTime) < settings.taphold_threshold)
+ {
+ triggerCustomEvent(thisObject, 'singletap', e, touchData);
+ }
+ }
+ }, settings.doubletap_int);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // tap Event:
+ $.event.special.tap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ origTarget = null,
+ start_time,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ touches;
+
+ $this.on(settings.startevent, function tapFunc1(e) {
+ $this.data('callee1', tapFunc1);
+
+ if( e.which && e.which !== 1 )
+ {
+ return false;
+ }
+ else
+ {
+ started = true;
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ start_time = Date.now();
+ origTarget = e.target;
+
+ touches = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches : [ e ];
+ return true;
+ }
+ }).on(settings.endevent, function tapFunc2(e) {
+ $this.data('callee2', tapFunc2);
+
+ // Only trigger if they've started, and the target matches:
+ var end_x = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY,
+ diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y),
+ eventName;
+
+ if (origTarget == e.target && started && ((Date.now() - start_time) < settings.taphold_threshold) && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ var origEvent = e.originalEvent;
+ var touchData = [ ];
+
+ for( var i = 0; i < touches.length; i++)
+ {
+ var touch = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[i].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[i].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ touchData.push( touch );
+ }
+
+ triggerCustomEvent(thisObject, 'tap', e, touchData);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // swipe Event (also handles swipeup, swiperight, swipedown and swipeleft):
+ $.event.special.swipe = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ hasSwiped = false,
+ originalCoord = {
+ x: 0,
+ y: 0
+ },
+ finalCoord = {
+ x: 0,
+ y: 0
+ },
+ startEvnt;
+
+ // Screen touched, store the original coordinate
+
+ function touchStart(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee1', touchStart);
+ originalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ originalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ finalCoord.x = originalCoord.x;
+ finalCoord.y = originalCoord.y;
+ started = true;
+ var origEvent = e.originalEvent;
+ // Read event data into our startEvt:
+ startEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ }
+
+ // Store coordinates as finger is swiping
+
+ function touchMove(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee2', touchMove);
+ finalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ finalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ var swipedir;
+
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = ($this.parent().data('xthreshold')) ? $this.parent().data('xthreshold') : $this.data('xthreshold'),
+ ele_y_threshold = ($this.parent().data('ythreshold')) ? $this.parent().data('ythreshold') : $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ if (originalCoord.y > finalCoord.y && (originalCoord.y - finalCoord.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (originalCoord.x < finalCoord.x && (finalCoord.x - originalCoord.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (originalCoord.y < finalCoord.y && (finalCoord.y - originalCoord.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (originalCoord.x > finalCoord.x && (originalCoord.x - finalCoord.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+ if (swipedir != undefined && started) {
+ originalCoord.x = 0;
+ originalCoord.y = 0;
+ finalCoord.x = 0;
+ finalCoord.y = 0;
+ started = false;
+
+ // Read event data into our endEvnt:
+ var origEvent = e.originalEvent;
+ var endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ };
+ hasSwiped = true;
+ $this.trigger('swipe', touchData).trigger(swipedir, touchData);
+ }
+ }
+
+ function touchEnd(e) {
+ $this = $(e.currentTarget);
+ var swipedir = "";
+ $this.data('callee3', touchEnd);
+ if (hasSwiped) {
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = $this.data('xthreshold'),
+ ele_y_threshold = $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ var origEvent = e.originalEvent;
+ var endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Read event data into our endEvnt:
+ if (startEvnt.position.y > endEvnt.position.y && (startEvnt.position.y - endEvnt.position.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (startEvnt.position.x < endEvnt.position.x && (endEvnt.position.x - startEvnt.position.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (startEvnt.position.y < endEvnt.position.y && (endEvnt.position.y - startEvnt.position.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (startEvnt.position.x > endEvnt.position.x && (startEvnt.position.x - endEvnt.position.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ };
+ $this.trigger('swipeend', touchData);
+ }
+
+ started = false;
+ hasSwiped = false;
+ }
+
+ $this.on(settings.startevent, touchStart);
+ $this.on(settings.moveevent, touchMove);
+ $this.on(settings.endevent, touchEnd);
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.moveevent, $(this).data.callee2).off(settings.endevent, $(this).data.callee3);
+ }
+ };
+
+ // scrollstart Event (also handles scrollend):
+ $.event.special.scrollstart = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ scrolling,
+ timer;
+
+ function trigger(event, state) {
+ scrolling = state;
+ triggerCustomEvent(thisObject, scrolling ? 'scrollstart' : 'scrollend', event);
+ }
+
+ // iPhone triggers scroll after a small delay; use touchmove instead
+ $this.on(settings.scrollevent, function scrollFunc(event) {
+ $this.data('callee', scrollFunc);
+
+ if (!scrolling) {
+ trigger(event, true);
+ }
+
+ clearTimeout(timer);
+ timer = setTimeout(function () {
+ trigger(event, false);
+ }, 50);
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.scrollevent, $(this).data.callee);
+ }
+ };
+
+ // This is the orientation change (largely borrowed from jQuery Mobile):
+ var win = $(window),
+ special_event,
+ get_orientation,
+ last_orientation,
+ initial_orientation_is_landscape,
+ initial_orientation_is_default,
+ portrait_map = {
+ '0': true,
+ '180': true
+ };
+
+ if (settings.orientation_support) {
+ var ww = window.innerWidth || win.width(),
+ wh = window.innerHeight || win.height(),
+ landscape_threshold = 50;
+
+ initial_orientation_is_landscape = ww > wh && (ww - wh) > landscape_threshold;
+ initial_orientation_is_default = portrait_map[window.orientation];
+
+ if ((initial_orientation_is_landscape && initial_orientation_is_default) || (!initial_orientation_is_landscape && !initial_orientation_is_default)) {
+ portrait_map = {
+ '-90': true,
+ '90': true
+ };
+ }
+ }
+
+ $.event.special.orientationchange = special_event = {
+ setup: function () {
+ // If the event is supported natively, return false so that jQuery
+ // will on to the event using DOM methods.
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ // Get the current orientation to avoid initial double-triggering.
+ last_orientation = get_orientation();
+
+ win.on('throttledresize', handler);
+ return true;
+ },
+ teardown: function () {
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ win.off('throttledresize', handler);
+ return true;
+ },
+ add: function (handleObj) {
+ // Save a reference to the bound event handler.
+ var old_handler = handleObj.handler;
+
+ handleObj.handler = function (event) {
+ event.orientation = get_orientation();
+ return old_handler.apply(this, arguments);
+ };
+ }
+ };
+
+ // If the event is not supported natively, this handler will be bound to
+ // the window resize event to simulate the orientationchange event.
+
+ function handler() {
+ // Get the current orientation.
+ var orientation = get_orientation();
+
+ if (orientation !== last_orientation) {
+ // The orientation has changed, so trigger the orientationchange event.
+ last_orientation = orientation;
+ win.trigger("orientationchange");
+ }
+ }
+
+ $.event.special.orientationchange.orientation = get_orientation = function () {
+ var isPortrait = true,
+ elem = document.documentElement;
+
+ if (settings.orientation_support) {
+ isPortrait = portrait_map[window.orientation];
+ } else {
+ isPortrait = elem && elem.clientWidth / elem.clientHeight < 1.1;
+ }
+
+ return isPortrait ? 'portrait' : 'landscape';
+ };
+
+ // throttle Handler:
+ $.event.special.throttledresize = {
+ setup: function () {
+ $(this).on('resize', throttle_handler);
+ },
+ teardown: function () {
+ $(this).off('resize', throttle_handler);
+ }
+ };
+
+ var throttle = 250,
+ throttle_handler = function () {
+ curr = Date.now();
+ diff = curr - lastCall;
+
+ if (diff >= throttle) {
+ lastCall = curr;
+ $(this).trigger('throttledresize');
+
+ } else {
+ if (heldCall) {
+ window.clearTimeout(heldCall);
+ }
+
+ // Promise a held call will still execute
+ heldCall = window.setTimeout(handler, throttle - diff);
+ }
+ },
+ lastCall = 0,
+ heldCall,
+ curr,
+ diff;
+
+ // Trigger a custom event:
+
+ function triggerCustomEvent(obj, eventType, event, touchData) {
+ var originalType = event.type;
+ event.type = eventType;
+
+ $.event.dispatch.call(obj, event, touchData);
+ event.type = originalType;
+ }
+
+ // Correctly on anything we've overloaded:
+ $.each({
+ scrollend: 'scrollstart',
+ swipeup: 'swipe',
+ swiperight: 'swipe',
+ swipedown: 'swipe',
+ swipeleft: 'swipe',
+ swipeend: 'swipe',
+ tap2: 'tap'
+ }, function (e, srcE) {
+ $.event.special[e] = {
+ setup: function () {
+ $(this).on(srcE, $.noop);
+ }
+ };
+ });
+
+}(jQuery));
diff --git a/src/1.0.9/jquery.mobile-events.min.js b/src/1.0.9/jquery.mobile-events.min.js
new file mode 100644
index 0000000..0269098
--- /dev/null
+++ b/src/1.0.9/jquery.mobile-events.min.js
@@ -0,0 +1,28 @@
+/*!
+ * jQuery Mobile Events
+ * by Ben Major
+ *
+ * Copyright 2011-2017, Ben Major
+ * Licensed under the MIT License:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+'use strict';(function(a){function b(){var x=j();x!==k&&(k=x,g.trigger('orientationchange'))}function c(x,y,z,A){var B=z.type;z.type=y,a.event.dispatch.call(x,z,A),z.type=B}a.attrFn=a.attrFn||{};var d='ontouchstart'in window,f={tap_pixel_range:5,swipe_h_threshold:50,swipe_v_threshold:50,taphold_threshold:750,doubletap_int:500,touch_capable:d,orientation_support:'orientation'in window&&'onorientationchange'in window,startevent:d?'touchstart':'mousedown',endevent:d?'touchend':'mouseup',moveevent:d?'touchmove':'mousemove',tapevent:d?'tap':'click',scrollevent:d?'touchmove':'scroll',hold_timer:null,tap_timer:null};a.isTouchCapable=function(){return f.touch_capable},a.getStartEvent=function(){return f.startevent},a.getEndEvent=function(){return f.endevent},a.getMoveEvent=function(){return f.moveevent},a.getTapEvent=function(){return f.tapevent},a.getScrollEvent=function(){return f.scrollevent},a.each(['tapstart','tapend','tapmove','tap','tap2','tap3','tap4','singletap','doubletap','taphold','swipe','swipeup','swiperight','swipedown','swipeleft','swipeend','scrollstart','scrollend','orientationchange'],function(x,y){a.fn[y]=function(z){return z?this.on(y,z):this.trigger(y)},a.attrFn[y]=!0}),a.event.special.tapstart={setup:function(){var x=this,y=a(x);y.on(f.startevent,function z(A){if(y.data('callee',z),A.which&&1!==A.which)return!1;var B=A.originalEvent,C={position:{x:f.touch_capable?B.touches[0].screenX:A.screenX,y:f.touch_capable?B.touches[0].screenY:A.screenY},offset:{x:f.touch_capable?Math.round(B.changedTouches[0].pageX-(y.offset()?y.offset().left:0)):Math.round(A.pageX-(y.offset()?y.offset().left:0)),y:f.touch_capable?Math.round(B.changedTouches[0].pageY-(y.offset()?y.offset().top:0)):Math.round(A.pageY-(y.offset()?y.offset().top:0))},time:Date.now(),target:A.target};return c(x,'tapstart',A,C),!0})},remove:function(){a(this).off(f.startevent,a(this).data.callee)}},a.event.special.tapmove={setup:function(){var x=this,y=a(x);y.on(f.moveevent,function z(A){y.data('callee',z);var B=A.originalEvent,C={position:{x:f.touch_capable?B.touches[0].screenX:A.screenX,y:f.touch_capable?B.touches[0].screenY:A.screenY},offset:{x:f.touch_capable?Math.round(B.changedTouches[0].pageX-(y.offset()?y.offset().left:0)):Math.round(A.pageX-(y.offset()?y.offset().left:0)),y:f.touch_capable?Math.round(B.changedTouches[0].pageY-(y.offset()?y.offset().top:0)):Math.round(A.pageY-(y.offset()?y.offset().top:0))},time:Date.now(),target:A.target};return c(x,'tapmove',A,C),!0})},remove:function(){a(this).off(f.moveevent,a(this).data.callee)}},a.event.special.tapend={setup:function(){var x=this,y=a(x);y.on(f.endevent,function z(A){y.data('callee',z);var B=A.originalEvent,C={position:{x:f.touch_capable?B.changedTouches[0].screenX:A.screenX,y:f.touch_capable?B.changedTouches[0].screenY:A.screenY},offset:{x:f.touch_capable?Math.round(B.changedTouches[0].pageX-(y.offset()?y.offset().left:0)):Math.round(A.pageX-(y.offset()?y.offset().left:0)),y:f.touch_capable?Math.round(B.changedTouches[0].pageY-(y.offset()?y.offset().top:0)):Math.round(A.pageY-(y.offset()?y.offset().top:0))},time:Date.now(),target:A.target};return c(x,'tapend',A,C),!0})},remove:function(){a(this).off(f.endevent,a(this).data.callee)}},a.event.special.taphold={setup:function(){var z,x=this,y=a(x),A={x:0,y:0},B=0,C=0;y.on(f.startevent,function D(E){if(E.which&&1!==E.which)return!1;y.data('tapheld',!1),z=E.target;var F=E.originalEvent,G=Date.now(),H={x:f.touch_capable?F.touches[0].screenX:E.screenX,y:f.touch_capable?F.touches[0].screenY:E.screenY},I={x:f.touch_capable?F.touches[0].pageX-F.touches[0].target.offsetLeft:E.offsetX,y:f.touch_capable?F.touches[0].pageY-F.touches[0].target.offsetTop:E.offsetY};A.x=E.originalEvent.targetTouches?E.originalEvent.targetTouches[0].pageX:E.pageX,A.y=E.originalEvent.targetTouches?E.originalEvent.targetTouches[0].pageY:E.pageY,B=A.x,C=A.y;var J=y.parent().data('threshold')?y.parent().data('threshold'):y.data('threshold'),K='undefined'!=typeof J&&!1!==J&&parseInt(J)?parseInt(J):f.taphold_threshold;return f.hold_timer=window.setTimeout(function(){var L=A.x-B,M=A.y-C;if(E.target==z&&(A.x==B&&A.y==C||L>=-f.tap_pixel_range&&L<=f.tap_pixel_range&&M>=-f.tap_pixel_range&&M<=f.tap_pixel_range)){y.data('tapheld',!0);var N=Date.now(),O={x:f.touch_capable?F.touches[0].screenX:E.screenX,y:f.touch_capable?F.touches[0].screenY:E.screenY},P={x:f.touch_capable?Math.round(F.changedTouches[0].pageX-(y.offset()?y.offset().left:0)):Math.round(E.pageX-(y.offset()?y.offset().left:0)),y:f.touch_capable?Math.round(F.changedTouches[0].pageY-(y.offset()?y.offset().top:0)):Math.round(E.pageY-(y.offset()?y.offset().top:0))},R={startTime:G,endTime:N,startPosition:H,startOffset:I,endPosition:O,endOffset:P,duration:N-G,target:E.target};y.data('callee1',D),c(x,'taphold',E,R)}},K),!0}).on(f.endevent,function D(){y.data('callee2',D),y.data('tapheld',!1),window.clearTimeout(f.hold_timer)}).on(f.moveevent,function D(E){y.data('callee3',D),B=E.originalEvent.targetTouches?E.originalEvent.targetTouches[0].pageX:E.pageX,C=E.originalEvent.targetTouches?E.originalEvent.targetTouches[0].pageY:E.pageY})},remove:function(){a(this).off(f.startevent,a(this).data.callee1).off(f.endevent,a(this).data.callee2).off(f.moveevent,a(this).data.callee3)}},a.event.special.doubletap={setup:function(){var z,A,C,D,x=this,y=a(x),B=null,E=!1;y.on(f.startevent,function F(G){return G.which&&1!==G.which?!1:(y.data('doubletapped',!1),z=G.target,y.data('callee1',F),C=G.originalEvent,B||(B={position:{x:f.touch_capable?C.touches[0].screenX:G.screenX,y:f.touch_capable?C.touches[0].screenY:G.screenY},offset:{x:f.touch_capable?Math.round(C.changedTouches[0].pageX-(y.offset()?y.offset().left:0)):Math.round(G.pageX-(y.offset()?y.offset().left:0)),y:f.touch_capable?Math.round(C.changedTouches[0].pageY-(y.offset()?y.offset().top:0)):Math.round(G.pageY-(y.offset()?y.offset().top:0))},time:Date.now(),target:G.target,element:G.originalEvent.srcElement,index:a(G.target).index()}),!0)}).on(f.endevent,function F(G){var H=Date.now(),I=y.data('lastTouch')||H+1,J=H-I;if(window.clearTimeout(A),y.data('callee2',F),J=-f.tap_pixel_range&&G<=f.tap_pixel_range&&H>=-f.tap_pixel_range&&H<=f.tap_pixel_range)){var I=D.originalEvent,J={position:{x:f.touch_capable?I.changedTouches[0].screenX:D.screenX,y:f.touch_capable?I.changedTouches[0].screenY:D.screenY},offset:{x:f.touch_capable?Math.round(I.changedTouches[0].pageX-(y.offset()?y.offset().left:0)):Math.round(D.pageX-(y.offset()?y.offset().left:0)),y:f.touch_capable?Math.round(I.changedTouches[0].pageY-(y.offset()?y.offset().top:0)):Math.round(D.pageY-(y.offset()?y.offset().top:0))},time:Date.now(),target:D.target};J.time-A=-f.tap_pixel_range&&I<=f.tap_pixel_range&&J>=-f.tap_pixel_range&&J<=f.tap_pixel_range)){for(var O,L=F.originalEvent,M=[],N=0;NF.y&&E.y-F.y>M&&(I='swipeup'),E.xL&&(I='swiperight'),E.yM&&(I='swipedown'),E.x>F.x&&E.x-F.x>L&&(I='swipeleft'),void 0!=I&&C){E.x=0,E.y=0,F.x=0,F.y=0,C=!1;var N=H.originalEvent,O={position:{x:f.touch_capable?N.touches[0].screenX:H.screenX,y:f.touch_capable?N.touches[0].screenY:H.screenY},offset:{x:f.touch_capable?Math.round(N.changedTouches[0].pageX-(B.offset()?B.offset().left:0)):Math.round(H.pageX-(B.offset()?B.offset().left:0)),y:f.touch_capable?Math.round(N.changedTouches[0].pageY-(B.offset()?B.offset().top:0)):Math.round(H.pageY-(B.offset()?B.offset().top:0))},time:Date.now(),target:H.target},P=Math.abs(G.position.x-O.position.x),Q=Math.abs(G.position.y-O.position.y),R={startEvnt:G,endEvnt:O,direction:I.replace('swipe',''),xAmount:P,yAmount:Q,duration:O.time-G.time};D=!0,B.trigger('swipe',R).trigger(I,R)}}function z(H){B=a(H.currentTarget);var I='';if(B.data('callee3',z),D){var J=B.data('xthreshold'),K=B.data('ythreshold'),L='undefined'!=typeof J&&!1!==J&&parseInt(J)?parseInt(J):f.swipe_h_threshold,M='undefined'!=typeof K&&!1!==K&&parseInt(K)?parseInt(K):f.swipe_v_threshold,N=H.originalEvent,O={position:{x:f.touch_capable?N.changedTouches[0].screenX:H.screenX,y:f.touch_capable?N.changedTouches[0].screenY:H.screenY},offset:{x:f.touch_capable?Math.round(N.changedTouches[0].pageX-(B.offset()?B.offset().left:0)):Math.round(H.pageX-(B.offset()?B.offset().left:0)),y:f.touch_capable?Math.round(N.changedTouches[0].pageY-(B.offset()?B.offset().top:0)):Math.round(H.pageY-(B.offset()?B.offset().top:0))},time:Date.now(),target:H.target};G.position.y>O.position.y&&G.position.y-O.position.y>M&&(I='swipeup'),G.position.xL&&(I='swiperight'),G.position.yM&&(I='swipedown'),G.position.x>O.position.x&&G.position.x-O.position.x>L&&(I='swipeleft');var P=Math.abs(G.position.x-O.position.x),Q=Math.abs(G.position.y-O.position.y),R={startEvnt:G,endEvnt:O,direction:I.replace('swipe',''),xAmount:P,yAmount:Q,duration:O.time-G.time};B.trigger('swipeend',R)}C=!1,D=!1}var G,A=this,B=a(A),C=!1,D=!1,E={x:0,y:0},F={x:0,y:0};B.on(f.startevent,x),B.on(f.moveevent,y),B.on(f.endevent,z)},remove:function(){a(this).off(f.startevent,a(this).data.callee1).off(f.moveevent,a(this).data.callee2).off(f.endevent,a(this).data.callee3)}},a.event.special.scrollstart={setup:function(){function x(C,D){A=D,c(y,A?'scrollstart':'scrollend',C)}var A,B,y=this,z=a(y);z.on(f.scrollevent,function C(D){z.data('callee',C),A||x(D,!0),clearTimeout(B),B=setTimeout(function(){x(D,!1)},50)})},remove:function(){a(this).off(f.scrollevent,a(this).data.callee)}};var h,j,k,l,m,g=a(window),n={0:!0,180:!0};if(f.orientation_support){var o=window.innerWidth||g.width(),p=window.innerHeight||g.height();l=o>p&&o-p>50,m=n[window.orientation],(l&&m||!l&&!m)&&(n={90:!0,'-90':!0})}a.event.special.orientationchange=h={setup:function(){return!f.orientation_support&&(k=j(),g.on('throttledresize',b),!0)},teardown:function(){return!f.orientation_support&&(g.off('throttledresize',b),!0)},add:function(x){var y=x.handler;x.handler=function(z){return z.orientation=j(),y.apply(this,arguments)}}},a.event.special.orientationchange.orientation=j=function(){var x=!0,y=document.documentElement;return x=f.orientation_support?n[window.orientation]:y&&1.1>y.clientWidth/y.clientHeight,x?'portrait':'landscape'},a.event.special.throttledresize={setup:function(){a(this).on('resize',s)},teardown:function(){a(this).off('resize',s)}};var u,v,w,r=250,s=function(){v=Date.now(),w=v-t,w>=r?(t=v,a(this).trigger('throttledresize')):(u&&window.clearTimeout(u),u=window.setTimeout(b,r-w))},t=0;a.each({scrollend:'scrollstart',swipeup:'swipe',swiperight:'swipe',swipedown:'swipe',swipeleft:'swipe',swipeend:'swipe',tap2:'tap'},function(x,y){a.event.special[x]={setup:function(){a(this).on(y,a.noop)}}})})(jQuery);
diff --git a/src/2.0.0/jquery.mobile-events.js b/src/2.0.0/jquery.mobile-events.js
new file mode 100644
index 0000000..d0bcca8
--- /dev/null
+++ b/src/2.0.0/jquery.mobile-events.js
@@ -0,0 +1,920 @@
+/*!
+ * jQuery Mobile Events
+ * by Ben Major
+ *
+ * Copyright 2011-2017, Ben Major
+ * Licensed under the MIT License:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+"use strict";
+
+(function ($) {
+ $.attrFn = $.attrFn || {};
+
+ var touchCapable = ('ontouchstart' in window),
+
+ settings = {
+ tap_pixel_range: 5,
+ swipe_h_threshold: 50,
+ swipe_v_threshold: 50,
+ taphold_threshold: 750,
+ doubletap_int: 500,
+ shake_threshold: 15,
+
+ touch_capable: touchCapable,
+ orientation_support: ('orientation' in window && 'onorientationchange' in window),
+
+ startevent: (touchCapable) ? 'touchstart' : 'mousedown',
+ endevent: (touchCapable) ? 'touchend' : 'mouseup',
+ moveevent: (touchCapable) ? 'touchmove' : 'mousemove',
+ tapevent: (touchCapable) ? 'tap' : 'click',
+ scrollevent: (touchCapable) ? 'touchmove' : 'scroll',
+
+ hold_timer: null,
+ tap_timer: null
+ };
+
+ // Declare touch namespace:
+ $.touch = { };
+
+ // Convenience functions:
+ $.isTouchCapable = function() { return settings.touch_capable; };
+ $.getStartEvent = function() { return settings.startevent; };
+ $.getEndEvent = function() { return settings.endevent; };
+ $.getMoveEvent = function() { return settings.moveevent; };
+ $.getTapEvent = function() { return settings.tapevent; };
+ $.getScrollEvent = function() { return settings.scrollevent; };
+
+ // SETTERS:
+ // Set the X threshold of swipe events:
+ $.touch.setSwipeThresholdX = function( threshold ) {
+ if( typeof threshold !== 'number' ) { throw new Error('Threshold parameter must be a type of number'); }
+ settings.swipe_h_threshold = threshold;
+ };
+
+ // Set the Y threshold of swipe events:
+ $.touch.setSwipeThresholdY = function( threshold ) {
+ if( typeof threshold !== 'number' ) { throw new Error('Threshold parameter must be a type of number'); }
+ settings.swipe_v_threshold = threshold;
+ };
+
+ // Set the double tap interval:
+ $.touch.setDoubleTapInt = function( interval ) {
+ if( typeof interval !== 'number' ) { throw new Error('Interval parameter must be a type of number'); }
+ settings.doubletap_int = interval;
+ };
+
+ // Set the taphold threshold:
+ $.touch.setTapHoldThreshold = function( threshold ) {
+ if( typeof threshold !== 'number' ) { throw new Error('Threshold parameter must be a type of number'); }
+ settings.taphold_threshold = threshold;
+ };
+
+ // Set the pixel range for tapas:
+ $.touch.setTapRange = function( range ) {
+ if( typeof range !== 'number' ) { throw new Error('Ranger parameter must be a type of number'); }
+ settings.tap_pixel_range = threshold;
+ };
+
+ // Add Event shortcuts:
+ $.each(['tapstart', 'tapend', 'tapmove', 'tap', 'singletap', 'doubletap', 'taphold', 'swipe', 'swipeup', 'swiperight', 'swipedown', 'swipeleft', 'swipeend', 'scrollstart', 'scrollend', 'orientationchange', 'tap2', 'taphold2'], function (i, name) {
+ $.fn[name] = function (fn) {
+ return fn ? this.on(name, fn) : this.trigger(name);
+ };
+
+ $.attrFn[name] = true;
+ });
+
+ // tapstart Event:
+ $.event.special.tapstart = {
+ setup: function () {
+
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.startevent, function tapStartFunc(e) {
+
+ $this.data('callee', tapStartFunc);
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapstart', e, touchData);
+ return true;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee);
+ }
+ };
+
+ // tapmove Event:
+ $.event.special.tapmove = {
+ setup: function() {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.moveevent, function tapMoveFunc(e) {
+ $this.data('callee', tapMoveFunc);
+
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapmove', e, touchData);
+ return true;
+ });
+ },
+ remove: function() {
+ $(this).off(settings.moveevent, $(this).data.callee);
+ }
+ };
+
+ // tapend Event:
+ $.event.special.tapend = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.endevent, function tapEndFunc(e) {
+ // Touch event data:
+ $this.data('callee', tapEndFunc);
+
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ triggerCustomEvent(thisObject, 'tapend', e, touchData);
+ return true;
+ });
+ },
+ remove: function () {
+ $(this).off(settings.endevent, $(this).data.callee);
+ }
+ };
+
+ // taphold Event:
+ $.event.special.taphold = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ end_x = 0,
+ end_y = 0;
+
+ $this.on(settings.startevent, function tapHoldFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ $this.data('tapheld', false);
+ origTarget = e.target;
+
+ var origEvent = e.originalEvent;
+ var start_time = Date.now(),
+ startPosition = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
+ },
+ startOffset = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ };
+
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ end_x = start_pos.x;
+ end_y = start_pos.y;
+
+ // Get the element's threshold:
+ var ele_threshold = ($this.parent().data('threshold')) ? $this.parent().data('threshold') : $this.data('threshold'),
+ threshold = (typeof ele_threshold !== 'undefined' && ele_threshold !== false && parseInt(ele_threshold)) ? parseInt(ele_threshold) : settings.taphold_threshold;
+
+ settings.hold_timer = window.setTimeout(function () {
+
+ var diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y);
+
+ if (e.target == origTarget && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ $this.data('tapheld', true);
+
+ var end_time = Date.now();
+
+ var duration = end_time - start_time,
+ touches = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches : [ e ],
+ touchData = [ ];
+
+ for( var i = 0; i < touches.length; i++)
+ {
+ var touch = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[i].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[i].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target,
+ 'duration': duration
+ };
+
+ touchData.push( touch );
+ }
+
+ var evt_name = ( touches.length == 2 ) ? 'taphold2' : 'taphold';
+
+ $this.data('callee1', tapHoldFunc1);
+
+ triggerCustomEvent(thisObject, evt_name, e, touchData);
+ }
+ }, threshold);
+
+ return true;
+ }
+ }).on(settings.endevent, function tapHoldFunc2() {
+ $this.data('callee2', tapHoldFunc2);
+ $this.data('tapheld', false);
+ window.clearTimeout(settings.hold_timer);
+ })
+ .on(settings.moveevent, function tapHoldFunc3(e) {
+ $this.data('callee3', tapHoldFunc3);
+
+ end_x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2).off(settings.moveevent, $(this).data.callee3);
+ }
+ };
+
+ // doubletap Event:
+ $.event.special.doubletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ action,
+ firstTap = null,
+ origEvent,
+ cooloff,
+ cooling = false;
+
+ $this.on(settings.startevent, function doubleTapFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+
+ $this.data('doubletapped', false);
+ origTarget = e.target;
+ $this.data('callee1', doubleTapFunc1);
+
+ origEvent = e.originalEvent;
+ if (!firstTap) {
+ firstTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target,
+ 'element': e.originalEvent.srcElement,
+ 'index': $(e.target).index()
+ };
+ }
+
+ return true;
+ }).on(settings.endevent, function doubleTapFunc2(e) {
+
+ var now = Date.now();
+ var lastTouch = $this.data('lastTouch') || now + 1;
+ var delta = now - lastTouch;
+ window.clearTimeout(action);
+ $this.data('callee2', doubleTapFunc2);
+
+ if (delta < settings.doubletap_int && ($(e.target).index() == firstTap.index) && delta > 100) {
+ $this.data('doubletapped', true);
+ window.clearTimeout(settings.tap_timer);
+
+ // Now get the current event:
+ var lastTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? e.originalEvent.changedTouches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target,
+ 'element': e.originalEvent.srcElement,
+ 'index': $(e.target).index()
+ };
+
+ var touchData = {
+ 'firstTap': firstTap,
+ 'secondTap': lastTap,
+ 'interval': lastTap.time - firstTap.time
+ };
+
+ if (!cooling) {
+ triggerCustomEvent(thisObject, 'doubletap', e, touchData);
+ firstTap = null;
+ }
+
+ cooling = true;
+
+ cooloff = window.setTimeout(function () {
+ cooling = false;
+ }, settings.doubletap_int);
+
+ } else {
+ $this.data('lastTouch', now);
+ action = window.setTimeout(function () {
+ firstTap = null;
+ window.clearTimeout(action);
+ }, settings.doubletap_int, [e]);
+ }
+ $this.data('lastTouch', now);
+ });
+ },
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // singletap Event:
+ // This is used in conjuction with doubletap when both events are needed on the same element
+ $.event.special.singletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget = null,
+ startTime = null,
+ start_pos = {
+ x: 0,
+ y: 0
+ };
+
+ $this.on(settings.startevent, function singleTapFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ startTime = Date.now();
+ origTarget = e.target;
+ $this.data('callee1', singleTapFunc1);
+
+ // Get the start x and y position:
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ return true;
+ }
+ }).on(settings.endevent, function singleTapFunc2(e) {
+ $this.data('callee2', singleTapFunc2);
+ if (e.target == origTarget) {
+
+ // Get the end point:
+ var end_pos_x = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ end_pos_y = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY;
+
+ // We need to check if it was a taphold:
+
+ settings.tap_timer = window.setTimeout(function () {
+
+ var diff_x = (start_pos.x - end_pos_x), diff_y = (start_pos.y - end_pos_y);
+
+ if(!$this.data('doubletapped') && !$this.data('tapheld') && (((start_pos.x == end_pos_x) && (start_pos.y == end_pos_y)) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Was it a taphold?
+ if((touchData.time - startTime) < settings.taphold_threshold)
+ {
+ triggerCustomEvent(thisObject, 'singletap', e, touchData);
+ }
+ }
+ }, settings.doubletap_int);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // tap Event:
+ $.event.special.tap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ origTarget = null,
+ start_time,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ touches;
+
+ $this.on(settings.startevent, function tapFunc1(e) {
+ $this.data('callee1', tapFunc1);
+
+ if( e.which && e.which !== 1 )
+ {
+ return false;
+ }
+ else
+ {
+ started = true;
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ start_time = Date.now();
+ origTarget = e.target;
+
+ touches = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches : [ e ];
+ return true;
+ }
+ }).on(settings.endevent, function tapFunc2(e) {
+ $this.data('callee2', tapFunc2);
+
+ // Only trigger if they've started, and the target matches:
+ var end_x = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY,
+ diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y),
+ eventName;
+
+ if (origTarget == e.target && started && ((Date.now() - start_time) < settings.taphold_threshold) && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ var origEvent = e.originalEvent;
+ var touchData = [ ];
+
+ for( var i = 0; i < touches.length; i++)
+ {
+ var touch = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[i].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[i].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ touchData.push( touch );
+ }
+
+ var evt_name = ( touches.length == 2 ) ? 'tap2' : 'tap';
+
+ triggerCustomEvent(thisObject, evt_name, e, touchData);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // swipe Event (also handles swipeup, swiperight, swipedown and swipeleft):
+ $.event.special.swipe = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ hasSwiped = false,
+ originalCoord = {
+ x: 0,
+ y: 0
+ },
+ finalCoord = {
+ x: 0,
+ y: 0
+ },
+ startEvnt;
+
+ // Screen touched, store the original coordinate
+
+ function touchStart(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee1', touchStart);
+ originalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ originalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ finalCoord.x = originalCoord.x;
+ finalCoord.y = originalCoord.y;
+ started = true;
+ var origEvent = e.originalEvent;
+ // Read event data into our startEvt:
+ startEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ }
+
+ // Store coordinates as finger is swiping
+
+ function touchMove(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee2', touchMove);
+ finalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ finalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ var swipedir;
+
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = ($this.parent().data('xthreshold')) ? $this.parent().data('xthreshold') : $this.data('xthreshold'),
+ ele_y_threshold = ($this.parent().data('ythreshold')) ? $this.parent().data('ythreshold') : $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ if (originalCoord.y > finalCoord.y && (originalCoord.y - finalCoord.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (originalCoord.x < finalCoord.x && (finalCoord.x - originalCoord.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (originalCoord.y < finalCoord.y && (finalCoord.y - originalCoord.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (originalCoord.x > finalCoord.x && (originalCoord.x - finalCoord.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+ if (swipedir != undefined && started) {
+ originalCoord.x = 0;
+ originalCoord.y = 0;
+ finalCoord.x = 0;
+ finalCoord.y = 0;
+ started = false;
+
+ // Read event data into our endEvnt:
+ var origEvent = e.originalEvent;
+ var endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ };
+ hasSwiped = true;
+ $this.trigger('swipe', touchData).trigger(swipedir, touchData);
+ }
+ }
+
+ function touchEnd(e) {
+ $this = $(e.currentTarget);
+ var swipedir = "";
+ $this.data('callee3', touchEnd);
+ if (hasSwiped) {
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = $this.data('xthreshold'),
+ ele_y_threshold = $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ var origEvent = e.originalEvent;
+ var endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Read event data into our endEvnt:
+ if (startEvnt.position.y > endEvnt.position.y && (startEvnt.position.y - endEvnt.position.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (startEvnt.position.x < endEvnt.position.x && (endEvnt.position.x - startEvnt.position.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (startEvnt.position.y < endEvnt.position.y && (endEvnt.position.y - startEvnt.position.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (startEvnt.position.x > endEvnt.position.x && (startEvnt.position.x - endEvnt.position.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ };
+ $this.trigger('swipeend', touchData);
+ }
+
+ started = false;
+ hasSwiped = false;
+ }
+
+ $this.on(settings.startevent, touchStart);
+ $this.on(settings.moveevent, touchMove);
+ $this.on(settings.endevent, touchEnd);
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.moveevent, $(this).data.callee2).off(settings.endevent, $(this).data.callee3);
+ }
+ };
+
+ // scrollstart Event (also handles scrollend):
+ $.event.special.scrollstart = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ scrolling,
+ timer;
+
+ function trigger(event, state) {
+ scrolling = state;
+ triggerCustomEvent(thisObject, scrolling ? 'scrollstart' : 'scrollend', event);
+ }
+
+ // iPhone triggers scroll after a small delay; use touchmove instead
+ $this.on(settings.scrollevent, function scrollFunc(event) {
+ $this.data('callee', scrollFunc);
+
+ if (!scrolling) {
+ trigger(event, true);
+ }
+
+ clearTimeout(timer);
+ timer = setTimeout(function () {
+ trigger(event, false);
+ }, 50);
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.scrollevent, $(this).data.callee);
+ }
+ };
+
+ // This is the orientation change (largely borrowed from jQuery Mobile):
+ var win = $(window),
+ special_event,
+ get_orientation,
+ last_orientation,
+ initial_orientation_is_landscape,
+ initial_orientation_is_default,
+ portrait_map = {
+ '0': true,
+ '180': true
+ };
+
+ if (settings.orientation_support) {
+ var ww = window.innerWidth || win.width(),
+ wh = window.innerHeight || win.height(),
+ landscape_threshold = 50;
+
+ initial_orientation_is_landscape = ww > wh && (ww - wh) > landscape_threshold;
+ initial_orientation_is_default = portrait_map[window.orientation];
+
+ if ((initial_orientation_is_landscape && initial_orientation_is_default) || (!initial_orientation_is_landscape && !initial_orientation_is_default)) {
+ portrait_map = {
+ '-90': true,
+ '90': true
+ };
+ }
+ }
+
+ $.event.special.orientationchange = special_event = {
+ setup: function () {
+ // If the event is supported natively, return false so that jQuery
+ // will on to the event using DOM methods.
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ // Get the current orientation to avoid initial double-triggering.
+ last_orientation = get_orientation();
+
+ win.on('throttledresize', handler);
+ return true;
+ },
+ teardown: function () {
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ win.off('throttledresize', handler);
+ return true;
+ },
+ add: function (handleObj) {
+ // Save a reference to the bound event handler.
+ var old_handler = handleObj.handler;
+
+ handleObj.handler = function (event) {
+ event.orientation = get_orientation();
+ return old_handler.apply(this, arguments);
+ };
+ }
+ };
+
+ // If the event is not supported natively, this handler will be bound to
+ // the window resize event to simulate the orientationchange event.
+
+ function handler() {
+ // Get the current orientation.
+ var orientation = get_orientation();
+
+ if (orientation !== last_orientation) {
+ // The orientation has changed, so trigger the orientationchange event.
+ last_orientation = orientation;
+ win.trigger("orientationchange");
+ }
+ }
+
+ $.event.special.orientationchange.orientation = get_orientation = function () {
+ var isPortrait = true,
+ elem = document.documentElement;
+
+ if (settings.orientation_support) {
+ isPortrait = portrait_map[window.orientation];
+ } else {
+ isPortrait = elem && elem.clientWidth / elem.clientHeight < 1.1;
+ }
+
+ return isPortrait ? 'portrait' : 'landscape';
+ };
+
+ // throttle Handler:
+ $.event.special.throttledresize = {
+ setup: function () {
+ $(this).on('resize', throttle_handler);
+ },
+ teardown: function () {
+ $(this).off('resize', throttle_handler);
+ }
+ };
+
+ var throttle = 250,
+ throttle_handler = function () {
+ curr = Date.now();
+ diff = curr - lastCall;
+
+ if (diff >= throttle) {
+ lastCall = curr;
+ $(this).trigger('throttledresize');
+
+ } else {
+ if (heldCall) {
+ window.clearTimeout(heldCall);
+ }
+
+ // Promise a held call will still execute
+ heldCall = window.setTimeout(handler, throttle - diff);
+ }
+ },
+ lastCall = 0,
+ heldCall,
+ curr,
+ diff;
+
+ // Trigger a custom event:
+
+ function triggerCustomEvent(obj, eventType, event, touchData) {
+ var originalType = event.type;
+ event.type = eventType;
+
+ $.event.dispatch.call(obj, event, touchData);
+ event.type = originalType;
+ }
+
+ // Correctly on anything we've overloaded:
+ $.each({
+ scrollend: 'scrollstart',
+ swipeup: 'swipe',
+ swiperight: 'swipe',
+ swipedown: 'swipe',
+ swipeleft: 'swipe',
+ swipeend: 'swipe',
+ tap2: 'tap',
+ taphold2: 'taphold'
+ }, function (e, srcE) {
+ $.event.special[e] = {
+ setup: function () {
+ $(this).on(srcE, $.noop);
+ }
+ };
+ });
+
+}(jQuery));
diff --git a/src/2.0.0/jquery.mobile-events.min.js b/src/2.0.0/jquery.mobile-events.min.js
new file mode 100644
index 0000000..36a20fb
--- /dev/null
+++ b/src/2.0.0/jquery.mobile-events.min.js
@@ -0,0 +1,28 @@
+/*!
+ * jQuery Mobile Events
+ * by Ben Major
+ *
+ * Copyright 2011-2017, Ben Major
+ * Licensed under the MIT License:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+"use strict";!function(e){e.attrFn=e.attrFn||{};var t="ontouchstart"in window,a={tap_pixel_range:5,swipe_h_threshold:50,swipe_v_threshold:50,taphold_threshold:750,doubletap_int:500,shake_threshold:15,touch_capable:t,orientation_support:"orientation"in window&&"onorientationchange"in window,startevent:t?"touchstart":"mousedown",endevent:t?"touchend":"mouseup",moveevent:t?"touchmove":"mousemove",tapevent:t?"tap":"click",scrollevent:t?"touchmove":"scroll",hold_timer:null,tap_timer:null};e.touch={},e.isTouchCapable=function(){return a.touch_capable},e.getStartEvent=function(){return a.startevent},e.getEndEvent=function(){return a.endevent},e.getMoveEvent=function(){return a.moveevent},e.getTapEvent=function(){return a.tapevent},e.getScrollEvent=function(){return a.scrollevent},e.touch.setSwipeThresholdX=function(e){if("number"!=typeof e)throw new Error("Threshold parameter must be a type of number");a.swipe_h_threshold=e},e.touch.setSwipeThresholdY=function(e){if("number"!=typeof e)throw new Error("Threshold parameter must be a type of number");a.swipe_v_threshold=e},e.touch.setDoubleTapInt=function(e){if("number"!=typeof e)throw new Error("Interval parameter must be a type of number");a.doubletap_int=e},e.touch.setTapHoldThreshold=function(e){if("number"!=typeof e)throw new Error("Threshold parameter must be a type of number");a.taphold_threshold=e},e.touch.setTapRange=function(e){if("number"!=typeof e)throw new Error("Ranger parameter must be a type of number");a.tap_pixel_range=threshold},e.each(["tapstart","tapend","tapmove","tap","singletap","doubletap","taphold","swipe","swipeup","swiperight","swipedown","swipeleft","swipeend","scrollstart","scrollend","orientationchange","tap2","taphold2"],function(t,a){e.fn[a]=function(e){return e?this.on(a,e):this.trigger(a)},e.attrFn[a]=!0}),e.event.special.tapstart={setup:function(){var t=this,o=e(t);o.on(a.startevent,function e(n){if(o.data("callee",e),n.which&&1!==n.which)return!1;var i=n.originalEvent,r={position:{x:a.touch_capable?i.touches[0].pageX:n.pageX,y:a.touch_capable?i.touches[0].pageY:n.pageY},offset:{x:a.touch_capable?Math.round(i.changedTouches[0].pageX-(o.offset()?o.offset().left:0)):Math.round(n.pageX-(o.offset()?o.offset().left:0)),y:a.touch_capable?Math.round(i.changedTouches[0].pageY-(o.offset()?o.offset().top:0)):Math.round(n.pageY-(o.offset()?o.offset().top:0))},time:Date.now(),target:n.target};return w(t,"tapstart",n,r),!0})},remove:function(){e(this).off(a.startevent,e(this).data.callee)}},e.event.special.tapmove={setup:function(){var t=this,o=e(t);o.on(a.moveevent,function e(n){o.data("callee",e);var i=n.originalEvent,r={position:{x:a.touch_capable?i.touches[0].pageX:n.pageX,y:a.touch_capable?i.touches[0].pageY:n.pageY},offset:{x:a.touch_capable?Math.round(i.changedTouches[0].pageX-(o.offset()?o.offset().left:0)):Math.round(n.pageX-(o.offset()?o.offset().left:0)),y:a.touch_capable?Math.round(i.changedTouches[0].pageY-(o.offset()?o.offset().top:0)):Math.round(n.pageY-(o.offset()?o.offset().top:0))},time:Date.now(),target:n.target};return w(t,"tapmove",n,r),!0})},remove:function(){e(this).off(a.moveevent,e(this).data.callee)}},e.event.special.tapend={setup:function(){var t=this,o=e(t);o.on(a.endevent,function e(n){o.data("callee",e);var i=n.originalEvent,r={position:{x:a.touch_capable?i.changedTouches[0].pageX:n.pageX,y:a.touch_capable?i.changedTouches[0].pageY:n.pageY},offset:{x:a.touch_capable?Math.round(i.changedTouches[0].pageX-(o.offset()?o.offset().left:0)):Math.round(n.pageX-(o.offset()?o.offset().left:0)),y:a.touch_capable?Math.round(i.changedTouches[0].pageY-(o.offset()?o.offset().top:0)):Math.round(n.pageY-(o.offset()?o.offset().top:0))},time:Date.now(),target:n.target};return w(t,"tapend",n,r),!0})},remove:function(){e(this).off(a.endevent,e(this).data.callee)}},e.event.special.taphold={setup:function(){var t,o=this,n=e(o),i={x:0,y:0},r=0,s=0;n.on(a.startevent,function e(p){if(p.which&&1!==p.which)return!1;n.data("tapheld",!1),t=p.target;var h=p.originalEvent,c=Date.now();a.touch_capable?h.touches[0].pageX:p.pageX,a.touch_capable?h.touches[0].pageY:p.pageY,a.touch_capable?(h.touches[0].pageX,h.touches[0].target.offsetLeft):p.offsetX,a.touch_capable?(h.touches[0].pageY,h.touches[0].target.offsetTop):p.offsetY;i.x=p.originalEvent.targetTouches?p.originalEvent.targetTouches[0].pageX:p.pageX,i.y=p.originalEvent.targetTouches?p.originalEvent.targetTouches[0].pageY:p.pageY,r=i.x,s=i.y;var u=n.parent().data("threshold")?n.parent().data("threshold"):n.data("threshold"),f=void 0!==u&&!1!==u&&parseInt(u)?parseInt(u):a.taphold_threshold;return a.hold_timer=window.setTimeout(function(){var u=i.x-r,f=i.y-s;if(p.target==t&&(i.x==r&&i.y==s||u>=-a.tap_pixel_range&&u<=a.tap_pixel_range&&f>=-a.tap_pixel_range&&f<=a.tap_pixel_range)){n.data("tapheld",!0);for(var l=Date.now()-c,g=p.originalEvent.targetTouches?p.originalEvent.targetTouches:[p],d=[],v=0;v100){i.data("doubletapped",!0),window.clearTimeout(a.tap_timer);var f={position:{x:a.touch_capable?h.originalEvent.changedTouches[0].pageX:h.pageX,y:a.touch_capable?h.originalEvent.changedTouches[0].pageY:h.pageY},offset:{x:a.touch_capable?Math.round(o.changedTouches[0].pageX-(i.offset()?i.offset().left:0)):Math.round(h.pageX-(i.offset()?i.offset().left:0)),y:a.touch_capable?Math.round(o.changedTouches[0].pageY-(i.offset()?i.offset().top:0)):Math.round(h.pageY-(i.offset()?i.offset().top:0))},time:Date.now(),target:h.target,element:h.originalEvent.srcElement,index:e(h.target).index()},l={firstTap:r,secondTap:f,interval:f.time-r.time};s||(w(n,"doubletap",h,l),r=null),s=!0,window.setTimeout(function(){s=!1},a.doubletap_int)}else i.data("lastTouch",c),t=window.setTimeout(function(){r=null,window.clearTimeout(t)},a.doubletap_int,[h]);i.data("lastTouch",c)})},remove:function(){e(this).off(a.startevent,e(this).data.callee1).off(a.endevent,e(this).data.callee2)}},e.event.special.singletap={setup:function(){var t=this,o=e(t),n=null,i=null,r={x:0,y:0};o.on(a.startevent,function e(t){return(!t.which||1===t.which)&&(i=Date.now(),n=t.target,o.data("callee1",e),r.x=t.originalEvent.targetTouches?t.originalEvent.targetTouches[0].pageX:t.pageX,r.y=t.originalEvent.targetTouches?t.originalEvent.targetTouches[0].pageY:t.pageY,!0)}).on(a.endevent,function e(s){if(o.data("callee2",e),s.target==n){var p=s.originalEvent.changedTouches?s.originalEvent.changedTouches[0].pageX:s.pageX,h=s.originalEvent.changedTouches?s.originalEvent.changedTouches[0].pageY:s.pageY;a.tap_timer=window.setTimeout(function(){var e=r.x-p,n=r.y-h;if(!o.data("doubletapped")&&!o.data("tapheld")&&(r.x==p&&r.y==h||e>=-a.tap_pixel_range&&e<=a.tap_pixel_range&&n>=-a.tap_pixel_range&&n<=a.tap_pixel_range)){var c=s.originalEvent,u={position:{x:a.touch_capable?c.changedTouches[0].pageX:s.pageX,y:a.touch_capable?c.changedTouches[0].pageY:s.pageY},offset:{x:a.touch_capable?Math.round(c.changedTouches[0].pageX-(o.offset()?o.offset().left:0)):Math.round(s.pageX-(o.offset()?o.offset().left:0)),y:a.touch_capable?Math.round(c.changedTouches[0].pageY-(o.offset()?o.offset().top:0)):Math.round(s.pageY-(o.offset()?o.offset().top:0))},time:Date.now(),target:s.target};u.time-i=-a.tap_pixel_range&&f<=a.tap_pixel_range&&l>=-a.tap_pixel_range&&l<=a.tap_pixel_range)){for(var g=h.originalEvent,d=[],v=0;vs.y&&r.y-s.y>g&&(c="swipeup"),r.xl&&(c="swiperight"),r.yg&&(c="swipedown"),r.x>s.x&&r.x-s.x>l&&(c="swipeleft"),void 0!=c&&n){r.x=0,r.y=0,s.x=0,s.y=0,n=!1;var d=h.originalEvent,v={position:{x:a.touch_capable?d.touches[0].pageX:h.pageX,y:a.touch_capable?d.touches[0].pageY:h.pageY},offset:{x:a.touch_capable?Math.round(d.changedTouches[0].pageX-(o.offset()?o.offset().left:0)):Math.round(h.pageX-(o.offset()?o.offset().left:0)),y:a.touch_capable?Math.round(d.changedTouches[0].pageY-(o.offset()?o.offset().top:0)):Math.round(h.pageY-(o.offset()?o.offset().top:0))},time:Date.now(),target:h.target},w=Math.abs(t.position.x-v.position.x),_=Math.abs(t.position.y-v.position.y),T={startEvnt:t,endEvnt:v,direction:c.replace("swipe",""),xAmount:w,yAmount:_,duration:v.time-t.time};i=!0,o.trigger("swipe",T).trigger(c,T)}}),o.on(a.endevent,function r(s){var p="";if((o=e(s.currentTarget)).data("callee3",r),i){var h=o.data("xthreshold"),c=o.data("ythreshold"),u=void 0!==h&&!1!==h&&parseInt(h)?parseInt(h):a.swipe_h_threshold,f=void 0!==c&&!1!==c&&parseInt(c)?parseInt(c):a.swipe_v_threshold,l=s.originalEvent,g={position:{x:a.touch_capable?l.changedTouches[0].pageX:s.pageX,y:a.touch_capable?l.changedTouches[0].pageY:s.pageY},offset:{x:a.touch_capable?Math.round(l.changedTouches[0].pageX-(o.offset()?o.offset().left:0)):Math.round(s.pageX-(o.offset()?o.offset().left:0)),y:a.touch_capable?Math.round(l.changedTouches[0].pageY-(o.offset()?o.offset().top:0)):Math.round(s.pageY-(o.offset()?o.offset().top:0))},time:Date.now(),target:s.target};t.position.y>g.position.y&&t.position.y-g.position.y>f&&(p="swipeup"),t.position.xu&&(p="swiperight"),t.position.yf&&(p="swipedown"),t.position.x>g.position.x&&t.position.x-g.position.x>u&&(p="swipeleft");var d=Math.abs(t.position.x-g.position.x),v=Math.abs(t.position.y-g.position.y),w={startEvnt:t,endEvnt:g,direction:p.replace("swipe",""),xAmount:d,yAmount:v,duration:g.time-t.time};o.trigger("swipeend",w)}n=!1,i=!1})},remove:function(){e(this).off(a.startevent,e(this).data.callee1).off(a.moveevent,e(this).data.callee2).off(a.endevent,e(this).data.callee3)}},e.event.special.scrollstart={setup:function(){var t,o,n=this,i=e(n);function r(e,a){w(n,(t=a)?"scrollstart":"scrollend",e)}i.on(a.scrollevent,function e(a){i.data("callee",e),t||r(a,!0),clearTimeout(o),o=setTimeout(function(){r(a,!1)},50)})},remove:function(){e(this).off(a.scrollevent,e(this).data.callee)}};var o,n,i,r,s=e(window),p={0:!0,180:!0};if(a.orientation_support){var h=window.innerWidth||s.width(),c=window.innerHeight||s.height();i=h>c&&h-c>50,r=p[window.orientation],(i&&r||!i&&!r)&&(p={"-90":!0,90:!0})}function u(){var e=o();e!==n&&(n=e,s.trigger("orientationchange"))}e.event.special.orientationchange={setup:function(){return!a.orientation_support&&(n=o(),s.on("throttledresize",u),!0)},teardown:function(){return!a.orientation_support&&(s.off("throttledresize",u),!0)},add:function(e){var t=e.handler;e.handler=function(e){return e.orientation=o(),t.apply(this,arguments)}}},e.event.special.orientationchange.orientation=o=function(){var e=document.documentElement;return(a.orientation_support?p[window.orientation]:e&&e.clientWidth/e.clientHeight<1.1)?"portrait":"landscape"},e.event.special.throttledresize={setup:function(){e(this).on("resize",d)},teardown:function(){e(this).off("resize",d)}};var f,l,g,d=function(){l=Date.now(),(g=l-v)>=250?(v=l,e(this).trigger("throttledresize")):(f&&window.clearTimeout(f),f=window.setTimeout(u,250-g))},v=0;function w(t,a,o,n){var i=o.type;o.type=a,e.event.dispatch.call(t,o,n),o.type=i}e.each({scrollend:"scrollstart",swipeup:"swipe",swiperight:"swipe",swipedown:"swipe",swipeleft:"swipe",swipeend:"swipe",tap2:"tap",taphold2:"taphold"},function(t,a){e.event.special[t]={setup:function(){e(this).on(a,e.noop)}}})}(jQuery);
diff --git a/src/2.0.1/jquery.mobile-events.js b/src/2.0.1/jquery.mobile-events.js
new file mode 100644
index 0000000..ef7630c
--- /dev/null
+++ b/src/2.0.1/jquery.mobile-events.js
@@ -0,0 +1,920 @@
+/*!
+ * jQuery Mobile Events
+ * by Ben Major
+ *
+ * Copyright 2011-2019, Ben Major
+ * Licensed under the MIT License:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+"use strict";
+
+(function ($) {
+ $.attrFn = $.attrFn || {};
+
+ var touchCapable = ('ontouchstart' in window),
+
+ settings = {
+ tap_pixel_range: 5,
+ swipe_h_threshold: 50,
+ swipe_v_threshold: 50,
+ taphold_threshold: 750,
+ doubletap_int: 500,
+ shake_threshold: 15,
+
+ touch_capable: touchCapable,
+ orientation_support: ('orientation' in window && 'onorientationchange' in window),
+
+ startevent: (touchCapable) ? 'touchstart' : 'mousedown',
+ endevent: (touchCapable) ? 'touchend' : 'mouseup',
+ moveevent: (touchCapable) ? 'touchmove' : 'mousemove',
+ tapevent: (touchCapable) ? 'tap' : 'click',
+ scrollevent: (touchCapable) ? 'touchmove' : 'scroll',
+
+ hold_timer: null,
+ tap_timer: null
+ };
+
+ // Declare touch namespace:
+ $.touch = { };
+
+ // Convenience functions:
+ $.isTouchCapable = function() { return settings.touch_capable; };
+ $.getStartEvent = function() { return settings.startevent; };
+ $.getEndEvent = function() { return settings.endevent; };
+ $.getMoveEvent = function() { return settings.moveevent; };
+ $.getTapEvent = function() { return settings.tapevent; };
+ $.getScrollEvent = function() { return settings.scrollevent; };
+
+ // SETTERS:
+ // Set the X threshold of swipe events:
+ $.touch.setSwipeThresholdX = function( threshold ) {
+ if( typeof threshold !== 'number' ) { throw new Error('Threshold parameter must be a type of number'); }
+ settings.swipe_h_threshold = threshold;
+ };
+
+ // Set the Y threshold of swipe events:
+ $.touch.setSwipeThresholdY = function( threshold ) {
+ if( typeof threshold !== 'number' ) { throw new Error('Threshold parameter must be a type of number'); }
+ settings.swipe_v_threshold = threshold;
+ };
+
+ // Set the double tap interval:
+ $.touch.setDoubleTapInt = function( interval ) {
+ if( typeof interval !== 'number' ) { throw new Error('Interval parameter must be a type of number'); }
+ settings.doubletap_int = interval;
+ };
+
+ // Set the taphold threshold:
+ $.touch.setTapHoldThreshold = function( threshold ) {
+ if( typeof threshold !== 'number' ) { throw new Error('Threshold parameter must be a type of number'); }
+ settings.taphold_threshold = threshold;
+ };
+
+ // Set the pixel range for tapas:
+ $.touch.setTapRange = function( range ) {
+ if( typeof range !== 'number' ) { throw new Error('Ranger parameter must be a type of number'); }
+ settings.tap_pixel_range = threshold;
+ };
+
+ // Add Event shortcuts:
+ $.each(['tapstart', 'tapend', 'tapmove', 'tap', 'singletap', 'doubletap', 'taphold', 'swipe', 'swipeup', 'swiperight', 'swipedown', 'swipeleft', 'swipeend', 'scrollstart', 'scrollend', 'orientationchange', 'tap2', 'taphold2'], function (i, name) {
+ $.fn[name] = function (fn) {
+ return fn ? this.on(name, fn) : this.trigger(name);
+ };
+
+ $.attrFn[name] = true;
+ });
+
+ // tapstart Event:
+ $.event.special.tapstart = {
+ setup: function () {
+
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.startevent, function tapStartFunc(e) {
+
+ $this.data('callee', tapStartFunc);
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapstart', e, touchData);
+ return true;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee);
+ }
+ };
+
+ // tapmove Event:
+ $.event.special.tapmove = {
+ setup: function() {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.moveevent, function tapMoveFunc(e) {
+ $this.data('callee', tapMoveFunc);
+
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapmove', e, touchData);
+ return true;
+ });
+ },
+ remove: function() {
+ $(this).off(settings.moveevent, $(this).data.callee);
+ }
+ };
+
+ // tapend Event:
+ $.event.special.tapend = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.endevent, function tapEndFunc(e) {
+ // Touch event data:
+ $this.data('callee', tapEndFunc);
+
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ triggerCustomEvent(thisObject, 'tapend', e, touchData);
+ return true;
+ });
+ },
+ remove: function () {
+ $(this).off(settings.endevent, $(this).data.callee);
+ }
+ };
+
+ // taphold Event:
+ $.event.special.taphold = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ end_x = 0,
+ end_y = 0;
+
+ $this.on(settings.startevent, function tapHoldFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ $this.data('tapheld', false);
+ origTarget = e.target;
+
+ var origEvent = e.originalEvent;
+ var start_time = Date.now(),
+ startPosition = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
+ },
+ startOffset = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ };
+
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ end_x = start_pos.x;
+ end_y = start_pos.y;
+
+ // Get the element's threshold:
+ var ele_threshold = ($this.parent().data('threshold')) ? $this.parent().data('threshold') : $this.data('threshold'),
+ threshold = (typeof ele_threshold !== 'undefined' && ele_threshold !== false && parseInt(ele_threshold)) ? parseInt(ele_threshold) : settings.taphold_threshold;
+
+ $this.data('hold_timer', window.setTimeout(function () {
+
+ var diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y);
+
+ if (e.target == origTarget && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ $this.data('tapheld', true);
+
+ var end_time = Date.now();
+
+ var duration = end_time - start_time,
+ touches = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches : [ e ],
+ touchData = [ ];
+
+ for( var i = 0; i < touches.length; i++)
+ {
+ var touch = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[i].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[i].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target,
+ 'duration': duration
+ };
+
+ touchData.push( touch );
+ }
+
+ var evt_name = ( touches.length == 2 ) ? 'taphold2' : 'taphold';
+
+ $this.data('callee1', tapHoldFunc1);
+
+ triggerCustomEvent(thisObject, evt_name, e, touchData);
+ }
+ }, threshold) );
+
+ return true;
+ }
+ }).on(settings.endevent, function tapHoldFunc2() {
+ $this.data('callee2', tapHoldFunc2);
+ $this.data('tapheld', false);
+ window.clearTimeout( $this.data('hold_timer') );
+ })
+ .on(settings.moveevent, function tapHoldFunc3(e) {
+ $this.data('callee3', tapHoldFunc3);
+
+ end_x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2).off(settings.moveevent, $(this).data.callee3);
+ }
+ };
+
+ // doubletap Event:
+ $.event.special.doubletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ action,
+ firstTap = null,
+ origEvent,
+ cooloff,
+ cooling = false;
+
+ $this.on(settings.startevent, function doubleTapFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+
+ $this.data('doubletapped', false);
+ origTarget = e.target;
+ $this.data('callee1', doubleTapFunc1);
+
+ origEvent = e.originalEvent;
+ if (!firstTap) {
+ firstTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target,
+ 'element': e.originalEvent.srcElement,
+ 'index': $(e.target).index()
+ };
+ }
+
+ return true;
+ }).on(settings.endevent, function doubleTapFunc2(e) {
+
+ var now = Date.now();
+ var lastTouch = $this.data('lastTouch') || now + 1;
+ var delta = now - lastTouch;
+ window.clearTimeout(action);
+ $this.data('callee2', doubleTapFunc2);
+
+ if (delta < settings.doubletap_int && ($(e.target).index() == firstTap.index) && delta > 100) {
+ $this.data('doubletapped', true);
+ window.clearTimeout(settings.tap_timer);
+
+ // Now get the current event:
+ var lastTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? e.originalEvent.changedTouches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target,
+ 'element': e.originalEvent.srcElement,
+ 'index': $(e.target).index()
+ };
+
+ var touchData = {
+ 'firstTap': firstTap,
+ 'secondTap': lastTap,
+ 'interval': lastTap.time - firstTap.time
+ };
+
+ if (!cooling) {
+ triggerCustomEvent(thisObject, 'doubletap', e, touchData);
+ firstTap = null;
+ }
+
+ cooling = true;
+
+ cooloff = window.setTimeout(function () {
+ cooling = false;
+ }, settings.doubletap_int);
+
+ } else {
+ $this.data('lastTouch', now);
+ action = window.setTimeout(function () {
+ firstTap = null;
+ window.clearTimeout(action);
+ }, settings.doubletap_int, [e]);
+ }
+ $this.data('lastTouch', now);
+ });
+ },
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // singletap Event:
+ // This is used in conjuction with doubletap when both events are needed on the same element
+ $.event.special.singletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget = null,
+ startTime = null,
+ start_pos = {
+ x: 0,
+ y: 0
+ };
+
+ $this.on(settings.startevent, function singleTapFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ startTime = Date.now();
+ origTarget = e.target;
+ $this.data('callee1', singleTapFunc1);
+
+ // Get the start x and y position:
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ return true;
+ }
+ }).on(settings.endevent, function singleTapFunc2(e) {
+ $this.data('callee2', singleTapFunc2);
+ if (e.target == origTarget) {
+
+ // Get the end point:
+ var end_pos_x = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ end_pos_y = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY;
+
+ // We need to check if it was a taphold:
+
+ settings.tap_timer = window.setTimeout(function () {
+
+ var diff_x = (start_pos.x - end_pos_x), diff_y = (start_pos.y - end_pos_y);
+
+ if(!$this.data('doubletapped') && !$this.data('tapheld') && (((start_pos.x == end_pos_x) && (start_pos.y == end_pos_y)) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Was it a taphold?
+ if((touchData.time - startTime) < settings.taphold_threshold)
+ {
+ triggerCustomEvent(thisObject, 'singletap', e, touchData);
+ }
+ }
+ }, settings.doubletap_int);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // tap Event:
+ $.event.special.tap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ origTarget = null,
+ start_time,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ touches;
+
+ $this.on(settings.startevent, function tapFunc1(e) {
+ $this.data('callee1', tapFunc1);
+
+ if( e.which && e.which !== 1 )
+ {
+ return false;
+ }
+ else
+ {
+ started = true;
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ start_time = Date.now();
+ origTarget = e.target;
+
+ touches = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches : [ e ];
+ return true;
+ }
+ }).on(settings.endevent, function tapFunc2(e) {
+ $this.data('callee2', tapFunc2);
+
+ // Only trigger if they've started, and the target matches:
+ var end_x = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY,
+ diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y),
+ eventName;
+
+ if (origTarget == e.target && started && ((Date.now() - start_time) < settings.taphold_threshold) && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ var origEvent = e.originalEvent;
+ var touchData = [ ];
+
+ for( var i = 0; i < touches.length; i++)
+ {
+ var touch = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[i].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[i].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ touchData.push( touch );
+ }
+
+ var evt_name = ( touches.length == 2 ) ? 'tap2' : 'tap';
+
+ triggerCustomEvent(thisObject, evt_name, e, touchData);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // swipe Event (also handles swipeup, swiperight, swipedown and swipeleft):
+ $.event.special.swipe = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ hasSwiped = false,
+ originalCoord = {
+ x: 0,
+ y: 0
+ },
+ finalCoord = {
+ x: 0,
+ y: 0
+ },
+ startEvnt;
+
+ // Screen touched, store the original coordinate
+
+ function touchStart(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee1', touchStart);
+ originalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ originalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ finalCoord.x = originalCoord.x;
+ finalCoord.y = originalCoord.y;
+ started = true;
+ var origEvent = e.originalEvent;
+ // Read event data into our startEvt:
+ startEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ }
+
+ // Store coordinates as finger is swiping
+
+ function touchMove(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee2', touchMove);
+ finalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ finalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ var swipedir;
+
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = ($this.parent().data('xthreshold')) ? $this.parent().data('xthreshold') : $this.data('xthreshold'),
+ ele_y_threshold = ($this.parent().data('ythreshold')) ? $this.parent().data('ythreshold') : $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ if (originalCoord.y > finalCoord.y && (originalCoord.y - finalCoord.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (originalCoord.x < finalCoord.x && (finalCoord.x - originalCoord.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (originalCoord.y < finalCoord.y && (finalCoord.y - originalCoord.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (originalCoord.x > finalCoord.x && (originalCoord.x - finalCoord.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+ if (swipedir != undefined && started) {
+ originalCoord.x = 0;
+ originalCoord.y = 0;
+ finalCoord.x = 0;
+ finalCoord.y = 0;
+ started = false;
+
+ // Read event data into our endEvnt:
+ var origEvent = e.originalEvent;
+ var endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ };
+ hasSwiped = true;
+ $this.trigger('swipe', touchData).trigger(swipedir, touchData);
+ }
+ }
+
+ function touchEnd(e) {
+ $this = $(e.currentTarget);
+ var swipedir = "";
+ $this.data('callee3', touchEnd);
+ if (hasSwiped) {
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = $this.data('xthreshold'),
+ ele_y_threshold = $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ var origEvent = e.originalEvent;
+ var endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - ($this.offset() ? $this.offset().left : 0)) : Math.round(e.pageX - ($this.offset() ? $this.offset().left : 0)),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - ($this.offset() ? $this.offset().top : 0)) : Math.round(e.pageY - ($this.offset() ? $this.offset().top : 0))
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Read event data into our endEvnt:
+ if (startEvnt.position.y > endEvnt.position.y && (startEvnt.position.y - endEvnt.position.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (startEvnt.position.x < endEvnt.position.x && (endEvnt.position.x - startEvnt.position.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (startEvnt.position.y < endEvnt.position.y && (endEvnt.position.y - startEvnt.position.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (startEvnt.position.x > endEvnt.position.x && (startEvnt.position.x - endEvnt.position.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ };
+ $this.trigger('swipeend', touchData);
+ }
+
+ started = false;
+ hasSwiped = false;
+ }
+
+ $this.on(settings.startevent, touchStart);
+ $this.on(settings.moveevent, touchMove);
+ $this.on(settings.endevent, touchEnd);
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.moveevent, $(this).data.callee2).off(settings.endevent, $(this).data.callee3);
+ }
+ };
+
+ // scrollstart Event (also handles scrollend):
+ $.event.special.scrollstart = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ scrolling,
+ timer;
+
+ function trigger(event, state) {
+ scrolling = state;
+ triggerCustomEvent(thisObject, scrolling ? 'scrollstart' : 'scrollend', event);
+ }
+
+ // iPhone triggers scroll after a small delay; use touchmove instead
+ $this.on(settings.scrollevent, function scrollFunc(event) {
+ $this.data('callee', scrollFunc);
+
+ if (!scrolling) {
+ trigger(event, true);
+ }
+
+ clearTimeout(timer);
+ timer = setTimeout(function () {
+ trigger(event, false);
+ }, 50);
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.scrollevent, $(this).data.callee);
+ }
+ };
+
+ // This is the orientation change (largely borrowed from jQuery Mobile):
+ var win = $(window),
+ special_event,
+ get_orientation,
+ last_orientation,
+ initial_orientation_is_landscape,
+ initial_orientation_is_default,
+ portrait_map = {
+ '0': true,
+ '180': true
+ };
+
+ if (settings.orientation_support) {
+ var ww = window.innerWidth || win.width(),
+ wh = window.innerHeight || win.height(),
+ landscape_threshold = 50;
+
+ initial_orientation_is_landscape = ww > wh && (ww - wh) > landscape_threshold;
+ initial_orientation_is_default = portrait_map[window.orientation];
+
+ if ((initial_orientation_is_landscape && initial_orientation_is_default) || (!initial_orientation_is_landscape && !initial_orientation_is_default)) {
+ portrait_map = {
+ '-90': true,
+ '90': true
+ };
+ }
+ }
+
+ $.event.special.orientationchange = special_event = {
+ setup: function () {
+ // If the event is supported natively, return false so that jQuery
+ // will on to the event using DOM methods.
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ // Get the current orientation to avoid initial double-triggering.
+ last_orientation = get_orientation();
+
+ win.on('throttledresize', handler);
+ return true;
+ },
+ teardown: function () {
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ win.off('throttledresize', handler);
+ return true;
+ },
+ add: function (handleObj) {
+ // Save a reference to the bound event handler.
+ var old_handler = handleObj.handler;
+
+ handleObj.handler = function (event) {
+ event.orientation = get_orientation();
+ return old_handler.apply(this, arguments);
+ };
+ }
+ };
+
+ // If the event is not supported natively, this handler will be bound to
+ // the window resize event to simulate the orientationchange event.
+
+ function handler() {
+ // Get the current orientation.
+ var orientation = get_orientation();
+
+ if (orientation !== last_orientation) {
+ // The orientation has changed, so trigger the orientationchange event.
+ last_orientation = orientation;
+ win.trigger("orientationchange");
+ }
+ }
+
+ $.event.special.orientationchange.orientation = get_orientation = function () {
+ var isPortrait = true,
+ elem = document.documentElement;
+
+ if (settings.orientation_support) {
+ isPortrait = portrait_map[window.orientation];
+ } else {
+ isPortrait = elem && elem.clientWidth / elem.clientHeight < 1.1;
+ }
+
+ return isPortrait ? 'portrait' : 'landscape';
+ };
+
+ // throttle Handler:
+ $.event.special.throttledresize = {
+ setup: function () {
+ $(this).on('resize', throttle_handler);
+ },
+ teardown: function () {
+ $(this).off('resize', throttle_handler);
+ }
+ };
+
+ var throttle = 250,
+ throttle_handler = function () {
+ curr = Date.now();
+ diff = curr - lastCall;
+
+ if (diff >= throttle) {
+ lastCall = curr;
+ $(this).trigger('throttledresize');
+
+ } else {
+ if (heldCall) {
+ window.clearTimeout(heldCall);
+ }
+
+ // Promise a held call will still execute
+ heldCall = window.setTimeout(handler, throttle - diff);
+ }
+ },
+ lastCall = 0,
+ heldCall,
+ curr,
+ diff;
+
+ // Trigger a custom event:
+
+ function triggerCustomEvent(obj, eventType, event, touchData) {
+ var originalType = event.type;
+ event.type = eventType;
+
+ $.event.dispatch.call(obj, event, touchData);
+ event.type = originalType;
+ }
+
+ // Correctly on anything we've overloaded:
+ $.each({
+ scrollend: 'scrollstart',
+ swipeup: 'swipe',
+ swiperight: 'swipe',
+ swipedown: 'swipe',
+ swipeleft: 'swipe',
+ swipeend: 'swipe',
+ tap2: 'tap',
+ taphold2: 'taphold'
+ }, function (e, srcE) {
+ $.event.special[e] = {
+ setup: function () {
+ $(this).on(srcE, $.noop);
+ }
+ };
+ });
+
+}(jQuery));
diff --git a/src/2.0.1/jquery.mobile-events.min.js b/src/2.0.1/jquery.mobile-events.min.js
new file mode 100644
index 0000000..10b8c00
--- /dev/null
+++ b/src/2.0.1/jquery.mobile-events.min.js
@@ -0,0 +1,27 @@
+/*!
+ * jQuery Mobile Events
+ * by Ben Major
+ *
+ * Copyright 2011-2019, Ben Major
+ * Licensed under the MIT License:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ "use strict";!function(e){e.attrFn=e.attrFn||{};var t="ontouchstart"in window,a={tap_pixel_range:5,swipe_h_threshold:50,swipe_v_threshold:50,taphold_threshold:750,doubletap_int:500,shake_threshold:15,touch_capable:t,orientation_support:"orientation"in window&&"onorientationchange"in window,startevent:t?"touchstart":"mousedown",endevent:t?"touchend":"mouseup",moveevent:t?"touchmove":"mousemove",tapevent:t?"tap":"click",scrollevent:t?"touchmove":"scroll",hold_timer:null,tap_timer:null};e.touch={},e.isTouchCapable=function(){return a.touch_capable},e.getStartEvent=function(){return a.startevent},e.getEndEvent=function(){return a.endevent},e.getMoveEvent=function(){return a.moveevent},e.getTapEvent=function(){return a.tapevent},e.getScrollEvent=function(){return a.scrollevent},e.touch.setSwipeThresholdX=function(e){if("number"!=typeof e)throw new Error("Threshold parameter must be a type of number");a.swipe_h_threshold=e},e.touch.setSwipeThresholdY=function(e){if("number"!=typeof e)throw new Error("Threshold parameter must be a type of number");a.swipe_v_threshold=e},e.touch.setDoubleTapInt=function(e){if("number"!=typeof e)throw new Error("Interval parameter must be a type of number");a.doubletap_int=e},e.touch.setTapHoldThreshold=function(e){if("number"!=typeof e)throw new Error("Threshold parameter must be a type of number");a.taphold_threshold=e},e.touch.setTapRange=function(e){if("number"!=typeof e)throw new Error("Ranger parameter must be a type of number");a.tap_pixel_range=threshold},e.each(["tapstart","tapend","tapmove","tap","singletap","doubletap","taphold","swipe","swipeup","swiperight","swipedown","swipeleft","swipeend","scrollstart","scrollend","orientationchange","tap2","taphold2"],function(t,a){e.fn[a]=function(e){return e?this.on(a,e):this.trigger(a)},e.attrFn[a]=!0}),e.event.special.tapstart={setup:function(){var t=this,o=e(t);o.on(a.startevent,function e(n){if(o.data("callee",e),n.which&&1!==n.which)return!1;var i=n.originalEvent,r={position:{x:a.touch_capable?i.touches[0].pageX:n.pageX,y:a.touch_capable?i.touches[0].pageY:n.pageY},offset:{x:a.touch_capable?Math.round(i.changedTouches[0].pageX-(o.offset()?o.offset().left:0)):Math.round(n.pageX-(o.offset()?o.offset().left:0)),y:a.touch_capable?Math.round(i.changedTouches[0].pageY-(o.offset()?o.offset().top:0)):Math.round(n.pageY-(o.offset()?o.offset().top:0))},time:Date.now(),target:n.target};return w(t,"tapstart",n,r),!0})},remove:function(){e(this).off(a.startevent,e(this).data.callee)}},e.event.special.tapmove={setup:function(){var t=this,o=e(t);o.on(a.moveevent,function e(n){o.data("callee",e);var i=n.originalEvent,r={position:{x:a.touch_capable?i.touches[0].pageX:n.pageX,y:a.touch_capable?i.touches[0].pageY:n.pageY},offset:{x:a.touch_capable?Math.round(i.changedTouches[0].pageX-(o.offset()?o.offset().left:0)):Math.round(n.pageX-(o.offset()?o.offset().left:0)),y:a.touch_capable?Math.round(i.changedTouches[0].pageY-(o.offset()?o.offset().top:0)):Math.round(n.pageY-(o.offset()?o.offset().top:0))},time:Date.now(),target:n.target};return w(t,"tapmove",n,r),!0})},remove:function(){e(this).off(a.moveevent,e(this).data.callee)}},e.event.special.tapend={setup:function(){var t=this,o=e(t);o.on(a.endevent,function e(n){o.data("callee",e);var i=n.originalEvent,r={position:{x:a.touch_capable?i.changedTouches[0].pageX:n.pageX,y:a.touch_capable?i.changedTouches[0].pageY:n.pageY},offset:{x:a.touch_capable?Math.round(i.changedTouches[0].pageX-(o.offset()?o.offset().left:0)):Math.round(n.pageX-(o.offset()?o.offset().left:0)),y:a.touch_capable?Math.round(i.changedTouches[0].pageY-(o.offset()?o.offset().top:0)):Math.round(n.pageY-(o.offset()?o.offset().top:0))},time:Date.now(),target:n.target};return w(t,"tapend",n,r),!0})},remove:function(){e(this).off(a.endevent,e(this).data.callee)}},e.event.special.taphold={setup:function(){var t,o=this,n=e(o),i={x:0,y:0},r=0,s=0;n.on(a.startevent,function e(p){if(p.which&&1!==p.which)return!1;n.data("tapheld",!1),t=p.target;var h=p.originalEvent,c=Date.now();a.touch_capable?h.touches[0].pageX:p.pageX,a.touch_capable?h.touches[0].pageY:p.pageY,a.touch_capable?(h.touches[0].pageX,h.touches[0].target.offsetLeft):p.offsetX,a.touch_capable?(h.touches[0].pageY,h.touches[0].target.offsetTop):p.offsetY;i.x=p.originalEvent.targetTouches?p.originalEvent.targetTouches[0].pageX:p.pageX,i.y=p.originalEvent.targetTouches?p.originalEvent.targetTouches[0].pageY:p.pageY,r=i.x,s=i.y;var u=n.parent().data("threshold")?n.parent().data("threshold"):n.data("threshold"),l=void 0!==u&&!1!==u&&parseInt(u)?parseInt(u):a.taphold_threshold;return n.data("hold_timer",window.setTimeout(function(){var u=i.x-r,l=i.y-s;if(p.target==t&&(i.x==r&&i.y==s||u>=-a.tap_pixel_range&&u<=a.tap_pixel_range&&l>=-a.tap_pixel_range&&l<=a.tap_pixel_range)){n.data("tapheld",!0);for(var f=Date.now()-c,g=p.originalEvent.targetTouches?p.originalEvent.targetTouches:[p],d=[],v=0;v100){i.data("doubletapped",!0),window.clearTimeout(a.tap_timer);var l={position:{x:a.touch_capable?h.originalEvent.changedTouches[0].pageX:h.pageX,y:a.touch_capable?h.originalEvent.changedTouches[0].pageY:h.pageY},offset:{x:a.touch_capable?Math.round(o.changedTouches[0].pageX-(i.offset()?i.offset().left:0)):Math.round(h.pageX-(i.offset()?i.offset().left:0)),y:a.touch_capable?Math.round(o.changedTouches[0].pageY-(i.offset()?i.offset().top:0)):Math.round(h.pageY-(i.offset()?i.offset().top:0))},time:Date.now(),target:h.target,element:h.originalEvent.srcElement,index:e(h.target).index()},f={firstTap:r,secondTap:l,interval:l.time-r.time};s||(w(n,"doubletap",h,f),r=null),s=!0,window.setTimeout(function(){s=!1},a.doubletap_int)}else i.data("lastTouch",c),t=window.setTimeout(function(){r=null,window.clearTimeout(t)},a.doubletap_int,[h]);i.data("lastTouch",c)})},remove:function(){e(this).off(a.startevent,e(this).data.callee1).off(a.endevent,e(this).data.callee2)}},e.event.special.singletap={setup:function(){var t=this,o=e(t),n=null,i=null,r={x:0,y:0};o.on(a.startevent,function e(t){return(!t.which||1===t.which)&&(i=Date.now(),n=t.target,o.data("callee1",e),r.x=t.originalEvent.targetTouches?t.originalEvent.targetTouches[0].pageX:t.pageX,r.y=t.originalEvent.targetTouches?t.originalEvent.targetTouches[0].pageY:t.pageY,!0)}).on(a.endevent,function e(s){if(o.data("callee2",e),s.target==n){var p=s.originalEvent.changedTouches?s.originalEvent.changedTouches[0].pageX:s.pageX,h=s.originalEvent.changedTouches?s.originalEvent.changedTouches[0].pageY:s.pageY;a.tap_timer=window.setTimeout(function(){var e=r.x-p,n=r.y-h;if(!o.data("doubletapped")&&!o.data("tapheld")&&(r.x==p&&r.y==h||e>=-a.tap_pixel_range&&e<=a.tap_pixel_range&&n>=-a.tap_pixel_range&&n<=a.tap_pixel_range)){var c=s.originalEvent,u={position:{x:a.touch_capable?c.changedTouches[0].pageX:s.pageX,y:a.touch_capable?c.changedTouches[0].pageY:s.pageY},offset:{x:a.touch_capable?Math.round(c.changedTouches[0].pageX-(o.offset()?o.offset().left:0)):Math.round(s.pageX-(o.offset()?o.offset().left:0)),y:a.touch_capable?Math.round(c.changedTouches[0].pageY-(o.offset()?o.offset().top:0)):Math.round(s.pageY-(o.offset()?o.offset().top:0))},time:Date.now(),target:s.target};u.time-i=-a.tap_pixel_range&&l<=a.tap_pixel_range&&f>=-a.tap_pixel_range&&f<=a.tap_pixel_range)){for(var g=h.originalEvent,d=[],v=0;vs.y&&r.y-s.y>g&&(c="swipeup"),r.xf&&(c="swiperight"),r.yg&&(c="swipedown"),r.x>s.x&&r.x-s.x>f&&(c="swipeleft"),null!=c&&n){r.x=0,r.y=0,s.x=0,s.y=0,n=!1;var d=h.originalEvent,v={position:{x:a.touch_capable?d.touches[0].pageX:h.pageX,y:a.touch_capable?d.touches[0].pageY:h.pageY},offset:{x:a.touch_capable?Math.round(d.changedTouches[0].pageX-(o.offset()?o.offset().left:0)):Math.round(h.pageX-(o.offset()?o.offset().left:0)),y:a.touch_capable?Math.round(d.changedTouches[0].pageY-(o.offset()?o.offset().top:0)):Math.round(h.pageY-(o.offset()?o.offset().top:0))},time:Date.now(),target:h.target},w=Math.abs(t.position.x-v.position.x),_=Math.abs(t.position.y-v.position.y),T={startEvnt:t,endEvnt:v,direction:c.replace("swipe",""),xAmount:w,yAmount:_,duration:v.time-t.time};i=!0,o.trigger("swipe",T).trigger(c,T)}}),o.on(a.endevent,function r(s){var p="";if((o=e(s.currentTarget)).data("callee3",r),i){var h=o.data("xthreshold"),c=o.data("ythreshold"),u=void 0!==h&&!1!==h&&parseInt(h)?parseInt(h):a.swipe_h_threshold,l=void 0!==c&&!1!==c&&parseInt(c)?parseInt(c):a.swipe_v_threshold,f=s.originalEvent,g={position:{x:a.touch_capable?f.changedTouches[0].pageX:s.pageX,y:a.touch_capable?f.changedTouches[0].pageY:s.pageY},offset:{x:a.touch_capable?Math.round(f.changedTouches[0].pageX-(o.offset()?o.offset().left:0)):Math.round(s.pageX-(o.offset()?o.offset().left:0)),y:a.touch_capable?Math.round(f.changedTouches[0].pageY-(o.offset()?o.offset().top:0)):Math.round(s.pageY-(o.offset()?o.offset().top:0))},time:Date.now(),target:s.target};t.position.y>g.position.y&&t.position.y-g.position.y>l&&(p="swipeup"),t.position.xu&&(p="swiperight"),t.position.yl&&(p="swipedown"),t.position.x>g.position.x&&t.position.x-g.position.x>u&&(p="swipeleft");var d=Math.abs(t.position.x-g.position.x),v=Math.abs(t.position.y-g.position.y),w={startEvnt:t,endEvnt:g,direction:p.replace("swipe",""),xAmount:d,yAmount:v,duration:g.time-t.time};o.trigger("swipeend",w)}n=!1,i=!1})},remove:function(){e(this).off(a.startevent,e(this).data.callee1).off(a.moveevent,e(this).data.callee2).off(a.endevent,e(this).data.callee3)}},e.event.special.scrollstart={setup:function(){var t,o,n=this,i=e(n);function r(e,a){w(n,(t=a)?"scrollstart":"scrollend",e)}i.on(a.scrollevent,function e(a){i.data("callee",e),t||r(a,!0),clearTimeout(o),o=setTimeout(function(){r(a,!1)},50)})},remove:function(){e(this).off(a.scrollevent,e(this).data.callee)}};var o,n,i,r,s=e(window),p={0:!0,180:!0};if(a.orientation_support){var h=window.innerWidth||s.width(),c=window.innerHeight||s.height();i=h>c&&h-c>50,r=p[window.orientation],(i&&r||!i&&!r)&&(p={"-90":!0,90:!0})}function u(){var e=o();e!==n&&(n=e,s.trigger("orientationchange"))}e.event.special.orientationchange={setup:function(){return!a.orientation_support&&(n=o(),s.on("throttledresize",u),!0)},teardown:function(){return!a.orientation_support&&(s.off("throttledresize",u),!0)},add:function(e){var t=e.handler;e.handler=function(e){return e.orientation=o(),t.apply(this,arguments)}}},e.event.special.orientationchange.orientation=o=function(){var e=document.documentElement;return(a.orientation_support?p[window.orientation]:e&&e.clientWidth/e.clientHeight<1.1)?"portrait":"landscape"},e.event.special.throttledresize={setup:function(){e(this).on("resize",d)},teardown:function(){e(this).off("resize",d)}};var l,f,g,d=function(){f=Date.now(),(g=f-v)>=250?(v=f,e(this).trigger("throttledresize")):(l&&window.clearTimeout(l),l=window.setTimeout(u,250-g))},v=0;function w(t,a,o,n){var i=o.type;o.type=a,e.event.dispatch.call(t,o,n),o.type=i}e.each({scrollend:"scrollstart",swipeup:"swipe",swiperight:"swipe",swipedown:"swipe",swipeleft:"swipe",swipeend:"swipe",tap2:"tap",taphold2:"taphold"},function(t,a){e.event.special[t]={setup:function(){e(this).on(a,e.noop)}}})}(jQuery);
diff --git a/src/2.0.2/jquery.mobile-events.js b/src/2.0.2/jquery.mobile-events.js
new file mode 100644
index 0000000..1e11ee7
--- /dev/null
+++ b/src/2.0.2/jquery.mobile-events.js
@@ -0,0 +1,931 @@
+/*!
+ * jQuery Mobile Events
+ * by Ben Major
+ *
+ * Copyright 2011-2019, Ben Major
+ * Licensed under the MIT License:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+"use strict";
+
+(function ($) {
+ $.attrFn = $.attrFn || {};
+
+ var touchCapable = ('ontouchstart' in window),
+
+ settings = {
+ tap_pixel_range: 5,
+ swipe_h_threshold: 50,
+ swipe_v_threshold: 50,
+ taphold_threshold: 750,
+ doubletap_int: 500,
+ shake_threshold: 15,
+
+ touch_capable: touchCapable,
+ orientation_support: ('orientation' in window && 'onorientationchange' in window),
+
+ startevent: (touchCapable) ? 'touchstart' : 'mousedown',
+ endevent: (touchCapable) ? 'touchend' : 'mouseup',
+ moveevent: (touchCapable) ? 'touchmove' : 'mousemove',
+ tapevent: (touchCapable) ? 'tap' : 'click',
+ scrollevent: (touchCapable) ? 'touchmove' : 'scroll',
+
+ hold_timer: null,
+ tap_timer: null
+ };
+
+ // Declare touch namespace:
+ $.touch = { };
+
+ // Convenience functions:
+ $.isTouchCapable = function() { return settings.touch_capable; };
+ $.getStartEvent = function() { return settings.startevent; };
+ $.getEndEvent = function() { return settings.endevent; };
+ $.getMoveEvent = function() { return settings.moveevent; };
+ $.getTapEvent = function() { return settings.tapevent; };
+ $.getScrollEvent = function() { return settings.scrollevent; };
+
+ // SETTERS:
+ // Set the X threshold of swipe events:
+ $.touch.setSwipeThresholdX = function( threshold ) {
+ if( typeof threshold !== 'number' ) { throw new Error('Threshold parameter must be a type of number'); }
+ settings.swipe_h_threshold = threshold;
+ };
+
+ // Set the Y threshold of swipe events:
+ $.touch.setSwipeThresholdY = function( threshold ) {
+ if( typeof threshold !== 'number' ) { throw new Error('Threshold parameter must be a type of number'); }
+ settings.swipe_v_threshold = threshold;
+ };
+
+ // Set the double tap interval:
+ $.touch.setDoubleTapInt = function( interval ) {
+ if( typeof interval !== 'number' ) { throw new Error('Interval parameter must be a type of number'); }
+ settings.doubletap_int = interval;
+ };
+
+ // Set the taphold threshold:
+ $.touch.setTapHoldThreshold = function( threshold ) {
+ if( typeof threshold !== 'number' ) { throw new Error('Threshold parameter must be a type of number'); }
+ settings.taphold_threshold = threshold;
+ };
+
+ // Set the pixel range for tapas:
+ $.touch.setTapRange = function( range ) {
+ if( typeof range !== 'number' ) { throw new Error('Ranger parameter must be a type of number'); }
+ settings.tap_pixel_range = threshold;
+ };
+
+ // Add Event shortcuts:
+ $.each(['tapstart', 'tapend', 'tapmove', 'tap', 'singletap', 'doubletap', 'taphold', 'swipe', 'swipeup', 'swiperight', 'swipedown', 'swipeleft', 'swipeend', 'scrollstart', 'scrollend', 'orientationchange', 'tap2', 'taphold2'], function (i, name) {
+ $.fn[name] = function (fn) {
+ return fn ? this.on(name, fn) : this.trigger(name);
+ };
+
+ $.attrFn[name] = true;
+ });
+
+ // tapstart Event:
+ $.event.special.tapstart = {
+ setup: function () {
+
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.startevent, function tapStartFunc(e) {
+
+ $this.data('callee', tapStartFunc);
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapstart', e, touchData);
+ return true;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee);
+ }
+ };
+
+ // tapmove Event:
+ $.event.special.tapmove = {
+ setup: function() {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.moveevent, function tapMoveFunc(e) {
+ $this.data('callee', tapMoveFunc);
+
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapmove', e, touchData);
+ return true;
+ });
+ },
+ remove: function() {
+ $(this).off(settings.moveevent, $(this).data.callee);
+ }
+ };
+
+ // tapend Event:
+ $.event.special.tapend = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.endevent, function tapEndFunc(e) {
+ // Touch event data:
+ $this.data('callee', tapEndFunc);
+
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ triggerCustomEvent(thisObject, 'tapend', e, touchData);
+ return true;
+ });
+ },
+ remove: function () {
+ $(this).off(settings.endevent, $(this).data.callee);
+ }
+ };
+
+ // taphold Event:
+ $.event.special.taphold = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ end_x = 0,
+ end_y = 0;
+
+ $this.on(settings.startevent, function tapHoldFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ $this.data('tapheld', false);
+ origTarget = e.target;
+
+ var origEvent = e.originalEvent;
+ var start_time = Date.now(),
+ startPosition = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
+ },
+ startOffset = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ };
+
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ end_x = start_pos.x;
+ end_y = start_pos.y;
+
+ // Get the element's threshold:
+ var ele_threshold = ($this.parent().data('threshold')) ? $this.parent().data('threshold') : $this.data('threshold'),
+ threshold = (typeof ele_threshold !== 'undefined' && ele_threshold !== false && parseInt(ele_threshold)) ? parseInt(ele_threshold) : settings.taphold_threshold;
+
+ $this.data('hold_timer', window.setTimeout(function () {
+
+ var diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y);
+
+ if (e.target == origTarget && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ $this.data('tapheld', true);
+
+ var end_time = Date.now();
+
+ var duration = end_time - start_time,
+ touches = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches : [ e ],
+ touchData = [ ];
+
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
+ for( var i = 0; i < touches.length; i++)
+ {
+ var touch = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[i].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[i].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageY - offset.top) : Math.round(e.pageY - offset.top)
+ },
+ 'time': Date.now(),
+ 'target': e.target,
+ 'duration': duration
+ };
+
+ touchData.push( touch );
+ }
+
+ var evt_name = ( touches.length == 2 ) ? 'taphold2' : 'taphold';
+
+ $this.data('callee1', tapHoldFunc1);
+
+ triggerCustomEvent(thisObject, evt_name, e, touchData);
+ }
+ }, threshold) );
+
+ return true;
+ }
+ }).on(settings.endevent, function tapHoldFunc2() {
+ $this.data('callee2', tapHoldFunc2);
+ $this.data('tapheld', false);
+ window.clearTimeout( $this.data('hold_timer') );
+ })
+ .on(settings.moveevent, function tapHoldFunc3(e) {
+ $this.data('callee3', tapHoldFunc3);
+
+ end_x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2).off(settings.moveevent, $(this).data.callee3);
+ }
+ };
+
+ // doubletap Event:
+ $.event.special.doubletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ action,
+ firstTap = null,
+ origEvent,
+ cooloff,
+ cooling = false;
+
+ $this.on(settings.startevent, function doubleTapFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+
+ $this.data('doubletapped', false);
+ origTarget = e.target;
+ $this.data('callee1', doubleTapFunc1);
+
+ origEvent = e.originalEvent;
+ if (!firstTap) {
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
+ firstTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
+ },
+ 'time': Date.now(),
+ 'target': e.target,
+ 'element': e.originalEvent.srcElement,
+ 'index': $(e.target).index()
+ };
+ }
+
+ return true;
+ }).on(settings.endevent, function doubleTapFunc2(e) {
+
+ var now = Date.now();
+ var lastTouch = $this.data('lastTouch') || now + 1;
+ var delta = now - lastTouch;
+ window.clearTimeout(action);
+ $this.data('callee2', doubleTapFunc2);
+
+ if (delta < settings.doubletap_int && ($(e.target).index() == firstTap.index) && delta > 100) {
+ $this.data('doubletapped', true);
+ window.clearTimeout(settings.tap_timer);
+
+ // Now get the current event:
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
+ var lastTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? e.originalEvent.changedTouches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
+ },
+ 'time': Date.now(),
+ 'target': e.target,
+ 'element': e.originalEvent.srcElement,
+ 'index': $(e.target).index()
+ };
+
+ var touchData = {
+ 'firstTap': firstTap,
+ 'secondTap': lastTap,
+ 'interval': lastTap.time - firstTap.time
+ };
+
+ if (!cooling) {
+ triggerCustomEvent(thisObject, 'doubletap', e, touchData);
+ firstTap = null;
+ }
+
+ cooling = true;
+
+ cooloff = window.setTimeout(function () {
+ cooling = false;
+ }, settings.doubletap_int);
+
+ } else {
+ $this.data('lastTouch', now);
+ action = window.setTimeout(function () {
+ firstTap = null;
+ window.clearTimeout(action);
+ }, settings.doubletap_int, [e]);
+ }
+ $this.data('lastTouch', now);
+ });
+ },
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // singletap Event:
+ // This is used in conjuction with doubletap when both events are needed on the same element
+ $.event.special.singletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget = null,
+ startTime = null,
+ start_pos = {
+ x: 0,
+ y: 0
+ };
+
+ $this.on(settings.startevent, function singleTapFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ startTime = Date.now();
+ origTarget = e.target;
+ $this.data('callee1', singleTapFunc1);
+
+ // Get the start x and y position:
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ return true;
+ }
+ }).on(settings.endevent, function singleTapFunc2(e) {
+ $this.data('callee2', singleTapFunc2);
+ if (e.target == origTarget) {
+
+ // Get the end point:
+ var end_pos_x = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ end_pos_y = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY;
+
+ // We need to check if it was a taphold:
+
+ settings.tap_timer = window.setTimeout(function () {
+
+ var diff_x = (start_pos.x - end_pos_x), diff_y = (start_pos.y - end_pos_y);
+
+ if(!$this.data('doubletapped') && !$this.data('tapheld') && (((start_pos.x == end_pos_x) && (start_pos.y == end_pos_y)) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Was it a taphold?
+ if((touchData.time - startTime) < settings.taphold_threshold)
+ {
+ triggerCustomEvent(thisObject, 'singletap', e, touchData);
+ }
+ }
+ }, settings.doubletap_int);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // tap Event:
+ $.event.special.tap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ origTarget = null,
+ start_time,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ touches;
+
+ $this.on(settings.startevent, function tapFunc1(e) {
+ $this.data('callee1', tapFunc1);
+
+ if( e.which && e.which !== 1 )
+ {
+ return false;
+ }
+ else
+ {
+ started = true;
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ start_time = Date.now();
+ origTarget = e.target;
+
+ touches = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches : [ e ];
+ return true;
+ }
+ }).on(settings.endevent, function tapFunc2(e) {
+ $this.data('callee2', tapFunc2);
+
+ // Only trigger if they've started, and the target matches:
+ var end_x = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY,
+ diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y),
+ eventName;
+
+ if (origTarget == e.target && started && ((Date.now() - start_time) < settings.taphold_threshold) && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
+ var origEvent = e.originalEvent;
+ var touchData = [ ];
+
+ for( var i = 0; i < touches.length; i++)
+ {
+ var touch = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[i].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[i].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageY - offset.top) : Math.round(e.pageY - offset.top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ touchData.push( touch );
+ }
+
+ var evt_name = ( touches.length == 2 ) ? 'tap2' : 'tap';
+
+ triggerCustomEvent(thisObject, evt_name, e, touchData);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // swipe Event (also handles swipeup, swiperight, swipedown and swipeleft):
+ $.event.special.swipe = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ hasSwiped = false,
+ originalCoord = {
+ x: 0,
+ y: 0
+ },
+ finalCoord = {
+ x: 0,
+ y: 0
+ },
+ startEvnt;
+
+ // Screen touched, store the original coordinate
+
+ function touchStart(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee1', touchStart);
+ originalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ originalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ finalCoord.x = originalCoord.x;
+ finalCoord.y = originalCoord.y;
+ started = true;
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
+ var origEvent = e.originalEvent;
+ // Read event data into our startEvt:
+ startEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ }
+
+ // Store coordinates as finger is swiping
+
+ function touchMove(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee2', touchMove);
+ finalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ finalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ var swipedir;
+
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = ($this.parent().data('xthreshold')) ? $this.parent().data('xthreshold') : $this.data('xthreshold'),
+ ele_y_threshold = ($this.parent().data('ythreshold')) ? $this.parent().data('ythreshold') : $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ if (originalCoord.y > finalCoord.y && (originalCoord.y - finalCoord.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (originalCoord.x < finalCoord.x && (finalCoord.x - originalCoord.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (originalCoord.y < finalCoord.y && (finalCoord.y - originalCoord.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (originalCoord.x > finalCoord.x && (originalCoord.x - finalCoord.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+ if (swipedir != undefined && started) {
+ originalCoord.x = 0;
+ originalCoord.y = 0;
+ finalCoord.x = 0;
+ finalCoord.y = 0;
+ started = false;
+
+ // Read event data into our endEvnt:
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
+ var origEvent = e.originalEvent;
+ var endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ };
+ hasSwiped = true;
+ $this.trigger('swipe', touchData).trigger(swipedir, touchData);
+ }
+ }
+
+ function touchEnd(e) {
+ $this = $(e.currentTarget);
+ var swipedir = "";
+ $this.data('callee3', touchEnd);
+ if (hasSwiped) {
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = $this.data('xthreshold'),
+ ele_y_threshold = $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
+ var origEvent = e.originalEvent;
+ var endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Read event data into our endEvnt:
+ if (startEvnt.position.y > endEvnt.position.y && (startEvnt.position.y - endEvnt.position.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (startEvnt.position.x < endEvnt.position.x && (endEvnt.position.x - startEvnt.position.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (startEvnt.position.y < endEvnt.position.y && (endEvnt.position.y - startEvnt.position.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ if (startEvnt.position.x > endEvnt.position.x && (startEvnt.position.x - endEvnt.position.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ };
+ $this.trigger('swipeend', touchData);
+ }
+
+ started = false;
+ hasSwiped = false;
+ }
+
+ $this.on(settings.startevent, touchStart);
+ $this.on(settings.moveevent, touchMove);
+ $this.on(settings.endevent, touchEnd);
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.moveevent, $(this).data.callee2).off(settings.endevent, $(this).data.callee3);
+ }
+ };
+
+ // scrollstart Event (also handles scrollend):
+ $.event.special.scrollstart = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ scrolling,
+ timer;
+
+ function trigger(event, state) {
+ scrolling = state;
+ triggerCustomEvent(thisObject, scrolling ? 'scrollstart' : 'scrollend', event);
+ }
+
+ // iPhone triggers scroll after a small delay; use touchmove instead
+ $this.on(settings.scrollevent, function scrollFunc(event) {
+ $this.data('callee', scrollFunc);
+
+ if (!scrolling) {
+ trigger(event, true);
+ }
+
+ clearTimeout(timer);
+ timer = setTimeout(function () {
+ trigger(event, false);
+ }, 50);
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.scrollevent, $(this).data.callee);
+ }
+ };
+
+ // This is the orientation change (largely borrowed from jQuery Mobile):
+ var win = $(window),
+ special_event,
+ get_orientation,
+ last_orientation,
+ initial_orientation_is_landscape,
+ initial_orientation_is_default,
+ portrait_map = {
+ '0': true,
+ '180': true
+ };
+
+ if (settings.orientation_support) {
+ var ww = window.innerWidth || win.width(),
+ wh = window.innerHeight || win.height(),
+ landscape_threshold = 50;
+
+ initial_orientation_is_landscape = ww > wh && (ww - wh) > landscape_threshold;
+ initial_orientation_is_default = portrait_map[window.orientation];
+
+ if ((initial_orientation_is_landscape && initial_orientation_is_default) || (!initial_orientation_is_landscape && !initial_orientation_is_default)) {
+ portrait_map = {
+ '-90': true,
+ '90': true
+ };
+ }
+ }
+
+ $.event.special.orientationchange = special_event = {
+ setup: function () {
+ // If the event is supported natively, return false so that jQuery
+ // will on to the event using DOM methods.
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ // Get the current orientation to avoid initial double-triggering.
+ last_orientation = get_orientation();
+
+ win.on('throttledresize', handler);
+ return true;
+ },
+ teardown: function () {
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ win.off('throttledresize', handler);
+ return true;
+ },
+ add: function (handleObj) {
+ // Save a reference to the bound event handler.
+ var old_handler = handleObj.handler;
+
+ handleObj.handler = function (event) {
+ event.orientation = get_orientation();
+ return old_handler.apply(this, arguments);
+ };
+ }
+ };
+
+ // If the event is not supported natively, this handler will be bound to
+ // the window resize event to simulate the orientationchange event.
+
+ function handler() {
+ // Get the current orientation.
+ var orientation = get_orientation();
+
+ if (orientation !== last_orientation) {
+ // The orientation has changed, so trigger the orientationchange event.
+ last_orientation = orientation;
+ win.trigger("orientationchange");
+ }
+ }
+
+ $.event.special.orientationchange.orientation = get_orientation = function () {
+ var isPortrait = true,
+ elem = document.documentElement;
+
+ if (settings.orientation_support) {
+ isPortrait = portrait_map[window.orientation];
+ } else {
+ isPortrait = elem && elem.clientWidth / elem.clientHeight < 1.1;
+ }
+
+ return isPortrait ? 'portrait' : 'landscape';
+ };
+
+ // throttle Handler:
+ $.event.special.throttledresize = {
+ setup: function () {
+ $(this).on('resize', throttle_handler);
+ },
+ teardown: function () {
+ $(this).off('resize', throttle_handler);
+ }
+ };
+
+ var throttle = 250,
+ throttle_handler = function () {
+ curr = Date.now();
+ diff = curr - lastCall;
+
+ if (diff >= throttle) {
+ lastCall = curr;
+ $(this).trigger('throttledresize');
+
+ } else {
+ if (heldCall) {
+ window.clearTimeout(heldCall);
+ }
+
+ // Promise a held call will still execute
+ heldCall = window.setTimeout(handler, throttle - diff);
+ }
+ },
+ lastCall = 0,
+ heldCall,
+ curr,
+ diff;
+
+ // Trigger a custom event:
+
+ function triggerCustomEvent(obj, eventType, event, touchData) {
+ var originalType = event.type;
+ event.type = eventType;
+
+ $.event.dispatch.call(obj, event, touchData);
+ event.type = originalType;
+ }
+
+ // Correctly on anything we've overloaded:
+ $.each({
+ scrollend: 'scrollstart',
+ swipeup: 'swipe',
+ swiperight: 'swipe',
+ swipedown: 'swipe',
+ swipeleft: 'swipe',
+ swipeend: 'swipe',
+ tap2: 'tap',
+ taphold2: 'taphold'
+ }, function (e, srcE) {
+ $.event.special[e] = {
+ setup: function () {
+ $(this).on(srcE, $.noop);
+ }
+ };
+ });
+
+}(jQuery));
diff --git a/src/2.0.2/jquery.mobile-events.min.js b/src/2.0.2/jquery.mobile-events.min.js
new file mode 100644
index 0000000..6ac0a92
--- /dev/null
+++ b/src/2.0.2/jquery.mobile-events.min.js
@@ -0,0 +1,27 @@
+/*!
+ * jQuery Mobile Events
+ * by Ben Major
+ *
+ * Copyright 2011-2019, Ben Major
+ * Licensed under the MIT License:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+"use strict";!function(e){e.attrFn=e.attrFn||{};var t="ontouchstart"in window,a={tap_pixel_range:5,swipe_h_threshold:50,swipe_v_threshold:50,taphold_threshold:750,doubletap_int:500,shake_threshold:15,touch_capable:t,orientation_support:"orientation"in window&&"onorientationchange"in window,startevent:t?"touchstart":"mousedown",endevent:t?"touchend":"mouseup",moveevent:t?"touchmove":"mousemove",tapevent:t?"tap":"click",scrollevent:t?"touchmove":"scroll",hold_timer:null,tap_timer:null};e.touch={},e.isTouchCapable=function(){return a.touch_capable},e.getStartEvent=function(){return a.startevent},e.getEndEvent=function(){return a.endevent},e.getMoveEvent=function(){return a.moveevent},e.getTapEvent=function(){return a.tapevent},e.getScrollEvent=function(){return a.scrollevent},e.touch.setSwipeThresholdX=function(e){if("number"!=typeof e)throw new Error("Threshold parameter must be a type of number");a.swipe_h_threshold=e},e.touch.setSwipeThresholdY=function(e){if("number"!=typeof e)throw new Error("Threshold parameter must be a type of number");a.swipe_v_threshold=e},e.touch.setDoubleTapInt=function(e){if("number"!=typeof e)throw new Error("Interval parameter must be a type of number");a.doubletap_int=e},e.touch.setTapHoldThreshold=function(e){if("number"!=typeof e)throw new Error("Threshold parameter must be a type of number");a.taphold_threshold=e},e.touch.setTapRange=function(e){if("number"!=typeof e)throw new Error("Ranger parameter must be a type of number");a.tap_pixel_range=threshold},e.each(["tapstart","tapend","tapmove","tap","singletap","doubletap","taphold","swipe","swipeup","swiperight","swipedown","swipeleft","swipeend","scrollstart","scrollend","orientationchange","tap2","taphold2"],function(t,a){e.fn[a]=function(e){return e?this.on(a,e):this.trigger(a)},e.attrFn[a]=!0}),e.event.special.tapstart={setup:function(){var t=this,o=e(t);o.on(a.startevent,function e(n){if(o.data("callee",e),n.which&&1!==n.which)return!1;var i=o.get(0)!==window&&o.get(0)!==document?o.offset():{left:0,top:0},r=n.originalEvent,p={position:{x:a.touch_capable?r.touches[0].pageX:n.pageX,y:a.touch_capable?r.touches[0].pageY:n.pageY},offset:{x:a.touch_capable?Math.round(r.changedTouches[0].pageX-i.left):Math.round(n.pageX-i.left),y:a.touch_capable?Math.round(r.changedTouches[0].pageY-i.top):Math.round(n.pageY-i.top)},time:Date.now(),target:n.target};return w(t,"tapstart",n,p),!0})},remove:function(){e(this).off(a.startevent,e(this).data.callee)}},e.event.special.tapmove={setup:function(){var t=this,o=e(t);o.on(a.moveevent,function e(n){o.data("callee",e);var i=o.get(0)!==window&&o.get(0)!==document?o.offset():{left:0,top:0},r=n.originalEvent,p={position:{x:a.touch_capable?r.touches[0].pageX:n.pageX,y:a.touch_capable?r.touches[0].pageY:n.pageY},offset:{x:a.touch_capable?Math.round(r.changedTouches[0].pageX-i.left):Math.round(n.pageX-i.left),y:a.touch_capable?Math.round(r.changedTouches[0].pageY-i.top):Math.round(n.pageY-i.top)},time:Date.now(),target:n.target};return w(t,"tapmove",n,p),!0})},remove:function(){e(this).off(a.moveevent,e(this).data.callee)}},e.event.special.tapend={setup:function(){var t=this,o=e(t);o.on(a.endevent,function e(n){o.data("callee",e);var i=o.get(0)!==window&&o.get(0)!==document?o.offset():{left:0,top:0},r=n.originalEvent,p={position:{x:a.touch_capable?r.changedTouches[0].pageX:n.pageX,y:a.touch_capable?r.changedTouches[0].pageY:n.pageY},offset:{x:a.touch_capable?Math.round(r.changedTouches[0].pageX-i.left):Math.round(n.pageX-i.left),y:a.touch_capable?Math.round(r.changedTouches[0].pageY-i.top):Math.round(n.pageY-i.top)},time:Date.now(),target:n.target};return w(t,"tapend",n,p),!0})},remove:function(){e(this).off(a.endevent,e(this).data.callee)}},e.event.special.taphold={setup:function(){var t,o=this,n=e(o),i={x:0,y:0},r=0,p=0;n.on(a.startevent,function e(h){if(h.which&&1!==h.which)return!1;n.data("tapheld",!1),t=h.target;var c=h.originalEvent,u=Date.now();a.touch_capable?c.touches[0].pageX:h.pageX,a.touch_capable?c.touches[0].pageY:h.pageY,a.touch_capable?(c.touches[0].pageX,c.touches[0].target.offsetLeft):h.offsetX,a.touch_capable?(c.touches[0].pageY,c.touches[0].target.offsetTop):h.offsetY;i.x=h.originalEvent.targetTouches?h.originalEvent.targetTouches[0].pageX:h.pageX,i.y=h.originalEvent.targetTouches?h.originalEvent.targetTouches[0].pageY:h.pageY,r=i.x,p=i.y;var s=n.parent().data("threshold")?n.parent().data("threshold"):n.data("threshold"),l=void 0!==s&&!1!==s&&parseInt(s)?parseInt(s):a.taphold_threshold;return n.data("hold_timer",window.setTimeout(function(){var s=i.x-r,l=i.y-p;if(h.target==t&&(i.x==r&&i.y==p||s>=-a.tap_pixel_range&&s<=a.tap_pixel_range&&l>=-a.tap_pixel_range&&l<=a.tap_pixel_range)){n.data("tapheld",!0);for(var g=Date.now()-u,d=h.originalEvent.targetTouches?h.originalEvent.targetTouches:[h],f=[],v=n.get(0)!==window&&n.get(0)!==document?n.offset():{left:0,top:0},_=0;_100){i.data("doubletapped",!0),window.clearTimeout(a.tap_timer);var l=i.get(0)!==window&&i.get(0)!==document?i.offset():{left:0,top:0},g={position:{x:a.touch_capable?c.originalEvent.changedTouches[0].pageX:c.pageX,y:a.touch_capable?c.originalEvent.changedTouches[0].pageY:c.pageY},offset:{x:a.touch_capable?Math.round(o.changedTouches[0].pageX-l.left):Math.round(c.pageX-l.left),y:a.touch_capable?Math.round(o.changedTouches[0].pageY-l.top):Math.round(c.pageY-l.top)},time:Date.now(),target:c.target,element:c.originalEvent.srcElement,index:e(c.target).index()},d={firstTap:r,secondTap:g,interval:g.time-r.time};p||(w(n,"doubletap",c,d),r=null),p=!0,window.setTimeout(function(){p=!1},a.doubletap_int)}else i.data("lastTouch",u),t=window.setTimeout(function(){r=null,window.clearTimeout(t)},a.doubletap_int,[c]);i.data("lastTouch",u)})},remove:function(){e(this).off(a.startevent,e(this).data.callee1).off(a.endevent,e(this).data.callee2)}},e.event.special.singletap={setup:function(){var t=this,o=e(t),n=null,i=null,r={x:0,y:0};o.on(a.startevent,function e(t){return(!t.which||1===t.which)&&(i=Date.now(),n=t.target,o.data("callee1",e),r.x=t.originalEvent.targetTouches?t.originalEvent.targetTouches[0].pageX:t.pageX,r.y=t.originalEvent.targetTouches?t.originalEvent.targetTouches[0].pageY:t.pageY,!0)}).on(a.endevent,function e(p){if(o.data("callee2",e),p.target==n){var h=p.originalEvent.changedTouches?p.originalEvent.changedTouches[0].pageX:p.pageX,c=p.originalEvent.changedTouches?p.originalEvent.changedTouches[0].pageY:p.pageY;a.tap_timer=window.setTimeout(function(){var e=r.x-h,n=r.y-c;if(!o.data("doubletapped")&&!o.data("tapheld")&&(r.x==h&&r.y==c||e>=-a.tap_pixel_range&&e<=a.tap_pixel_range&&n>=-a.tap_pixel_range&&n<=a.tap_pixel_range)){var u=o.get(0)!==window&&o.get(0)!==document?o.offset():{left:0,top:0},s=p.originalEvent,l={position:{x:a.touch_capable?s.changedTouches[0].pageX:p.pageX,y:a.touch_capable?s.changedTouches[0].pageY:p.pageY},offset:{x:a.touch_capable?Math.round(s.changedTouches[0].pageX-u.left):Math.round(p.pageX-u.left),y:a.touch_capable?Math.round(s.changedTouches[0].pageY-u.top):Math.round(p.pageY-u.top)},time:Date.now(),target:p.target};l.time-i=-a.tap_pixel_range&&l<=a.tap_pixel_range&&g>=-a.tap_pixel_range&&g<=a.tap_pixel_range)){for(var d=i.get(0)!==window&&i.get(0)!==document?i.offset():{left:0,top:0},f=c.originalEvent,v=[],_=0;_p.y&&r.y-p.y>d&&(u="swipeup"),r.xg&&(u="swiperight"),r.yd&&(u="swipedown"),r.x>p.x&&r.x-p.x>g&&(u="swipeleft"),null!=u&&n){r.x=0,r.y=0,p.x=0,p.y=0,n=!1;var f=o.get(0)!==window&&o.get(0)!==document?o.offset():{left:0,top:0},v=c.originalEvent,w={position:{x:a.touch_capable?v.touches[0].pageX:c.pageX,y:a.touch_capable?v.touches[0].pageY:c.pageY},offset:{x:a.touch_capable?Math.round(v.changedTouches[0].pageX-f.left):Math.round(c.pageX-f.left),y:a.touch_capable?Math.round(v.changedTouches[0].pageY-f.top):Math.round(c.pageY-f.top)},time:Date.now(),target:c.target},_=Math.abs(t.position.x-w.position.x),m=Math.abs(t.position.y-w.position.y),T={startEvnt:t,endEvnt:w,direction:u.replace("swipe",""),xAmount:_,yAmount:m,duration:w.time-t.time};i=!0,o.trigger("swipe",T).trigger(u,T)}}),o.on(a.endevent,function r(p){var h="";if((o=e(p.currentTarget)).data("callee3",r),i){var c=o.data("xthreshold"),u=o.data("ythreshold"),s=void 0!==c&&!1!==c&&parseInt(c)?parseInt(c):a.swipe_h_threshold,l=void 0!==u&&!1!==u&&parseInt(u)?parseInt(u):a.swipe_v_threshold,g=o.get(0)!==window&&o.get(0)!==document?o.offset():{left:0,top:0},d=p.originalEvent,f={position:{x:a.touch_capable?d.changedTouches[0].pageX:p.pageX,y:a.touch_capable?d.changedTouches[0].pageY:p.pageY},offset:{x:a.touch_capable?Math.round(d.changedTouches[0].pageX-g.left):Math.round(p.pageX-g.left),y:a.touch_capable?Math.round(d.changedTouches[0].pageY-g.top):Math.round(p.pageY-g.top)},time:Date.now(),target:p.target};t.position.y>f.position.y&&t.position.y-f.position.y>l&&(h="swipeup"),t.position.xs&&(h="swiperight"),t.position.yl&&(h="swipedown"),t.position.x>f.position.x&&t.position.x-f.position.x>s&&(h="swipeleft");var v=Math.abs(t.position.x-f.position.x),w=Math.abs(t.position.y-f.position.y),_={startEvnt:t,endEvnt:f,direction:h.replace("swipe",""),xAmount:v,yAmount:w,duration:f.time-t.time};o.trigger("swipeend",_)}n=!1,i=!1})},remove:function(){e(this).off(a.startevent,e(this).data.callee1).off(a.moveevent,e(this).data.callee2).off(a.endevent,e(this).data.callee3)}},e.event.special.scrollstart={setup:function(){var t,o,n=this,i=e(n);function r(e,a){w(n,(t=a)?"scrollstart":"scrollend",e)}i.on(a.scrollevent,function e(a){i.data("callee",e),t||r(a,!0),clearTimeout(o),o=setTimeout(function(){r(a,!1)},50)})},remove:function(){e(this).off(a.scrollevent,e(this).data.callee)}};var o,n,i,r,p=e(window),h={0:!0,180:!0};if(a.orientation_support){var c=window.innerWidth||p.width(),u=window.innerHeight||p.height();i=c>u&&c-u>50,r=h[window.orientation],(i&&r||!i&&!r)&&(h={"-90":!0,90:!0})}function s(){var e=o();e!==n&&(n=e,p.trigger("orientationchange"))}e.event.special.orientationchange={setup:function(){return!a.orientation_support&&(n=o(),p.on("throttledresize",s),!0)},teardown:function(){return!a.orientation_support&&(p.off("throttledresize",s),!0)},add:function(e){var t=e.handler;e.handler=function(e){return e.orientation=o(),t.apply(this,arguments)}}},e.event.special.orientationchange.orientation=o=function(){var e=document.documentElement;return(a.orientation_support?h[window.orientation]:e&&e.clientWidth/e.clientHeight<1.1)?"portrait":"landscape"},e.event.special.throttledresize={setup:function(){e(this).on("resize",f)},teardown:function(){e(this).off("resize",f)}};var l,g,d,f=function(){g=Date.now(),(d=g-v)>=250?(v=g,e(this).trigger("throttledresize")):(l&&window.clearTimeout(l),l=window.setTimeout(s,250-d))},v=0;function w(t,a,o,n){var i=o.type;o.type=a,e.event.dispatch.call(t,o,n),o.type=i}e.each({scrollend:"scrollstart",swipeup:"swipe",swiperight:"swipe",swipedown:"swipe",swipeleft:"swipe",swipeend:"swipe",tap2:"tap",taphold2:"taphold"},function(t,a){e.event.special[t]={setup:function(){e(this).on(a,e.noop)}}})}(jQuery);
diff --git a/src/2.0.3/jquery.mobile-events.js b/src/2.0.3/jquery.mobile-events.js
new file mode 100644
index 0000000..627afdd
--- /dev/null
+++ b/src/2.0.3/jquery.mobile-events.js
@@ -0,0 +1,940 @@
+/*!
+ * jQuery Mobile Events
+ * by Ben Major
+ *
+ * Copyright 2011-2019, Ben Major
+ * Licensed under the MIT License:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+"use strict";
+
+(function ($) {
+ $.attrFn = $.attrFn || {};
+
+ var touchCapable = ('ontouchstart' in window),
+
+ settings = {
+ tap_pixel_range: 5,
+ swipe_h_threshold: 50,
+ swipe_v_threshold: 50,
+ taphold_threshold: 750,
+ doubletap_int: 500,
+ shake_threshold: 15,
+
+ touch_capable: touchCapable,
+ orientation_support: ('orientation' in window && 'onorientationchange' in window),
+
+ startevent: (touchCapable) ? 'touchstart' : 'mousedown',
+ endevent: (touchCapable) ? 'touchend' : 'mouseup',
+ moveevent: (touchCapable) ? 'touchmove' : 'mousemove',
+ tapevent: (touchCapable) ? 'tap' : 'click',
+ scrollevent: (touchCapable) ? 'touchmove' : 'scroll',
+
+ hold_timer: null,
+ tap_timer: null
+ };
+
+ // Declare touch namespace:
+ $.touch = { };
+
+ // Convenience functions:
+ $.isTouchCapable = function() { return settings.touch_capable; };
+ $.getStartEvent = function() { return settings.startevent; };
+ $.getEndEvent = function() { return settings.endevent; };
+ $.getMoveEvent = function() { return settings.moveevent; };
+ $.getTapEvent = function() { return settings.tapevent; };
+ $.getScrollEvent = function() { return settings.scrollevent; };
+
+ // SETTERS:
+ // Set the X threshold of swipe events:
+ $.touch.setSwipeThresholdX = function( threshold ) {
+ if( typeof threshold !== 'number' ) { throw new Error('Threshold parameter must be a type of number'); }
+ settings.swipe_h_threshold = threshold;
+ };
+
+ // Set the Y threshold of swipe events:
+ $.touch.setSwipeThresholdY = function( threshold ) {
+ if( typeof threshold !== 'number' ) { throw new Error('Threshold parameter must be a type of number'); }
+ settings.swipe_v_threshold = threshold;
+ };
+
+ // Set the double tap interval:
+ $.touch.setDoubleTapInt = function( interval ) {
+ if( typeof interval !== 'number' ) { throw new Error('Interval parameter must be a type of number'); }
+ settings.doubletap_int = interval;
+ };
+
+ // Set the taphold threshold:
+ $.touch.setTapHoldThreshold = function( threshold ) {
+ if( typeof threshold !== 'number' ) { throw new Error('Threshold parameter must be a type of number'); }
+ settings.taphold_threshold = threshold;
+ };
+
+ // Set the pixel range for tapas:
+ $.touch.setTapRange = function( range ) {
+ if( typeof range !== 'number' ) { throw new Error('Ranger parameter must be a type of number'); }
+ settings.tap_pixel_range = threshold;
+ };
+
+ // Add Event shortcuts:
+ $.each(['tapstart', 'tapend', 'tapmove', 'tap', 'singletap', 'doubletap', 'taphold', 'swipe', 'swipeup', 'swiperight', 'swipedown', 'swipeleft', 'swipeend', 'scrollstart', 'scrollend', 'orientationchange', 'tap2', 'taphold2'], function (i, name) {
+ $.fn[name] = function (fn) {
+ return fn ? this.on(name, fn) : this.trigger(name);
+ };
+
+ $.attrFn[name] = true;
+ });
+
+ // tapstart Event:
+ $.event.special.tapstart = {
+ setup: function () {
+
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.startevent, function tapStartFunc(e) {
+
+ $this.data('callee', tapStartFunc);
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapstart', e, touchData);
+ return true;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee);
+ }
+ };
+
+ // tapmove Event:
+ $.event.special.tapmove = {
+ setup: function() {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.moveevent, function tapMoveFunc(e) {
+ $this.data('callee', tapMoveFunc);
+
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
+ var origEvent = e.originalEvent,
+ touchData = {
+ 'position': {
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ triggerCustomEvent(thisObject, 'tapmove', e, touchData);
+ return true;
+ });
+ },
+ remove: function() {
+ $(this).off(settings.moveevent, $(this).data.callee);
+ }
+ };
+
+ // tapend Event:
+ $.event.special.tapend = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.endevent, function tapEndFunc(e) {
+ // Touch event data:
+ $this.data('callee', tapEndFunc);
+
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ triggerCustomEvent(thisObject, 'tapend', e, touchData);
+ return true;
+ });
+ },
+ remove: function () {
+ $(this).off(settings.endevent, $(this).data.callee);
+ }
+ };
+
+ // taphold Event:
+ $.event.special.taphold = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ end_x = 0,
+ end_y = 0;
+
+ $this.on(settings.startevent, function tapHoldFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ $this.data('tapheld', false);
+ origTarget = e.target;
+
+ var origEvent = e.originalEvent;
+ var start_time = Date.now(),
+ startPosition = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
+ },
+ startOffset = {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ };
+
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ end_x = start_pos.x;
+ end_y = start_pos.y;
+
+ // Get the element's threshold:
+ var ele_threshold = ($this.parent().data('threshold')) ? $this.parent().data('threshold') : $this.data('threshold'),
+ threshold = (typeof ele_threshold !== 'undefined' && ele_threshold !== false && parseInt(ele_threshold)) ? parseInt(ele_threshold) : settings.taphold_threshold;
+
+ $this.data('hold_timer', window.setTimeout(function () {
+
+ var diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y);
+
+ if (e.target == origTarget && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ $this.data('tapheld', true);
+
+ var end_time = Date.now();
+
+ var duration = end_time - start_time,
+ touches = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches : [ e ],
+ touchData = [ ];
+
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
+ for( var i = 0; i < touches.length; i++)
+ {
+ var touch = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[i].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[i].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageY - offset.top) : Math.round(e.pageY - offset.top)
+ },
+ 'time': Date.now(),
+ 'target': e.target,
+ 'duration': duration
+ };
+
+ touchData.push( touch );
+ }
+
+ var evt_name = ( touches.length == 2 ) ? 'taphold2' : 'taphold';
+
+ $this.data('callee1', tapHoldFunc1);
+
+ triggerCustomEvent(thisObject, evt_name, e, touchData);
+ }
+ }, threshold) );
+
+ return true;
+ }
+ }).on(settings.endevent, function tapHoldFunc2() {
+ $this.data('callee2', tapHoldFunc2);
+ $this.data('tapheld', false);
+ window.clearTimeout( $this.data('hold_timer') );
+ })
+ .on(settings.moveevent, function tapHoldFunc3(e) {
+ $this.data('callee3', tapHoldFunc3);
+
+ end_x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2).off(settings.moveevent, $(this).data.callee3);
+ }
+ };
+
+ // doubletap Event:
+ $.event.special.doubletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget,
+ action,
+ firstTap = null,
+ origEvent,
+ cooloff,
+ cooling = false;
+
+ $this.on(settings.startevent, function doubleTapFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ }
+
+ $this.data('doubletapped', false);
+ origTarget = e.target;
+ $this.data('callee1', doubleTapFunc1);
+
+ origEvent = e.originalEvent;
+ if (!firstTap) {
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
+ firstTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
+ },
+ 'time': Date.now(),
+ 'target': e.target,
+ 'element': e.originalEvent.srcElement,
+ 'index': $(e.target).index()
+ };
+ }
+
+ return true;
+ }).on(settings.endevent, function doubleTapFunc2(e) {
+
+ var now = Date.now();
+ var lastTouch = $this.data('lastTouch') || now + 1;
+ var delta = now - lastTouch;
+ window.clearTimeout(action);
+ $this.data('callee2', doubleTapFunc2);
+
+ if (delta < settings.doubletap_int && ($(e.target).index() == firstTap.index) && delta > 100) {
+ $this.data('doubletapped', true);
+ window.clearTimeout(settings.tap_timer);
+
+ // Now get the current event:
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
+ var lastTap = {
+ 'position': {
+ 'x': (settings.touch_capable) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? e.originalEvent.changedTouches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
+ },
+ 'time': Date.now(),
+ 'target': e.target,
+ 'element': e.originalEvent.srcElement,
+ 'index': $(e.target).index()
+ };
+
+ var touchData = {
+ 'firstTap': firstTap,
+ 'secondTap': lastTap,
+ 'interval': lastTap.time - firstTap.time
+ };
+
+ if (!cooling) {
+ triggerCustomEvent(thisObject, 'doubletap', e, touchData);
+ firstTap = null;
+ }
+
+ cooling = true;
+
+ cooloff = window.setTimeout(function () {
+ cooling = false;
+ }, settings.doubletap_int);
+
+ } else {
+ $this.data('lastTouch', now);
+ action = window.setTimeout(function () {
+ firstTap = null;
+ window.clearTimeout(action);
+ }, settings.doubletap_int, [e]);
+ }
+ $this.data('lastTouch', now);
+ });
+ },
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // singletap Event:
+ // This is used in conjuction with doubletap when both events are needed on the same element
+ $.event.special.singletap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ origTarget = null,
+ startTime = null,
+ start_pos = {
+ x: 0,
+ y: 0
+ };
+
+ $this.on(settings.startevent, function singleTapFunc1(e) {
+ if (e.which && e.which !== 1) {
+ return false;
+ } else {
+ startTime = Date.now();
+ origTarget = e.target;
+ $this.data('callee1', singleTapFunc1);
+
+ // Get the start x and y position:
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ return true;
+ }
+ }).on(settings.endevent, function singleTapFunc2(e) {
+ $this.data('callee2', singleTapFunc2);
+ if (e.target == origTarget) {
+
+ // Get the end point:
+ var end_pos_x = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ end_pos_y = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY;
+
+ // We need to check if it was a taphold:
+
+ settings.tap_timer = window.setTimeout(function () {
+
+ var diff_x = (start_pos.x - end_pos_x), diff_y = (start_pos.y - end_pos_y);
+
+ if(!$this.data('doubletapped') && !$this.data('tapheld') && (((start_pos.x == end_pos_x) && (start_pos.y == end_pos_y)) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
+ var origEvent = e.originalEvent;
+ var touchData = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Was it a taphold?
+ if((touchData.time - startTime) < settings.taphold_threshold)
+ {
+ triggerCustomEvent(thisObject, 'singletap', e, touchData);
+ }
+ }
+ }, settings.doubletap_int);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // tap Event:
+ $.event.special.tap = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ origTarget = null,
+ start_time,
+ start_pos = {
+ x: 0,
+ y: 0
+ },
+ touches;
+
+ $this.on(settings.startevent, function tapFunc1(e) {
+ $this.data('callee1', tapFunc1);
+
+ if( e.which && e.which !== 1 )
+ {
+ return false;
+ }
+ else
+ {
+ started = true;
+ start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ start_time = Date.now();
+ origTarget = e.target;
+
+ touches = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches : [ e ];
+ return true;
+ }
+ }).on(settings.endevent, function tapFunc2(e) {
+ $this.data('callee2', tapFunc2);
+
+ // Only trigger if they've started, and the target matches:
+ var end_x = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY,
+ diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y),
+ eventName;
+
+ if (origTarget == e.target && started && ((Date.now() - start_time) < settings.taphold_threshold) && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
+ var origEvent = e.originalEvent;
+ var touchData = [ ];
+
+ for( var i = 0; i < touches.length; i++)
+ {
+ var touch = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[i].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[i].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageY - offset.top) : Math.round(e.pageY - offset.top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ touchData.push( touch );
+ }
+
+ var evt_name = ( touches.length == 2 ) ? 'tap2' : 'tap';
+
+ triggerCustomEvent(thisObject, evt_name, e, touchData);
+ }
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ }
+ };
+
+ // swipe Event (also handles swipeup, swiperight, swipedown and swipeleft):
+ $.event.special.swipe = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ started = false,
+ hasSwiped = false,
+ originalCoord = {
+ x: 0,
+ y: 0
+ },
+ finalCoord = {
+ x: 0,
+ y: 0
+ },
+ startEvnt;
+
+ // Screen touched, store the original coordinate
+
+ function touchStart(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee1', touchStart);
+ originalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ originalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ finalCoord.x = originalCoord.x;
+ finalCoord.y = originalCoord.y;
+ started = true;
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
+ var origEvent = e.originalEvent;
+ // Read event data into our startEvt:
+ startEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+ }
+
+ // Store coordinates as finger is swiping
+
+ function touchMove(e) {
+ $this = $(e.currentTarget);
+ $this.data('callee2', touchMove);
+ finalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ finalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
+ var swipedir;
+
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = ($this.parent().data('xthreshold')) ? $this.parent().data('xthreshold') : $this.data('xthreshold'),
+ ele_y_threshold = ($this.parent().data('ythreshold')) ? $this.parent().data('ythreshold') : $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ if (Math.abs(finalCoord.x - originalCoord.x) > Math.abs(finalCoord.y - originalCoord.y)) {
+ if (originalCoord.x < finalCoord.x && (finalCoord.x - originalCoord.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (originalCoord.x > finalCoord.x && (originalCoord.x - finalCoord.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+ }
+ else {
+ if (originalCoord.y > finalCoord.y && (originalCoord.y - finalCoord.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (originalCoord.y < finalCoord.y && (finalCoord.y - originalCoord.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ }
+
+ if (swipedir != undefined && started) {
+ originalCoord.x = 0;
+ originalCoord.y = 0;
+ finalCoord.x = 0;
+ finalCoord.y = 0;
+ started = false;
+
+ // Read event data into our endEvnt:
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
+ var origEvent = e.originalEvent;
+ var endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ };
+ hasSwiped = true;
+ $this.trigger('swipe', touchData).trigger(swipedir, touchData);
+ }
+ }
+
+ function touchEnd(e) {
+ $this = $(e.currentTarget);
+ var swipedir = "";
+ $this.data('callee3', touchEnd);
+ if (hasSwiped) {
+ // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
+ var ele_x_threshold = $this.data('xthreshold'),
+ ele_y_threshold = $this.data('ythreshold'),
+ h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
+ var origEvent = e.originalEvent;
+ var endEvnt = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ // Calculate the swipe amount (normalized):
+ var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
+ yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+
+ // Read event data into our endEvnt:
+ if (xAmount > yAmount) {
+ if (startEvnt.position.x < endEvnt.position.x && (endEvnt.position.x - startEvnt.position.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (startEvnt.position.x > endEvnt.position.x && (startEvnt.position.x - endEvnt.position.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+ }
+ else {
+ if (startEvnt.position.y > endEvnt.position.y && (startEvnt.position.y - endEvnt.position.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (startEvnt.position.y < endEvnt.position.y && (endEvnt.position.y - startEvnt.position.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ }
+
+ var touchData = {
+ 'startEvnt': startEvnt,
+ 'endEvnt': endEvnt,
+ 'direction': swipedir.replace('swipe', ''),
+ 'xAmount': xAmount,
+ 'yAmount': yAmount,
+ 'duration': endEvnt.time - startEvnt.time
+ };
+ $this.trigger('swipeend', touchData);
+ }
+
+ started = false;
+ hasSwiped = false;
+ }
+
+ $this.on(settings.startevent, touchStart);
+ $this.on(settings.moveevent, touchMove);
+ $this.on(settings.endevent, touchEnd);
+ },
+
+ remove: function () {
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.moveevent, $(this).data.callee2).off(settings.endevent, $(this).data.callee3);
+ }
+ };
+
+ // scrollstart Event (also handles scrollend):
+ $.event.special.scrollstart = {
+ setup: function () {
+ var thisObject = this,
+ $this = $(thisObject),
+ scrolling,
+ timer;
+
+ function trigger(event, state) {
+ scrolling = state;
+ triggerCustomEvent(thisObject, scrolling ? 'scrollstart' : 'scrollend', event);
+ }
+
+ // iPhone triggers scroll after a small delay; use touchmove instead
+ $this.on(settings.scrollevent, function scrollFunc(event) {
+ $this.data('callee', scrollFunc);
+
+ if (!scrolling) {
+ trigger(event, true);
+ }
+
+ clearTimeout(timer);
+ timer = setTimeout(function () {
+ trigger(event, false);
+ }, 50);
+ });
+ },
+
+ remove: function () {
+ $(this).off(settings.scrollevent, $(this).data.callee);
+ }
+ };
+
+ // This is the orientation change (largely borrowed from jQuery Mobile):
+ var win = $(window),
+ special_event,
+ get_orientation,
+ last_orientation,
+ initial_orientation_is_landscape,
+ initial_orientation_is_default,
+ portrait_map = {
+ '0': true,
+ '180': true
+ };
+
+ if (settings.orientation_support) {
+ var ww = window.innerWidth || win.width(),
+ wh = window.innerHeight || win.height(),
+ landscape_threshold = 50;
+
+ initial_orientation_is_landscape = ww > wh && (ww - wh) > landscape_threshold;
+ initial_orientation_is_default = portrait_map[window.orientation];
+
+ if ((initial_orientation_is_landscape && initial_orientation_is_default) || (!initial_orientation_is_landscape && !initial_orientation_is_default)) {
+ portrait_map = {
+ '-90': true,
+ '90': true
+ };
+ }
+ }
+
+ $.event.special.orientationchange = special_event = {
+ setup: function () {
+ // If the event is supported natively, return false so that jQuery
+ // will on to the event using DOM methods.
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ // Get the current orientation to avoid initial double-triggering.
+ last_orientation = get_orientation();
+
+ win.on('throttledresize', handler);
+ return true;
+ },
+ teardown: function () {
+ if (settings.orientation_support) {
+ return false;
+ }
+
+ win.off('throttledresize', handler);
+ return true;
+ },
+ add: function (handleObj) {
+ // Save a reference to the bound event handler.
+ var old_handler = handleObj.handler;
+
+ handleObj.handler = function (event) {
+ event.orientation = get_orientation();
+ return old_handler.apply(this, arguments);
+ };
+ }
+ };
+
+ // If the event is not supported natively, this handler will be bound to
+ // the window resize event to simulate the orientationchange event.
+
+ function handler() {
+ // Get the current orientation.
+ var orientation = get_orientation();
+
+ if (orientation !== last_orientation) {
+ // The orientation has changed, so trigger the orientationchange event.
+ last_orientation = orientation;
+ win.trigger("orientationchange");
+ }
+ }
+
+ $.event.special.orientationchange.orientation = get_orientation = function () {
+ var isPortrait = true,
+ elem = document.documentElement;
+
+ if (settings.orientation_support) {
+ isPortrait = portrait_map[window.orientation];
+ } else {
+ isPortrait = elem && elem.clientWidth / elem.clientHeight < 1.1;
+ }
+
+ return isPortrait ? 'portrait' : 'landscape';
+ };
+
+ // throttle Handler:
+ $.event.special.throttledresize = {
+ setup: function () {
+ $(this).on('resize', throttle_handler);
+ },
+ teardown: function () {
+ $(this).off('resize', throttle_handler);
+ }
+ };
+
+ var throttle = 250,
+ throttle_handler = function () {
+ curr = Date.now();
+ diff = curr - lastCall;
+
+ if (diff >= throttle) {
+ lastCall = curr;
+ $(this).trigger('throttledresize');
+
+ } else {
+ if (heldCall) {
+ window.clearTimeout(heldCall);
+ }
+
+ // Promise a held call will still execute
+ heldCall = window.setTimeout(handler, throttle - diff);
+ }
+ },
+ lastCall = 0,
+ heldCall,
+ curr,
+ diff;
+
+ // Trigger a custom event:
+
+ function triggerCustomEvent(obj, eventType, event, touchData) {
+ var originalType = event.type;
+ event.type = eventType;
+
+ $.event.dispatch.call(obj, event, touchData);
+ event.type = originalType;
+ }
+
+ // Correctly on anything we've overloaded:
+ $.each({
+ scrollend: 'scrollstart',
+ swipeup: 'swipe',
+ swiperight: 'swipe',
+ swipedown: 'swipe',
+ swipeleft: 'swipe',
+ swipeend: 'swipe',
+ tap2: 'tap',
+ taphold2: 'taphold'
+ }, function (e, srcE) {
+ $.event.special[e] = {
+ setup: function () {
+ $(this).on(srcE, $.noop);
+ }
+ };
+ });
+
+}(jQuery));
\ No newline at end of file
diff --git a/src/2.0.3/jquery.mobile-events.min.js b/src/2.0.3/jquery.mobile-events.min.js
new file mode 100644
index 0000000..1a8870d
--- /dev/null
+++ b/src/2.0.3/jquery.mobile-events.min.js
@@ -0,0 +1,27 @@
+/*!
+ * jQuery Mobile Events
+ * by Ben Major
+ *
+ * Copyright 2011-2019, Ben Major
+ * Licensed under the MIT License:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+"use strict";!function(e){e.attrFn=e.attrFn||{};var t="ontouchstart"in window,a={tap_pixel_range:5,swipe_h_threshold:50,swipe_v_threshold:50,taphold_threshold:750,doubletap_int:500,shake_threshold:15,touch_capable:t,orientation_support:"orientation"in window&&"onorientationchange"in window,startevent:t?"touchstart":"mousedown",endevent:t?"touchend":"mouseup",moveevent:t?"touchmove":"mousemove",tapevent:t?"tap":"click",scrollevent:t?"touchmove":"scroll",hold_timer:null,tap_timer:null};e.touch={},e.isTouchCapable=function(){return a.touch_capable},e.getStartEvent=function(){return a.startevent},e.getEndEvent=function(){return a.endevent},e.getMoveEvent=function(){return a.moveevent},e.getTapEvent=function(){return a.tapevent},e.getScrollEvent=function(){return a.scrollevent},e.touch.setSwipeThresholdX=function(e){if("number"!=typeof e)throw new Error("Threshold parameter must be a type of number");a.swipe_h_threshold=e},e.touch.setSwipeThresholdY=function(e){if("number"!=typeof e)throw new Error("Threshold parameter must be a type of number");a.swipe_v_threshold=e},e.touch.setDoubleTapInt=function(e){if("number"!=typeof e)throw new Error("Interval parameter must be a type of number");a.doubletap_int=e},e.touch.setTapHoldThreshold=function(e){if("number"!=typeof e)throw new Error("Threshold parameter must be a type of number");a.taphold_threshold=e},e.touch.setTapRange=function(e){if("number"!=typeof e)throw new Error("Ranger parameter must be a type of number");a.tap_pixel_range=threshold},e.each(["tapstart","tapend","tapmove","tap","singletap","doubletap","taphold","swipe","swipeup","swiperight","swipedown","swipeleft","swipeend","scrollstart","scrollend","orientationchange","tap2","taphold2"],function(t,a){e.fn[a]=function(e){return e?this.on(a,e):this.trigger(a)},e.attrFn[a]=!0}),e.event.special.tapstart={setup:function(){var t=this,o=e(t);o.on(a.startevent,function e(n){if(o.data("callee",e),n.which&&1!==n.which)return!1;var i=o.get(0)!==window&&o.get(0)!==document?o.offset():{left:0,top:0},r=n.originalEvent,p={position:{x:a.touch_capable?r.touches[0].pageX:n.pageX,y:a.touch_capable?r.touches[0].pageY:n.pageY},offset:{x:a.touch_capable?Math.round(r.changedTouches[0].pageX-i.left):Math.round(n.pageX-i.left),y:a.touch_capable?Math.round(r.changedTouches[0].pageY-i.top):Math.round(n.pageY-i.top)},time:Date.now(),target:n.target};return w(t,"tapstart",n,p),!0})},remove:function(){e(this).off(a.startevent,e(this).data.callee)}},e.event.special.tapmove={setup:function(){var t=this,o=e(t);o.on(a.moveevent,function e(n){o.data("callee",e);var i=o.get(0)!==window&&o.get(0)!==document?o.offset():{left:0,top:0},r=n.originalEvent,p={position:{x:a.touch_capable?r.touches[0].pageX:n.pageX,y:a.touch_capable?r.touches[0].pageY:n.pageY},offset:{x:a.touch_capable?Math.round(r.changedTouches[0].pageX-i.left):Math.round(n.pageX-i.left),y:a.touch_capable?Math.round(r.changedTouches[0].pageY-i.top):Math.round(n.pageY-i.top)},time:Date.now(),target:n.target};return w(t,"tapmove",n,p),!0})},remove:function(){e(this).off(a.moveevent,e(this).data.callee)}},e.event.special.tapend={setup:function(){var t=this,o=e(t);o.on(a.endevent,function e(n){o.data("callee",e);var i=o.get(0)!==window&&o.get(0)!==document?o.offset():{left:0,top:0},r=n.originalEvent,p={position:{x:a.touch_capable?r.changedTouches[0].pageX:n.pageX,y:a.touch_capable?r.changedTouches[0].pageY:n.pageY},offset:{x:a.touch_capable?Math.round(r.changedTouches[0].pageX-i.left):Math.round(n.pageX-i.left),y:a.touch_capable?Math.round(r.changedTouches[0].pageY-i.top):Math.round(n.pageY-i.top)},time:Date.now(),target:n.target};return w(t,"tapend",n,p),!0})},remove:function(){e(this).off(a.endevent,e(this).data.callee)}},e.event.special.taphold={setup:function(){var t,o=this,n=e(o),i={x:0,y:0},r=0,p=0;n.on(a.startevent,function e(h){if(h.which&&1!==h.which)return!1;n.data("tapheld",!1),t=h.target;var c=h.originalEvent,s=Date.now();a.touch_capable?c.touches[0].pageX:h.pageX,a.touch_capable?c.touches[0].pageY:h.pageY,a.touch_capable?(c.touches[0].pageX,c.touches[0].target.offsetLeft):h.offsetX,a.touch_capable?(c.touches[0].pageY,c.touches[0].target.offsetTop):h.offsetY;i.x=h.originalEvent.targetTouches?h.originalEvent.targetTouches[0].pageX:h.pageX,i.y=h.originalEvent.targetTouches?h.originalEvent.targetTouches[0].pageY:h.pageY,r=i.x,p=i.y;var u=n.parent().data("threshold")?n.parent().data("threshold"):n.data("threshold"),l=void 0!==u&&!1!==u&&parseInt(u)?parseInt(u):a.taphold_threshold;return n.data("hold_timer",window.setTimeout(function(){var u=i.x-r,l=i.y-p;if(h.target==t&&(i.x==r&&i.y==p||u>=-a.tap_pixel_range&&u<=a.tap_pixel_range&&l>=-a.tap_pixel_range&&l<=a.tap_pixel_range)){n.data("tapheld",!0);for(var g=Date.now()-s,d=h.originalEvent.targetTouches?h.originalEvent.targetTouches:[h],f=[],v=n.get(0)!==window&&n.get(0)!==document?n.offset():{left:0,top:0},_=0;_100){i.data("doubletapped",!0),window.clearTimeout(a.tap_timer);var l=i.get(0)!==window&&i.get(0)!==document?i.offset():{left:0,top:0},g={position:{x:a.touch_capable?c.originalEvent.changedTouches[0].pageX:c.pageX,y:a.touch_capable?c.originalEvent.changedTouches[0].pageY:c.pageY},offset:{x:a.touch_capable?Math.round(o.changedTouches[0].pageX-l.left):Math.round(c.pageX-l.left),y:a.touch_capable?Math.round(o.changedTouches[0].pageY-l.top):Math.round(c.pageY-l.top)},time:Date.now(),target:c.target,element:c.originalEvent.srcElement,index:e(c.target).index()},d={firstTap:r,secondTap:g,interval:g.time-r.time};p||(w(n,"doubletap",c,d),r=null),p=!0,window.setTimeout(function(){p=!1},a.doubletap_int)}else i.data("lastTouch",s),t=window.setTimeout(function(){r=null,window.clearTimeout(t)},a.doubletap_int,[c]);i.data("lastTouch",s)})},remove:function(){e(this).off(a.startevent,e(this).data.callee1).off(a.endevent,e(this).data.callee2)}},e.event.special.singletap={setup:function(){var t=this,o=e(t),n=null,i=null,r={x:0,y:0};o.on(a.startevent,function e(t){return(!t.which||1===t.which)&&(i=Date.now(),n=t.target,o.data("callee1",e),r.x=t.originalEvent.targetTouches?t.originalEvent.targetTouches[0].pageX:t.pageX,r.y=t.originalEvent.targetTouches?t.originalEvent.targetTouches[0].pageY:t.pageY,!0)}).on(a.endevent,function e(p){if(o.data("callee2",e),p.target==n){var h=p.originalEvent.changedTouches?p.originalEvent.changedTouches[0].pageX:p.pageX,c=p.originalEvent.changedTouches?p.originalEvent.changedTouches[0].pageY:p.pageY;a.tap_timer=window.setTimeout(function(){var e=r.x-h,n=r.y-c;if(!o.data("doubletapped")&&!o.data("tapheld")&&(r.x==h&&r.y==c||e>=-a.tap_pixel_range&&e<=a.tap_pixel_range&&n>=-a.tap_pixel_range&&n<=a.tap_pixel_range)){var s=o.get(0)!==window&&o.get(0)!==document?o.offset():{left:0,top:0},u=p.originalEvent,l={position:{x:a.touch_capable?u.changedTouches[0].pageX:p.pageX,y:a.touch_capable?u.changedTouches[0].pageY:p.pageY},offset:{x:a.touch_capable?Math.round(u.changedTouches[0].pageX-s.left):Math.round(p.pageX-s.left),y:a.touch_capable?Math.round(u.changedTouches[0].pageY-s.top):Math.round(p.pageY-s.top)},time:Date.now(),target:p.target};l.time-i=-a.tap_pixel_range&&l<=a.tap_pixel_range&&g>=-a.tap_pixel_range&&g<=a.tap_pixel_range)){for(var d=i.get(0)!==window&&i.get(0)!==document?i.offset():{left:0,top:0},f=c.originalEvent,v=[],_=0;_Math.abs(p.y-r.y)?(r.xg&&(s="swiperight"),r.x>p.x&&r.x-p.x>g&&(s="swipeleft")):(r.y>p.y&&r.y-p.y>d&&(s="swipeup"),r.yd&&(s="swipedown")),null!=s&&n){r.x=0,r.y=0,p.x=0,p.y=0,n=!1;var f=o.get(0)!==window&&o.get(0)!==document?o.offset():{left:0,top:0},v=c.originalEvent,w={position:{x:a.touch_capable?v.touches[0].pageX:c.pageX,y:a.touch_capable?v.touches[0].pageY:c.pageY},offset:{x:a.touch_capable?Math.round(v.changedTouches[0].pageX-f.left):Math.round(c.pageX-f.left),y:a.touch_capable?Math.round(v.changedTouches[0].pageY-f.top):Math.round(c.pageY-f.top)},time:Date.now(),target:c.target},_=Math.abs(t.position.x-w.position.x),m=Math.abs(t.position.y-w.position.y),T={startEvnt:t,endEvnt:w,direction:s.replace("swipe",""),xAmount:_,yAmount:m,duration:w.time-t.time};i=!0,o.trigger("swipe",T).trigger(s,T)}}),o.on(a.endevent,function r(p){var h="";if((o=e(p.currentTarget)).data("callee3",r),i){var c=o.data("xthreshold"),s=o.data("ythreshold"),u=void 0!==c&&!1!==c&&parseInt(c)?parseInt(c):a.swipe_h_threshold,l=void 0!==s&&!1!==s&&parseInt(s)?parseInt(s):a.swipe_v_threshold,g=o.get(0)!==window&&o.get(0)!==document?o.offset():{left:0,top:0},d=p.originalEvent,f={position:{x:a.touch_capable?d.changedTouches[0].pageX:p.pageX,y:a.touch_capable?d.changedTouches[0].pageY:p.pageY},offset:{x:a.touch_capable?Math.round(d.changedTouches[0].pageX-g.left):Math.round(p.pageX-g.left),y:a.touch_capable?Math.round(d.changedTouches[0].pageY-g.top):Math.round(p.pageY-g.top)},time:Date.now(),target:p.target},v=Math.abs(t.position.x-f.position.x),w=Math.abs(t.position.y-f.position.y);v>w?(t.position.xu&&(h="swiperight"),t.position.x>f.position.x&&t.position.x-f.position.x>u&&(h="swipeleft")):(t.position.y>f.position.y&&t.position.y-f.position.y>l&&(h="swipeup"),t.position.yl&&(h="swipedown"));var _={startEvnt:t,endEvnt:f,direction:h.replace("swipe",""),xAmount:v,yAmount:w,duration:f.time-t.time};o.trigger("swipeend",_)}n=!1,i=!1})},remove:function(){e(this).off(a.startevent,e(this).data.callee1).off(a.moveevent,e(this).data.callee2).off(a.endevent,e(this).data.callee3)}},e.event.special.scrollstart={setup:function(){var t,o,n=this,i=e(n);function r(e,a){w(n,(t=a)?"scrollstart":"scrollend",e)}i.on(a.scrollevent,function e(a){i.data("callee",e),t||r(a,!0),clearTimeout(o),o=setTimeout(function(){r(a,!1)},50)})},remove:function(){e(this).off(a.scrollevent,e(this).data.callee)}};var o,n,i,r,p=e(window),h={0:!0,180:!0};if(a.orientation_support){var c=window.innerWidth||p.width(),s=window.innerHeight||p.height();i=c>s&&c-s>50,r=h[window.orientation],(i&&r||!i&&!r)&&(h={"-90":!0,90:!0})}function u(){var e=o();e!==n&&(n=e,p.trigger("orientationchange"))}e.event.special.orientationchange={setup:function(){return!a.orientation_support&&(n=o(),p.on("throttledresize",u),!0)},teardown:function(){return!a.orientation_support&&(p.off("throttledresize",u),!0)},add:function(e){var t=e.handler;e.handler=function(e){return e.orientation=o(),t.apply(this,arguments)}}},e.event.special.orientationchange.orientation=o=function(){var e=document.documentElement;return(a.orientation_support?h[window.orientation]:e&&e.clientWidth/e.clientHeight<1.1)?"portrait":"landscape"},e.event.special.throttledresize={setup:function(){e(this).on("resize",f)},teardown:function(){e(this).off("resize",f)}};var l,g,d,f=function(){g=Date.now(),(d=g-v)>=250?(v=g,e(this).trigger("throttledresize")):(l&&window.clearTimeout(l),l=window.setTimeout(u,250-d))},v=0;function w(t,a,o,n){var i=o.type;o.type=a,e.event.dispatch.call(t,o,n),o.type=i}e.each({scrollend:"scrollstart",swipeup:"swipe",swiperight:"swipe",swipedown:"swipe",swipeleft:"swipe",swipeend:"swipe",tap2:"tap",taphold2:"taphold"},function(t,a){e.event.special[t]={setup:function(){e(this).on(a,e.noop)}}})}(jQuery);
\ No newline at end of file
diff --git a/src/jquery.mobile-events.js b/src/jquery.mobile-events.js
index 9b6026e..341fce2 100644
--- a/src/jquery.mobile-events.js
+++ b/src/jquery.mobile-events.js
@@ -1,8 +1,8 @@
/*!
* jQuery Mobile Events
- * by Ben Major (www.ben-major.co.uk)
+ * by Ben Major
*
- * Copyright 2011, Ben Major
+ * Copyright 2011-2019, Ben Major
* Licensed under the MIT License:
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -24,47 +24,79 @@
* THE SOFTWARE.
*
*/
+
+"use strict";
+
(function ($) {
$.attrFn = $.attrFn || {};
- // navigator.userAgent.toLowerCase() isn't reliable for Chrome installs
- // on mobile devices. As such, we will create a boolean isChromeDesktop
- // The reason that we need to do this is because Chrome annoyingly
- // purports support for touch events even if the underlying hardware
- // does not!
- var agent = navigator.userAgent.toLowerCase(),
- isChromeDesktop = (agent.indexOf('chrome') > -1 && ((agent.indexOf('windows') > -1) || (agent.indexOf('macintosh') > -1) || (agent.indexOf('linux') > -1)) && agent.indexOf('mobile') < 0 && agent.indexOf('nexus') < 0),
-
+ var touchCapable = ('ontouchstart' in window),
+
settings = {
- tap_pixel_range: 5,
+ tap_pixel_range: 5,
swipe_h_threshold: 50,
swipe_v_threshold: 50,
taphold_threshold: 750,
doubletap_int: 500,
+ shake_threshold: 15,
- touch_capable: ('ontouchstart' in document.documentElement && !isChromeDesktop),
+ touch_capable: touchCapable,
orientation_support: ('orientation' in window && 'onorientationchange' in window),
- startevent: ('ontouchstart' in document.documentElement && !isChromeDesktop) ? 'touchstart' : 'mousedown',
- endevent: ('ontouchstart' in document.documentElement && !isChromeDesktop) ? 'touchend' : 'mouseup',
- moveevent: ('ontouchstart' in document.documentElement && !isChromeDesktop) ? 'touchmove' : 'mousemove',
- tapevent: ('ontouchstart' in document.documentElement && !isChromeDesktop) ? 'tap' : 'click',
- scrollevent: ('ontouchstart' in document.documentElement && !isChromeDesktop) ? 'touchmove' : 'scroll',
+ startevent: (touchCapable) ? 'touchstart' : 'mousedown',
+ endevent: (touchCapable) ? 'touchend' : 'mouseup',
+ moveevent: (touchCapable) ? 'touchmove' : 'mousemove',
+ tapevent: (touchCapable) ? 'tap' : 'click',
+ scrollevent: (touchCapable) ? 'touchmove' : 'scroll',
hold_timer: null,
tap_timer: null
};
+ // Declare touch namespace:
+ $.touch = { };
+
// Convenience functions:
$.isTouchCapable = function() { return settings.touch_capable; };
- $.getStartEvent = function() { return settings.startevent; };
- $.getEndEvent = function() { return settings.endevent; };
- $.getMoveEvent = function() { return settings.moveevent; };
- $.getTapEvent = function() { return settings.tapevent; };
- $.getScrollEvent = function() { return settings.scrollevent; };
+ $.getStartEvent = function() { return settings.startevent; };
+ $.getEndEvent = function() { return settings.endevent; };
+ $.getMoveEvent = function() { return settings.moveevent; };
+ $.getTapEvent = function() { return settings.tapevent; };
+ $.getScrollEvent = function() { return settings.scrollevent; };
+
+ // SETTERS:
+ // Set the X threshold of swipe events:
+ $.touch.setSwipeThresholdX = function( threshold ) {
+ if( typeof threshold !== 'number' ) { throw new Error('Threshold parameter must be a type of number'); }
+ settings.swipe_h_threshold = threshold;
+ };
+
+ // Set the Y threshold of swipe events:
+ $.touch.setSwipeThresholdY = function( threshold ) {
+ if( typeof threshold !== 'number' ) { throw new Error('Threshold parameter must be a type of number'); }
+ settings.swipe_v_threshold = threshold;
+ };
+
+ // Set the double tap interval:
+ $.touch.setDoubleTapInt = function( interval ) {
+ if( typeof interval !== 'number' ) { throw new Error('Interval parameter must be a type of number'); }
+ settings.doubletap_int = interval;
+ };
+
+ // Set the taphold threshold:
+ $.touch.setTapHoldThreshold = function( threshold ) {
+ if( typeof threshold !== 'number' ) { throw new Error('Threshold parameter must be a type of number'); }
+ settings.taphold_threshold = threshold;
+ };
+
+ // Set the pixel range for tapas:
+ $.touch.setTapRange = function( threshold ) {
+ if( typeof threshold !== 'number' ) { throw new Error('Ranger parameter must be a type of number'); }
+ settings.tap_pixel_range = threshold;
+ };
// Add Event shortcuts:
- $.each(['tapstart', 'tapend', 'tap', 'singletap', 'doubletap', 'taphold', 'swipe', 'swipeup', 'swiperight', 'swipedown', 'swipeleft', 'swipeend', 'scrollstart', 'scrollend', 'orientationchange'], function (i, name) {
+ $.each(['tapstart', 'tapend', 'tapmove', 'tap', 'singletap', 'doubletap', 'taphold', 'swipe', 'swipeup', 'swiperight', 'swipedown', 'swipeleft', 'swipeend', 'scrollstart', 'scrollend', 'orientationchange', 'tap2', 'taphold2'], function (i, name) {
$.fn[name] = function (fn) {
return fn ? this.on(name, fn) : this.trigger(name);
};
@@ -75,29 +107,32 @@
// tapstart Event:
$.event.special.tapstart = {
setup: function () {
+
var thisObject = this,
$this = $(thisObject);
-
- $this.on(settings.startevent, function (e) {
- $this.data('callee', arguments.callee);
+
+ $this.on(settings.startevent, function tapStartFunc(e) {
+
+ $this.data('callee', tapStartFunc);
if (e.which && e.which !== 1) {
return false;
}
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
var origEvent = e.originalEvent,
touchData = {
'position': {
- 'x': ((settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX),
- 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY,
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
},
'offset': {
- 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
- 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY,
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
},
- 'time': new Date().getTime(),
+ 'time': Date.now(),
'target': e.target
};
-
+
triggerCustomEvent(thisObject, 'tapstart', e, touchData);
return true;
});
@@ -107,38 +142,39 @@
$(this).off(settings.startevent, $(this).data.callee);
}
};
-
- // tapmove Event:
- $.event.special.tapmove = {
- setup: function() {
- var thisObject = this,
- $this = $(thisObject);
-
- $this.on(settings.moveevent, function(e) {
- $this.data('callee', arguments.callee);
-
- var origEvent = e.originalEvent,
- touchData = {
+
+ // tapmove Event:
+ $.event.special.tapmove = {
+ setup: function() {
+ var thisObject = this,
+ $this = $(thisObject);
+
+ $this.on(settings.moveevent, function tapMoveFunc(e) {
+ $this.data('callee', tapMoveFunc);
+
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
+ var origEvent = e.originalEvent,
+ touchData = {
'position': {
- 'x': ((settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX),
- 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY,
+ 'x': ((settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX),
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
},
'offset': {
- 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
- 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY,
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
},
- 'time': new Date().getTime(),
+ 'time': Date.now(),
'target': e.target
};
-
- triggerCustomEvent(thisObject, 'tapmove', e, touchData);
- return true;
- });
- },
- remove: function() {
- $(this).off(settings.moveevent, $(this).data.callee);
- }
- }
+
+ triggerCustomEvent(thisObject, 'tapmove', e, touchData);
+ return true;
+ });
+ },
+ remove: function() {
+ $(this).off(settings.moveevent, $(this).data.callee);
+ }
+ };
// tapend Event:
$.event.special.tapend = {
@@ -146,21 +182,22 @@
var thisObject = this,
$this = $(thisObject);
- $this.on(settings.endevent, function (e) {
+ $this.on(settings.endevent, function tapEndFunc(e) {
// Touch event data:
- $this.data('callee', arguments.callee);
+ $this.data('callee', tapEndFunc);
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
var origEvent = e.originalEvent;
var touchData = {
'position': {
- 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
- 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY : e.pageY
},
'offset': {
- 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX - origEvent.changedTouches[0].target.offsetLeft : e.offsetX,
- 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY - origEvent.changedTouches[0].target.offsetTop : e.offsetY
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
},
- 'time': new Date().getTime(),
+ 'time': Date.now(),
'target': e.target
};
triggerCustomEvent(thisObject, 'tapend', e, touchData);
@@ -178,13 +215,14 @@
var thisObject = this,
$this = $(thisObject),
origTarget,
- timer,
start_pos = {
x: 0,
y: 0
- };
+ },
+ end_x = 0,
+ end_y = 0;
- $this.on(settings.startevent, function (e) {
+ $this.on(settings.startevent, function tapHoldFunc1(e) {
if (e.which && e.which !== 1) {
return false;
} else {
@@ -192,10 +230,10 @@
origTarget = e.target;
var origEvent = e.originalEvent;
- var start_time = new Date().getTime(),
+ var start_time = Date.now(),
startPosition = {
- 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
- 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
},
startOffset = {
'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
@@ -205,52 +243,72 @@
start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
- settings.hold_timer = window.setTimeout(function () {
+ end_x = start_pos.x;
+ end_y = start_pos.y;
+
+ // Get the element's threshold:
+ var ele_threshold = ($this.parent().data('threshold')) ? $this.parent().data('threshold') : $this.data('threshold'),
+ threshold = (typeof ele_threshold !== 'undefined' && ele_threshold !== false && parseInt(ele_threshold)) ? parseInt(ele_threshold) : settings.taphold_threshold;
+
+ $this.data('hold_timer', window.setTimeout(function () {
- var end_x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX,
- end_y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+ var diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y);
- if (e.target == origTarget && (start_pos.x == end_x && start_pos.y == end_y)) {
+ if (e.target == origTarget && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
$this.data('tapheld', true);
- var end_time = new Date().getTime(),
- endPosition = {
- 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
- 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
- },
- endOffset = {
- 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
- 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ var end_time = Date.now();
+
+ var duration = end_time - start_time,
+ touches = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches : [ e ],
+ touchData = [ ];
+
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
+ for( var i = 0; i < touches.length; i++)
+ {
+ var touch = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[i].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[i].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageY - offset.top) : Math.round(e.pageY - offset.top)
+ },
+ 'time': Date.now(),
+ 'target': e.target,
+ 'duration': duration
};
- duration = end_time - start_time;
-
- // Build the touch data:
- var touchData = {
- 'startTime': start_time,
- 'endTime': end_time,
- 'startPosition': startPosition,
- 'startOffset': startOffset,
- 'endPosition': endPosition,
- 'endOffset': endOffset,
- 'duration': duration,
- 'target': e.target
+
+ touchData.push( touch );
}
- $this.data('callee1', arguments.callee);
- triggerCustomEvent(thisObject, 'taphold', e, touchData);
+
+ var evt_name = ( touches.length == 2 ) ? 'taphold2' : 'taphold';
+
+ $this.data('callee1', tapHoldFunc1);
+
+ triggerCustomEvent(thisObject, evt_name, e, touchData);
}
- }, settings.taphold_threshold);
+ }, threshold) );
return true;
}
- }).on(settings.endevent, function () {
- $this.data('callee2', arguments.callee);
+ }).on(settings.endevent, function tapHoldFunc2() {
+ $this.data('callee2', tapHoldFunc2);
$this.data('tapheld', false);
- window.clearTimeout(settings.hold_timer);
+ window.clearTimeout( $this.data('hold_timer') );
+ })
+ .on(settings.moveevent, function tapHoldFunc3(e) {
+ $this.data('callee3', tapHoldFunc3);
+
+ end_x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
});
},
remove: function () {
- $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2);
+ $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2).off(settings.moveevent, $(this).data.callee3);
}
};
@@ -261,57 +319,68 @@
$this = $(thisObject),
origTarget,
action,
- firstTap,
- origEvent;
+ firstTap = null,
+ origEvent,
+ cooloff,
+ cooling = false;
- $this.on(settings.startevent, function (e) {
+ $this.on(settings.startevent, function doubleTapFunc1(e) {
if (e.which && e.which !== 1) {
return false;
- } else if(!$this.data('lastTouch')) {
- $this.data('doubletapped', false);
- origTarget = e.target;
- $this.data('callee1', arguments.callee);
-
- origEvent = e.originalEvent;
+ }
+
+ $this.data('doubletapped', false);
+ origTarget = e.target;
+ $this.data('callee1', doubleTapFunc1);
+
+ origEvent = e.originalEvent;
+ if (!firstTap) {
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
firstTap = {
'position': {
- 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
- 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
},
'offset': {
- 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
- 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
},
- 'time': new Date().getTime(),
- 'target': e.target
+ 'time': Date.now(),
+ 'target': e.target,
+ 'element': e.originalEvent.srcElement,
+ 'index': $(e.target).index()
};
-
- return true;
}
- }).on(settings.endevent, function (e) {
- var now = new Date().getTime();
+
+ return true;
+ }).on(settings.endevent, function doubleTapFunc2(e) {
+
+ var now = Date.now();
var lastTouch = $this.data('lastTouch') || now + 1;
var delta = now - lastTouch;
window.clearTimeout(action);
- $this.data('callee2', arguments.callee);
+ $this.data('callee2', doubleTapFunc2);
- if (delta < settings.doubletap_int && delta > 0 && (e.target == origTarget) && delta > 100) {
+ if (delta < settings.doubletap_int && ($(e.target).index() == firstTap.index) && delta > 100) {
$this.data('doubletapped', true);
window.clearTimeout(settings.tap_timer);
// Now get the current event:
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
var lastTap = {
'position': {
- 'x': (settings.touch_capable) ? e.originalEvent.changedTouches[0].screenX : e.screenX,
- 'y': (settings.touch_capable) ? e.originalEvent.changedTouches[0].screenY : e.screenY
+ 'x': (settings.touch_capable) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? e.originalEvent.changedTouches[0].pageY : e.pageY
},
'offset': {
- 'x': (settings.touch_capable) ? e.originalEvent.changedTouches[0].pageX - e.originalEvent.changedTouches[0].target.offsetLeft : e.offsetX,
- 'y': (settings.touch_capable) ? e.originalEvent.changedTouches[0].pageY - e.originalEvent.changedTouches[0].target.offsetTop : e.offsetY
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
},
- 'time': new Date().getTime(),
- 'target': e.target
- }
+ 'time': Date.now(),
+ 'target': e.target,
+ 'element': e.originalEvent.srcElement,
+ 'index': $(e.target).index()
+ };
var touchData = {
'firstTap': firstTap,
@@ -319,10 +388,21 @@
'interval': lastTap.time - firstTap.time
};
- triggerCustomEvent(thisObject, 'doubletap', e, touchData);
+ if (!cooling) {
+ triggerCustomEvent(thisObject, 'doubletap', e, touchData);
+ firstTap = null;
+ }
+
+ cooling = true;
+
+ cooloff = window.setTimeout(function () {
+ cooling = false;
+ }, settings.doubletap_int);
+
} else {
$this.data('lastTouch', now);
- action = window.setTimeout(function (e) {
+ action = window.setTimeout(function () {
+ firstTap = null;
window.clearTimeout(action);
}, settings.doubletap_int, [e]);
}
@@ -347,41 +427,48 @@
y: 0
};
- $this.on(settings.startevent, function (e) {
+ $this.on(settings.startevent, function singleTapFunc1(e) {
if (e.which && e.which !== 1) {
return false;
} else {
- startTime = new Date().getTime();
+ startTime = Date.now();
origTarget = e.target;
- $this.data('callee1', arguments.callee);
+ $this.data('callee1', singleTapFunc1);
// Get the start x and y position:
start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
+
return true;
}
- }).on(settings.endevent, function (e) {
- $this.data('callee2', arguments.callee);
+ }).on(settings.endevent, function singleTapFunc2(e) {
+ $this.data('callee2', singleTapFunc2);
if (e.target == origTarget) {
+
// Get the end point:
- end_pos_x = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX;
- end_pos_y = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY;
+ var end_pos_x = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
+ end_pos_y = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY;
// We need to check if it was a taphold:
settings.tap_timer = window.setTimeout(function () {
- if (!$this.data('doubletapped') && !$this.data('tapheld') && (start_pos.x == end_pos_x) && (start_pos.y == end_pos_y)) {
+
+ var diff_x = (start_pos.x - end_pos_x), diff_y = (start_pos.y - end_pos_y);
+
+ if(!$this.data('doubletapped') && !$this.data('tapheld') && (((start_pos.x == end_pos_x) && (start_pos.y == end_pos_y)) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
var origEvent = e.originalEvent;
var touchData = {
'position': {
- 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
- 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY,
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY : e.pageY
},
'offset': {
- 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX - origEvent.changedTouches[0].target.offsetLeft : e.offsetX,
- 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY - origEvent.changedTouches[0].target.offsetTop : e.offsetY,
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
},
- 'time': new Date().getTime(),
+ 'time': Date.now(),
'target': e.target
};
@@ -412,46 +499,63 @@
start_pos = {
x: 0,
y: 0
- };
+ },
+ touches;
- $this.on(settings.startevent, function (e) {
- $this.data('callee1', arguments.callee);
+ $this.on(settings.startevent, function tapFunc1(e) {
+ $this.data('callee1', tapFunc1);
- if (e.which && e.which !== 1) {
+ if( e.which && e.which !== 1 )
+ {
return false;
- } else {
+ }
+ else
+ {
started = true;
start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
- start_time = new Date().getTime();
+ start_time = Date.now();
origTarget = e.target;
+
+ touches = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches : [ e ];
return true;
}
- }).on(settings.endevent, function (e) {
- $this.data('callee2', arguments.callee);
+ }).on(settings.endevent, function tapFunc2(e) {
+ $this.data('callee2', tapFunc2);
// Only trigger if they've started, and the target matches:
var end_x = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
- end_y = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY;
- diff_x = (start_pos.x - end_x),
- diff_y = (start_pos.y - end_y);
-
- if (origTarget == e.target && started && ((new Date().getTime() - start_time) < settings.taphold_threshold) && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ end_y = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY,
+ diff_x = (start_pos.x - end_x),
+ diff_y = (start_pos.y - end_y),
+ eventName;
+
+ if (origTarget == e.target && started && ((Date.now() - start_time) < settings.taphold_threshold) && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) {
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
var origEvent = e.originalEvent;
- var touchData = {
- 'position': {
- 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
- 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY,
- },
- 'offset': {
- 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX - origEvent.changedTouches[0].target.offsetLeft : e.offsetX,
- 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY - origEvent.changedTouches[0].target.offsetTop : e.offsetY,
- },
- 'time': new Date().getTime(),
- 'target': e.target
- };
-
- triggerCustomEvent(thisObject, 'tap', e, touchData);
+ var touchData = [ ];
+
+ for( var i = 0; i < touches.length; i++)
+ {
+ var touch = {
+ 'position': {
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[i].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[i].pageY : e.pageY
+ },
+ 'offset': {
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[i].pageY - offset.top) : Math.round(e.pageY - offset.top)
+ },
+ 'time': Date.now(),
+ 'target': e.target
+ };
+
+ touchData.push( touch );
+ }
+
+ var evt_name = ( touches.length == 2 ) ? 'tap2' : 'tap';
+
+ triggerCustomEvent(thisObject, evt_name, e, touchData);
}
});
},
@@ -481,63 +585,63 @@
// Screen touched, store the original coordinate
function touchStart(e) {
- $this = $(e.target);
- $this.data('callee1', arguments.callee);
+ $this = $(e.currentTarget);
+ $this.data('callee1', touchStart);
originalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
originalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
finalCoord.x = originalCoord.x;
finalCoord.y = originalCoord.y;
started = true;
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
var origEvent = e.originalEvent;
// Read event data into our startEvt:
startEvnt = {
'position': {
- 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
- 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY,
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
},
'offset': {
- 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
- 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY,
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
},
- 'time': new Date().getTime(),
+ 'time': Date.now(),
'target': e.target
};
-
- // For some reason, we need to add a 100ms pause in order to trigger swiping
- // on Playbooks:
- var dt = new Date();
- while ((new Date()) - dt < 100) {}
}
// Store coordinates as finger is swiping
function touchMove(e) {
- $this = $(e.target);
- $this.data('callee2', arguments.callee);
+ $this = $(e.currentTarget);
+ $this.data('callee2', touchMove);
finalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX;
finalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY;
- window.clearTimeout(settings.hold_timer);
var swipedir;
// We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
- var ele_x_threshold = $this.data('xthreshold'),
- ele_y_threshold = $this.data('ythreshold'),
+ var ele_x_threshold = ($this.parent().data('xthreshold')) ? $this.parent().data('xthreshold') : $this.data('xthreshold'),
+ ele_y_threshold = ($this.parent().data('ythreshold')) ? $this.parent().data('ythreshold') : $this.data('ythreshold'),
h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
- v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
-
- if (originalCoord.y > finalCoord.y && (originalCoord.y - finalCoord.y > v_threshold)) {
- swipedir = 'swipeup';
- }
- if (originalCoord.x < finalCoord.x && (finalCoord.x - originalCoord.x > h_threshold)) {
- swipedir = 'swiperight';
- }
- if (originalCoord.y < finalCoord.y && (finalCoord.y - originalCoord.y > v_threshold)) {
- swipedir = 'swipedown';
+ v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+
+ if (Math.abs(finalCoord.x - originalCoord.x) > Math.abs(finalCoord.y - originalCoord.y)) {
+ if (originalCoord.x < finalCoord.x && (finalCoord.x - originalCoord.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (originalCoord.x > finalCoord.x && (originalCoord.x - finalCoord.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
}
- if (originalCoord.x > finalCoord.x && (originalCoord.x - finalCoord.x > h_threshold)) {
- swipedir = 'swipeleft';
+ else {
+ if (originalCoord.y > finalCoord.y && (originalCoord.y - finalCoord.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (originalCoord.y < finalCoord.y && (finalCoord.y - originalCoord.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
}
+
if (swipedir != undefined && started) {
originalCoord.x = 0;
originalCoord.y = 0;
@@ -546,17 +650,18 @@
started = false;
// Read event data into our endEvnt:
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
var origEvent = e.originalEvent;
- endEvnt = {
+ var endEvnt = {
'position': {
- 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX,
- 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY,
+ 'x': (settings.touch_capable) ? origEvent.touches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.touches[0].pageY : e.pageY
},
'offset': {
- 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX,
- 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY,
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
},
- 'time': new Date().getTime(),
+ 'time': Date.now(),
'target': e.target
};
@@ -571,16 +676,16 @@
'xAmount': xAmount,
'yAmount': yAmount,
'duration': endEvnt.time - startEvnt.time
- }
+ };
hasSwiped = true;
$this.trigger('swipe', touchData).trigger(swipedir, touchData);
}
}
function touchEnd(e) {
- $this = $(e.target);
+ $this = $(e.currentTarget);
var swipedir = "";
- $this.data('callee3', arguments.callee);
+ $this.data('callee3', touchEnd);
if (hasSwiped) {
// We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold:
var ele_x_threshold = $this.data('xthreshold'),
@@ -588,38 +693,43 @@
h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold,
v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold;
+ var offset = ($this.get(0) !== window && $this.get(0) !== document) ? $this.offset() : { left: 0, top: 0 };
var origEvent = e.originalEvent;
- endEvnt = {
+ var endEvnt = {
'position': {
- 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX,
- 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY,
+ 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX : e.pageX,
+ 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY : e.pageY
},
'offset': {
- 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX - origEvent.changedTouches[0].target.offsetLeft : e.offsetX,
- 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY - origEvent.changedTouches[0].target.offsetTop : e.offsetY,
+ 'x': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageX - offset.left) : Math.round(e.pageX - offset.left),
+ 'y': (settings.touch_capable) ? Math.round(origEvent.changedTouches[0].pageY - offset.top) : Math.round(e.pageY - offset.top)
},
- 'time': new Date().getTime(),
+ 'time': Date.now(),
'target': e.target
};
- // Read event data into our endEvnt:
- if (startEvnt.position.y > endEvnt.position.y && (startEvnt.position.y - endEvnt.position.y > v_threshold)) {
- swipedir = 'swipeup';
- }
- if (startEvnt.position.x < endEvnt.position.x && (endEvnt.position.x - startEvnt.position.x > h_threshold)) {
- swipedir = 'swiperight';
- }
- if (startEvnt.position.y < endEvnt.position.y && (endEvnt.position.y - startEvnt.position.y > v_threshold)) {
- swipedir = 'swipedown';
- }
- if (startEvnt.position.x > endEvnt.position.x && (startEvnt.position.x - endEvnt.position.x > h_threshold)) {
- swipedir = 'swipeleft';
- }
-
// Calculate the swipe amount (normalized):
var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x),
yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y);
+ // Read event data into our endEvnt:
+ if (xAmount > yAmount) {
+ if (startEvnt.position.x < endEvnt.position.x && (endEvnt.position.x - startEvnt.position.x > h_threshold)) {
+ swipedir = 'swiperight';
+ }
+ if (startEvnt.position.x > endEvnt.position.x && (startEvnt.position.x - endEvnt.position.x > h_threshold)) {
+ swipedir = 'swipeleft';
+ }
+ }
+ else {
+ if (startEvnt.position.y > endEvnt.position.y && (startEvnt.position.y - endEvnt.position.y > v_threshold)) {
+ swipedir = 'swipeup';
+ }
+ if (startEvnt.position.y < endEvnt.position.y && (endEvnt.position.y - startEvnt.position.y > v_threshold)) {
+ swipedir = 'swipedown';
+ }
+ }
+
var touchData = {
'startEvnt': startEvnt,
'endEvnt': endEvnt,
@@ -627,7 +737,7 @@
'xAmount': xAmount,
'yAmount': yAmount,
'duration': endEvnt.time - startEvnt.time
- }
+ };
$this.trigger('swipeend', touchData);
}
@@ -659,8 +769,8 @@
}
// iPhone triggers scroll after a small delay; use touchmove instead
- $this.on(settings.scrollevent, function (event) {
- $this.data('callee', arguments.callee);
+ $this.on(settings.scrollevent, function scrollFunc(event) {
+ $this.data('callee', scrollFunc);
if (!scrolling) {
trigger(event, true);
@@ -691,8 +801,8 @@
};
if (settings.orientation_support) {
- var ww = window.innerWidth || $(window).width(),
- wh = window.innerHeight || $(window).height(),
+ var ww = window.innerWidth || win.width(),
+ wh = window.innerHeight || win.height(),
landscape_threshold = 50;
initial_orientation_is_landscape = ww > wh && (ww - wh) > landscape_threshold;
@@ -778,7 +888,7 @@
var throttle = 250,
throttle_handler = function () {
- curr = (new Date()).getTime();
+ curr = Date.now();
diff = curr - lastCall;
if (diff >= throttle) {
@@ -817,7 +927,9 @@
swipedown: 'swipe',
swipeleft: 'swipe',
swipeend: 'swipe',
- }, function (e, srcE, touchData) {
+ tap2: 'tap',
+ taphold2: 'taphold'
+ }, function (e, srcE) {
$.event.special[e] = {
setup: function () {
$(this).on(srcE, $.noop);
@@ -825,4 +937,4 @@
};
});
-})(jQuery);
+}(jQuery));
diff --git a/src/jquery.mobile-events.min.js b/src/jquery.mobile-events.min.js
index b8479c6..3b76e55 100644
--- a/src/jquery.mobile-events.min.js
+++ b/src/jquery.mobile-events.min.js
@@ -1 +1,27 @@
-(function(e){function d(){var e=o();if(e!==u){u=e;i.trigger("orientationchange")}}function E(t,n,r,i){var s=r.type;r.type=n;e.event.dispatch.call(t,r,i);r.type=s}e.attrFn=e.attrFn||{};var t=navigator.userAgent.toLowerCase(),n=t.indexOf("chrome")>-1&&(t.indexOf("windows")>-1||t.indexOf("macintosh")>-1||t.indexOf("linux")>-1)&&t.indexOf("mobile")<0&&t.indexOf("nexus")<0,r={tap_pixel_range:5,swipe_h_threshold:50,swipe_v_threshold:50,taphold_threshold:750,doubletap_int:500,touch_capable:"ontouchstart"in document.documentElement&&!n,orientation_support:"orientation"in window&&"onorientationchange"in window,startevent:"ontouchstart"in document.documentElement&&!n?"touchstart":"mousedown",endevent:"ontouchstart"in document.documentElement&&!n?"touchend":"mouseup",moveevent:"ontouchstart"in document.documentElement&&!n?"touchmove":"mousemove",tapevent:"ontouchstart"in document.documentElement&&!n?"tap":"click",scrollevent:"ontouchstart"in document.documentElement&&!n?"touchmove":"scroll",hold_timer:null,tap_timer:null};e.isTouchCapable=function(){return r.touch_capable};e.getStartEvent=function(){return r.startevent};e.getEndEvent=function(){return r.endevent};e.getMoveEvent=function(){return r.moveevent};e.getTapEvent=function(){return r.tapevent};e.getScrollEvent=function(){return r.scrollevent};e.each(["tapstart","tapend","tap","singletap","doubletap","taphold","swipe","swipeup","swiperight","swipedown","swipeleft","swipeend","scrollstart","scrollend","orientationchange"],function(t,n){e.fn[n]=function(e){return e?this.on(n,e):this.trigger(n)};e.attrFn[n]=true});e.event.special.tapstart={setup:function(){var t=this,n=e(t);n.on(r.startevent,function(e){n.data("callee",arguments.callee);if(e.which&&e.which!==1){return false}var i=e.originalEvent,s={position:{x:r.touch_capable?i.touches[0].screenX:e.screenX,y:r.touch_capable?i.touches[0].screenY:e.screenY},offset:{x:r.touch_capable?i.touches[0].pageX-i.touches[0].target.offsetLeft:e.offsetX,y:r.touch_capable?i.touches[0].pageY-i.touches[0].target.offsetTop:e.offsetY},time:(new Date).getTime(),target:e.target};E(t,"tapstart",e,s);return true})},remove:function(){e(this).off(r.startevent,e(this).data.callee)}};e.event.special.tapmove={setup:function(){var t=this,n=e(t);n.on(r.moveevent,function(e){n.data("callee",arguments.callee);var i=e.originalEvent,s={position:{x:r.touch_capable?i.touches[0].screenX:e.screenX,y:r.touch_capable?i.touches[0].screenY:e.screenY},offset:{x:r.touch_capable?i.touches[0].pageX-i.touches[0].target.offsetLeft:e.offsetX,y:r.touch_capable?i.touches[0].pageY-i.touches[0].target.offsetTop:e.offsetY},time:(new Date).getTime(),target:e.target};E(t,"tapmove",e,s);return true})},remove:function(){e(this).off(r.moveevent,e(this).data.callee)}};e.event.special.tapend={setup:function(){var t=this,n=e(t);n.on(r.endevent,function(e){n.data("callee",arguments.callee);var i=e.originalEvent;var s={position:{x:r.touch_capable?i.changedTouches[0].screenX:e.screenX,y:r.touch_capable?i.changedTouches[0].screenY:e.screenY},offset:{x:r.touch_capable?i.changedTouches[0].pageX-i.changedTouches[0].target.offsetLeft:e.offsetX,y:r.touch_capable?i.changedTouches[0].pageY-i.changedTouches[0].target.offsetTop:e.offsetY},time:(new Date).getTime(),target:e.target};E(t,"tapend",e,s);return true})},remove:function(){e(this).off(r.endevent,e(this).data.callee)}};e.event.special.taphold={setup:function(){var t=this,n=e(t),i,s,o={x:0,y:0};n.on(r.startevent,function(e){if(e.which&&e.which!==1){return false}else{n.data("tapheld",false);i=e.target;var s=e.originalEvent;var u=(new Date).getTime(),a={x:r.touch_capable?s.touches[0].screenX:e.screenX,y:r.touch_capable?s.touches[0].screenY:e.screenY},f={x:r.touch_capable?s.touches[0].pageX-s.touches[0].target.offsetLeft:e.offsetX,y:r.touch_capable?s.touches[0].pageY-s.touches[0].target.offsetTop:e.offsetY};o.x=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageX:e.pageX;o.y=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageY:e.pageY;r.hold_timer=window.setTimeout(function(){var l=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageX:e.pageX,c=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageY:e.pageY;if(e.target==i&&o.x==l&&o.y==c){n.data("tapheld",true);var h=(new Date).getTime(),p={x:r.touch_capable?s.touches[0].screenX:e.screenX,y:r.touch_capable?s.touches[0].screenY:e.screenY},d={x:r.touch_capable?s.touches[0].pageX-s.touches[0].target.offsetLeft:e.offsetX,y:r.touch_capable?s.touches[0].pageY-s.touches[0].target.offsetTop:e.offsetY};duration=h-u;var v={startTime:u,endTime:h,startPosition:a,startOffset:f,endPosition:p,endOffset:d,duration:duration,target:e.target};n.data("callee1",arguments.callee);E(t,"taphold",e,v)}},r.taphold_threshold);return true}}).on(r.endevent,function(){n.data("callee2",arguments.callee);n.data("tapheld",false);window.clearTimeout(r.hold_timer)})},remove:function(){e(this).off(r.startevent,e(this).data.callee1).off(r.endevent,e(this).data.callee2)}};e.event.special.doubletap={setup:function(){var t=this,n=e(t),i,s,o,u;n.on(r.startevent,function(e){if(e.which&&e.which!==1){return false}else if(!n.data("lastTouch")){n.data("doubletapped",false);i=e.target;n.data("callee1",arguments.callee);u=e.originalEvent;o={position:{x:r.touch_capable?u.touches[0].screenX:e.screenX,y:r.touch_capable?u.touches[0].screenY:e.screenY},offset:{x:r.touch_capable?u.touches[0].pageX-u.touches[0].target.offsetLeft:e.offsetX,y:r.touch_capable?u.touches[0].pageY-u.touches[0].target.offsetTop:e.offsetY},time:(new Date).getTime(),target:e.target};return true}}).on(r.endevent,function(e){var u=(new Date).getTime();var a=n.data("lastTouch")||u+1;var f=u-a;window.clearTimeout(s);n.data("callee2",arguments.callee);if(f0&&e.target==i&&f>100){n.data("doubletapped",true);window.clearTimeout(r.tap_timer);var l={position:{x:r.touch_capable?e.originalEvent.changedTouches[0].screenX:e.screenX,y:r.touch_capable?e.originalEvent.changedTouches[0].screenY:e.screenY},offset:{x:r.touch_capable?e.originalEvent.changedTouches[0].pageX-e.originalEvent.changedTouches[0].target.offsetLeft:e.offsetX,y:r.touch_capable?e.originalEvent.changedTouches[0].pageY-e.originalEvent.changedTouches[0].target.offsetTop:e.offsetY},time:(new Date).getTime(),target:e.target};var c={firstTap:o,secondTap:l,interval:l.time-o.time};E(t,"doubletap",e,c)}else{n.data("lastTouch",u);s=window.setTimeout(function(e){window.clearTimeout(s)},r.doubletap_int,[e])}n.data("lastTouch",u)})},remove:function(){e(this).off(r.startevent,e(this).data.callee1).off(r.endevent,e(this).data.callee2)}};e.event.special.singletap={setup:function(){var t=this,n=e(t),i=null,s=null,o={x:0,y:0};n.on(r.startevent,function(e){if(e.which&&e.which!==1){return false}else{s=(new Date).getTime();i=e.target;n.data("callee1",arguments.callee);o.x=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageX:e.pageX;o.y=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageY:e.pageY;return true}}).on(r.endevent,function(e){n.data("callee2",arguments.callee);if(e.target==i){end_pos_x=e.originalEvent.changedTouches?e.originalEvent.changedTouches[0].pageX:e.pageX;end_pos_y=e.originalEvent.changedTouches?e.originalEvent.changedTouches[0].pageY:e.pageY;r.tap_timer=window.setTimeout(function(){if(!n.data("doubletapped")&&!n.data("tapheld")&&o.x==end_pos_x&&o.y==end_pos_y){var i=e.originalEvent;var u={position:{x:r.touch_capable?i.changedTouches[0].screenX:e.screenX,y:r.touch_capable?i.changedTouches[0].screenY:e.screenY},offset:{x:r.touch_capable?i.changedTouches[0].pageX-i.changedTouches[0].target.offsetLeft:e.offsetX,y:r.touch_capable?i.changedTouches[0].pageY-i.changedTouches[0].target.offsetTop:e.offsetY},time:(new Date).getTime(),target:e.target};if(u.time-s=-r.tap_pixel_range&&diff_x<=r.tap_pixel_range&&diff_y>=-r.tap_pixel_range&&diff_y<=r.tap_pixel_range)){var l=e.originalEvent;var c={position:{x:r.touch_capable?l.changedTouches[0].screenX:e.screenX,y:r.touch_capable?l.changedTouches[0].screenY:e.screenY},offset:{x:r.touch_capable?l.changedTouches[0].pageX-l.changedTouches[0].target.offsetLeft:e.offsetX,y:r.touch_capable?l.changedTouches[0].pageY-l.changedTouches[0].target.offsetTop:e.offsetY},time:(new Date).getTime(),target:e.target};E(t,"tap",e,c)}})},remove:function(){e(this).off(r.startevent,e(this).data.callee1).off(r.endevent,e(this).data.callee2)}};e.event.special.swipe={setup:function(){function f(t){n=e(t.target);n.data("callee1",arguments.callee);o.x=t.originalEvent.targetTouches?t.originalEvent.targetTouches[0].pageX:t.pageX;o.y=t.originalEvent.targetTouches?t.originalEvent.targetTouches[0].pageY:t.pageY;u.x=o.x;u.y=o.y;i=true;var s=t.originalEvent;a={position:{x:r.touch_capable?s.touches[0].screenX:t.screenX,y:r.touch_capable?s.touches[0].screenY:t.screenY},offset:{x:r.touch_capable?s.touches[0].pageX-s.touches[0].target.offsetLeft:t.offsetX,y:r.touch_capable?s.touches[0].pageY-s.touches[0].target.offsetTop:t.offsetY},time:(new Date).getTime(),target:t.target};var f=new Date;while(new Date-f<100){}}function l(t){n=e(t.target);n.data("callee2",arguments.callee);u.x=t.originalEvent.targetTouches?t.originalEvent.targetTouches[0].pageX:t.pageX;u.y=t.originalEvent.targetTouches?t.originalEvent.targetTouches[0].pageY:t.pageY;window.clearTimeout(r.hold_timer);var f;var l=n.data("xthreshold"),c=n.data("ythreshold"),h=typeof l!=="undefined"&&l!==false&&parseInt(l)?parseInt(l):r.swipe_h_threshold,p=typeof c!=="undefined"&&c!==false&&parseInt(c)?parseInt(c):r.swipe_v_threshold;if(o.y>u.y&&o.y-u.y>p){f="swipeup"}if(o.xh){f="swiperight"}if(o.yp){f="swipedown"}if(o.x>u.x&&o.x-u.x>h){f="swipeleft"}if(f!=undefined&&i){o.x=0;o.y=0;u.x=0;u.y=0;i=false;var d=t.originalEvent;endEvnt={position:{x:r.touch_capable?d.touches[0].screenX:t.screenX,y:r.touch_capable?d.touches[0].screenY:t.screenY},offset:{x:r.touch_capable?d.touches[0].pageX-d.touches[0].target.offsetLeft:t.offsetX,y:r.touch_capable?d.touches[0].pageY-d.touches[0].target.offsetTop:t.offsetY},time:(new Date).getTime(),target:t.target};var v=Math.abs(a.position.x-endEvnt.position.x),m=Math.abs(a.position.y-endEvnt.position.y);var g={startEvnt:a,endEvnt:endEvnt,direction:f.replace("swipe",""),xAmount:v,yAmount:m,duration:endEvnt.time-a.time};s=true;n.trigger("swipe",g).trigger(f,g)}}function c(t){n=e(t.target);var o="";n.data("callee3",arguments.callee);if(s){var u=n.data("xthreshold"),f=n.data("ythreshold"),l=typeof u!=="undefined"&&u!==false&&parseInt(u)?parseInt(u):r.swipe_h_threshold,c=typeof f!=="undefined"&&f!==false&&parseInt(f)?parseInt(f):r.swipe_v_threshold;var h=t.originalEvent;endEvnt={position:{x:r.touch_capable?h.changedTouches[0].screenX:t.screenX,y:r.touch_capable?h.changedTouches[0].screenY:t.screenY},offset:{x:r.touch_capable?h.changedTouches[0].pageX-h.changedTouches[0].target.offsetLeft:t.offsetX,y:r.touch_capable?h.changedTouches[0].pageY-h.changedTouches[0].target.offsetTop:t.offsetY},time:(new Date).getTime(),target:t.target};if(a.position.y>endEvnt.position.y&&a.position.y-endEvnt.position.y>c){o="swipeup"}if(a.position.xl){o="swiperight"}if(a.position.yc){o="swipedown"}if(a.position.x>endEvnt.position.x&&a.position.x-endEvnt.position.x>l){o="swipeleft"}var p=Math.abs(a.position.x-endEvnt.position.x),d=Math.abs(a.position.y-endEvnt.position.y);var v={startEvnt:a,endEvnt:endEvnt,direction:o.replace("swipe",""),xAmount:p,yAmount:d,duration:endEvnt.time-a.time};n.trigger("swipeend",v)}i=false;s=false}var t=this,n=e(t),i=false,s=false,o={x:0,y:0},u={x:0,y:0},a;n.on(r.startevent,f);n.on(r.moveevent,l);n.on(r.endevent,c)},remove:function(){e(this).off(r.startevent,e(this).data.callee1).off(r.moveevent,e(this).data.callee2).off(r.endevent,e(this).data.callee3)}};e.event.special.scrollstart={setup:function(){function o(e,n){i=n;E(t,i?"scrollstart":"scrollend",e)}var t=this,n=e(t),i,s;n.on(r.scrollevent,function(e){n.data("callee",arguments.callee);if(!i){o(e,true)}clearTimeout(s);s=setTimeout(function(){o(e,false)},50)})},remove:function(){e(this).off(r.scrollevent,e(this).data.callee)}};var i=e(window),s,o,u,a,f,l={0:true,180:true};if(r.orientation_support){var c=window.innerWidth||e(window).width(),h=window.innerHeight||e(window).height(),p=50;a=c>h&&c-h>p;f=l[window.orientation];if(a&&f||!a&&!f){l={"-90":true,90:true}}}e.event.special.orientationchange=s={setup:function(){if(r.orientation_support){return false}u=o();i.on("throttledresize",d);return true},teardown:function(){if(r.orientation_support){return false}i.off("throttledresize",d);return true},add:function(e){var t=e.handler;e.handler=function(e){e.orientation=o();return t.apply(this,arguments)}}};e.event.special.orientationchange.orientation=o=function(){var e=true,t=document.documentElement;if(r.orientation_support){e=l[window.orientation]}else{e=t&&t.clientWidth/t.clientHeight<1.1}return e?"portrait":"landscape"};e.event.special.throttledresize={setup:function(){e(this).on("resize",m)},teardown:function(){e(this).off("resize",m)}};var v=250,m=function(){b=(new Date).getTime();w=b-g;if(w>=v){g=b;e(this).trigger("throttledresize")}else{if(y){window.clearTimeout(y)}y=window.setTimeout(d,v-w)}},g=0,y,b,w;e.each({scrollend:"scrollstart",swipeup:"swipe",swiperight:"swipe",swipedown:"swipe",swipeleft:"swipe",swipeend:"swipe"},function(t,n,r){e.event.special[t]={setup:function(){e(this).on(n,e.noop)}}})})(jQuery)
+/*!
+ * jQuery Mobile Events
+ * by Ben Major
+ *
+ * Copyright 2011-2019, Ben Major
+ * Licensed under the MIT License:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+"use strict";!function(e){e.attrFn=e.attrFn||{};var t="ontouchstart"in window,a={tap_pixel_range:5,swipe_h_threshold:50,swipe_v_threshold:50,taphold_threshold:750,doubletap_int:500,shake_threshold:15,touch_capable:t,orientation_support:"orientation"in window&&"onorientationchange"in window,startevent:t?"touchstart":"mousedown",endevent:t?"touchend":"mouseup",moveevent:t?"touchmove":"mousemove",tapevent:t?"tap":"click",scrollevent:t?"touchmove":"scroll",hold_timer:null,tap_timer:null};e.touch={},e.isTouchCapable=function(){return a.touch_capable},e.getStartEvent=function(){return a.startevent},e.getEndEvent=function(){return a.endevent},e.getMoveEvent=function(){return a.moveevent},e.getTapEvent=function(){return a.tapevent},e.getScrollEvent=function(){return a.scrollevent},e.touch.setSwipeThresholdX=function(e){if("number"!=typeof e)throw new Error("Threshold parameter must be a type of number");a.swipe_h_threshold=e},e.touch.setSwipeThresholdY=function(e){if("number"!=typeof e)throw new Error("Threshold parameter must be a type of number");a.swipe_v_threshold=e},e.touch.setDoubleTapInt=function(e){if("number"!=typeof e)throw new Error("Interval parameter must be a type of number");a.doubletap_int=e},e.touch.setTapHoldThreshold=function(e){if("number"!=typeof e)throw new Error("Threshold parameter must be a type of number");a.taphold_threshold=e},e.touch.setTapRange=function(e){if("number"!=typeof e)throw new Error("Ranger parameter must be a type of number");a.tap_pixel_range=e},e.each(["tapstart","tapend","tapmove","tap","singletap","doubletap","taphold","swipe","swipeup","swiperight","swipedown","swipeleft","swipeend","scrollstart","scrollend","orientationchange","tap2","taphold2"],function(t,a){e.fn[a]=function(e){return e?this.on(a,e):this.trigger(a)},e.attrFn[a]=!0}),e.event.special.tapstart={setup:function(){var t=this,o=e(t);o.on(a.startevent,function e(n){if(o.data("callee",e),n.which&&1!==n.which)return!1;var i=o.get(0)!==window&&o.get(0)!==document?o.offset():{left:0,top:0},r=n.originalEvent,p={position:{x:a.touch_capable?r.touches[0].pageX:n.pageX,y:a.touch_capable?r.touches[0].pageY:n.pageY},offset:{x:a.touch_capable?Math.round(r.changedTouches[0].pageX-i.left):Math.round(n.pageX-i.left),y:a.touch_capable?Math.round(r.changedTouches[0].pageY-i.top):Math.round(n.pageY-i.top)},time:Date.now(),target:n.target};return w(t,"tapstart",n,p),!0})},remove:function(){e(this).off(a.startevent,e(this).data.callee)}},e.event.special.tapmove={setup:function(){var t=this,o=e(t);o.on(a.moveevent,function e(n){o.data("callee",e);var i=o.get(0)!==window&&o.get(0)!==document?o.offset():{left:0,top:0},r=n.originalEvent,p={position:{x:a.touch_capable?r.touches[0].pageX:n.pageX,y:a.touch_capable?r.touches[0].pageY:n.pageY},offset:{x:a.touch_capable?Math.round(r.changedTouches[0].pageX-i.left):Math.round(n.pageX-i.left),y:a.touch_capable?Math.round(r.changedTouches[0].pageY-i.top):Math.round(n.pageY-i.top)},time:Date.now(),target:n.target};return w(t,"tapmove",n,p),!0})},remove:function(){e(this).off(a.moveevent,e(this).data.callee)}},e.event.special.tapend={setup:function(){var t=this,o=e(t);o.on(a.endevent,function e(n){o.data("callee",e);var i=o.get(0)!==window&&o.get(0)!==document?o.offset():{left:0,top:0},r=n.originalEvent,p={position:{x:a.touch_capable?r.changedTouches[0].pageX:n.pageX,y:a.touch_capable?r.changedTouches[0].pageY:n.pageY},offset:{x:a.touch_capable?Math.round(r.changedTouches[0].pageX-i.left):Math.round(n.pageX-i.left),y:a.touch_capable?Math.round(r.changedTouches[0].pageY-i.top):Math.round(n.pageY-i.top)},time:Date.now(),target:n.target};return w(t,"tapend",n,p),!0})},remove:function(){e(this).off(a.endevent,e(this).data.callee)}},e.event.special.taphold={setup:function(){var t,o=this,n=e(o),i={x:0,y:0},r=0,p=0;n.on(a.startevent,function e(h){if(h.which&&1!==h.which)return!1;n.data("tapheld",!1),t=h.target;var c=h.originalEvent,s=Date.now();a.touch_capable?c.touches[0].pageX:h.pageX,a.touch_capable?c.touches[0].pageY:h.pageY,a.touch_capable?(c.touches[0].pageX,c.touches[0].target.offsetLeft):h.offsetX,a.touch_capable?(c.touches[0].pageY,c.touches[0].target.offsetTop):h.offsetY;i.x=h.originalEvent.targetTouches?h.originalEvent.targetTouches[0].pageX:h.pageX,i.y=h.originalEvent.targetTouches?h.originalEvent.targetTouches[0].pageY:h.pageY,r=i.x,p=i.y;var u=n.parent().data("threshold")?n.parent().data("threshold"):n.data("threshold"),l=void 0!==u&&!1!==u&&parseInt(u)?parseInt(u):a.taphold_threshold;return n.data("hold_timer",window.setTimeout(function(){var u=i.x-r,l=i.y-p;if(h.target==t&&(i.x==r&&i.y==p||u>=-a.tap_pixel_range&&u<=a.tap_pixel_range&&l>=-a.tap_pixel_range&&l<=a.tap_pixel_range)){n.data("tapheld",!0);for(var g=Date.now()-s,d=h.originalEvent.targetTouches?h.originalEvent.targetTouches:[h],f=[],v=n.get(0)!==window&&n.get(0)!==document?n.offset():{left:0,top:0},_=0;_100){i.data("doubletapped",!0),window.clearTimeout(a.tap_timer);var l=i.get(0)!==window&&i.get(0)!==document?i.offset():{left:0,top:0},g={position:{x:a.touch_capable?c.originalEvent.changedTouches[0].pageX:c.pageX,y:a.touch_capable?c.originalEvent.changedTouches[0].pageY:c.pageY},offset:{x:a.touch_capable?Math.round(o.changedTouches[0].pageX-l.left):Math.round(c.pageX-l.left),y:a.touch_capable?Math.round(o.changedTouches[0].pageY-l.top):Math.round(c.pageY-l.top)},time:Date.now(),target:c.target,element:c.originalEvent.srcElement,index:e(c.target).index()},d={firstTap:r,secondTap:g,interval:g.time-r.time};p||(w(n,"doubletap",c,d),r=null),p=!0,window.setTimeout(function(){p=!1},a.doubletap_int)}else i.data("lastTouch",s),t=window.setTimeout(function(){r=null,window.clearTimeout(t)},a.doubletap_int,[c]);i.data("lastTouch",s)})},remove:function(){e(this).off(a.startevent,e(this).data.callee1).off(a.endevent,e(this).data.callee2)}},e.event.special.singletap={setup:function(){var t=this,o=e(t),n=null,i=null,r={x:0,y:0};o.on(a.startevent,function e(t){return(!t.which||1===t.which)&&(i=Date.now(),n=t.target,o.data("callee1",e),r.x=t.originalEvent.targetTouches?t.originalEvent.targetTouches[0].pageX:t.pageX,r.y=t.originalEvent.targetTouches?t.originalEvent.targetTouches[0].pageY:t.pageY,!0)}).on(a.endevent,function e(p){if(o.data("callee2",e),p.target==n){var h=p.originalEvent.changedTouches?p.originalEvent.changedTouches[0].pageX:p.pageX,c=p.originalEvent.changedTouches?p.originalEvent.changedTouches[0].pageY:p.pageY;a.tap_timer=window.setTimeout(function(){var e=r.x-h,n=r.y-c;if(!o.data("doubletapped")&&!o.data("tapheld")&&(r.x==h&&r.y==c||e>=-a.tap_pixel_range&&e<=a.tap_pixel_range&&n>=-a.tap_pixel_range&&n<=a.tap_pixel_range)){var s=o.get(0)!==window&&o.get(0)!==document?o.offset():{left:0,top:0},u=p.originalEvent,l={position:{x:a.touch_capable?u.changedTouches[0].pageX:p.pageX,y:a.touch_capable?u.changedTouches[0].pageY:p.pageY},offset:{x:a.touch_capable?Math.round(u.changedTouches[0].pageX-s.left):Math.round(p.pageX-s.left),y:a.touch_capable?Math.round(u.changedTouches[0].pageY-s.top):Math.round(p.pageY-s.top)},time:Date.now(),target:p.target};l.time-i=-a.tap_pixel_range&&l<=a.tap_pixel_range&&g>=-a.tap_pixel_range&&g<=a.tap_pixel_range)){for(var d=i.get(0)!==window&&i.get(0)!==document?i.offset():{left:0,top:0},f=c.originalEvent,v=[],_=0;_Math.abs(p.y-r.y)?(r.xg&&(s="swiperight"),r.x>p.x&&r.x-p.x>g&&(s="swipeleft")):(r.y>p.y&&r.y-p.y>d&&(s="swipeup"),r.yd&&(s="swipedown")),null!=s&&n){r.x=0,r.y=0,p.x=0,p.y=0,n=!1;var f=o.get(0)!==window&&o.get(0)!==document?o.offset():{left:0,top:0},v=c.originalEvent,w={position:{x:a.touch_capable?v.touches[0].pageX:c.pageX,y:a.touch_capable?v.touches[0].pageY:c.pageY},offset:{x:a.touch_capable?Math.round(v.changedTouches[0].pageX-f.left):Math.round(c.pageX-f.left),y:a.touch_capable?Math.round(v.changedTouches[0].pageY-f.top):Math.round(c.pageY-f.top)},time:Date.now(),target:c.target},_=Math.abs(t.position.x-w.position.x),m=Math.abs(t.position.y-w.position.y),T={startEvnt:t,endEvnt:w,direction:s.replace("swipe",""),xAmount:_,yAmount:m,duration:w.time-t.time};i=!0,o.trigger("swipe",T).trigger(s,T)}}),o.on(a.endevent,function r(p){var h="";if((o=e(p.currentTarget)).data("callee3",r),i){var c=o.data("xthreshold"),s=o.data("ythreshold"),u=void 0!==c&&!1!==c&&parseInt(c)?parseInt(c):a.swipe_h_threshold,l=void 0!==s&&!1!==s&&parseInt(s)?parseInt(s):a.swipe_v_threshold,g=o.get(0)!==window&&o.get(0)!==document?o.offset():{left:0,top:0},d=p.originalEvent,f={position:{x:a.touch_capable?d.changedTouches[0].pageX:p.pageX,y:a.touch_capable?d.changedTouches[0].pageY:p.pageY},offset:{x:a.touch_capable?Math.round(d.changedTouches[0].pageX-g.left):Math.round(p.pageX-g.left),y:a.touch_capable?Math.round(d.changedTouches[0].pageY-g.top):Math.round(p.pageY-g.top)},time:Date.now(),target:p.target},v=Math.abs(t.position.x-f.position.x),w=Math.abs(t.position.y-f.position.y);v>w?(t.position.xu&&(h="swiperight"),t.position.x>f.position.x&&t.position.x-f.position.x>u&&(h="swipeleft")):(t.position.y>f.position.y&&t.position.y-f.position.y>l&&(h="swipeup"),t.position.yl&&(h="swipedown"));var _={startEvnt:t,endEvnt:f,direction:h.replace("swipe",""),xAmount:v,yAmount:w,duration:f.time-t.time};o.trigger("swipeend",_)}n=!1,i=!1})},remove:function(){e(this).off(a.startevent,e(this).data.callee1).off(a.moveevent,e(this).data.callee2).off(a.endevent,e(this).data.callee3)}},e.event.special.scrollstart={setup:function(){var t,o,n=this,i=e(n);function r(e,a){w(n,(t=a)?"scrollstart":"scrollend",e)}i.on(a.scrollevent,function e(a){i.data("callee",e),t||r(a,!0),clearTimeout(o),o=setTimeout(function(){r(a,!1)},50)})},remove:function(){e(this).off(a.scrollevent,e(this).data.callee)}};var o,n,i,r,p=e(window),h={0:!0,180:!0};if(a.orientation_support){var c=window.innerWidth||p.width(),s=window.innerHeight||p.height();i=c>s&&c-s>50,r=h[window.orientation],(i&&r||!i&&!r)&&(h={"-90":!0,90:!0})}function u(){var e=o();e!==n&&(n=e,p.trigger("orientationchange"))}e.event.special.orientationchange={setup:function(){return!a.orientation_support&&(n=o(),p.on("throttledresize",u),!0)},teardown:function(){return!a.orientation_support&&(p.off("throttledresize",u),!0)},add:function(e){var t=e.handler;e.handler=function(e){return e.orientation=o(),t.apply(this,arguments)}}},e.event.special.orientationchange.orientation=o=function(){var e=document.documentElement;return(a.orientation_support?h[window.orientation]:e&&e.clientWidth/e.clientHeight<1.1)?"portrait":"landscape"},e.event.special.throttledresize={setup:function(){e(this).on("resize",f)},teardown:function(){e(this).off("resize",f)}};var l,g,d,f=function(){g=Date.now(),(d=g-v)>=250?(v=g,e(this).trigger("throttledresize")):(l&&window.clearTimeout(l),l=window.setTimeout(u,250-d))},v=0;function w(t,a,o,n){var i=o.type;o.type=a,e.event.dispatch.call(t,o,n),o.type=i}e.each({scrollend:"scrollstart",swipeup:"swipe",swiperight:"swipe",swipedown:"swipe",swipeleft:"swipe",swipeend:"swipe",tap2:"tap",taphold2:"taphold"},function(t,a){e.event.special[t]={setup:function(){e(this).on(a,e.noop)}}})}(jQuery);