mirror of https://github.com/luileito/jsketch.git
Remember callStack
This commit is contained in:
parent
7fd41ed784
commit
361e33cdc6
|
|
@ -1,5 +1,5 @@
|
||||||
/*!
|
/*!
|
||||||
* Memento plugin for Sketchable | v2.1 | Luis A. Leiva | MIT license
|
* Memento plugin for Sketchable | v2.2 | Luis A. Leiva | MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// XXX: Requires `sketchable.utils.js` to be loaded first.
|
// XXX: Requires `sketchable.utils.js` to be loaded first.
|
||||||
|
|
@ -29,11 +29,13 @@
|
||||||
var self = this;
|
var self = this;
|
||||||
/**
|
/**
|
||||||
* 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 Sketchable API.
|
// Manipulate canvas via 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.handler(function(elem, data) {
|
instance.handler(function(elem, data) {
|
||||||
|
|
@ -42,8 +44,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();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
@ -113,7 +116,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.toDataURL(), strokes: data.strokes.slice()});
|
stack.push({
|
||||||
|
image: elem.toDataURL(),
|
||||||
|
strokes: data.strokes.slice(),
|
||||||
|
callStack: data.sketch.callStack.slice(),
|
||||||
|
});
|
||||||
stpos++;
|
stpos++;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -139,7 +146,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