diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 000000000..2c395eef1 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Angular + +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 966617b8d..79c2b1cf2 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,11 @@ # packaged angular-touch -This repo is for distribution on `npm` and `bower`. The source for this module is in the -[main AngularJS repo](https://github.com/angular/angular.js/tree/master/src/ngTouch). -Please file issues and pull requests against that repo. +**This package contains the legacy AngularJS (version 1.x). AngularJS support has officially ended +as of January 2022. +[See what ending support means](https://docs.angularjs.org/misc/version-support-status) and +[read the end of life announcement](https://goo.gle/angularjs-end-of-life).** + +**[See `@angular/core` for the actively supported Angular](https://npmjs.com/@angular/core).** ## Install @@ -14,21 +17,12 @@ You can install this package either with `npm` or with `bower`. npm install angular-touch ``` -Add a ` -``` - Then add `ngTouch` as a dependency for your app: ```javascript -angular.module('myApp', ['ngTouch']); +angular.module('myApp', [require('angular-touch')]); ``` -Note that this package is not in CommonJS format, so doing `require('angular-touch')` will -return `undefined`. - ### bower ```shell @@ -56,7 +50,7 @@ Documentation is available on the The MIT License -Copyright (c) 2010-2012 Google, Inc. http://angularjs.org +Copyright (c) 2022 Google LLC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/angular-touch.js b/angular-touch.js index 9acb48ce7..44e5cd9ea 100644 --- a/angular-touch.js +++ b/angular-touch.js @@ -1,46 +1,58 @@ /** - * @license AngularJS v1.3.9-build.3770+sha.034fade - * (c) 2010-2015 Google, Inc. http://angularjs.org + * @license AngularJS v1.8.3 + * (c) 2010-2020 Google LLC. http://angularjs.org * License: MIT */ -(function(window, angular, undefined) {'use strict'; +(function(window, angular) {'use strict'; /** * @ngdoc module * @name ngTouch * @description * - * # ngTouch - * - * The `ngTouch` module provides touch events and other helpers for touch-enabled devices. + * The `ngTouch` module provides helpers for touch-enabled devices. * The implementation is based on jQuery Mobile touch event handling - * ([jquerymobile.com](http://jquerymobile.com/)). - * + * ([jquerymobile.com](http://jquerymobile.com/)). * * * See {@link ngTouch.$swipe `$swipe`} for usage. * - *
- * + * @deprecated + * sinceVersion="1.7.0" + * The ngTouch module with the {@link ngTouch.$swipe `$swipe`} service and + * the {@link ngTouch.ngSwipeLeft} and {@link ngTouch.ngSwipeRight} directives are + * deprecated. Instead, stand-alone libraries for touch handling and gesture interaction + * should be used, for example [HammerJS](https://hammerjs.github.io/) (which is also used by + * Angular). */ // define ngTouch module -/* global -ngTouch */ +/* global ngTouch */ var ngTouch = angular.module('ngTouch', []); +ngTouch.info({ angularVersion: '1.8.3' }); + +function nodeName_(element) { + return angular.$$lowercase(element.nodeName || (element[0] && element[0].nodeName)); +} + /* global ngTouch: false */ /** * @ngdoc service * @name $swipe * + * @deprecated + * sinceVersion="1.7.0" + * + * See the {@link ngTouch module} documentation for more information. + * * @description * The `$swipe` service is a service that abstracts the messier details of hold-and-drag swipe * behavior, to make implementing swipe-related directives more convenient. * * Requires the {@link ngTouch `ngTouch`} module to be installed. * - * `$swipe` is used by the `ngSwipeLeft` and `ngSwipeRight` directives in `ngTouch`, and by - * `ngCarousel` in a separate component. + * `$swipe` is used by the `ngSwipeLeft` and `ngSwipeRight` directives in `ngTouch`. * * # Usage * The `$swipe` service is an object with a single method: `bind`. `bind` takes an element @@ -63,15 +75,19 @@ ngTouch.factory('$swipe', [function() { move: 'touchmove', end: 'touchend', cancel: 'touchcancel' + }, + 'pointer': { + start: 'pointerdown', + move: 'pointermove', + end: 'pointerup', + cancel: 'pointercancel' } }; function getCoordinates(event) { - var touches = event.touches && event.touches.length ? event.touches : [event]; - var e = (event.changedTouches && event.changedTouches[0]) || - (event.originalEvent && event.originalEvent.changedTouches && - event.originalEvent.changedTouches[0]) || - touches[0].originalEvent || touches[0]; + var originalEvent = event.originalEvent || event; + var touches = originalEvent.touches && originalEvent.touches.length ? originalEvent.touches : [originalEvent]; + var e = (originalEvent.changedTouches && originalEvent.changedTouches[0]) || touches[0]; return { x: e.clientX, @@ -99,14 +115,15 @@ ngTouch.factory('$swipe', [function() { * 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. + * third argument, which is an array of strings `'mouse'`, `'touch'` and `'pointer'`. By default, + * `$swipe` will listen for `mouse`, `touch` and `pointer` 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 }`. + * receive as a parameter a coordinates object of the form `{ x: 150, y: 310 }` and the raw + * `event`. `cancel` receives the raw `event` as its single parameter. * - * `start` is called on either `mousedown` or `touchstart`. After this event, `$swipe` is - * watching for `touchmove` or `mousemove` events. These events are ignored until the total + * `start` is called on either `mousedown`, `touchstart` or `pointerdown`. After this event, `$swipe` is + * watching for `touchmove`, `mousemove` or `pointermove` events. These events are ignored until the total * distance moved in either dimension exceeds a small threshold. * * Once this threshold is exceeded, either the horizontal or vertical delta is greater. @@ -114,12 +131,12 @@ ngTouch.factory('$swipe', [function() { * - If the vertical distance is greater, this is a scroll, and we let the browser take over. * A `cancel` event is sent. * - * `move` is called on `mousemove` and `touchmove` after the above logic has determined that + * `move` is called on `mousemove`, `touchmove` and `pointermove` after the above logic has determined that * a swipe is in progress. * - * `end` is called when a swipe is successfully completed with a `touchend` or `mouseup`. + * `end` is called when a swipe is successfully completed with a `touchend`, `mouseup` or `pointerup`. * - * `cancel` is called either on a `touchcancel` from the browser, or when we begin scrolling + * `cancel` is called either on a `touchcancel` or `pointercancel` from the browser, or when we begin scrolling * as described above. * */ @@ -133,20 +150,24 @@ ngTouch.factory('$swipe', [function() { // Whether a swipe is active. var active = false; - pointerTypes = pointerTypes || ['mouse', 'touch']; + pointerTypes = pointerTypes || ['mouse', 'touch', 'pointer']; element.on(getEvents(pointerTypes, 'start'), function(event) { startCoords = getCoordinates(event); active = true; totalX = 0; totalY = 0; lastPos = startCoords; - eventHandlers['start'] && eventHandlers['start'](startCoords, event); + if (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); + if (eventHandlers['cancel']) { + eventHandlers['cancel'](event); + } }); } @@ -175,19 +196,25 @@ ngTouch.factory('$swipe', [function() { if (totalY > totalX) { // Allow native scrolling to take over. active = false; - eventHandlers['cancel'] && eventHandlers['cancel'](event); + if (eventHandlers['cancel']) { + eventHandlers['cancel'](event); + } return; } else { // Prevent the browser from scrolling. event.preventDefault(); - eventHandlers['move'] && eventHandlers['move'](coords, event); + if (eventHandlers['move']) { + eventHandlers['move'](coords, event); + } } }); element.on(getEvents(pointerTypes, 'end'), function(event) { if (!active) return; active = false; - eventHandlers['end'] && eventHandlers['end'](getCoordinates(event), event); + if (eventHandlers['end']) { + eventHandlers['end'](getCoordinates(event), event); + } }); } }; @@ -197,298 +224,12 @@ ngTouch.factory('$swipe', [function() { /** * @ngdoc directive - * @name ngClick - * - * @description - * A more powerful replacement for the default ngClick designed to be used on touchscreen - * devices. Most mobile browsers wait about 300ms after a tap-and-release before sending - * the click event. This version handles them immediately, and then prevents the - * following click event from propagating. - * - * Requires the {@link ngTouch `ngTouch`} module to be installed. - * - * This directive can fall back to using an ordinary click event, and so works on desktop - * browsers as well as mobile. + * @name ngSwipeLeft * - * This directive also sets the CSS class `ng-click-active` while the element is being held - * down (by a mouse click or touch) so you can restyle the depressed element if you wish. + * @deprecated + * sinceVersion="1.7.0" * - * @element ANY - * @param {expression} ngClick {@link guide/expression Expression} to evaluate - * upon tap. (Event object is available as `$event`) - * - * @example -