mobomo / sketch.js

A jQuery plugin for dead simple Canvas-based drawing.
http://intridea.github.com/sketch.js
290 stars 110 forks source link

Mobile Error on method onEvent (with correction) #45

Open emitategh opened 8 years ago

emitategh commented 8 years ago

Hi, I was getting an "undefined getX" or "undefined getY" Because e.originalEvent.targetTouches had length 0 on last touchevent, that caused canvas to be wiped clear.

Sketch.prototype.onEvent = function(e) {
      console.log(e.originalEvent.targetTouches);
      if (e.originalEvent && e.originalEvent.targetTouches) {
        if (e.originalEvent.targetTouches.length){ ///-----------> Added
          e.pageX = e.originalEvent.targetTouches[0].pageX;
          e.pageY = e.originalEvent.targetTouches[0].pageY;
        }
      }
      $.sketch.tools[$(this).data('sketch').tool].onEvent.call($(this).data('sketch'), e);
      e.preventDefault();
      return false;
    };
merbin2012 commented 8 years ago

I was replace with the below code. The below function is found in 98th line in sketch.js file

    Sketch.prototype.onEvent = function(e) {
      if (e.originalEvent && e.originalEvent.targetTouches &&(e.originalEvent.targetTouches.length>0)) {

        e.pageX = e.originalEvent.targetTouches[0].pageX;
        e.pageY = e.originalEvent.targetTouches[0].pageY;

      }
      $.sketch.tools[$(this).data('sketch').tool].onEvent.call($(this).data('sketch'), e);
      e.preventDefault();
      return false;
    };