[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/yuilib/3.17.2/event-touch/ -> event-touch.js (source)

   1  /*
   2  YUI 3.17.2 (build 9c3c78e)
   3  Copyright 2014 Yahoo! Inc. All rights reserved.
   4  Licensed under the BSD License.
   5  http://yuilibrary.com/license/
   6  */
   7  
   8  YUI.add('event-touch', function (Y, NAME) {
   9  
  10  /**
  11  Adds touch event facade normalization properties (touches, changedTouches, targetTouches etc.) to the DOM event facade. Adds
  12  touch events to the DOM events whitelist.
  13  
  14  @example
  15      YUI().use('event-touch', function (Y) {
  16          Y.one('#myDiv').on('touchstart', function(e) {
  17              ...
  18          });
  19      });
  20  @module event
  21  @submodule event-touch
  22   */
  23  var SCALE = "scale",
  24      ROTATION = "rotation",
  25      IDENTIFIER = "identifier",
  26      win = Y.config.win,
  27      GESTURE_MAP = {};
  28  
  29  /**
  30   * Adds touch event facade normalization properties to the DOM event facade
  31   *
  32   * @method _touch
  33   * @for DOMEventFacade
  34   * @private
  35   * @param ev {Event} the DOM event
  36   * @param currentTarget {HTMLElement} the element the listener was attached to
  37   * @param wrapper {CustomEvent} the custom event wrapper for this DOM event
  38   */
  39  Y.DOMEventFacade.prototype._touch = function(e, currentTarget, wrapper) {
  40  
  41      var i,l, etCached, et,touchCache;
  42  
  43  
  44      if (e.touches) {
  45  
  46          /**
  47           * Array of individual touch events for touch points that are still in
  48           * contact with the touch surface.
  49           *
  50           * @property touches
  51           * @type {DOMEventFacade[]}
  52           */
  53          this.touches = [];
  54          touchCache = {};
  55  
  56          for (i = 0, l = e.touches.length; i < l; ++i) {
  57              et = e.touches[i];
  58              touchCache[Y.stamp(et)] = this.touches[i] = new Y.DOMEventFacade(et, currentTarget, wrapper);
  59          }
  60      }
  61  
  62      if (e.targetTouches) {
  63  
  64          /**
  65           * Array of individual touch events still in contact with the touch
  66           * surface and whose `touchstart` event occurred inside the same taregt
  67           * element as the current target element.
  68           *
  69           * @property targetTouches
  70           * @type {DOMEventFacade[]}
  71           */
  72          this.targetTouches = [];
  73  
  74          for (i = 0, l = e.targetTouches.length; i < l; ++i) {
  75              et = e.targetTouches[i];
  76              etCached = touchCache && touchCache[Y.stamp(et, true)];
  77  
  78              this.targetTouches[i] = etCached || new Y.DOMEventFacade(et, currentTarget, wrapper);
  79  
  80          }
  81      }
  82  
  83      if (e.changedTouches) {
  84  
  85          /**
  86          An array of event-specific touch events.
  87  
  88          For `touchstart`, the touch points that became active with the current
  89          event.
  90  
  91          For `touchmove`, the touch points that have changed since the last
  92          event.
  93  
  94          For `touchend`, the touch points that have been removed from the touch
  95          surface.
  96  
  97          @property changedTouches
  98          @type {DOMEventFacade[]}
  99          **/
 100          this.changedTouches = [];
 101  
 102          for (i = 0, l = e.changedTouches.length; i < l; ++i) {
 103              et = e.changedTouches[i];
 104              etCached = touchCache && touchCache[Y.stamp(et, true)];
 105  
 106              this.changedTouches[i] = etCached || new Y.DOMEventFacade(et, currentTarget, wrapper);
 107  
 108          }
 109      }
 110  
 111      if (SCALE in e) {
 112          this[SCALE] = e[SCALE];
 113      }
 114  
 115      if (ROTATION in e) {
 116          this[ROTATION] = e[ROTATION];
 117      }
 118  
 119      if (IDENTIFIER in e) {
 120          this[IDENTIFIER] = e[IDENTIFIER];
 121      }
 122  };
 123  
 124  //Adding MSPointer events to whitelisted DOM Events. MSPointer event payloads
 125  //have the same properties as mouse events.
 126  if (Y.Node.DOM_EVENTS) {
 127      Y.mix(Y.Node.DOM_EVENTS, {
 128          touchstart:1,
 129          touchmove:1,
 130          touchend:1,
 131          touchcancel:1,
 132          gesturestart:1,
 133          gesturechange:1,
 134          gestureend:1,
 135          MSPointerDown:1,
 136          MSPointerUp:1,
 137          MSPointerMove:1,
 138          MSPointerCancel:1,
 139          pointerdown:1,
 140          pointerup:1,
 141          pointermove:1,
 142          pointercancel:1
 143      });
 144  }
 145  
 146  //Add properties to Y.EVENT.GESTURE_MAP based on feature detection.
 147  if ((win && ("ontouchstart" in win)) && !(Y.UA.chrome && Y.UA.chrome < 6)) {
 148      GESTURE_MAP.start = ["touchstart", "mousedown"];
 149      GESTURE_MAP.end = ["touchend", "mouseup"];
 150      GESTURE_MAP.move = ["touchmove", "mousemove"];
 151      GESTURE_MAP.cancel = ["touchcancel", "mousecancel"];
 152  }
 153  
 154  else if (win && win.PointerEvent) {
 155      GESTURE_MAP.start = "pointerdown";
 156      GESTURE_MAP.end = "pointerup";
 157      GESTURE_MAP.move = "pointermove";
 158      GESTURE_MAP.cancel = "pointercancel";
 159  }
 160  
 161  else if (win && ("msPointerEnabled" in win.navigator)) {
 162      GESTURE_MAP.start = "MSPointerDown";
 163      GESTURE_MAP.end = "MSPointerUp";
 164      GESTURE_MAP.move = "MSPointerMove";
 165      GESTURE_MAP.cancel = "MSPointerCancel";
 166  }
 167  
 168  else {
 169      GESTURE_MAP.start = "mousedown";
 170      GESTURE_MAP.end = "mouseup";
 171      GESTURE_MAP.move = "mousemove";
 172      GESTURE_MAP.cancel = "mousecancel";
 173  }
 174  
 175  /**
 176   * A object literal with keys "start", "end", and "move". The value for each key is a
 177   * string representing the event for that environment. For touch environments, the respective
 178   * values are "touchstart", "touchend" and "touchmove". Mouse and MSPointer environments are also
 179   * supported via feature detection.
 180   *
 181   * @property _GESTURE_MAP
 182   * @type Object
 183   * @static
 184   */
 185  Y.Event._GESTURE_MAP = GESTURE_MAP;
 186  
 187  
 188  }, '3.17.2', {"requires": ["node-base"]});


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1