mirror of https://github.com/luileito/jsketch.git
Allow preserving strokes on high-level clear() method
This commit is contained in:
parent
adda3bbf7f
commit
c4cae4d8e0
|
|
@ -155,6 +155,7 @@
|
||||||
/**
|
/**
|
||||||
* Clears canvas <b>together with</b> associated strokes data.
|
* Clears canvas <b>together with</b> associated strokes data.
|
||||||
* @return {object} jQuery
|
* @return {object} jQuery
|
||||||
|
* @param {boolean} [keepStrokes] - Preserve stroke data (default: false).
|
||||||
* @memberof $.fn.sketchable
|
* @memberof $.fn.sketchable
|
||||||
* @see $.fn.sketchable.handler
|
* @see $.fn.sketchable.handler
|
||||||
* @example
|
* @example
|
||||||
|
|
@ -166,11 +167,13 @@
|
||||||
* data.sketch.clear();
|
* data.sketch.clear();
|
||||||
* });
|
* });
|
||||||
*/
|
*/
|
||||||
clear: function() {
|
clear: function(keepStrokes) {
|
||||||
return this.each(function() {
|
return this.each(function() {
|
||||||
var elem = $(this), data = elem.data(namespace), options = data.options;
|
var elem = $(this), data = elem.data(namespace), options = data.options;
|
||||||
if (data.sketch) {
|
|
||||||
data.sketch.clear();
|
data.sketch.clear();
|
||||||
|
|
||||||
|
if (!keepStrokes) {
|
||||||
data.strokes = [];
|
data.strokes = [];
|
||||||
data.coords = {};
|
data.coords = {};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -186,6 +186,7 @@
|
||||||
/**
|
/**
|
||||||
* Clears canvas <b>together with</b> associated strokes data.
|
* Clears canvas <b>together with</b> associated strokes data.
|
||||||
* @see Sketchable.handler
|
* @see Sketchable.handler
|
||||||
|
* @param {boolean} [keepStrokes] - Preserve stroke data (default: false).
|
||||||
* @return {Sketchable}
|
* @return {Sketchable}
|
||||||
* @memberof Sketchable
|
* @memberof Sketchable
|
||||||
* @example
|
* @example
|
||||||
|
|
@ -193,16 +194,21 @@
|
||||||
* // Warning: This will remove strokes data as well.
|
* // Warning: This will remove strokes data as well.
|
||||||
* sketcher.clear();
|
* sketcher.clear();
|
||||||
* // If you only need to clear the canvas, just do:
|
* // If you only need to clear the canvas, just do:
|
||||||
|
* sketcher.clear(true);
|
||||||
|
* // Or, alternatively:
|
||||||
* sketcher.handler(function(elem, data) {
|
* sketcher.handler(function(elem, data) {
|
||||||
* data.sketch.clear();
|
* data.sketch.clear();
|
||||||
* });
|
* });
|
||||||
*/
|
*/
|
||||||
clear: function() {
|
clear: function(keepStrokes) {
|
||||||
var elem = this.elem, data = dataBind(elem)[namespace], options = data.options;
|
var elem = this.elem, data = dataBind(elem)[namespace], options = data.options;
|
||||||
|
|
||||||
data.sketch.clear();
|
data.sketch.clear();
|
||||||
data.strokes = [];
|
|
||||||
data.coords = {};
|
if (!keepStrokes) {
|
||||||
|
data.strokes = [];
|
||||||
|
data.coords = {};
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof options.events.clear === 'function')
|
if (typeof options.events.clear === 'function')
|
||||||
options.events.clear(elem, data);
|
options.events.clear(elem, data);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue