Sha256: 319505ff3636b6ef21eacfde544c3fbe6ffecca1f81ff42b47fa275ef3693a6f

Contents?: true

Size: 1.16 KB

Versions: 7

Compression:

Stored size: 1.16 KB

Contents

/*
---

name: Mouse

description: Maps mouse events to their touch counterparts

authors: Christoph Pojer (@cpojer)

license: MIT-style license.

requires: [Custom-Event/Element.defineCustomEvent, Browser.Features.Touch]

provides: Mouse

...
*/

if (!Browser.Features.Touch) (function(){

var condition = function(event){
  event.targetTouches = [];
  event.changedTouches = event.touches = [{
    pageX: event.page.x, pageY: event.page.y,
    clientX: event.client.x, clientY: event.client.y
  }];

  return true;
};

var mouseup = function(e) {
  var target = e.target;
  while (target != this && (target = target.parentNode));
  this.fireEvent(target ? 'touchend' : 'touchcancel', arguments);
  document.removeEvent('mouseup', this.retrieve('touch:mouseup'));
};

Element.defineCustomEvent('touchstart', {

  base: 'mousedown',

  condition: function() {
    var bound = this.retrieve('touch:mouseup');
    if (!bound) {
      bound = mouseup.bind(this);
      this.store('touch:mouseup', bound);
    }
    document.addEvent('mouseup', bound);
    return condition.apply(this, arguments);
  }

}).defineCustomEvent('touchmove', {

  base: 'mousemove',

  condition: condition

});

})();

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
lsd_rails-0.1.6 Packages/mootools-mobile/Source/Desktop/Mouse.js
lsd_rails-0.1.5 Packages/mootools-mobile/Source/Desktop/Mouse.js
lsd_rails-0.1.4 Packages/mootools-mobile/Source/Desktop/Mouse.js
lsd_rails-0.1.3 Packages/mootools-mobile/Source/Desktop/Mouse.js
lsd_rails-0.1.2 Packages/mootools-mobile/Source/Desktop/Mouse.js
lsd_rails-0.1.1 Packages/mootools-mobile/Source/Desktop/Mouse.js
lsd_rails-0.1 Packages/mootools-mobile/Source/Desktop/Mouse.js