angularjs-rails 1.6.8 → 1.8.0

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.
@@ -1,12 +1,10 @@
1
1
  /**
2
- * @license AngularJS v1.6.8
3
- * (c) 2010-2017 Google, Inc. http://angularjs.org
2
+ * @license AngularJS v1.8.0
3
+ * (c) 2010-2020 Google, Inc. http://angularjs.org
4
4
  * License: MIT
5
5
  */
6
6
  (function(window, angular) {'use strict';
7
7
 
8
- /* global ngTouchClickDirectiveFactory: false */
9
-
10
8
  /**
11
9
  * @ngdoc module
12
10
  * @name ngTouch
@@ -18,116 +16,23 @@
18
16
  *
19
17
  * See {@link ngTouch.$swipe `$swipe`} for usage.
20
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).
21
26
  */
22
27
 
23
28
  // define ngTouch module
24
- /* global -ngTouch */
29
+ /* global ngTouch */
25
30
  var ngTouch = angular.module('ngTouch', []);
26
31
 
27
- ngTouch.info({ angularVersion: '1.6.8' });
28
-
29
- ngTouch.provider('$touch', $TouchProvider);
32
+ ngTouch.info({ angularVersion: '1.8.0' });
30
33
 
31
34
  function nodeName_(element) {
32
- return angular.lowercase(element.nodeName || (element[0] && element[0].nodeName));
33
- }
34
-
35
- /**
36
- * @ngdoc provider
37
- * @name $touchProvider
38
- *
39
- * @description
40
- * The `$touchProvider` allows enabling / disabling {@link ngTouch.ngClick ngTouch's ngClick directive}.
41
- */
42
- $TouchProvider.$inject = ['$provide', '$compileProvider'];
43
- function $TouchProvider($provide, $compileProvider) {
44
-
45
- /**
46
- * @ngdoc method
47
- * @name $touchProvider#ngClickOverrideEnabled
48
- *
49
- * @param {boolean=} enabled update the ngClickOverrideEnabled state if provided, otherwise just return the
50
- * current ngClickOverrideEnabled state
51
- * @returns {*} current value if used as getter or itself (chaining) if used as setter
52
- *
53
- * @kind function
54
- *
55
- * @description
56
- * Call this method to enable/disable {@link ngTouch.ngClick ngTouch's ngClick directive}. If enabled,
57
- * the default ngClick directive will be replaced by a version that eliminates the 300ms delay for
58
- * click events on browser for touch-devices.
59
- *
60
- * The default is `false`.
61
- *
62
- */
63
- var ngClickOverrideEnabled = false;
64
- var ngClickDirectiveAdded = false;
65
- // eslint-disable-next-line no-invalid-this
66
- this.ngClickOverrideEnabled = function(enabled) {
67
- if (angular.isDefined(enabled)) {
68
-
69
- if (enabled && !ngClickDirectiveAdded) {
70
- ngClickDirectiveAdded = true;
71
-
72
- // Use this to identify the correct directive in the delegate
73
- ngTouchClickDirectiveFactory.$$moduleName = 'ngTouch';
74
- $compileProvider.directive('ngClick', ngTouchClickDirectiveFactory);
75
-
76
- $provide.decorator('ngClickDirective', ['$delegate', function($delegate) {
77
- if (ngClickOverrideEnabled) {
78
- // drop the default ngClick directive
79
- $delegate.shift();
80
- } else {
81
- // drop the ngTouch ngClick directive if the override has been re-disabled (because
82
- // we cannot de-register added directives)
83
- var i = $delegate.length - 1;
84
- while (i >= 0) {
85
- if ($delegate[i].$$moduleName === 'ngTouch') {
86
- $delegate.splice(i, 1);
87
- break;
88
- }
89
- i--;
90
- }
91
- }
92
-
93
- return $delegate;
94
- }]);
95
- }
96
-
97
- ngClickOverrideEnabled = enabled;
98
- return this;
99
- }
100
-
101
- return ngClickOverrideEnabled;
102
- };
103
-
104
- /**
105
- * @ngdoc service
106
- * @name $touch
107
- * @kind object
108
- *
109
- * @description
110
- * Provides the {@link ngTouch.$touch#ngClickOverrideEnabled `ngClickOverrideEnabled`} method.
111
- *
112
- */
113
- // eslint-disable-next-line no-invalid-this
114
- this.$get = function() {
115
- return {
116
- /**
117
- * @ngdoc method
118
- * @name $touch#ngClickOverrideEnabled
119
- *
120
- * @returns {*} current value of `ngClickOverrideEnabled` set in the {@link ngTouch.$touchProvider $touchProvider},
121
- * i.e. if {@link ngTouch.ngClick ngTouch's ngClick} directive is enabled.
122
- *
123
- * @kind function
124
- */
125
- ngClickOverrideEnabled: function() {
126
- return ngClickOverrideEnabled;
127
- }
128
- };
129
- };
130
-
35
+ return angular.$$lowercase(element.nodeName || (element[0] && element[0].nodeName));
131
36
  }
132
37
 
133
38
  /* global ngTouch: false */
@@ -136,6 +41,11 @@ function $TouchProvider($provide, $compileProvider) {
136
41
  * @ngdoc service
137
42
  * @name $swipe
138
43
  *
44
+ * @deprecated
45
+ * sinceVersion="1.7.0"
46
+ *
47
+ * See the {@link ngTouch module} documentation for more information.
48
+ *
139
49
  * @description
140
50
  * The `$swipe` service is a service that abstracts the messier details of hold-and-drag swipe
141
51
  * behavior, to make implementing swipe-related directives more convenient.
@@ -310,308 +220,17 @@ ngTouch.factory('$swipe', [function() {
310
220
  };
311
221
  }]);
312
222
 
313
- /* global ngTouch: false,
314
- nodeName_: false
315
- */
316
-
317
- /**
318
- * @ngdoc directive
319
- * @name ngClick
320
- * @deprecated
321
- * sinceVersion="v1.5.0"
322
- * This directive is deprecated and **disabled** by default.
323
- * The directive will receive no further support and might be removed from future releases.
324
- * If you need the directive, you can enable it with the {@link ngTouch.$touchProvider $touchProvider#ngClickOverrideEnabled}
325
- * function. We also recommend that you migrate to [FastClick](https://github.com/ftlabs/fastclick).
326
- * To learn more about the 300ms delay, this [Telerik article](http://developer.telerik.com/featured/300-ms-click-delay-ios-8/)
327
- * gives a good overview.
328
- *
329
- * @description
330
- * A more powerful replacement for the default ngClick designed to be used on touchscreen
331
- * devices. Most mobile browsers wait about 300ms after a tap-and-release before sending
332
- * the click event. This version handles them immediately, and then prevents the
333
- * following click event from propagating.
334
- *
335
- * Requires the {@link ngTouch `ngTouch`} module to be installed.
336
- *
337
- * This directive can fall back to using an ordinary click event, and so works on desktop
338
- * browsers as well as mobile.
339
- *
340
- * This directive also sets the CSS class `ng-click-active` while the element is being held
341
- * down (by a mouse click or touch) so you can restyle the depressed element if you wish.
342
- *
343
- * @element ANY
344
- * @param {expression} ngClick {@link guide/expression Expression} to evaluate
345
- * upon tap. (Event object is available as `$event`)
346
- *
347
- * @example
348
- <example module="ngClickExample" deps="angular-touch.js" name="ng-touch-ng-click">
349
- <file name="index.html">
350
- <button ng-click="count = count + 1" ng-init="count=0">
351
- Increment
352
- </button>
353
- count: {{ count }}
354
- </file>
355
- <file name="script.js">
356
- angular.module('ngClickExample', ['ngTouch']);
357
- </file>
358
- </example>
359
- */
360
-
361
- var ngTouchClickDirectiveFactory = ['$parse', '$timeout', '$rootElement',
362
- function($parse, $timeout, $rootElement) {
363
- var TAP_DURATION = 750; // Shorter than 750ms is a tap, longer is a taphold or drag.
364
- var MOVE_TOLERANCE = 12; // 12px seems to work in most mobile browsers.
365
- var PREVENT_DURATION = 2500; // 2.5 seconds maximum from preventGhostClick call to click
366
- var CLICKBUSTER_THRESHOLD = 25; // 25 pixels in any dimension is the limit for busting clicks.
367
-
368
- var ACTIVE_CLASS_NAME = 'ng-click-active';
369
- var lastPreventedTime;
370
- var touchCoordinates;
371
- var lastLabelClickCoordinates;
372
-
373
-
374
- // TAP EVENTS AND GHOST CLICKS
375
- //
376
- // Why tap events?
377
- // Mobile browsers detect a tap, then wait a moment (usually ~300ms) to see if you're
378
- // double-tapping, and then fire a click event.
379
- //
380
- // This delay sucks and makes mobile apps feel unresponsive.
381
- // So we detect touchstart, touchcancel and touchend ourselves and determine when
382
- // the user has tapped on something.
383
- //
384
- // What happens when the browser then generates a click event?
385
- // The browser, of course, also detects the tap and fires a click after a delay. This results in
386
- // tapping/clicking twice. We do "clickbusting" to prevent it.
387
- //
388
- // How does it work?
389
- // We attach global touchstart and click handlers, that run during the capture (early) phase.
390
- // So the sequence for a tap is:
391
- // - global touchstart: Sets an "allowable region" at the point touched.
392
- // - element's touchstart: Starts a touch
393
- // (- touchcancel ends the touch, no click follows)
394
- // - element's touchend: Determines if the tap is valid (didn't move too far away, didn't hold
395
- // too long) and fires the user's tap handler. The touchend also calls preventGhostClick().
396
- // - preventGhostClick() removes the allowable region the global touchstart created.
397
- // - The browser generates a click event.
398
- // - The global click handler catches the click, and checks whether it was in an allowable region.
399
- // - If preventGhostClick was called, the region will have been removed, the click is busted.
400
- // - If the region is still there, the click proceeds normally. Therefore clicks on links and
401
- // other elements without ngTap on them work normally.
402
- //
403
- // This is an ugly, terrible hack!
404
- // Yeah, tell me about it. The alternatives are using the slow click events, or making our users
405
- // deal with the ghost clicks, so I consider this the least of evils. Fortunately Angular
406
- // encapsulates this ugly logic away from the user.
407
- //
408
- // Why not just put click handlers on the element?
409
- // We do that too, just to be sure. If the tap event caused the DOM to change,
410
- // it is possible another element is now in that position. To take account for these possibly
411
- // distinct elements, the handlers are global and care only about coordinates.
412
-
413
- // Checks if the coordinates are close enough to be within the region.
414
- function hit(x1, y1, x2, y2) {
415
- return Math.abs(x1 - x2) < CLICKBUSTER_THRESHOLD && Math.abs(y1 - y2) < CLICKBUSTER_THRESHOLD;
416
- }
417
-
418
- // Checks a list of allowable regions against a click location.
419
- // Returns true if the click should be allowed.
420
- // Splices out the allowable region from the list after it has been used.
421
- function checkAllowableRegions(touchCoordinates, x, y) {
422
- for (var i = 0; i < touchCoordinates.length; i += 2) {
423
- if (hit(touchCoordinates[i], touchCoordinates[i + 1], x, y)) {
424
- touchCoordinates.splice(i, i + 2);
425
- return true; // allowable region
426
- }
427
- }
428
- return false; // No allowable region; bust it.
429
- }
430
-
431
- // Global click handler that prevents the click if it's in a bustable zone and preventGhostClick
432
- // was called recently.
433
- function onClick(event) {
434
- if (Date.now() - lastPreventedTime > PREVENT_DURATION) {
435
- return; // Too old.
436
- }
437
-
438
- var touches = event.touches && event.touches.length ? event.touches : [event];
439
- var x = touches[0].clientX;
440
- var y = touches[0].clientY;
441
- // Work around desktop Webkit quirk where clicking a label will fire two clicks (on the label
442
- // and on the input element). Depending on the exact browser, this second click we don't want
443
- // to bust has either (0,0), negative coordinates, or coordinates equal to triggering label
444
- // click event
445
- if (x < 1 && y < 1) {
446
- return; // offscreen
447
- }
448
- if (lastLabelClickCoordinates &&
449
- lastLabelClickCoordinates[0] === x && lastLabelClickCoordinates[1] === y) {
450
- return; // input click triggered by label click
451
- }
452
- // reset label click coordinates on first subsequent click
453
- if (lastLabelClickCoordinates) {
454
- lastLabelClickCoordinates = null;
455
- }
456
- // remember label click coordinates to prevent click busting of trigger click event on input
457
- if (nodeName_(event.target) === 'label') {
458
- lastLabelClickCoordinates = [x, y];
459
- }
460
-
461
- // Look for an allowable region containing this click.
462
- // If we find one, that means it was created by touchstart and not removed by
463
- // preventGhostClick, so we don't bust it.
464
- if (checkAllowableRegions(touchCoordinates, x, y)) {
465
- return;
466
- }
467
-
468
- // If we didn't find an allowable region, bust the click.
469
- event.stopPropagation();
470
- event.preventDefault();
471
-
472
- // Blur focused form elements
473
- if (event.target && event.target.blur) {
474
- event.target.blur();
475
- }
476
- }
477
-
478
-
479
- // Global touchstart handler that creates an allowable region for a click event.
480
- // This allowable region can be removed by preventGhostClick if we want to bust it.
481
- function onTouchStart(event) {
482
- var touches = event.touches && event.touches.length ? event.touches : [event];
483
- var x = touches[0].clientX;
484
- var y = touches[0].clientY;
485
- touchCoordinates.push(x, y);
486
-
487
- $timeout(function() {
488
- // Remove the allowable region.
489
- for (var i = 0; i < touchCoordinates.length; i += 2) {
490
- if (touchCoordinates[i] === x && touchCoordinates[i + 1] === y) {
491
- touchCoordinates.splice(i, i + 2);
492
- return;
493
- }
494
- }
495
- }, PREVENT_DURATION, false);
496
- }
497
-
498
- // On the first call, attaches some event handlers. Then whenever it gets called, it creates a
499
- // zone around the touchstart where clicks will get busted.
500
- function preventGhostClick(x, y) {
501
- if (!touchCoordinates) {
502
- $rootElement[0].addEventListener('click', onClick, true);
503
- $rootElement[0].addEventListener('touchstart', onTouchStart, true);
504
- touchCoordinates = [];
505
- }
506
-
507
- lastPreventedTime = Date.now();
508
-
509
- checkAllowableRegions(touchCoordinates, x, y);
510
- }
511
-
512
- // Actual linking function.
513
- return function(scope, element, attr) {
514
- var clickHandler = $parse(attr.ngClick),
515
- tapping = false,
516
- tapElement, // Used to blur the element after a tap.
517
- startTime, // Used to check if the tap was held too long.
518
- touchStartX,
519
- touchStartY;
520
-
521
- function resetState() {
522
- tapping = false;
523
- element.removeClass(ACTIVE_CLASS_NAME);
524
- }
525
-
526
- element.on('touchstart', function(event) {
527
- tapping = true;
528
- tapElement = event.target ? event.target : event.srcElement; // IE uses srcElement.
529
- // Hack for Safari, which can target text nodes instead of containers.
530
- if (tapElement.nodeType === 3) {
531
- tapElement = tapElement.parentNode;
532
- }
533
-
534
- element.addClass(ACTIVE_CLASS_NAME);
535
-
536
- startTime = Date.now();
537
-
538
- // Use jQuery originalEvent
539
- var originalEvent = event.originalEvent || event;
540
- var touches = originalEvent.touches && originalEvent.touches.length ? originalEvent.touches : [originalEvent];
541
- var e = touches[0];
542
- touchStartX = e.clientX;
543
- touchStartY = e.clientY;
544
- });
545
-
546
- element.on('touchcancel', function(event) {
547
- resetState();
548
- });
549
-
550
- element.on('touchend', function(event) {
551
- var diff = Date.now() - startTime;
552
-
553
- // Use jQuery originalEvent
554
- var originalEvent = event.originalEvent || event;
555
- var touches = (originalEvent.changedTouches && originalEvent.changedTouches.length) ?
556
- originalEvent.changedTouches :
557
- ((originalEvent.touches && originalEvent.touches.length) ? originalEvent.touches : [originalEvent]);
558
- var e = touches[0];
559
- var x = e.clientX;
560
- var y = e.clientY;
561
- var dist = Math.sqrt(Math.pow(x - touchStartX, 2) + Math.pow(y - touchStartY, 2));
562
-
563
- if (tapping && diff < TAP_DURATION && dist < MOVE_TOLERANCE) {
564
- // Call preventGhostClick so the clickbuster will catch the corresponding click.
565
- preventGhostClick(x, y);
566
-
567
- // Blur the focused element (the button, probably) before firing the callback.
568
- // This doesn't work perfectly on Android Chrome, but seems to work elsewhere.
569
- // I couldn't get anything to work reliably on Android Chrome.
570
- if (tapElement) {
571
- tapElement.blur();
572
- }
573
-
574
- if (!angular.isDefined(attr.disabled) || attr.disabled === false) {
575
- element.triggerHandler('click', [event]);
576
- }
577
- }
578
-
579
- resetState();
580
- });
581
-
582
- // Hack for iOS Safari's benefit. It goes searching for onclick handlers and is liable to click
583
- // something else nearby.
584
- element.onclick = function(event) { };
585
-
586
- // Actual click handler.
587
- // There are three different kinds of clicks, only two of which reach this point.
588
- // - On desktop browsers without touch events, their clicks will always come here.
589
- // - On mobile browsers, the simulated "fast" click will call this.
590
- // - But the browser's follow-up slow click will be "busted" before it reaches this handler.
591
- // Therefore it's safe to use this directive on both mobile and desktop.
592
- element.on('click', function(event, touchend) {
593
- scope.$apply(function() {
594
- clickHandler(scope, {$event: (touchend || event)});
595
- });
596
- });
597
-
598
- element.on('mousedown', function(event) {
599
- element.addClass(ACTIVE_CLASS_NAME);
600
- });
601
-
602
- element.on('mousemove mouseup', function(event) {
603
- element.removeClass(ACTIVE_CLASS_NAME);
604
- });
605
-
606
- };
607
- }];
608
-
609
223
  /* global ngTouch: false */
610
224
 
611
225
  /**
612
226
  * @ngdoc directive
613
227
  * @name ngSwipeLeft
614
228
  *
229
+ * @deprecated
230
+ * sinceVersion="1.7.0"
231
+ *
232
+ * See the {@link ngTouch module} documentation for more information.
233
+ *
615
234
  * @description
616
235
  * Specify custom behavior when an element is swiped to the left on a touchscreen device.
617
236
  * A leftward swipe is a quick, right-to-left slide of the finger.
@@ -648,6 +267,11 @@ var ngTouchClickDirectiveFactory = ['$parse', '$timeout', '$rootElement',
648
267
  * @ngdoc directive
649
268
  * @name ngSwipeRight
650
269
  *
270
+ * @deprecated
271
+ * sinceVersion="1.7.0"
272
+ *
273
+ * See the {@link ngTouch module} documentation for more information.
274
+ *
651
275
  * @description
652
276
  * Specify custom behavior when an element is swiped to the right on a touchscreen device.
653
277
  * A rightward swipe is a quick, left-to-right slide of the finger.