angular-touch.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. /**
  2. * @license AngularJS v1.3.15
  3. * (c) 2010-2014 Google, Inc. http://angularjs.org
  4. * License: MIT
  5. */
  6. (function(window, angular, undefined) {'use strict';
  7. /**
  8. * @ngdoc module
  9. * @name ngTouch
  10. * @description
  11. *
  12. * # ngTouch
  13. *
  14. * The `ngTouch` module provides touch events and other helpers for touch-enabled devices.
  15. * The implementation is based on jQuery Mobile touch event handling
  16. * ([jquerymobile.com](http://jquerymobile.com/)).
  17. *
  18. *
  19. * See {@link ngTouch.$swipe `$swipe`} for usage.
  20. *
  21. * <div doc-module-components="ngTouch"></div>
  22. *
  23. */
  24. // define ngTouch module
  25. /* global -ngTouch */
  26. var ngTouch = angular.module('ngTouch', []);
  27. /* global ngTouch: false */
  28. /**
  29. * @ngdoc service
  30. * @name $swipe
  31. *
  32. * @description
  33. * The `$swipe` service is a service that abstracts the messier details of hold-and-drag swipe
  34. * behavior, to make implementing swipe-related directives more convenient.
  35. *
  36. * Requires the {@link ngTouch `ngTouch`} module to be installed.
  37. *
  38. * `$swipe` is used by the `ngSwipeLeft` and `ngSwipeRight` directives in `ngTouch`, and by
  39. * `ngCarousel` in a separate component.
  40. *
  41. * # Usage
  42. * The `$swipe` service is an object with a single method: `bind`. `bind` takes an element
  43. * which is to be watched for swipes, and an object with four handler functions. See the
  44. * documentation for `bind` below.
  45. */
  46. ngTouch.factory('$swipe', [function() {
  47. // The total distance in any direction before we make the call on swipe vs. scroll.
  48. var MOVE_BUFFER_RADIUS = 10;
  49. var POINTER_EVENTS = {
  50. 'mouse': {
  51. start: 'mousedown',
  52. move: 'mousemove',
  53. end: 'mouseup'
  54. },
  55. 'touch': {
  56. start: 'touchstart',
  57. move: 'touchmove',
  58. end: 'touchend',
  59. cancel: 'touchcancel'
  60. }
  61. };
  62. function getCoordinates(event) {
  63. var touches = event.touches && event.touches.length ? event.touches : [event];
  64. var e = (event.changedTouches && event.changedTouches[0]) ||
  65. (event.originalEvent && event.originalEvent.changedTouches &&
  66. event.originalEvent.changedTouches[0]) ||
  67. touches[0].originalEvent || touches[0];
  68. return {
  69. x: e.clientX,
  70. y: e.clientY
  71. };
  72. }
  73. function getEvents(pointerTypes, eventType) {
  74. var res = [];
  75. angular.forEach(pointerTypes, function(pointerType) {
  76. var eventName = POINTER_EVENTS[pointerType][eventType];
  77. if (eventName) {
  78. res.push(eventName);
  79. }
  80. });
  81. return res.join(' ');
  82. }
  83. return {
  84. /**
  85. * @ngdoc method
  86. * @name $swipe#bind
  87. *
  88. * @description
  89. * The main method of `$swipe`. It takes an element to be watched for swipe motions, and an
  90. * object containing event handlers.
  91. * The pointer types that should be used can be specified via the optional
  92. * third argument, which is an array of strings `'mouse'` and `'touch'`. By default,
  93. * `$swipe` will listen for `mouse` and `touch` events.
  94. *
  95. * The four events are `start`, `move`, `end`, and `cancel`. `start`, `move`, and `end`
  96. * receive as a parameter a coordinates object of the form `{ x: 150, y: 310 }`.
  97. *
  98. * `start` is called on either `mousedown` or `touchstart`. After this event, `$swipe` is
  99. * watching for `touchmove` or `mousemove` events. These events are ignored until the total
  100. * distance moved in either dimension exceeds a small threshold.
  101. *
  102. * Once this threshold is exceeded, either the horizontal or vertical delta is greater.
  103. * - If the horizontal distance is greater, this is a swipe and `move` and `end` events follow.
  104. * - If the vertical distance is greater, this is a scroll, and we let the browser take over.
  105. * A `cancel` event is sent.
  106. *
  107. * `move` is called on `mousemove` and `touchmove` after the above logic has determined that
  108. * a swipe is in progress.
  109. *
  110. * `end` is called when a swipe is successfully completed with a `touchend` or `mouseup`.
  111. *
  112. * `cancel` is called either on a `touchcancel` from the browser, or when we begin scrolling
  113. * as described above.
  114. *
  115. */
  116. bind: function(element, eventHandlers, pointerTypes) {
  117. // Absolute total movement, used to control swipe vs. scroll.
  118. var totalX, totalY;
  119. // Coordinates of the start position.
  120. var startCoords;
  121. // Last event's position.
  122. var lastPos;
  123. // Whether a swipe is active.
  124. var active = false;
  125. pointerTypes = pointerTypes || ['mouse', 'touch'];
  126. element.on(getEvents(pointerTypes, 'start'), function(event) {
  127. startCoords = getCoordinates(event);
  128. active = true;
  129. totalX = 0;
  130. totalY = 0;
  131. lastPos = startCoords;
  132. eventHandlers['start'] && eventHandlers['start'](startCoords, event);
  133. });
  134. var events = getEvents(pointerTypes, 'cancel');
  135. if (events) {
  136. element.on(events, function(event) {
  137. active = false;
  138. eventHandlers['cancel'] && eventHandlers['cancel'](event);
  139. });
  140. }
  141. element.on(getEvents(pointerTypes, 'move'), function(event) {
  142. if (!active) return;
  143. // Android will send a touchcancel if it thinks we're starting to scroll.
  144. // So when the total distance (+ or - or both) exceeds 10px in either direction,
  145. // we either:
  146. // - On totalX > totalY, we send preventDefault() and treat this as a swipe.
  147. // - On totalY > totalX, we let the browser handle it as a scroll.
  148. if (!startCoords) return;
  149. var coords = getCoordinates(event);
  150. totalX += Math.abs(coords.x - lastPos.x);
  151. totalY += Math.abs(coords.y - lastPos.y);
  152. lastPos = coords;
  153. if (totalX < MOVE_BUFFER_RADIUS && totalY < MOVE_BUFFER_RADIUS) {
  154. return;
  155. }
  156. // One of totalX or totalY has exceeded the buffer, so decide on swipe vs. scroll.
  157. if (totalY > totalX) {
  158. // Allow native scrolling to take over.
  159. active = false;
  160. eventHandlers['cancel'] && eventHandlers['cancel'](event);
  161. return;
  162. } else {
  163. // Prevent the browser from scrolling.
  164. event.preventDefault();
  165. eventHandlers['move'] && eventHandlers['move'](coords, event);
  166. }
  167. });
  168. element.on(getEvents(pointerTypes, 'end'), function(event) {
  169. if (!active) return;
  170. active = false;
  171. eventHandlers['end'] && eventHandlers['end'](getCoordinates(event), event);
  172. });
  173. }
  174. };
  175. }]);
  176. /* global ngTouch: false */
  177. /**
  178. * @ngdoc directive
  179. * @name ngClick
  180. *
  181. * @description
  182. * A more powerful replacement for the default ngClick designed to be used on touchscreen
  183. * devices. Most mobile browsers wait about 300ms after a tap-and-release before sending
  184. * the click event. This version handles them immediately, and then prevents the
  185. * following click event from propagating.
  186. *
  187. * Requires the {@link ngTouch `ngTouch`} module to be installed.
  188. *
  189. * This directive can fall back to using an ordinary click event, and so works on desktop
  190. * browsers as well as mobile.
  191. *
  192. * This directive also sets the CSS class `ng-click-active` while the element is being held
  193. * down (by a mouse click or touch) so you can restyle the depressed element if you wish.
  194. *
  195. * @element ANY
  196. * @param {expression} ngClick {@link guide/expression Expression} to evaluate
  197. * upon tap. (Event object is available as `$event`)
  198. *
  199. * @example
  200. <example module="ngClickExample" deps="angular-touch.js">
  201. <file name="index.html">
  202. <button ng-click="count = count + 1" ng-init="count=0">
  203. Increment
  204. </button>
  205. count: {{ count }}
  206. </file>
  207. <file name="script.js">
  208. angular.module('ngClickExample', ['ngTouch']);
  209. </file>
  210. </example>
  211. */
  212. ngTouch.config(['$provide', function($provide) {
  213. $provide.decorator('ngClickDirective', ['$delegate', function($delegate) {
  214. // drop the default ngClick directive
  215. $delegate.shift();
  216. return $delegate;
  217. }]);
  218. }]);
  219. ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
  220. function($parse, $timeout, $rootElement) {
  221. var TAP_DURATION = 750; // Shorter than 750ms is a tap, longer is a taphold or drag.
  222. var MOVE_TOLERANCE = 12; // 12px seems to work in most mobile browsers.
  223. var PREVENT_DURATION = 2500; // 2.5 seconds maximum from preventGhostClick call to click
  224. var CLICKBUSTER_THRESHOLD = 25; // 25 pixels in any dimension is the limit for busting clicks.
  225. var ACTIVE_CLASS_NAME = 'ng-click-active';
  226. var lastPreventedTime;
  227. var touchCoordinates;
  228. var lastLabelClickCoordinates;
  229. // TAP EVENTS AND GHOST CLICKS
  230. //
  231. // Why tap events?
  232. // Mobile browsers detect a tap, then wait a moment (usually ~300ms) to see if you're
  233. // double-tapping, and then fire a click event.
  234. //
  235. // This delay sucks and makes mobile apps feel unresponsive.
  236. // So we detect touchstart, touchmove, touchcancel and touchend ourselves and determine when
  237. // the user has tapped on something.
  238. //
  239. // What happens when the browser then generates a click event?
  240. // The browser, of course, also detects the tap and fires a click after a delay. This results in
  241. // tapping/clicking twice. We do "clickbusting" to prevent it.
  242. //
  243. // How does it work?
  244. // We attach global touchstart and click handlers, that run during the capture (early) phase.
  245. // So the sequence for a tap is:
  246. // - global touchstart: Sets an "allowable region" at the point touched.
  247. // - element's touchstart: Starts a touch
  248. // (- touchmove or touchcancel ends the touch, no click follows)
  249. // - element's touchend: Determines if the tap is valid (didn't move too far away, didn't hold
  250. // too long) and fires the user's tap handler. The touchend also calls preventGhostClick().
  251. // - preventGhostClick() removes the allowable region the global touchstart created.
  252. // - The browser generates a click event.
  253. // - The global click handler catches the click, and checks whether it was in an allowable region.
  254. // - If preventGhostClick was called, the region will have been removed, the click is busted.
  255. // - If the region is still there, the click proceeds normally. Therefore clicks on links and
  256. // other elements without ngTap on them work normally.
  257. //
  258. // This is an ugly, terrible hack!
  259. // Yeah, tell me about it. The alternatives are using the slow click events, or making our users
  260. // deal with the ghost clicks, so I consider this the least of evils. Fortunately Angular
  261. // encapsulates this ugly logic away from the user.
  262. //
  263. // Why not just put click handlers on the element?
  264. // We do that too, just to be sure. If the tap event caused the DOM to change,
  265. // it is possible another element is now in that position. To take account for these possibly
  266. // distinct elements, the handlers are global and care only about coordinates.
  267. // Checks if the coordinates are close enough to be within the region.
  268. function hit(x1, y1, x2, y2) {
  269. return Math.abs(x1 - x2) < CLICKBUSTER_THRESHOLD && Math.abs(y1 - y2) < CLICKBUSTER_THRESHOLD;
  270. }
  271. // Checks a list of allowable regions against a click location.
  272. // Returns true if the click should be allowed.
  273. // Splices out the allowable region from the list after it has been used.
  274. function checkAllowableRegions(touchCoordinates, x, y) {
  275. for (var i = 0; i < touchCoordinates.length; i += 2) {
  276. if (hit(touchCoordinates[i], touchCoordinates[i + 1], x, y)) {
  277. touchCoordinates.splice(i, i + 2);
  278. return true; // allowable region
  279. }
  280. }
  281. return false; // No allowable region; bust it.
  282. }
  283. // Global click handler that prevents the click if it's in a bustable zone and preventGhostClick
  284. // was called recently.
  285. function onClick(event) {
  286. if (Date.now() - lastPreventedTime > PREVENT_DURATION) {
  287. return; // Too old.
  288. }
  289. var touches = event.touches && event.touches.length ? event.touches : [event];
  290. var x = touches[0].clientX;
  291. var y = touches[0].clientY;
  292. // Work around desktop Webkit quirk where clicking a label will fire two clicks (on the label
  293. // and on the input element). Depending on the exact browser, this second click we don't want
  294. // to bust has either (0,0), negative coordinates, or coordinates equal to triggering label
  295. // click event
  296. if (x < 1 && y < 1) {
  297. return; // offscreen
  298. }
  299. if (lastLabelClickCoordinates &&
  300. lastLabelClickCoordinates[0] === x && lastLabelClickCoordinates[1] === y) {
  301. return; // input click triggered by label click
  302. }
  303. // reset label click coordinates on first subsequent click
  304. if (lastLabelClickCoordinates) {
  305. lastLabelClickCoordinates = null;
  306. }
  307. // remember label click coordinates to prevent click busting of trigger click event on input
  308. if (event.target.tagName.toLowerCase() === 'label') {
  309. lastLabelClickCoordinates = [x, y];
  310. }
  311. // Look for an allowable region containing this click.
  312. // If we find one, that means it was created by touchstart and not removed by
  313. // preventGhostClick, so we don't bust it.
  314. if (checkAllowableRegions(touchCoordinates, x, y)) {
  315. return;
  316. }
  317. // If we didn't find an allowable region, bust the click.
  318. event.stopPropagation();
  319. event.preventDefault();
  320. // Blur focused form elements
  321. event.target && event.target.blur();
  322. }
  323. // Global touchstart handler that creates an allowable region for a click event.
  324. // This allowable region can be removed by preventGhostClick if we want to bust it.
  325. function onTouchStart(event) {
  326. var touches = event.touches && event.touches.length ? event.touches : [event];
  327. var x = touches[0].clientX;
  328. var y = touches[0].clientY;
  329. touchCoordinates.push(x, y);
  330. $timeout(function() {
  331. // Remove the allowable region.
  332. for (var i = 0; i < touchCoordinates.length; i += 2) {
  333. if (touchCoordinates[i] == x && touchCoordinates[i + 1] == y) {
  334. touchCoordinates.splice(i, i + 2);
  335. return;
  336. }
  337. }
  338. }, PREVENT_DURATION, false);
  339. }
  340. // On the first call, attaches some event handlers. Then whenever it gets called, it creates a
  341. // zone around the touchstart where clicks will get busted.
  342. function preventGhostClick(x, y) {
  343. if (!touchCoordinates) {
  344. $rootElement[0].addEventListener('click', onClick, true);
  345. $rootElement[0].addEventListener('touchstart', onTouchStart, true);
  346. touchCoordinates = [];
  347. }
  348. lastPreventedTime = Date.now();
  349. checkAllowableRegions(touchCoordinates, x, y);
  350. }
  351. // Actual linking function.
  352. return function(scope, element, attr) {
  353. var clickHandler = $parse(attr.ngClick),
  354. tapping = false,
  355. tapElement, // Used to blur the element after a tap.
  356. startTime, // Used to check if the tap was held too long.
  357. touchStartX,
  358. touchStartY;
  359. function resetState() {
  360. tapping = false;
  361. element.removeClass(ACTIVE_CLASS_NAME);
  362. }
  363. element.on('touchstart', function(event) {
  364. tapping = true;
  365. tapElement = event.target ? event.target : event.srcElement; // IE uses srcElement.
  366. // Hack for Safari, which can target text nodes instead of containers.
  367. if (tapElement.nodeType == 3) {
  368. tapElement = tapElement.parentNode;
  369. }
  370. element.addClass(ACTIVE_CLASS_NAME);
  371. startTime = Date.now();
  372. var touches = event.touches && event.touches.length ? event.touches : [event];
  373. var e = touches[0].originalEvent || touches[0];
  374. touchStartX = e.clientX;
  375. touchStartY = e.clientY;
  376. });
  377. element.on('touchmove', function(event) {
  378. resetState();
  379. });
  380. element.on('touchcancel', function(event) {
  381. resetState();
  382. });
  383. element.on('touchend', function(event) {
  384. var diff = Date.now() - startTime;
  385. var touches = (event.changedTouches && event.changedTouches.length) ? event.changedTouches :
  386. ((event.touches && event.touches.length) ? event.touches : [event]);
  387. var e = touches[0].originalEvent || touches[0];
  388. var x = e.clientX;
  389. var y = e.clientY;
  390. var dist = Math.sqrt(Math.pow(x - touchStartX, 2) + Math.pow(y - touchStartY, 2));
  391. if (tapping && diff < TAP_DURATION && dist < MOVE_TOLERANCE) {
  392. // Call preventGhostClick so the clickbuster will catch the corresponding click.
  393. preventGhostClick(x, y);
  394. // Blur the focused element (the button, probably) before firing the callback.
  395. // This doesn't work perfectly on Android Chrome, but seems to work elsewhere.
  396. // I couldn't get anything to work reliably on Android Chrome.
  397. if (tapElement) {
  398. tapElement.blur();
  399. }
  400. if (!angular.isDefined(attr.disabled) || attr.disabled === false) {
  401. element.triggerHandler('click', [event]);
  402. }
  403. }
  404. resetState();
  405. });
  406. // Hack for iOS Safari's benefit. It goes searching for onclick handlers and is liable to click
  407. // something else nearby.
  408. element.onclick = function(event) { };
  409. // Actual click handler.
  410. // There are three different kinds of clicks, only two of which reach this point.
  411. // - On desktop browsers without touch events, their clicks will always come here.
  412. // - On mobile browsers, the simulated "fast" click will call this.
  413. // - But the browser's follow-up slow click will be "busted" before it reaches this handler.
  414. // Therefore it's safe to use this directive on both mobile and desktop.
  415. element.on('click', function(event, touchend) {
  416. scope.$apply(function() {
  417. clickHandler(scope, {$event: (touchend || event)});
  418. });
  419. });
  420. element.on('mousedown', function(event) {
  421. element.addClass(ACTIVE_CLASS_NAME);
  422. });
  423. element.on('mousemove mouseup', function(event) {
  424. element.removeClass(ACTIVE_CLASS_NAME);
  425. });
  426. };
  427. }]);
  428. /* global ngTouch: false */
  429. /**
  430. * @ngdoc directive
  431. * @name ngSwipeLeft
  432. *
  433. * @description
  434. * Specify custom behavior when an element is swiped to the left on a touchscreen device.
  435. * A leftward swipe is a quick, right-to-left slide of the finger.
  436. * Though ngSwipeLeft is designed for touch-based devices, it will work with a mouse click and drag
  437. * too.
  438. *
  439. * To disable the mouse click and drag functionality, add `ng-swipe-disable-mouse` to
  440. * the `ng-swipe-left` or `ng-swipe-right` DOM Element.
  441. *
  442. * Requires the {@link ngTouch `ngTouch`} module to be installed.
  443. *
  444. * @element ANY
  445. * @param {expression} ngSwipeLeft {@link guide/expression Expression} to evaluate
  446. * upon left swipe. (Event object is available as `$event`)
  447. *
  448. * @example
  449. <example module="ngSwipeLeftExample" deps="angular-touch.js">
  450. <file name="index.html">
  451. <div ng-show="!showActions" ng-swipe-left="showActions = true">
  452. Some list content, like an email in the inbox
  453. </div>
  454. <div ng-show="showActions" ng-swipe-right="showActions = false">
  455. <button ng-click="reply()">Reply</button>
  456. <button ng-click="delete()">Delete</button>
  457. </div>
  458. </file>
  459. <file name="script.js">
  460. angular.module('ngSwipeLeftExample', ['ngTouch']);
  461. </file>
  462. </example>
  463. */
  464. /**
  465. * @ngdoc directive
  466. * @name ngSwipeRight
  467. *
  468. * @description
  469. * Specify custom behavior when an element is swiped to the right on a touchscreen device.
  470. * A rightward swipe is a quick, left-to-right slide of the finger.
  471. * Though ngSwipeRight is designed for touch-based devices, it will work with a mouse click and drag
  472. * too.
  473. *
  474. * Requires the {@link ngTouch `ngTouch`} module to be installed.
  475. *
  476. * @element ANY
  477. * @param {expression} ngSwipeRight {@link guide/expression Expression} to evaluate
  478. * upon right swipe. (Event object is available as `$event`)
  479. *
  480. * @example
  481. <example module="ngSwipeRightExample" deps="angular-touch.js">
  482. <file name="index.html">
  483. <div ng-show="!showActions" ng-swipe-left="showActions = true">
  484. Some list content, like an email in the inbox
  485. </div>
  486. <div ng-show="showActions" ng-swipe-right="showActions = false">
  487. <button ng-click="reply()">Reply</button>
  488. <button ng-click="delete()">Delete</button>
  489. </div>
  490. </file>
  491. <file name="script.js">
  492. angular.module('ngSwipeRightExample', ['ngTouch']);
  493. </file>
  494. </example>
  495. */
  496. function makeSwipeDirective(directiveName, direction, eventName) {
  497. ngTouch.directive(directiveName, ['$parse', '$swipe', function($parse, $swipe) {
  498. // The maximum vertical delta for a swipe should be less than 75px.
  499. var MAX_VERTICAL_DISTANCE = 75;
  500. // Vertical distance should not be more than a fraction of the horizontal distance.
  501. var MAX_VERTICAL_RATIO = 0.3;
  502. // At least a 30px lateral motion is necessary for a swipe.
  503. var MIN_HORIZONTAL_DISTANCE = 30;
  504. return function(scope, element, attr) {
  505. var swipeHandler = $parse(attr[directiveName]);
  506. var startCoords, valid;
  507. function validSwipe(coords) {
  508. // Check that it's within the coordinates.
  509. // Absolute vertical distance must be within tolerances.
  510. // Horizontal distance, we take the current X - the starting X.
  511. // This is negative for leftward swipes and positive for rightward swipes.
  512. // After multiplying by the direction (-1 for left, +1 for right), legal swipes
  513. // (ie. same direction as the directive wants) will have a positive delta and
  514. // illegal ones a negative delta.
  515. // Therefore this delta must be positive, and larger than the minimum.
  516. if (!startCoords) return false;
  517. var deltaY = Math.abs(coords.y - startCoords.y);
  518. var deltaX = (coords.x - startCoords.x) * direction;
  519. return valid && // Short circuit for already-invalidated swipes.
  520. deltaY < MAX_VERTICAL_DISTANCE &&
  521. deltaX > 0 &&
  522. deltaX > MIN_HORIZONTAL_DISTANCE &&
  523. deltaY / deltaX < MAX_VERTICAL_RATIO;
  524. }
  525. var pointerTypes = ['touch'];
  526. if (!angular.isDefined(attr['ngSwipeDisableMouse'])) {
  527. pointerTypes.push('mouse');
  528. }
  529. $swipe.bind(element, {
  530. 'start': function(coords, event) {
  531. startCoords = coords;
  532. valid = true;
  533. },
  534. 'cancel': function(event) {
  535. valid = false;
  536. },
  537. 'end': function(coords, event) {
  538. if (validSwipe(coords)) {
  539. scope.$apply(function() {
  540. element.triggerHandler(eventName);
  541. swipeHandler(scope, {$event: event});
  542. });
  543. }
  544. }
  545. }, pointerTypes);
  546. };
  547. }]);
  548. }
  549. // Left is negative X-coordinate, right is positive.
  550. makeSwipeDirective('ngSwipeLeft', -1, 'swipeleft');
  551. makeSwipeDirective('ngSwipeRight', 1, 'swiperight');
  552. })(window, window.angular);