|
302 | 302 | $util.addEvent(this.playCanvas, eventType, callback);
|
303 | 303 | },
|
304 | 304 | //
|
305 |
| - mousedown: function(callback) { |
| 305 | + mousedown: function (callback) { |
306 | 306 | if (typeof callback !== "function") return;
|
307 | 307 | var canvas = this;
|
308 |
| - canvas.addEvent("mousedown", function(e) { |
| 308 | + var mousedown = function (e) { |
| 309 | + if (typeof e.type === "undefined") return; |
309 | 310 | e.preventDefault();
|
| 311 | + e.stopPropagation(); |
| 312 | + // console.dir(e.type); |
| 313 | + // console.dir(e); |
| 314 | + // mouse event |
| 315 | + if (e.type === "mousedown") { |
| 316 | + } |
| 317 | + // touch event |
| 318 | + if (e.type === "touchstart") { |
| 319 | + e = e.clientX ? e : e.touches.length ? e.touches[0] : { |
| 320 | + clientX: 0, |
| 321 | + clientY: 0 |
| 322 | + }; |
| 323 | + } |
310 | 324 | canvas.saveRevokeImgDatas();
|
| 325 | + canvas.saveDrawingSurface(); |
311 | 326 | callback(e, canvas.windowToCanvas(e.clientX, e.clientY));
|
312 |
| - }); |
| 327 | + }; |
| 328 | + canvas.addEvent("mousedown", mousedown); |
| 329 | + //Register touch event's listener if it's supported. |
| 330 | + if ('createTouch' in document) { |
| 331 | + canvas.addEvent("touchstart", mousedown); |
| 332 | + } |
313 | 333 | },
|
314 | 334 | //
|
315 |
| - mousemove: function(callback) { |
| 335 | + mousemove: function (callback) { |
316 | 336 | if (typeof callback !== "function") return;
|
317 | 337 | var canvas = this;
|
318 |
| - canvas.addEvent("mousemove", function(e) { |
| 338 | + var mousemove = function (e) { |
| 339 | + if (typeof e.type === "undefined") return; |
319 | 340 | e.preventDefault();
|
| 341 | + e.stopPropagation(); |
| 342 | + // console.dir(e.type); |
| 343 | + // console.dir(e); |
| 344 | + // mouse event |
| 345 | + if (e.type === "mousemove") { |
| 346 | + } |
| 347 | + // touch event |
| 348 | + if (e.type === "touchmove") { |
| 349 | + e = e.clientX ? e : e.touches.length ? e.touches[0] : { |
| 350 | + clientX: 0, |
| 351 | + clientY: 0 |
| 352 | + }; |
| 353 | + } |
320 | 354 | callback(e, canvas.windowToCanvas(e.clientX, e.clientY));
|
321 |
| - }); |
| 355 | + }; |
| 356 | + canvas.addEvent("mousemove", mousemove); |
| 357 | + if ('createTouch' in document) { |
| 358 | + canvas.addEvent("touchmove", mousemove); |
| 359 | + } |
322 | 360 | },
|
323 | 361 | //
|
324 |
| - mouseup: function(callback) { |
| 362 | + mouseup: function (callback) { |
325 | 363 | if (typeof callback !== "function") return;
|
326 | 364 | var canvas = this;
|
327 |
| - canvas.addEvent("mouseup", function(e) { |
| 365 | + var mouseup = function (e) { |
| 366 | + if (typeof e.type === "undefined") return; |
328 | 367 | e.preventDefault();
|
| 368 | + e.stopPropagation(); |
| 369 | + // console.dir(e.type); |
| 370 | + // console.dir(e); |
| 371 | + // mouse event |
| 372 | + if (e.type === "mouseup") { |
| 373 | + } |
| 374 | + // touch event |
| 375 | + if (e.type === "touchend") { |
| 376 | + e = e.clientX ? e : e.touches.length ? e.touches[0] : e.changedTouches.length ? e.changedTouches[0] : null; |
| 377 | + // if e is null ,do nothing |
| 378 | + if (e === null) return; |
| 379 | + } |
329 | 380 | callback(e, canvas.windowToCanvas(e.clientX, e.clientY));
|
330 | 381 | canvas.saveForwardRevokeFirstFrame();
|
331 |
| - }); |
| 382 | + }; |
| 383 | + canvas.addEvent("mouseup", mouseup); |
| 384 | + if ('createTouch' in document) { |
| 385 | + canvas.addEvent("touchend", mouseup); |
| 386 | + } |
332 | 387 | }
|
333 | 388 |
|
334 | 389 | };
|
|
0 commit comments