swipe.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*!
  2. * Angular Material Design
  3. * https://github.com/angular/material
  4. * @license MIT
  5. * v0.11.4
  6. */
  7. goog.provide('ng.material.components.swipe');
  8. goog.require('ng.material.core');
  9. /**
  10. * @ngdoc module
  11. * @name material.components.swipe
  12. * @description Swipe module!
  13. */
  14. /**
  15. * @ngdoc directive
  16. * @module material.components.swipe
  17. * @name mdSwipeLeft
  18. *
  19. * @restrict A
  20. *
  21. * @description
  22. * The md-swipe-left directives allows you to specify custom behavior when an element is swiped
  23. * left.
  24. *
  25. * @usage
  26. * <hljs lang="html">
  27. * <div md-swipe-left="onSwipeLeft()">Swipe me left!</div>
  28. * </hljs>
  29. */
  30. /**
  31. * @ngdoc directive
  32. * @module material.components.swipe
  33. * @name mdSwipeRight
  34. *
  35. * @restrict A
  36. *
  37. * @description
  38. * The md-swipe-right directives allows you to specify custom behavior when an element is swiped
  39. * right.
  40. *
  41. * @usage
  42. * <hljs lang="html">
  43. * <div md-swipe-right="onSwipeRight()">Swipe me right!</div>
  44. * </hljs>
  45. */
  46. angular.module('material.components.swipe', ['material.core'])
  47. .directive('mdSwipeLeft', getDirective('SwipeLeft'))
  48. .directive('mdSwipeRight', getDirective('SwipeRight'));
  49. function getDirective(name) {
  50. var directiveName = 'md' + name;
  51. var eventName = '$md.' + name.toLowerCase();
  52. DirectiveFactory.$inject = ["$parse"];
  53. return DirectiveFactory;
  54. /* ngInject */
  55. function DirectiveFactory($parse) {
  56. return { restrict: 'A', link: postLink };
  57. function postLink(scope, element, attr) {
  58. var fn = $parse(attr[directiveName]);
  59. element.on(eventName, function(ev) {
  60. scope.$apply(function() { fn(scope, { $event: ev }); });
  61. });
  62. }
  63. }
  64. }
  65. ng.material.components.swipe = angular.module("material.components.swipe");