From 6f8e3b4a1ed7400fa40adfff2375989dac9a2958 Mon Sep 17 00:00:00 2001 From: Kevin Ball Date: Wed, 4 Jan 2017 13:39:36 -0800 Subject: [PATCH] Initial barebones refactor of touch spotswipe to explicitly initialize --- js/foundation.util.touch.js | 46 ++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/js/foundation.util.touch.js b/js/foundation.util.touch.js index 8f648de13..9104b1589 100644 --- a/js/foundation.util.touch.js +++ b/js/foundation.util.touch.js @@ -4,19 +4,11 @@ //************************************************** (function($) { - $.spotSwipe = { - version: '1.0.0', - enabled: 'ontouchstart' in document.documentElement, - preventDefault: false, - moveThreshold: 75, - timeThreshold: 200 - }; - - var startPosX, - startPosY, - startTime, - elapsedTime, - isMoving = false; + var startPosX, + startPosY, + startTime, + elapsedTime, + isMoving = false; function onTouchEnd() { // alert(this); @@ -67,13 +59,29 @@ this.removeEventListener('touchstart', onTouchStart); } - $.event.special.swipe = { setup: init }; + class spotSwipe { + constructor($) { + this.version = '1.0.0'; + this.enabled = 'ontouchstart' in document.documentElement; + this.preventDefault = false; + this.moveThreshold = 75; + this.timeThreshold = 200; + this.$ = $; + this._init(); + } + + _init() { + var $ = this.$; + $.event.special.swipe = { setup: init }; - $.each(['left', 'up', 'down', 'right'], function () { - $.event.special[`swipe${this}`] = { setup: function(){ - $(this).on('swipe', $.noop); - } }; - }); + $.each(['left', 'up', 'down', 'right'], function () { + $.event.special[`swipe${this}`] = { setup: function(){ + $(this).on('swipe', $.noop); + } }; + }); + } + } + $.spotSwipe = new spotSwipe($); })(jQuery); /**************************************************** * Method for adding psuedo drag events to elements * -- 2.47.3