mirror of https://github.com/luileito/jsketch.git
Added stroke id
This commit is contained in:
parent
68678c052a
commit
6d37c9d1fd
|
|
@ -1,5 +1,5 @@
|
||||||
/*!
|
/*!
|
||||||
* jQuery sketchable | v2.1 | Luis A. Leiva | MIT license
|
* jQuery sketchable | v2.2 | Luis A. Leiva | MIT license
|
||||||
* A jQuery plugin for the jSketch drawing library.
|
* A jQuery plugin for the jSketch drawing library.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -57,7 +57,8 @@
|
||||||
// This will store one stroke per touching finger.
|
// This will store one stroke per touching finger.
|
||||||
coords: {},
|
coords: {},
|
||||||
// Date of first coord, used as time origin.
|
// Date of first coord, used as time origin.
|
||||||
timestamp: (new Date).getTime(),
|
// Will be initialized on drawing the first stroke.
|
||||||
|
timestamp: 0,
|
||||||
// Save a pointer to the drawing canvas (jSketch instance).
|
// Save a pointer to the drawing canvas (jSketch instance).
|
||||||
sketch: sketch,
|
sketch: sketch,
|
||||||
// Save also a pointer to the given options.
|
// Save also a pointer to the given options.
|
||||||
|
|
@ -214,7 +215,7 @@
|
||||||
* @namespace $.fn.sketchable
|
* @namespace $.fn.sketchable
|
||||||
* @param {string|object} method - Method to invoke, or a configuration object.
|
* @param {string|object} method - Method to invoke, or a configuration object.
|
||||||
* @return jQuery
|
* @return jQuery
|
||||||
* @version 2.1
|
* @version 2.2
|
||||||
* @author Luis A. Leiva
|
* @author Luis A. Leiva
|
||||||
* @license MIT license
|
* @license MIT license
|
||||||
* @example
|
* @example
|
||||||
|
|
@ -382,6 +383,7 @@
|
||||||
return {
|
return {
|
||||||
x: Math.round(e.pageX - pos.left),
|
x: Math.round(e.pageX - pos.left),
|
||||||
y: Math.round(e.pageY - pos.top),
|
y: Math.round(e.pageY - pos.top),
|
||||||
|
time: Date.now(),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -392,15 +394,14 @@
|
||||||
// Current coords are already initialized.
|
// Current coords are already initialized.
|
||||||
var coords = data.coords[idx];
|
var coords = data.coords[idx];
|
||||||
|
|
||||||
var time = (new Date).getTime();
|
|
||||||
if (data.options.relTimestamps) {
|
if (data.options.relTimestamps) {
|
||||||
// The first timestamp is relative to initialization time;
|
// The first timestamp is relative to initialization time;
|
||||||
// thus fix it so that it is relative to the timestamp of the first stroke.
|
// thus fix it so that it is relative to the timestamp of the first stroke.
|
||||||
if (data.strokes.length === 0 && coords.length === 0) data.timestamp = time;
|
if (data.strokes.length === 0 && coords.length === 0) data.timestamp = pt.time;
|
||||||
time -= data.timestamp;
|
pt.time -= data.timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
coords.push([pt.x, pt.y, time, +data.sketch.isDrawing]);
|
coords.push([pt.x, pt.y, pt.time, +data.sketch.isDrawing, idx]);
|
||||||
|
|
||||||
// Check if consecutive points should be removed.
|
// Check if consecutive points should be removed.
|
||||||
if (data.options.filterCoords && coords.length > 1) {
|
if (data.options.filterCoords && coords.length > 1) {
|
||||||
|
|
@ -571,7 +572,10 @@
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function execTouchEvent(e, callback) {
|
function execTouchEvent(e, callback) {
|
||||||
var elem = $(e.target), data = elem.data(namespace), options = data.options;
|
var elem = $(e.target),
|
||||||
|
data = elem.data(namespace),
|
||||||
|
options = data.options;
|
||||||
|
|
||||||
if (options.multitouch) {
|
if (options.multitouch) {
|
||||||
// Track all fingers.
|
// Track all fingers.
|
||||||
var touches = e.originalEvent.changedTouches;
|
var touches = e.originalEvent.changedTouches;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*!
|
/*!
|
||||||
* Sketchable | v2.1 | Luis A. Leiva | MIT license
|
* Sketchable | v2.2 | Luis A. Leiva | MIT license
|
||||||
* A plugin for the jSketch drawing library.
|
* A plugin for the jSketch drawing library.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
* @param {object} [options] - Configuration (default: {@link Sketchable#defaults}).
|
* @param {object} [options] - Configuration (default: {@link Sketchable#defaults}).
|
||||||
* @class
|
* @class
|
||||||
* @global
|
* @global
|
||||||
* @version 2.1
|
* @version 2.2
|
||||||
* @author Luis A. Leiva
|
* @author Luis A. Leiva
|
||||||
* @license MIT
|
* @license MIT
|
||||||
* @example
|
* @example
|
||||||
|
|
@ -80,7 +80,8 @@
|
||||||
// This will store one stroke per touching finger.
|
// This will store one stroke per touching finger.
|
||||||
coords: {},
|
coords: {},
|
||||||
// Date of first coord, used as time origin.
|
// Date of first coord, used as time origin.
|
||||||
timestamp: (new Date).getTime(),
|
// Will be initialized on drawing the first stroke.
|
||||||
|
timestamp: 0,
|
||||||
// Save a pointer to the drawing canvas (jSketch instance).
|
// Save a pointer to the drawing canvas (jSketch instance).
|
||||||
sketch: sketch,
|
sketch: sketch,
|
||||||
// Save also a pointer to the Sketchable instance.
|
// Save also a pointer to the Sketchable instance.
|
||||||
|
|
@ -94,9 +95,9 @@
|
||||||
// Trigger init event.
|
// Trigger init event.
|
||||||
if (typeof options.events.init === 'function')
|
if (typeof options.events.init === 'function')
|
||||||
options.events.init(elem, data);
|
options.events.init(elem, data);
|
||||||
|
|
||||||
// Initialize plugins.
|
// Initialize plugins.
|
||||||
for (var name in this.plugins) this.plugins[name](this);
|
for (var name in this.plugins)
|
||||||
|
this.plugins[name](this);
|
||||||
// Make methods chainable.
|
// Make methods chainable.
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
@ -381,6 +382,7 @@
|
||||||
return {
|
return {
|
||||||
x: Math.round(e.pageX - pos.left),
|
x: Math.round(e.pageX - pos.left),
|
||||||
y: Math.round(e.pageY - pos.top),
|
y: Math.round(e.pageY - pos.top),
|
||||||
|
time: Date.now(),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -391,15 +393,14 @@
|
||||||
// Current coords are already initialized.
|
// Current coords are already initialized.
|
||||||
var coords = data.coords[idx];
|
var coords = data.coords[idx];
|
||||||
|
|
||||||
var time = (new Date).getTime();
|
|
||||||
if (data.options.relTimestamps) {
|
if (data.options.relTimestamps) {
|
||||||
// The first timestamp is relative to initialization time;
|
// The first timestamp is relative to initialization time;
|
||||||
// thus fix it so that it is relative to the timestamp of the first stroke.
|
// thus fix it so that it is relative to the timestamp of the first stroke.
|
||||||
if (data.strokes.length === 0 && coords.length === 0) data.timestamp = time;
|
if (data.strokes.length === 0 && coords.length === 0) data.timestamp = pt.time;
|
||||||
time -= data.timestamp;
|
pt.time -= data.timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
coords.push([pt.x, pt.y, time, +data.sketch.isDrawing]);
|
coords.push([pt.x, pt.y, pt.time, +data.sketch.isDrawing, idx]);
|
||||||
|
|
||||||
// Check if consecutive points should be removed.
|
// Check if consecutive points should be removed.
|
||||||
if (data.options.filterCoords && coords.length > 1) {
|
if (data.options.filterCoords && coords.length > 1) {
|
||||||
|
|
@ -570,7 +571,10 @@
|
||||||
* @ignore
|
* @ignore
|
||||||
*/
|
*/
|
||||||
function execTouchEvent(e, callback) {
|
function execTouchEvent(e, callback) {
|
||||||
var elem = e.target, data = dataBind(elem)[namespace], options = data.options;
|
var elem = e.target,
|
||||||
|
data = dataBind(elem)[namespace],
|
||||||
|
options = data.options;
|
||||||
|
|
||||||
if (options.multitouch) {
|
if (options.multitouch) {
|
||||||
// Track all fingers.
|
// Track all fingers.
|
||||||
var touches = e.changedTouches;
|
var touches = e.changedTouches;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue