@angular-wave/angular.ts 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc.cjs +29 -0
  3. package/.github/workflows/playwright.yml +27 -0
  4. package/CHANGELOG.md +17974 -0
  5. package/CODE_OF_CONDUCT.md +3 -0
  6. package/CONTRIBUTING.md +246 -0
  7. package/DEVELOPERS.md +488 -0
  8. package/LICENSE +22 -0
  9. package/Makefile +31 -0
  10. package/README.md +115 -0
  11. package/RELEASE.md +98 -0
  12. package/SECURITY.md +16 -0
  13. package/TRIAGING.md +135 -0
  14. package/css/angular.css +22 -0
  15. package/dist/angular-ts.cjs.js +36843 -0
  16. package/dist/angular-ts.esm.js +36841 -0
  17. package/dist/angular-ts.umd.js +36848 -0
  18. package/dist/build/angular-animate.js +4272 -0
  19. package/dist/build/angular-aria.js +426 -0
  20. package/dist/build/angular-message-format.js +1072 -0
  21. package/dist/build/angular-messages.js +829 -0
  22. package/dist/build/angular-mocks.js +3757 -0
  23. package/dist/build/angular-parse-ext.js +1275 -0
  24. package/dist/build/angular-resource.js +911 -0
  25. package/dist/build/angular-route.js +1266 -0
  26. package/dist/build/angular-sanitize.js +891 -0
  27. package/dist/build/angular-touch.js +368 -0
  28. package/dist/build/angular.js +36600 -0
  29. package/e2e/unit.spec.ts +15 -0
  30. package/images/android-chrome-192x192.png +0 -0
  31. package/images/android-chrome-512x512.png +0 -0
  32. package/images/apple-touch-icon.png +0 -0
  33. package/images/favicon-16x16.png +0 -0
  34. package/images/favicon-32x32.png +0 -0
  35. package/images/favicon.ico +0 -0
  36. package/images/site.webmanifest +1 -0
  37. package/index.html +104 -0
  38. package/package.json +47 -0
  39. package/playwright.config.ts +78 -0
  40. package/public/circle.html +1 -0
  41. package/public/my_child_directive.html +1 -0
  42. package/public/my_directive.html +1 -0
  43. package/public/my_other_directive.html +1 -0
  44. package/public/test.html +1 -0
  45. package/rollup.config.js +31 -0
  46. package/src/animations/animateCache.js +55 -0
  47. package/src/animations/animateChildrenDirective.js +105 -0
  48. package/src/animations/animateCss.js +1139 -0
  49. package/src/animations/animateCssDriver.js +291 -0
  50. package/src/animations/animateJs.js +367 -0
  51. package/src/animations/animateJsDriver.js +67 -0
  52. package/src/animations/animateQueue.js +851 -0
  53. package/src/animations/animation.js +506 -0
  54. package/src/animations/module.js +779 -0
  55. package/src/animations/ngAnimateSwap.js +119 -0
  56. package/src/animations/rafScheduler.js +50 -0
  57. package/src/animations/shared.js +378 -0
  58. package/src/constants.js +20 -0
  59. package/src/core/animate.js +845 -0
  60. package/src/core/animateCss.js +73 -0
  61. package/src/core/animateRunner.js +195 -0
  62. package/src/core/attributes.js +199 -0
  63. package/src/core/cache.js +45 -0
  64. package/src/core/compile.js +4727 -0
  65. package/src/core/controller.js +225 -0
  66. package/src/core/exceptionHandler.js +63 -0
  67. package/src/core/filter.js +146 -0
  68. package/src/core/interpolate.js +442 -0
  69. package/src/core/interval.js +188 -0
  70. package/src/core/intervalFactory.js +57 -0
  71. package/src/core/location.js +1086 -0
  72. package/src/core/parser/parse.js +2562 -0
  73. package/src/core/parser/parse.md +13 -0
  74. package/src/core/q.js +746 -0
  75. package/src/core/rootScope.js +1596 -0
  76. package/src/core/sanitizeUri.js +85 -0
  77. package/src/core/sce.js +1161 -0
  78. package/src/core/taskTrackerFactory.js +125 -0
  79. package/src/core/timeout.js +121 -0
  80. package/src/core/urlUtils.js +187 -0
  81. package/src/core/utils.js +1349 -0
  82. package/src/directive/a.js +37 -0
  83. package/src/directive/attrs.js +283 -0
  84. package/src/directive/bind.js +51 -0
  85. package/src/directive/bind.md +142 -0
  86. package/src/directive/change.js +12 -0
  87. package/src/directive/change.md +25 -0
  88. package/src/directive/cloak.js +12 -0
  89. package/src/directive/cloak.md +24 -0
  90. package/src/directive/events.js +75 -0
  91. package/src/directive/events.md +166 -0
  92. package/src/directive/form.js +725 -0
  93. package/src/directive/init.js +15 -0
  94. package/src/directive/init.md +41 -0
  95. package/src/directive/input.js +1783 -0
  96. package/src/directive/list.js +46 -0
  97. package/src/directive/list.md +22 -0
  98. package/src/directive/ngClass.js +249 -0
  99. package/src/directive/ngController.js +64 -0
  100. package/src/directive/ngCsp.js +82 -0
  101. package/src/directive/ngIf.js +134 -0
  102. package/src/directive/ngInclude.js +217 -0
  103. package/src/directive/ngModel.js +1356 -0
  104. package/src/directive/ngModelOptions.js +509 -0
  105. package/src/directive/ngOptions.js +670 -0
  106. package/src/directive/ngRef.js +90 -0
  107. package/src/directive/ngRepeat.js +650 -0
  108. package/src/directive/ngShowHide.js +255 -0
  109. package/src/directive/ngSwitch.js +178 -0
  110. package/src/directive/ngTransclude.js +98 -0
  111. package/src/directive/non-bindable.js +11 -0
  112. package/src/directive/non-bindable.md +17 -0
  113. package/src/directive/script.js +30 -0
  114. package/src/directive/select.js +624 -0
  115. package/src/directive/style.js +25 -0
  116. package/src/directive/style.md +23 -0
  117. package/src/directive/validators.js +329 -0
  118. package/src/exts/aria.js +544 -0
  119. package/src/exts/messages.js +852 -0
  120. package/src/filters/filter.js +207 -0
  121. package/src/filters/filter.md +69 -0
  122. package/src/filters/filters.js +239 -0
  123. package/src/filters/json.md +16 -0
  124. package/src/filters/limit-to.js +43 -0
  125. package/src/filters/limit-to.md +19 -0
  126. package/src/filters/order-by.js +183 -0
  127. package/src/filters/order-by.md +83 -0
  128. package/src/index.js +13 -0
  129. package/src/injector.js +1034 -0
  130. package/src/jqLite.js +1117 -0
  131. package/src/loader.js +1320 -0
  132. package/src/public.js +215 -0
  133. package/src/routeToRegExp.js +41 -0
  134. package/src/services/anchorScroll.js +135 -0
  135. package/src/services/browser.js +321 -0
  136. package/src/services/cacheFactory.js +398 -0
  137. package/src/services/cookieReader.js +72 -0
  138. package/src/services/document.js +64 -0
  139. package/src/services/http.js +1537 -0
  140. package/src/services/httpBackend.js +206 -0
  141. package/src/services/log.js +160 -0
  142. package/src/services/templateRequest.js +139 -0
  143. package/test/angular.spec.js +2153 -0
  144. package/test/aria/aria.spec.js +1245 -0
  145. package/test/binding.spec.js +504 -0
  146. package/test/build-test.html +14 -0
  147. package/test/injector.spec.js +2327 -0
  148. package/test/jasmine/jasmine-5.1.2/boot0.js +65 -0
  149. package/test/jasmine/jasmine-5.1.2/boot1.js +133 -0
  150. package/test/jasmine/jasmine-5.1.2/jasmine-html.js +963 -0
  151. package/test/jasmine/jasmine-5.1.2/jasmine.css +320 -0
  152. package/test/jasmine/jasmine-5.1.2/jasmine.js +10824 -0
  153. package/test/jasmine/jasmine-5.1.2/jasmine_favicon.png +0 -0
  154. package/test/jasmine/jasmine-browser.json +17 -0
  155. package/test/jasmine/jasmine.json +9 -0
  156. package/test/jqlite.spec.js +2133 -0
  157. package/test/loader.spec.js +219 -0
  158. package/test/messages/messages.spec.js +1146 -0
  159. package/test/min-err.spec.js +174 -0
  160. package/test/mock-test.html +13 -0
  161. package/test/module-test.html +15 -0
  162. package/test/ng/anomate.spec.js +606 -0
  163. package/test/ng/cache-factor.spec.js +334 -0
  164. package/test/ng/compile.spec.js +17956 -0
  165. package/test/ng/controller-provider.spec.js +227 -0
  166. package/test/ng/cookie-reader.spec.js +98 -0
  167. package/test/ng/directive/a.spec.js +192 -0
  168. package/test/ng/directive/bind.spec.js +334 -0
  169. package/test/ng/directive/boolean.spec.js +136 -0
  170. package/test/ng/directive/change.spec.js +71 -0
  171. package/test/ng/directive/class.spec.js +858 -0
  172. package/test/ng/directive/click.spec.js +38 -0
  173. package/test/ng/directive/cloak.spec.js +44 -0
  174. package/test/ng/directive/constoller.spec.js +194 -0
  175. package/test/ng/directive/element-style.spec.js +92 -0
  176. package/test/ng/directive/event.spec.js +282 -0
  177. package/test/ng/directive/form.spec.js +1518 -0
  178. package/test/ng/directive/href.spec.js +143 -0
  179. package/test/ng/directive/if.spec.js +402 -0
  180. package/test/ng/directive/include.spec.js +828 -0
  181. package/test/ng/directive/init.spec.js +68 -0
  182. package/test/ng/directive/input.spec.js +3810 -0
  183. package/test/ng/directive/list.spec.js +170 -0
  184. package/test/ng/directive/model-options.spec.js +1008 -0
  185. package/test/ng/directive/model.spec.js +1905 -0
  186. package/test/ng/directive/non-bindable.spec.js +55 -0
  187. package/test/ng/directive/options.spec.js +3583 -0
  188. package/test/ng/directive/ref.spec.js +575 -0
  189. package/test/ng/directive/repeat.spec.js +1675 -0
  190. package/test/ng/directive/script.spec.js +52 -0
  191. package/test/ng/directive/scrset.spec.js +67 -0
  192. package/test/ng/directive/select.spec.js +2541 -0
  193. package/test/ng/directive/show-hide.spec.js +253 -0
  194. package/test/ng/directive/src.spec.js +157 -0
  195. package/test/ng/directive/style.spec.js +178 -0
  196. package/test/ng/directive/switch.spec.js +647 -0
  197. package/test/ng/directive/validators.spec.js +717 -0
  198. package/test/ng/document.spec.js +52 -0
  199. package/test/ng/filter/filter.spec.js +714 -0
  200. package/test/ng/filter/filters.spec.js +35 -0
  201. package/test/ng/filter/limit-to.spec.js +251 -0
  202. package/test/ng/filter/order-by.spec.js +891 -0
  203. package/test/ng/filter.spec.js +149 -0
  204. package/test/ng/http-backend.spec.js +398 -0
  205. package/test/ng/http.spec.js +4071 -0
  206. package/test/ng/interpolate.spec.js +642 -0
  207. package/test/ng/interval.spec.js +343 -0
  208. package/test/ng/location.spec.js +3488 -0
  209. package/test/ng/on.spec.js +229 -0
  210. package/test/ng/parse.spec.js +4655 -0
  211. package/test/ng/prop.spec.js +805 -0
  212. package/test/ng/q.spec.js +2904 -0
  213. package/test/ng/root-element.spec.js +16 -0
  214. package/test/ng/sanitize-uri.spec.js +249 -0
  215. package/test/ng/sce.spec.js +660 -0
  216. package/test/ng/scope.spec.js +3442 -0
  217. package/test/ng/template-request.spec.js +236 -0
  218. package/test/ng/timeout.spec.js +351 -0
  219. package/test/ng/url-utils.spec.js +156 -0
  220. package/test/ng/utils.spec.js +144 -0
  221. package/test/original-test.html +21 -0
  222. package/test/public.spec.js +34 -0
  223. package/test/sanitize/bing-html.spec.js +36 -0
  224. package/test/server/express.js +158 -0
  225. package/test/test-utils.js +11 -0
  226. package/tsconfig.json +17 -0
  227. package/types/angular.d.ts +138 -0
  228. package/types/global.d.ts +9 -0
  229. package/types/index.d.ts +2357 -0
  230. package/types/jqlite.d.ts +558 -0
  231. package/vite.config.js +14 -0
@@ -0,0 +1,368 @@
1
+ /**
2
+ * @license AngularJS v1.8.4-local+sha.4e1bd4b90
3
+ * (c) 2010-2020 Google LLC. http://angularjs.org
4
+ * License: MIT
5
+ */
6
+ (function(window, angular) {'use strict';
7
+
8
+ /**
9
+ * @ngdoc module
10
+ * @name ngTouch
11
+ * @description
12
+ *
13
+ * The `ngTouch` module provides helpers for touch-enabled devices.
14
+ * The implementation is based on jQuery Mobile touch event handling
15
+ * ([jquerymobile.com](http://jquerymobile.com/)). *
16
+ *
17
+ * See {@link ngTouch.$swipe `$swipe`} for usage.
18
+ *
19
+ * @deprecated
20
+ * sinceVersion="1.7.0"
21
+ * The ngTouch module with the {@link ngTouch.$swipe `$swipe`} service and
22
+ * the {@link ngTouch.ngSwipeLeft} and {@link ngTouch.ngSwipeRight} directives are
23
+ * deprecated. Instead, stand-alone libraries for touch handling and gesture interaction
24
+ * should be used, for example [HammerJS](https://hammerjs.github.io/) (which is also used by
25
+ * Angular).
26
+ */
27
+
28
+ // define ngTouch module
29
+ /* global ngTouch */
30
+ var ngTouch = angular.module('ngTouch', []);
31
+
32
+ ngTouch.info({ angularVersion: '1.8.4-local+sha.4e1bd4b90' });
33
+
34
+ function nodeName_(element) {
35
+ return angular.$$lowercase(element.nodeName || (element[0] && element[0].nodeName));
36
+ }
37
+
38
+ /* global ngTouch: false */
39
+
40
+ /**
41
+ * @ngdoc service
42
+ * @name $swipe
43
+ *
44
+ * @deprecated
45
+ * sinceVersion="1.7.0"
46
+ *
47
+ * See the {@link ngTouch module} documentation for more information.
48
+ *
49
+ * @description
50
+ * The `$swipe` service is a service that abstracts the messier details of hold-and-drag swipe
51
+ * behavior, to make implementing swipe-related directives more convenient.
52
+ *
53
+ * Requires the {@link ngTouch `ngTouch`} module to be installed.
54
+ *
55
+ * `$swipe` is used by the `ngSwipeLeft` and `ngSwipeRight` directives in `ngTouch`.
56
+ *
57
+ * # Usage
58
+ * The `$swipe` service is an object with a single method: `bind`. `bind` takes an element
59
+ * which is to be watched for swipes, and an object with four handler functions. See the
60
+ * documentation for `bind` below.
61
+ */
62
+
63
+ ngTouch.factory('$swipe', [function() {
64
+ // The total distance in any direction before we make the call on swipe vs. scroll.
65
+ var MOVE_BUFFER_RADIUS = 10;
66
+
67
+ var POINTER_EVENTS = {
68
+ 'mouse': {
69
+ start: 'mousedown',
70
+ move: 'mousemove',
71
+ end: 'mouseup'
72
+ },
73
+ 'touch': {
74
+ start: 'touchstart',
75
+ move: 'touchmove',
76
+ end: 'touchend',
77
+ cancel: 'touchcancel'
78
+ },
79
+ 'pointer': {
80
+ start: 'pointerdown',
81
+ move: 'pointermove',
82
+ end: 'pointerup',
83
+ cancel: 'pointercancel'
84
+ }
85
+ };
86
+
87
+ function getCoordinates(event) {
88
+ var originalEvent = event.originalEvent || event;
89
+ var touches = originalEvent.touches && originalEvent.touches.length ? originalEvent.touches : [originalEvent];
90
+ var e = (originalEvent.changedTouches && originalEvent.changedTouches[0]) || touches[0];
91
+
92
+ return {
93
+ x: e.clientX,
94
+ y: e.clientY
95
+ };
96
+ }
97
+
98
+ function getEvents(pointerTypes, eventType) {
99
+ var res = [];
100
+ angular.forEach(pointerTypes, function(pointerType) {
101
+ var eventName = POINTER_EVENTS[pointerType][eventType];
102
+ if (eventName) {
103
+ res.push(eventName);
104
+ }
105
+ });
106
+ return res.join(' ');
107
+ }
108
+
109
+ return {
110
+ /**
111
+ * @ngdoc method
112
+ * @name $swipe#bind
113
+ *
114
+ * @description
115
+ * The main method of `$swipe`. It takes an element to be watched for swipe motions, and an
116
+ * object containing event handlers.
117
+ * The pointer types that should be used can be specified via the optional
118
+ * third argument, which is an array of strings `'mouse'`, `'touch'` and `'pointer'`. By default,
119
+ * `$swipe` will listen for `mouse`, `touch` and `pointer` events.
120
+ *
121
+ * The four events are `start`, `move`, `end`, and `cancel`. `start`, `move`, and `end`
122
+ * receive as a parameter a coordinates object of the form `{ x: 150, y: 310 }` and the raw
123
+ * `event`. `cancel` receives the raw `event` as its single parameter.
124
+ *
125
+ * `start` is called on either `mousedown`, `touchstart` or `pointerdown`. After this event, `$swipe` is
126
+ * watching for `touchmove`, `mousemove` or `pointermove` events. These events are ignored until the total
127
+ * distance moved in either dimension exceeds a small threshold.
128
+ *
129
+ * Once this threshold is exceeded, either the horizontal or vertical delta is greater.
130
+ * - If the horizontal distance is greater, this is a swipe and `move` and `end` events follow.
131
+ * - If the vertical distance is greater, this is a scroll, and we let the browser take over.
132
+ * A `cancel` event is sent.
133
+ *
134
+ * `move` is called on `mousemove`, `touchmove` and `pointermove` after the above logic has determined that
135
+ * a swipe is in progress.
136
+ *
137
+ * `end` is called when a swipe is successfully completed with a `touchend`, `mouseup` or `pointerup`.
138
+ *
139
+ * `cancel` is called either on a `touchcancel` or `pointercancel` from the browser, or when we begin scrolling
140
+ * as described above.
141
+ *
142
+ */
143
+ bind: function(element, eventHandlers, pointerTypes) {
144
+ // Absolute total movement, used to control swipe vs. scroll.
145
+ var totalX, totalY;
146
+ // Coordinates of the start position.
147
+ var startCoords;
148
+ // Last event's position.
149
+ var lastPos;
150
+ // Whether a swipe is active.
151
+ var active = false;
152
+
153
+ pointerTypes = pointerTypes || ['mouse', 'touch', 'pointer'];
154
+ element.on(getEvents(pointerTypes, 'start'), function(event) {
155
+ startCoords = getCoordinates(event);
156
+ active = true;
157
+ totalX = 0;
158
+ totalY = 0;
159
+ lastPos = startCoords;
160
+ if (eventHandlers['start']) {
161
+ eventHandlers['start'](startCoords, event);
162
+ }
163
+ });
164
+ var events = getEvents(pointerTypes, 'cancel');
165
+ if (events) {
166
+ element.on(events, function(event) {
167
+ active = false;
168
+ if (eventHandlers['cancel']) {
169
+ eventHandlers['cancel'](event);
170
+ }
171
+ });
172
+ }
173
+
174
+ element.on(getEvents(pointerTypes, 'move'), function(event) {
175
+ if (!active) return;
176
+
177
+ // Android will send a touchcancel if it thinks we're starting to scroll.
178
+ // So when the total distance (+ or - or both) exceeds 10px in either direction,
179
+ // we either:
180
+ // - On totalX > totalY, we send preventDefault() and treat this as a swipe.
181
+ // - On totalY > totalX, we let the browser handle it as a scroll.
182
+
183
+ if (!startCoords) return;
184
+ var coords = getCoordinates(event);
185
+
186
+ totalX += Math.abs(coords.x - lastPos.x);
187
+ totalY += Math.abs(coords.y - lastPos.y);
188
+
189
+ lastPos = coords;
190
+
191
+ if (totalX < MOVE_BUFFER_RADIUS && totalY < MOVE_BUFFER_RADIUS) {
192
+ return;
193
+ }
194
+
195
+ // One of totalX or totalY has exceeded the buffer, so decide on swipe vs. scroll.
196
+ if (totalY > totalX) {
197
+ // Allow native scrolling to take over.
198
+ active = false;
199
+ if (eventHandlers['cancel']) {
200
+ eventHandlers['cancel'](event);
201
+ }
202
+ return;
203
+ } else {
204
+ // Prevent the browser from scrolling.
205
+ event.preventDefault();
206
+ if (eventHandlers['move']) {
207
+ eventHandlers['move'](coords, event);
208
+ }
209
+ }
210
+ });
211
+
212
+ element.on(getEvents(pointerTypes, 'end'), function(event) {
213
+ if (!active) return;
214
+ active = false;
215
+ if (eventHandlers['end']) {
216
+ eventHandlers['end'](getCoordinates(event), event);
217
+ }
218
+ });
219
+ }
220
+ };
221
+ }]);
222
+
223
+ /* global ngTouch: false */
224
+
225
+ /**
226
+ * @ngdoc directive
227
+ * @name ngSwipeLeft
228
+ *
229
+ * @deprecated
230
+ * sinceVersion="1.7.0"
231
+ *
232
+ * See the {@link ngTouch module} documentation for more information.
233
+ *
234
+ * @description
235
+ * Specify custom behavior when an element is swiped to the left on a touchscreen device.
236
+ * A leftward swipe is a quick, right-to-left slide of the finger.
237
+ * Though ngSwipeLeft is designed for touch-based devices, it will work with a mouse click and drag
238
+ * too.
239
+ *
240
+ * To disable the mouse click and drag functionality, add `ng-swipe-disable-mouse` to
241
+ * the `ng-swipe-left` or `ng-swipe-right` DOM Element.
242
+ *
243
+ * Requires the {@link ngTouch `ngTouch`} module to be installed.
244
+ *
245
+ * @element ANY
246
+ * @param {expression} ngSwipeLeft {@link guide/expression Expression} to evaluate
247
+ * upon left swipe. (Event object is available as `$event`)
248
+ *
249
+ * @example
250
+ <example module="ngSwipeLeftExample" deps="angular-touch.js" name="ng-swipe-left">
251
+ <file name="index.html">
252
+ <div ng-show="!showActions" ng-swipe-left="showActions = true">
253
+ Some list content, like an email in the inbox
254
+ </div>
255
+ <div ng-show="showActions" ng-swipe-right="showActions = false">
256
+ <button ng-click="reply()">Reply</button>
257
+ <button ng-click="delete()">Delete</button>
258
+ </div>
259
+ </file>
260
+ <file name="script.js">
261
+ angular.module('ngSwipeLeftExample', ['ngTouch']);
262
+ </file>
263
+ </example>
264
+ */
265
+
266
+ /**
267
+ * @ngdoc directive
268
+ * @name ngSwipeRight
269
+ *
270
+ * @deprecated
271
+ * sinceVersion="1.7.0"
272
+ *
273
+ * See the {@link ngTouch module} documentation for more information.
274
+ *
275
+ * @description
276
+ * Specify custom behavior when an element is swiped to the right on a touchscreen device.
277
+ * A rightward swipe is a quick, left-to-right slide of the finger.
278
+ * Though ngSwipeRight is designed for touch-based devices, it will work with a mouse click and drag
279
+ * too.
280
+ *
281
+ * Requires the {@link ngTouch `ngTouch`} module to be installed.
282
+ *
283
+ * @element ANY
284
+ * @param {expression} ngSwipeRight {@link guide/expression Expression} to evaluate
285
+ * upon right swipe. (Event object is available as `$event`)
286
+ *
287
+ * @example
288
+ <example module="ngSwipeRightExample" deps="angular-touch.js" name="ng-swipe-right">
289
+ <file name="index.html">
290
+ <div ng-show="!showActions" ng-swipe-left="showActions = true">
291
+ Some list content, like an email in the inbox
292
+ </div>
293
+ <div ng-show="showActions" ng-swipe-right="showActions = false">
294
+ <button ng-click="reply()">Reply</button>
295
+ <button ng-click="delete()">Delete</button>
296
+ </div>
297
+ </file>
298
+ <file name="script.js">
299
+ angular.module('ngSwipeRightExample', ['ngTouch']);
300
+ </file>
301
+ </example>
302
+ */
303
+
304
+ function makeSwipeDirective(directiveName, direction, eventName) {
305
+ ngTouch.directive(directiveName, ['$parse', '$swipe', function($parse, $swipe) {
306
+ // The maximum vertical delta for a swipe should be less than 75px.
307
+ var MAX_VERTICAL_DISTANCE = 75;
308
+ // Vertical distance should not be more than a fraction of the horizontal distance.
309
+ var MAX_VERTICAL_RATIO = 0.3;
310
+ // At least a 30px lateral motion is necessary for a swipe.
311
+ var MIN_HORIZONTAL_DISTANCE = 30;
312
+
313
+ return function(scope, element, attr) {
314
+ var swipeHandler = $parse(attr[directiveName]);
315
+
316
+ var startCoords, valid;
317
+
318
+ function validSwipe(coords) {
319
+ // Check that it's within the coordinates.
320
+ // Absolute vertical distance must be within tolerances.
321
+ // Horizontal distance, we take the current X - the starting X.
322
+ // This is negative for leftward swipes and positive for rightward swipes.
323
+ // After multiplying by the direction (-1 for left, +1 for right), legal swipes
324
+ // (ie. same direction as the directive wants) will have a positive delta and
325
+ // illegal ones a negative delta.
326
+ // Therefore this delta must be positive, and larger than the minimum.
327
+ if (!startCoords) return false;
328
+ var deltaY = Math.abs(coords.y - startCoords.y);
329
+ var deltaX = (coords.x - startCoords.x) * direction;
330
+ return valid && // Short circuit for already-invalidated swipes.
331
+ deltaY < MAX_VERTICAL_DISTANCE &&
332
+ deltaX > 0 &&
333
+ deltaX > MIN_HORIZONTAL_DISTANCE &&
334
+ deltaY / deltaX < MAX_VERTICAL_RATIO;
335
+ }
336
+
337
+ var pointerTypes = ['touch'];
338
+ if (!angular.isDefined(attr['ngSwipeDisableMouse'])) {
339
+ pointerTypes.push('mouse');
340
+ }
341
+ $swipe.bind(element, {
342
+ 'start': function(coords, event) {
343
+ startCoords = coords;
344
+ valid = true;
345
+ },
346
+ 'cancel': function(event) {
347
+ valid = false;
348
+ },
349
+ 'end': function(coords, event) {
350
+ if (validSwipe(coords)) {
351
+ scope.$apply(function() {
352
+ element.triggerHandler(eventName);
353
+ swipeHandler(scope, {$event: event});
354
+ });
355
+ }
356
+ }
357
+ }, pointerTypes);
358
+ };
359
+ }]);
360
+ }
361
+
362
+ // Left is negative X-coordinate, right is positive.
363
+ makeSwipeDirective('ngSwipeLeft', -1, 'swipeleft');
364
+ makeSwipeDirective('ngSwipeRight', 1, 'swiperight');
365
+
366
+
367
+
368
+ })(window, window.angular);