]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Merge pull request #9923 from dragthor/pseudo-spelling
authorKevin Ball <kmball11@gmail.com>
Fri, 19 May 2017 17:57:08 +0000 (10:57 -0700)
committerGitHub <noreply@github.com>
Fri, 19 May 2017 17:57:08 +0000 (10:57 -0700)
pseudo spelling correction

1  2 
docs/pages/javascript-utilities.md
js/foundation.sticky.js
js/foundation.util.touch.js

Simple merge
Simple merge
index 5e5b1c1fb96cb7535581c607dd6979acf2483624,4b40f11aee24bcc7d8a0f3bdaa1a26afa6b1e1fc..a0d311c0b9595acb350330aef83fee69b06aa9ce
  //**Work inspired by multiple jquery swipe plugins**
  //**Done by Yohai Ararat ***************************
  //**************************************************
 -(function($) {
  
 -  $.spotSwipe = {
 -    version: '1.0.0',
 -    enabled: 'ontouchstart' in document.documentElement,
 -    preventDefault: false,
 -    moveThreshold: 75,
 -    timeThreshold: 200
 -  };
 +import $ from 'jquery';
  
 -  var   startPosX,
 -        startPosY,
 -        startTime,
 -        elapsedTime,
 -        isMoving = false;
 +var Touch = {};
  
 -  function onTouchEnd() {
 -    //  alert(this);
 -    this.removeEventListener('touchmove', onTouchMove);
 -    this.removeEventListener('touchend', onTouchEnd);
 +var startPosX,
 +    startPosY,
 +    startTime,
 +    elapsedTime,
      isMoving = false;
 -  }
  
 -  function onTouchMove(e) {
 -    if ($.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;
 -      elapsedTime = new Date().getTime() - startTime;
 -      if(Math.abs(dx) >= $.spotSwipe.moveThreshold && elapsedTime <= $.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.call(this);
 -        $(this).trigger('swipe', dir).trigger(`swipe${dir}`);
 -      }
 +function onTouchEnd() {
 +  //  alert(this);
 +  this.removeEventListener('touchmove', onTouchMove);
 +  this.removeEventListener('touchend', onTouchEnd);
 +  isMoving = false;
 +}
 +
 +function onTouchMove(e) {
 +  if ($.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;
 +    elapsedTime = new Date().getTime() - startTime;
 +    if(Math.abs(dx) >= $.spotSwipe.moveThreshold && elapsedTime <= $.spotSwipe.timeThreshold) {
 +      dir = dx > 0 ? 'left' : 'right';
      }
 -  }
 -
 -  function onTouchStart(e) {
 -    if (e.touches.length == 1) {
 -      startPosX = e.touches[0].pageX;
 -      startPosY = e.touches[0].pageY;
 -      isMoving = true;
 -      startTime = new Date().getTime();
 -      this.addEventListener('touchmove', onTouchMove, false);
 -      this.addEventListener('touchend', onTouchEnd, false);
 +    // else if(Math.abs(dy) >= $.spotSwipe.moveThreshold && elapsedTime <= $.spotSwipe.timeThreshold) {
 +    //   dir = dy > 0 ? 'down' : 'up';
 +    // }
 +    if(dir) {
 +      e.preventDefault();
 +      onTouchEnd.call(this);
 +      $(this).trigger('swipe', dir).trigger(`swipe${dir}`);
      }
    }
 -
 -  function init() {
 -    this.addEventListener && this.addEventListener('touchstart', onTouchStart, false);
 +}
 +
 +function onTouchStart(e) {
 +  if (e.touches.length == 1) {
 +    startPosX = e.touches[0].pageX;
 +    startPosY = e.touches[0].pageY;
 +    isMoving = true;
 +    startTime = new Date().getTime();
 +    this.addEventListener('touchmove', onTouchMove, false);
 +    this.addEventListener('touchend', onTouchEnd, false);
    }
 +}
 +
 +function init() {
 +  this.addEventListener && this.addEventListener('touchstart', onTouchStart, false);
 +}
 +
 +function teardown() {
 +  this.removeEventListener('touchstart', onTouchStart);
 +}
 +
 +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 };
  
 -  function teardown() {
 -    this.removeEventListener('touchstart', onTouchStart);
 +    $.each(['left', 'up', 'down', 'right'], function () {
 +      $.event.special[`swipe${this}`] = { setup: function(){
 +        $(this).on('swipe', $.noop);
 +      } };
 +    });
    }
 +}
  
 -  $.event.special.swipe = { setup: init };
 +/****************************************************
 + * 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($) {
 +  $.spotSwipe = new SpotSwipe($);
 +};
  
 -  $.each(['left', 'up', 'down', 'right'], function () {
 -    $.event.special[`swipe${this}`] = { setup: function(){
 -      $(this).on('swipe', $.noop);
 -    } };
 -  });
 -})(jQuery);
  /****************************************************
-  * Method for adding psuedo drag events to elements *
+  * Method for adding pseudo drag events to elements *
   ***************************************************/
 -!function($){
 +Touch.setupTouchHandler = function($) {
    $.fn.addTouch = function(){
      this.each(function(i,el){
        $(el).bind('touchstart touchmove touchend touchcancel',function(){