Skip to content
This repository has been archived by the owner on Aug 25, 2022. It is now read-only.

Fixed race condition that affected Android + Chrome on mobile when a "sc... #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/wScratchPad.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,15 @@
e.pageY = Math.floor(e.pageY - this.canvasOffset.top);

this['_scratch' + event](e);
if (this.options.realtime || event === 'Up') {

if (this.options.realtime || event !== 'Move') {
if (this.options['scratch' + event]) {
this.options['scratch' + event].apply(this, [e, this._scratchPercent()]);
// Setup callback to execute later, since scratch percentage calculation takes too long in some mobile browsers
// and will cause Chrome to fire a "touchcancel" event prematurely when touching down at first.
var _this = this;
setTimeout(function() {
_this.options['scratch' + event].apply(_this, [e, _this._scratchPercent()]);
}, 0);
}
}
},
Expand Down Expand Up @@ -277,7 +282,7 @@
size : 5, // The size of the brush/scratch.
bg : '#cacaca', // Background (image path or hex color).
fg : '#6699ff', // Foreground (image path or hex color).
realtime : true, // Calculates percentage in realitime
realtime : true, // Calculates percentage in real time (on move events, not just mouse up).
scratchDown : null, // Set scratchDown callback.
scratchUp : null, // Set scratchUp callback.
scratchMove : null, // Set scratcMove callback.
Expand All @@ -292,6 +297,7 @@

switch (event.type) {
case 'touchstart':
event.preventDefault();
type = 'mousedown';
break;
case 'touchmove':
Expand Down