foundation.util.touch.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("./foundation.core"), require("jquery"));
  4. else if(typeof define === 'function' && define.amd)
  5. define(["./foundation.core", "jquery"], factory);
  6. else if(typeof exports === 'object')
  7. exports["foundation.util.touch"] = factory(require("./foundation.core"), require("jquery"));
  8. else
  9. root["__FOUNDATION_EXTERNAL__"] = root["__FOUNDATION_EXTERNAL__"] || {}, root["__FOUNDATION_EXTERNAL__"]["foundation.util.touch"] = factory(root["__FOUNDATION_EXTERNAL__"]["foundation.core"], root["jQuery"]);
  10. })(window, function(__WEBPACK_EXTERNAL_MODULE__foundation_core__, __WEBPACK_EXTERNAL_MODULE_jquery__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = 28);
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "./foundation.core":
  99. /*!****************************************************************************************************************************************************************!*\
  100. !*** external {"root":["__FOUNDATION_EXTERNAL__","foundation.core"],"amd":"./foundation.core","commonjs":"./foundation.core","commonjs2":"./foundation.core"} ***!
  101. \****************************************************************************************************************************************************************/
  102. /*! no static exports found */
  103. /***/ (function(module, exports) {
  104. module.exports = __WEBPACK_EXTERNAL_MODULE__foundation_core__;
  105. /***/ }),
  106. /***/ "./js/entries/plugins/foundation.util.touch.js":
  107. /*!*****************************************************!*\
  108. !*** ./js/entries/plugins/foundation.util.touch.js ***!
  109. \*****************************************************/
  110. /*! exports provided: Foundation, Touch */
  111. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  112. "use strict";
  113. __webpack_require__.r(__webpack_exports__);
  114. /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! jquery */ "jquery");
  115. /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_0__);
  116. /* harmony import */ var _foundation_util_touch__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../foundation.util.touch */ "./js/foundation.util.touch.js");
  117. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Touch", function() { return _foundation_util_touch__WEBPACK_IMPORTED_MODULE_1__["Touch"]; });
  118. /* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./foundation.core */ "./foundation.core");
  119. /* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_foundation_core__WEBPACK_IMPORTED_MODULE_2__);
  120. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Foundation", function() { return _foundation_core__WEBPACK_IMPORTED_MODULE_2__["Foundation"]; });
  121. _foundation_util_touch__WEBPACK_IMPORTED_MODULE_1__["Touch"].init(jquery__WEBPACK_IMPORTED_MODULE_0___default.a);
  122. window.Foundation.Touch = _foundation_util_touch__WEBPACK_IMPORTED_MODULE_1__["Touch"];
  123. /***/ }),
  124. /***/ "./js/foundation.util.touch.js":
  125. /*!*************************************!*\
  126. !*** ./js/foundation.util.touch.js ***!
  127. \*************************************/
  128. /*! exports provided: Touch */
  129. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  130. "use strict";
  131. __webpack_require__.r(__webpack_exports__);
  132. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Touch", function() { return Touch; });
  133. /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! jquery */ "jquery");
  134. /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_0__);
  135. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  136. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  137. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  138. //**************************************************
  139. //**Work inspired by multiple jquery swipe plugins**
  140. //**Done by Yohai Ararat ***************************
  141. //**************************************************
  142. var Touch = {};
  143. var startPosX,
  144. startPosY,
  145. startTime,
  146. elapsedTime,
  147. startEvent,
  148. isMoving = false,
  149. didMoved = false;
  150. function onTouchEnd(e) {
  151. this.removeEventListener('touchmove', onTouchMove);
  152. this.removeEventListener('touchend', onTouchEnd); // If the touch did not move, consider it as a "tap"
  153. if (!didMoved) {
  154. var tapEvent = jquery__WEBPACK_IMPORTED_MODULE_0___default.a.Event('tap', startEvent || e);
  155. jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).trigger(tapEvent);
  156. }
  157. startEvent = null;
  158. isMoving = false;
  159. didMoved = false;
  160. }
  161. function onTouchMove(e) {
  162. if (jquery__WEBPACK_IMPORTED_MODULE_0___default.a.spotSwipe.preventDefault) {
  163. e.preventDefault();
  164. }
  165. if (isMoving) {
  166. var x = e.touches[0].pageX;
  167. var y = e.touches[0].pageY;
  168. var dx = startPosX - x;
  169. var dy = startPosY - y;
  170. var dir;
  171. didMoved = true;
  172. elapsedTime = new Date().getTime() - startTime;
  173. if (Math.abs(dx) >= jquery__WEBPACK_IMPORTED_MODULE_0___default.a.spotSwipe.moveThreshold && elapsedTime <= jquery__WEBPACK_IMPORTED_MODULE_0___default.a.spotSwipe.timeThreshold) {
  174. dir = dx > 0 ? 'left' : 'right';
  175. } // else if(Math.abs(dy) >= $.spotSwipe.moveThreshold && elapsedTime <= $.spotSwipe.timeThreshold) {
  176. // dir = dy > 0 ? 'down' : 'up';
  177. // }
  178. if (dir) {
  179. e.preventDefault();
  180. onTouchEnd.apply(this, arguments);
  181. jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).trigger(jquery__WEBPACK_IMPORTED_MODULE_0___default.a.Event('swipe', Object.assign({}, e)), dir).trigger(jquery__WEBPACK_IMPORTED_MODULE_0___default.a.Event("swipe".concat(dir), Object.assign({}, e)));
  182. }
  183. }
  184. }
  185. function onTouchStart(e) {
  186. if (e.touches.length == 1) {
  187. startPosX = e.touches[0].pageX;
  188. startPosY = e.touches[0].pageY;
  189. startEvent = e;
  190. isMoving = true;
  191. didMoved = false;
  192. startTime = new Date().getTime();
  193. this.addEventListener('touchmove', onTouchMove, false);
  194. this.addEventListener('touchend', onTouchEnd, false);
  195. }
  196. }
  197. function init() {
  198. this.addEventListener && this.addEventListener('touchstart', onTouchStart, false);
  199. }
  200. function teardown() {
  201. this.removeEventListener('touchstart', onTouchStart);
  202. }
  203. var SpotSwipe =
  204. /*#__PURE__*/
  205. function () {
  206. function SpotSwipe($) {
  207. _classCallCheck(this, SpotSwipe);
  208. this.version = '1.0.0';
  209. this.enabled = 'ontouchstart' in document.documentElement;
  210. this.preventDefault = false;
  211. this.moveThreshold = 75;
  212. this.timeThreshold = 200;
  213. this.$ = $;
  214. this._init();
  215. }
  216. _createClass(SpotSwipe, [{
  217. key: "_init",
  218. value: function _init() {
  219. var $ = this.$;
  220. $.event.special.swipe = {
  221. setup: init
  222. };
  223. $.event.special.tap = {
  224. setup: init
  225. };
  226. $.each(['left', 'up', 'down', 'right'], function () {
  227. $.event.special["swipe".concat(this)] = {
  228. setup: function setup() {
  229. $(this).on('swipe', $.noop);
  230. }
  231. };
  232. });
  233. }
  234. }]);
  235. return SpotSwipe;
  236. }();
  237. /****************************************************
  238. * As far as I can tell, both setupSpotSwipe and *
  239. * setupTouchHandler should be idempotent, *
  240. * because they directly replace functions & *
  241. * values, and do not add event handlers directly. *
  242. ****************************************************/
  243. Touch.setupSpotSwipe = function ($) {
  244. $.spotSwipe = new SpotSwipe($);
  245. };
  246. /****************************************************
  247. * Method for adding pseudo drag events to elements *
  248. ***************************************************/
  249. Touch.setupTouchHandler = function ($) {
  250. $.fn.addTouch = function () {
  251. this.each(function (i, el) {
  252. $(el).bind('touchstart touchmove touchend touchcancel', function (event) {
  253. //we pass the original event object because the jQuery event
  254. //object is normalized to w3c specs and does not provide the TouchList
  255. handleTouch(event);
  256. });
  257. });
  258. var handleTouch = function handleTouch(event) {
  259. var touches = event.changedTouches,
  260. first = touches[0],
  261. eventTypes = {
  262. touchstart: 'mousedown',
  263. touchmove: 'mousemove',
  264. touchend: 'mouseup'
  265. },
  266. type = eventTypes[event.type],
  267. simulatedEvent;
  268. if ('MouseEvent' in window && typeof window.MouseEvent === 'function') {
  269. simulatedEvent = new window.MouseEvent(type, {
  270. 'bubbles': true,
  271. 'cancelable': true,
  272. 'screenX': first.screenX,
  273. 'screenY': first.screenY,
  274. 'clientX': first.clientX,
  275. 'clientY': first.clientY
  276. });
  277. } else {
  278. simulatedEvent = document.createEvent('MouseEvent');
  279. simulatedEvent.initMouseEvent(type, true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY, false, false, false, false, 0
  280. /*left*/
  281. , null);
  282. }
  283. first.target.dispatchEvent(simulatedEvent);
  284. };
  285. };
  286. };
  287. Touch.init = function ($) {
  288. if (typeof $.spotSwipe === 'undefined') {
  289. Touch.setupSpotSwipe($);
  290. Touch.setupTouchHandler($);
  291. }
  292. };
  293. /***/ }),
  294. /***/ 28:
  295. /*!***********************************************************!*\
  296. !*** multi ./js/entries/plugins/foundation.util.touch.js ***!
  297. \***********************************************************/
  298. /*! no static exports found */
  299. /***/ (function(module, exports, __webpack_require__) {
  300. module.exports = __webpack_require__(/*! /Users/joeworkman/Development/foundation-sites/js/entries/plugins/foundation.util.touch.js */"./js/entries/plugins/foundation.util.touch.js");
  301. /***/ }),
  302. /***/ "jquery":
  303. /*!********************************************************************************************!*\
  304. !*** external {"root":["jQuery"],"amd":"jquery","commonjs":"jquery","commonjs2":"jquery"} ***!
  305. \********************************************************************************************/
  306. /*! no static exports found */
  307. /***/ (function(module, exports) {
  308. module.exports = __WEBPACK_EXTERNAL_MODULE_jquery__;
  309. /***/ })
  310. /******/ });
  311. });
  312. //# sourceMappingURL=foundation.util.touch.js.map