]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Initial barebones refactor of touch spotswipe to explicitly initialize
authorKevin Ball <kmball11@gmail.com>
Wed, 4 Jan 2017 21:39:36 +0000 (13:39 -0800)
committerKevin Ball <kmball11@gmail.com>
Tue, 18 Apr 2017 16:44:40 +0000 (09:44 -0700)
js/foundation.util.touch.js

index 8f648de13a0fd09df9f2df61ac176d88910f43f0..9104b1589cac2064c27c9a0b27f0853d9c15c7d8 100644 (file)
@@ -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);
     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 *