UNPKG

foundation-sites

Version:

The most advanced responsive front-end framework in the world.

309 lines (289 loc) 14.4 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("jquery"), require("./foundation.core")); else if(typeof define === 'function' && define.amd) define(["jquery", "./foundation.core"], factory); else if(typeof exports === 'object') exports["__FOUNDATION_EXTERNAL__"] = factory(require("jquery"), require("./foundation.core")); else root["__FOUNDATION_EXTERNAL__"] = root["__FOUNDATION_EXTERNAL__"] || {}, root["__FOUNDATION_EXTERNAL__"]["foundation.util.touch"] = factory(root["jQuery"], root["__FOUNDATION_EXTERNAL__"]["foundation.core"]); })(self, function(__WEBPACK_EXTERNAL_MODULE_jquery__, __WEBPACK_EXTERNAL_MODULE__foundation_core__) { return /******/ (function() { // webpackBootstrap /******/ "use strict"; /******/ var __webpack_modules__ = ({ /***/ "./js/foundation.util.touch.js": /*!*************************************!*\ !*** ./js/foundation.util.touch.js ***! \*************************************/ /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ Touch: function() { return /* binding */ Touch; } /* harmony export */ }); /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! jquery */ "jquery"); /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_0__); function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } //************************************************** //**Work inspired by multiple jquery swipe plugins** //**Done by Yohai Ararat *************************** //************************************************** var Touch = {}; var startPosX, startTime, elapsedTime, startEvent, isMoving = false, didMoved = false; function onTouchEnd(e) { this.removeEventListener('touchmove', onTouchMove); this.removeEventListener('touchend', onTouchEnd); // If the touch did not move, consider it as a "tap" if (!didMoved) { var tapEvent = jquery__WEBPACK_IMPORTED_MODULE_0___default().Event('tap', startEvent || e); jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).trigger(tapEvent); } startEvent = null; isMoving = false; didMoved = false; } function onTouchMove(e) { if (true === (jquery__WEBPACK_IMPORTED_MODULE_0___default().spotSwipe).preventDefault) { e.preventDefault(); } if (isMoving) { var x = e.touches[0].pageX; // var y = e.touches[0].pageY; var dx = startPosX - x; // var dy = startPosY - y; var dir; didMoved = true; elapsedTime = new Date().getTime() - startTime; if (Math.abs(dx) >= (jquery__WEBPACK_IMPORTED_MODULE_0___default().spotSwipe).moveThreshold && elapsedTime <= (jquery__WEBPACK_IMPORTED_MODULE_0___default().spotSwipe).timeThreshold) { dir = dx > 0 ? 'left' : 'right'; } // else if(Math.abs(dy) >= $.spotSwipe.moveThreshold && elapsedTime <= $.spotSwipe.timeThreshold) { // dir = dy > 0 ? 'down' : 'up'; // } if (dir) { e.preventDefault(); onTouchEnd.apply(this, arguments); jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).trigger(jquery__WEBPACK_IMPORTED_MODULE_0___default().Event('swipe', Object.assign({}, e)), dir).trigger(jquery__WEBPACK_IMPORTED_MODULE_0___default().Event("swipe".concat(dir), Object.assign({}, e))); } } } function onTouchStart(e) { if (e.touches.length === 1) { startPosX = e.touches[0].pageX; startEvent = e; isMoving = true; didMoved = false; startTime = new Date().getTime(); this.addEventListener('touchmove', onTouchMove, { passive: true === (jquery__WEBPACK_IMPORTED_MODULE_0___default().spotSwipe).preventDefault }); this.addEventListener('touchend', onTouchEnd, false); } } function init() { this.addEventListener && this.addEventListener('touchstart', onTouchStart, { passive: true }); } // function teardown() { // this.removeEventListener('touchstart', onTouchStart); // } var SpotSwipe = /*#__PURE__*/function () { function SpotSwipe() { _classCallCheck(this, SpotSwipe); this.version = '1.0.0'; this.enabled = 'ontouchstart' in document.documentElement; this.preventDefault = false; this.moveThreshold = 75; this.timeThreshold = 200; this._init(); } return _createClass(SpotSwipe, [{ key: "_init", value: function _init() { (jquery__WEBPACK_IMPORTED_MODULE_0___default().event).special.swipe = { setup: init }; (jquery__WEBPACK_IMPORTED_MODULE_0___default().event).special.tap = { setup: init }; jquery__WEBPACK_IMPORTED_MODULE_0___default().each(['left', 'up', 'down', 'right'], function () { (jquery__WEBPACK_IMPORTED_MODULE_0___default().event).special["swipe".concat(this)] = { setup: function setup() { jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).on('swipe', (jquery__WEBPACK_IMPORTED_MODULE_0___default().noop)); } }; }); } }]); }(); /**************************************************** * As far as I can tell, both setupSpotSwipe and * * setupTouchHandler should be idempotent, * * because they directly replace functions & * * values, and do not add event handlers directly. * ****************************************************/ Touch.setupSpotSwipe = function () { (jquery__WEBPACK_IMPORTED_MODULE_0___default().spotSwipe) = new SpotSwipe((jquery__WEBPACK_IMPORTED_MODULE_0___default())); }; /**************************************************** * Method for adding pseudo drag events to elements * ***************************************************/ Touch.setupTouchHandler = function () { (jquery__WEBPACK_IMPORTED_MODULE_0___default().fn).addTouch = function () { this.each(function (i, el) { jquery__WEBPACK_IMPORTED_MODULE_0___default()(el).bind('touchstart touchmove touchend touchcancel', function (event) { //we pass the original event object because the jQuery event //object is normalized to w3c specs and does not provide the TouchList handleTouch(event); }); }); var handleTouch = function handleTouch(event) { var touches = event.changedTouches, first = touches[0], eventTypes = { touchstart: 'mousedown', touchmove: 'mousemove', touchend: 'mouseup' }, type = eventTypes[event.type], simulatedEvent; if ('MouseEvent' in window && typeof window.MouseEvent === 'function') { simulatedEvent = new window.MouseEvent(type, { 'bubbles': true, 'cancelable': true, 'screenX': first.screenX, 'screenY': first.screenY, 'clientX': first.clientX, 'clientY': first.clientY }); } else { simulatedEvent = document.createEvent('MouseEvent'); simulatedEvent.initMouseEvent(type, true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY, false, false, false, false, 0 /*left*/, null); } first.target.dispatchEvent(simulatedEvent); }; }; }; Touch.init = function () { if (typeof (jquery__WEBPACK_IMPORTED_MODULE_0___default().spotSwipe) === 'undefined') { Touch.setupSpotSwipe((jquery__WEBPACK_IMPORTED_MODULE_0___default())); Touch.setupTouchHandler((jquery__WEBPACK_IMPORTED_MODULE_0___default())); } }; /***/ }), /***/ "./foundation.core": /*!****************************************************************************************************************************************************************!*\ !*** external {"root":["__FOUNDATION_EXTERNAL__","foundation.core"],"amd":"./foundation.core","commonjs":"./foundation.core","commonjs2":"./foundation.core"} ***! \****************************************************************************************************************************************************************/ /***/ (function(module) { module.exports = __WEBPACK_EXTERNAL_MODULE__foundation_core__; /***/ }), /***/ "jquery": /*!********************************************************************************************!*\ !*** external {"root":["jQuery"],"amd":"jquery","commonjs":"jquery","commonjs2":"jquery"} ***! \********************************************************************************************/ /***/ (function(module) { module.exports = __WEBPACK_EXTERNAL_MODULE_jquery__; /***/ }) /******/ }); /************************************************************************/ /******/ // The module cache /******/ var __webpack_module_cache__ = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ var cachedModule = __webpack_module_cache__[moduleId]; /******/ if (cachedModule !== undefined) { /******/ return cachedModule.exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = __webpack_module_cache__[moduleId] = { /******/ // no module.id needed /******/ // no module.loaded needed /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /************************************************************************/ /******/ /* webpack/runtime/compat get default export */ /******/ !function() { /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function() { return module['default']; } : /******/ function() { return module; }; /******/ __webpack_require__.d(getter, { a: getter }); /******/ return getter; /******/ }; /******/ }(); /******/ /******/ /* webpack/runtime/define property getters */ /******/ !function() { /******/ // define getter functions for harmony exports /******/ __webpack_require__.d = function(exports, definition) { /******/ for(var key in definition) { /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); /******/ } /******/ } /******/ }; /******/ }(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ /******/ !function() { /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } /******/ }(); /******/ /******/ /* webpack/runtime/make namespace object */ /******/ !function() { /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ }(); /******/ /************************************************************************/ var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. !function() { /*!*****************************************************!*\ !*** ./js/entries/plugins/foundation.util.touch.js ***! \*****************************************************/ __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ Foundation: function() { return /* reexport safe */ _foundation_core__WEBPACK_IMPORTED_MODULE_2__.Foundation; }, /* harmony export */ Touch: function() { return /* reexport safe */ _foundation_util_touch__WEBPACK_IMPORTED_MODULE_1__.Touch; } /* harmony export */ }); /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! jquery */ "jquery"); /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var _foundation_util_touch__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../foundation.util.touch */ "./js/foundation.util.touch.js"); /* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./foundation.core */ "./foundation.core"); /* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_foundation_core__WEBPACK_IMPORTED_MODULE_2__); _foundation_util_touch__WEBPACK_IMPORTED_MODULE_1__.Touch.init((jquery__WEBPACK_IMPORTED_MODULE_0___default())); window.Foundation.Touch = _foundation_util_touch__WEBPACK_IMPORTED_MODULE_1__.Touch; }(); /******/ return __webpack_exports__; /******/ })() ; }); //# sourceMappingURL=foundation.util.touch.js.map