mirror of https://github.com/luileito/jsketch.git
Remember callStack
This commit is contained in:
parent
361e33cdc6
commit
16401758a9
|
|
@ -1,5 +1,5 @@
|
||||||
/*!
|
/*!
|
||||||
* Memento plugin for jQuery Sketchable | v2.1 | Luis A. Leiva | MIT license
|
* Memento plugin for jQuery Sketchable | v2.2 | Luis A. Leiva | MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* eslint-env browser */
|
/* eslint-env browser */
|
||||||
|
|
@ -28,10 +28,12 @@
|
||||||
/**
|
/**
|
||||||
* Update state.
|
* Update state.
|
||||||
* @param {Image} snapshot - Image object.
|
* @param {Image} snapshot - Image object.
|
||||||
* @param {array} strokes - Strokes associated with snapshot.
|
* @param {object} state - State associated with snapshot.
|
||||||
|
* @param {object} state.strokes - Strokes data.
|
||||||
|
* @param {object} state.callStack - Actions history.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function draw(snapshot, strokes) {
|
function draw(snapshot, state) {
|
||||||
// Manipulate canvas via jQuery sketchable API.
|
// Manipulate canvas via jQuery sketchable API.
|
||||||
// This way, we don't lose default drawing settings et al.
|
// This way, we don't lose default drawing settings et al.
|
||||||
$instance.sketchable('handler', function(elem, data) {
|
$instance.sketchable('handler', function(elem, data) {
|
||||||
|
|
@ -40,8 +42,9 @@
|
||||||
// so use the native HTMLCanvasElement.drawImage method instead.
|
// so use the native HTMLCanvasElement.drawImage method instead.
|
||||||
data.sketch.clear();
|
data.sketch.clear();
|
||||||
data.sketch.context.drawImage(snapshot, 0, 0);
|
data.sketch.context.drawImage(snapshot, 0, 0);
|
||||||
// Update strokes.
|
// Update state data.
|
||||||
data.strokes = strokes.slice();
|
data.strokes = state.strokes.slice();
|
||||||
|
data.sketch.callStack = state.callStack.slice();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
@ -111,7 +114,11 @@
|
||||||
if (ev && ev.identifier > 0) {
|
if (ev && ev.identifier > 0) {
|
||||||
stack[stpos].strokes = data.strokes.slice();
|
stack[stpos].strokes = data.strokes.slice();
|
||||||
} else {
|
} else {
|
||||||
stack.push({image: elem[0].toDataURL(), strokes: data.strokes.slice()});
|
stack.push({
|
||||||
|
image: elem.get(0).toDataURL(),
|
||||||
|
strokes: data.strokes.slice(),
|
||||||
|
callStack: data.sketch.callStack.slice(),
|
||||||
|
});
|
||||||
stpos++;
|
stpos++;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -137,7 +144,7 @@
|
||||||
var snapshot = new Image();
|
var snapshot = new Image();
|
||||||
snapshot.src = state.image;
|
snapshot.src = state.image;
|
||||||
snapshot.onload = function() {
|
snapshot.onload = function() {
|
||||||
draw(this, state.strokes);
|
draw(this, state);
|
||||||
};
|
};
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue