From 16401758a95bd2d32513b226681f903ad10f73d5 Mon Sep 17 00:00:00 2001 From: Luis Leiva Date: Sun, 26 May 2019 19:34:21 +0300 Subject: [PATCH] Remember callStack --- jquery.sketchable.memento.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/jquery.sketchable.memento.js b/jquery.sketchable.memento.js index 2f4d160..92836d3 100644 --- a/jquery.sketchable.memento.js +++ b/jquery.sketchable.memento.js @@ -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 */ @@ -28,10 +28,12 @@ /** * Update state. * @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 */ - function draw(snapshot, strokes) { + function draw(snapshot, state) { // Manipulate canvas via jQuery sketchable API. // This way, we don't lose default drawing settings et al. $instance.sketchable('handler', function(elem, data) { @@ -40,8 +42,9 @@ // so use the native HTMLCanvasElement.drawImage method instead. data.sketch.clear(); data.sketch.context.drawImage(snapshot, 0, 0); - // Update strokes. - data.strokes = strokes.slice(); + // Update state data. + data.strokes = state.strokes.slice(); + data.sketch.callStack = state.callStack.slice(); }); } /** @@ -111,7 +114,11 @@ if (ev && ev.identifier > 0) { stack[stpos].strokes = data.strokes.slice(); } 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++; } }); @@ -137,7 +144,7 @@ var snapshot = new Image(); snapshot.src = state.image; snapshot.onload = function() { - draw(this, state.strokes); + draw(this, state); }; return this; };