Skip to content
This repository was archived by the owner on Aug 25, 2022. It is now read-only.
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "wScratchPad",
"title": "wScratchPad jQuery Plugin",
"version": "2.1.0",
"version": "2.1.0-dev",
"description": "A jQuery plugin to mimic a scratch card or pad behaviour. Allowing you to scratch off an overlay as either a color or image.",
"main": "wScratchPad.js",
"repository": {
Expand Down
23 changes: 19 additions & 4 deletions src/wScratchPad.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

// Setup event handlers.
this.$scratchpad
.mousedown($.proxy(function (e) {
.on('mousedown', $.proxy(function (e) {

// If disabled we just return true which menas
// our our this.scratch will remain as false.
Expand All @@ -52,12 +52,21 @@
this.scratch = true;
this._scratchFunc(e, 'Down');
}, this))
.mousemove($.proxy(function (e) {
.on('mousemove', $.proxy(function (e) {
if (this.scratch) {
this._scratchFunc(e, 'Move');
}
}, this))
.mouseup($.proxy(function (e) {
.on('mouseup', $.proxy(function (e) {
if (this.scratch) {
this.scratch = false;
this._scratchFunc(e, 'Up');
}
}, this));

// Catch mouseup outside of image or outside of window
// (might not fire in all browsers)
$(document).on('mouseup', $.proxy(function (e) {
if (this.scratch) {
this.scratch = false;
this._scratchFunc(e, 'Up');
Expand Down Expand Up @@ -122,7 +131,7 @@
$(new Image())
.attr('crossOrigin', '')
.attr('src', this.options.fg)
.load(function () {
.on('load', function () {
_this.ctx.drawImage(this, 0, 0, width, height);
_this.$img.show();
});
Expand Down Expand Up @@ -212,11 +221,17 @@
//start the path for a drag
this.ctx.beginPath();
this.ctx.moveTo(e.pageX, e.pageY);

// force redraw to fix android browser bug
this.canvas.style.zIndex++;
},

_scratchMove: function (e) {
this.ctx.lineTo(e.pageX, e.pageY);
this.ctx.stroke();

// force redraw to fix android browser bug
this.canvas.style.zIndex++;
},

_scratchUp: function () {
Expand Down
3 changes: 2 additions & 1 deletion wScratchPad.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.