hammer.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**
  2. * Simple way to create a manager with a default set of recognizers.
  3. * @param {HTMLElement} element
  4. * @param {Object} [options]
  5. * @constructor
  6. */
  7. function Hammer(element, options) {
  8. options = options || {};
  9. options.recognizers = ifUndefined(options.recognizers, Hammer.defaults.preset);
  10. return new Manager(element, options);
  11. }
  12. /**
  13. * @const {string}
  14. */
  15. Hammer.VERSION = '{{PKG_VERSION}}';
  16. /**
  17. * default settings
  18. * @namespace
  19. */
  20. Hammer.defaults = {
  21. /**
  22. * set if DOM events are being triggered.
  23. * But this is slower and unused by simple implementations, so disabled by default.
  24. * @type {Boolean}
  25. * @default false
  26. */
  27. domEvents: false,
  28. /**
  29. * The value for the touchAction property/fallback.
  30. * When set to `compute` it will magically set the correct value based on the added recognizers.
  31. * @type {String}
  32. * @default compute
  33. */
  34. touchAction: TOUCH_ACTION_COMPUTE,
  35. /**
  36. * @type {Boolean}
  37. * @default true
  38. */
  39. enable: true,
  40. /**
  41. * EXPERIMENTAL FEATURE -- can be removed/changed
  42. * Change the parent input target element.
  43. * If Null, then it is being set the to main element.
  44. * @type {Null|EventTarget}
  45. * @default null
  46. */
  47. inputTarget: null,
  48. /**
  49. * force an input class
  50. * @type {Null|Function}
  51. * @default null
  52. */
  53. inputClass: null,
  54. /**
  55. * Default recognizer setup when calling `Hammer()`
  56. * When creating a new Manager these will be skipped.
  57. * @type {Array}
  58. */
  59. preset: [
  60. // RecognizerClass, options, [recognizeWith, ...], [requireFailure, ...]
  61. [RotateRecognizer, {enable: false}],
  62. [PinchRecognizer, {enable: false}, ['rotate']],
  63. [SwipeRecognizer, {direction: DIRECTION_HORIZONTAL}],
  64. [PanRecognizer, {direction: DIRECTION_HORIZONTAL}, ['swipe']],
  65. [TapRecognizer],
  66. [TapRecognizer, {event: 'doubletap', taps: 2}, ['tap']],
  67. [PressRecognizer]
  68. ],
  69. /**
  70. * Some CSS properties can be used to improve the working of Hammer.
  71. * Add them to this method and they will be set when creating a new Manager.
  72. * @namespace
  73. */
  74. cssProps: {
  75. /**
  76. * Disables text selection to improve the dragging gesture. Mainly for desktop browsers.
  77. * @type {String}
  78. * @default 'none'
  79. */
  80. userSelect: 'none',
  81. /**
  82. * Disable the Windows Phone grippers when pressing an element.
  83. * @type {String}
  84. * @default 'none'
  85. */
  86. touchSelect: 'none',
  87. /**
  88. * Disables the default callout shown when you touch and hold a touch target.
  89. * On iOS, when you touch and hold a touch target such as a link, Safari displays
  90. * a callout containing information about the link. This property allows you to disable that callout.
  91. * @type {String}
  92. * @default 'none'
  93. */
  94. touchCallout: 'none',
  95. /**
  96. * Specifies whether zooming is enabled. Used by IE10>
  97. * @type {String}
  98. * @default 'none'
  99. */
  100. contentZooming: 'none',
  101. /**
  102. * Specifies that an entire element should be draggable instead of its contents. Mainly for desktop browsers.
  103. * @type {String}
  104. * @default 'none'
  105. */
  106. userDrag: 'none',
  107. /**
  108. * Overrides the highlight color shown when the user taps a link or a JavaScript
  109. * clickable element in iOS. This property obeys the alpha value, if specified.
  110. * @type {String}
  111. * @default 'rgba(0,0,0,0)'
  112. */
  113. tapHighlightColor: 'rgba(0,0,0,0)'
  114. }
  115. };