summaryrefslogtreecommitdiff
path: root/xstatic/pkg/angular/data/angular-touch.js
diff options
context:
space:
mode:
Diffstat (limited to 'xstatic/pkg/angular/data/angular-touch.js')
-rw-r--r--xstatic/pkg/angular/data/angular-touch.js91
1 files changed, 69 insertions, 22 deletions
diff --git a/xstatic/pkg/angular/data/angular-touch.js b/xstatic/pkg/angular/data/angular-touch.js
index 4157f2a..d53a732 100644
--- a/xstatic/pkg/angular/data/angular-touch.js
+++ b/xstatic/pkg/angular/data/angular-touch.js
@@ -1,5 +1,5 @@
/**
- * @license AngularJS v1.2.16
+ * @license AngularJS v1.3.7
* (c) 2010-2014 Google, Inc. http://angularjs.org
* License: MIT
*/
@@ -52,6 +52,20 @@ ngTouch.factory('$swipe', [function() {
// The total distance in any direction before we make the call on swipe vs. scroll.
var MOVE_BUFFER_RADIUS = 10;
+ var POINTER_EVENTS = {
+ 'mouse': {
+ start: 'mousedown',
+ move: 'mousemove',
+ end: 'mouseup'
+ },
+ 'touch': {
+ start: 'touchstart',
+ move: 'touchmove',
+ end: 'touchend',
+ cancel: 'touchcancel'
+ }
+ };
+
function getCoordinates(event) {
var touches = event.touches && event.touches.length ? event.touches : [event];
var e = (event.changedTouches && event.changedTouches[0]) ||
@@ -65,6 +79,17 @@ ngTouch.factory('$swipe', [function() {
};
}
+ function getEvents(pointerTypes, eventType) {
+ var res = [];
+ angular.forEach(pointerTypes, function(pointerType) {
+ var eventName = POINTER_EVENTS[pointerType][eventType];
+ if (eventName) {
+ res.push(eventName);
+ }
+ });
+ return res.join(' ');
+ }
+
return {
/**
* @ngdoc method
@@ -73,6 +98,9 @@ ngTouch.factory('$swipe', [function() {
* @description
* The main method of `$swipe`. It takes an element to be watched for swipe motions, and an
* object containing event handlers.
+ * The pointer types that should be used can be specified via the optional
+ * third argument, which is an array of strings `'mouse'` and `'touch'`. By default,
+ * `$swipe` will listen for `mouse` and `touch` events.
*
* The four events are `start`, `move`, `end`, and `cancel`. `start`, `move`, and `end`
* receive as a parameter a coordinates object of the form `{ x: 150, y: 310 }`.
@@ -95,7 +123,7 @@ ngTouch.factory('$swipe', [function() {
* as described above.
*
*/
- bind: function(element, eventHandlers) {
+ bind: function(element, eventHandlers, pointerTypes) {
// Absolute total movement, used to control swipe vs. scroll.
var totalX, totalY;
// Coordinates of the start position.
@@ -105,7 +133,8 @@ ngTouch.factory('$swipe', [function() {
// Whether a swipe is active.
var active = false;
- element.on('touchstart mousedown', function(event) {
+ pointerTypes = pointerTypes || ['mouse', 'touch'];
+ element.on(getEvents(pointerTypes, 'start'), function(event) {
startCoords = getCoordinates(event);
active = true;
totalX = 0;
@@ -113,13 +142,15 @@ ngTouch.factory('$swipe', [function() {
lastPos = startCoords;
eventHandlers['start'] && eventHandlers['start'](startCoords, event);
});
+ var events = getEvents(pointerTypes, 'cancel');
+ if (events) {
+ element.on(events, function(event) {
+ active = false;
+ eventHandlers['cancel'] && eventHandlers['cancel'](event);
+ });
+ }
- element.on('touchcancel', function(event) {
- active = false;
- eventHandlers['cancel'] && eventHandlers['cancel'](event);
- });
-
- element.on('touchmove mousemove', function(event) {
+ element.on(getEvents(pointerTypes, 'move'), function(event) {
if (!active) return;
// Android will send a touchcancel if it thinks we're starting to scroll.
@@ -153,7 +184,7 @@ ngTouch.factory('$swipe', [function() {
}
});
- element.on('touchend mouseup', function(event) {
+ element.on(getEvents(pointerTypes, 'end'), function(event) {
if (!active) return;
active = false;
eventHandlers['end'] && eventHandlers['end'](getCoordinates(event), event);
@@ -187,13 +218,16 @@ ngTouch.factory('$swipe', [function() {
* upon tap. (Event object is available as `$event`)
*
* @example
- <example>
+ <example module="ngClickExample" deps="angular-touch.js">
<file name="index.html">
<button ng-click="count = count + 1" ng-init="count=0">
Increment
</button>
count: {{ count }}
</file>
+ <file name="script.js">
+ angular.module('ngClickExample', ['ngTouch']);
+ </file>
</example>
*/
@@ -230,7 +264,7 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
//
// What happens when the browser then generates a click event?
// The browser, of course, also detects the tap and fires a click after a delay. This results in
- // tapping/clicking twice. So we do "clickbusting" to prevent it.
+ // tapping/clicking twice. We do "clickbusting" to prevent it.
//
// How does it work?
// We attach global touchstart and click handlers, that run during the capture (early) phase.
@@ -253,9 +287,9 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
// encapsulates this ugly logic away from the user.
//
// Why not just put click handlers on the element?
- // We do that too, just to be sure. The problem is that the tap event might have caused the DOM
- // to change, so that the click fires in the same position but something else is there now. So
- // the handlers are global and care only about coordinates and not elements.
+ // We do that too, just to be sure. If the tap event caused the DOM to change,
+ // it is possible another element is now in that position. To take account for these possibly
+ // distinct elements, the handlers are global and care only about coordinates.
// Checks if the coordinates are close enough to be within the region.
function hit(x1, y1, x2, y2) {
@@ -267,7 +301,7 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
// Splices out the allowable region from the list after it has been used.
function checkAllowableRegions(touchCoordinates, x, y) {
for (var i = 0; i < touchCoordinates.length; i += 2) {
- if (hit(touchCoordinates[i], touchCoordinates[i+1], x, y)) {
+ if (hit(touchCoordinates[i], touchCoordinates[i + 1], x, y)) {
touchCoordinates.splice(i, i + 2);
return true; // allowable region
}
@@ -332,7 +366,7 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
$timeout(function() {
// Remove the allowable region.
for (var i = 0; i < touchCoordinates.length; i += 2) {
- if (touchCoordinates[i] == x && touchCoordinates[i+1] == y) {
+ if (touchCoordinates[i] == x && touchCoordinates[i + 1] == y) {
touchCoordinates.splice(i, i + 2);
return;
}
@@ -372,7 +406,7 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
tapping = true;
tapElement = event.target ? event.target : event.srcElement; // IE uses srcElement.
// Hack for Safari, which can target text nodes instead of containers.
- if(tapElement.nodeType == 3) {
+ if (tapElement.nodeType == 3) {
tapElement = tapElement.parentNode;
}
@@ -402,7 +436,7 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
var e = touches[0].originalEvent || touches[0];
var x = e.clientX;
var y = e.clientY;
- var dist = Math.sqrt( Math.pow(x - touchStartX, 2) + Math.pow(y - touchStartY, 2) );
+ var dist = Math.sqrt(Math.pow(x - touchStartX, 2) + Math.pow(y - touchStartY, 2));
if (tapping && diff < TAP_DURATION && dist < MOVE_TOLERANCE) {
// Call preventGhostClick so the clickbuster will catch the corresponding click.
@@ -462,6 +496,9 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
* Though ngSwipeLeft is designed for touch-based devices, it will work with a mouse click and drag
* too.
*
+ * To disable the mouse click and drag functionality, add `ng-swipe-disable-mouse` to
+ * the `ng-swipe-left` or `ng-swipe-right` DOM Element.
+ *
* Requires the {@link ngTouch `ngTouch`} module to be installed.
*
* @element ANY
@@ -469,7 +506,7 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
* upon left swipe. (Event object is available as `$event`)
*
* @example
- <example>
+ <example module="ngSwipeLeftExample" deps="angular-touch.js">
<file name="index.html">
<div ng-show="!showActions" ng-swipe-left="showActions = true">
Some list content, like an email in the inbox
@@ -479,6 +516,9 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
<button ng-click="delete()">Delete</button>
</div>
</file>
+ <file name="script.js">
+ angular.module('ngSwipeLeftExample', ['ngTouch']);
+ </file>
</example>
*/
@@ -499,7 +539,7 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
* upon right swipe. (Event object is available as `$event`)
*
* @example
- <example>
+ <example module="ngSwipeRightExample" deps="angular-touch.js">
<file name="index.html">
<div ng-show="!showActions" ng-swipe-left="showActions = true">
Some list content, like an email in the inbox
@@ -509,6 +549,9 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
<button ng-click="delete()">Delete</button>
</div>
</file>
+ <file name="script.js">
+ angular.module('ngSwipeRightExample', ['ngTouch']);
+ </file>
</example>
*/
@@ -545,6 +588,10 @@ function makeSwipeDirective(directiveName, direction, eventName) {
deltaY / deltaX < MAX_VERTICAL_RATIO;
}
+ var pointerTypes = ['touch'];
+ if (!angular.isDefined(attr['ngSwipeDisableMouse'])) {
+ pointerTypes.push('mouse');
+ }
$swipe.bind(element, {
'start': function(coords, event) {
startCoords = coords;
@@ -561,7 +608,7 @@ function makeSwipeDirective(directiveName, direction, eventName) {
});
}
}
- });
+ }, pointerTypes);
};
}]);
}