diff --git a/src/jquery.sketchable.js b/src/jquery.sketchable.js
index 17a30f4..cd19e96 100644
--- a/src/jquery.sketchable.js
+++ b/src/jquery.sketchable.js
@@ -155,6 +155,7 @@
/**
* Clears canvas together with associated strokes data.
* @return {object} jQuery
+ * @param {boolean} [keepStrokes] - Preserve stroke data (default: false).
* @memberof $.fn.sketchable
* @see $.fn.sketchable.handler
* @example
@@ -166,11 +167,13 @@
* data.sketch.clear();
* });
*/
- clear: function() {
+ clear: function(keepStrokes) {
return this.each(function() {
var elem = $(this), data = elem.data(namespace), options = data.options;
- if (data.sketch) {
- data.sketch.clear();
+
+ data.sketch.clear();
+
+ if (!keepStrokes) {
data.strokes = [];
data.coords = {};
}
diff --git a/src/sketchable.js b/src/sketchable.js
index fec0683..ad05dca 100644
--- a/src/sketchable.js
+++ b/src/sketchable.js
@@ -186,6 +186,7 @@
/**
* Clears canvas together with associated strokes data.
* @see Sketchable.handler
+ * @param {boolean} [keepStrokes] - Preserve stroke data (default: false).
* @return {Sketchable}
* @memberof Sketchable
* @example
@@ -193,16 +194,21 @@
* // Warning: This will remove strokes data as well.
* sketcher.clear();
* // If you only need to clear the canvas, just do:
+ * sketcher.clear(true);
+ * // Or, alternatively:
* sketcher.handler(function(elem, data) {
* data.sketch.clear();
* });
*/
- clear: function() {
+ clear: function(keepStrokes) {
var elem = this.elem, data = dataBind(elem)[namespace], options = data.options;
data.sketch.clear();
- data.strokes = [];
- data.coords = {};
+
+ if (!keepStrokes) {
+ data.strokes = [];
+ data.coords = {};
+ }
if (typeof options.events.clear === 'function')
options.events.clear(elem, data);