mirror of https://github.com/luileito/jsketch.git
Unified casing and naming conventions for event callbacks
This commit is contained in:
parent
254b5bb1a0
commit
1cab773403
|
|
@ -71,8 +71,8 @@
|
|||
this.onselectstart = function(){ return false };
|
||||
}
|
||||
}
|
||||
if (typeof options.events.create === 'function') {
|
||||
options.events.create(elem, elem.data(_ns));
|
||||
if (typeof options.events.init === 'function') {
|
||||
options.events.init(elem, elem.data(_ns));
|
||||
}
|
||||
});
|
||||
},
|
||||
|
|
@ -197,7 +197,7 @@
|
|||
} else if (typeof method === 'object' || !method) {
|
||||
return methods.init.apply(this, arguments);
|
||||
} else {
|
||||
$.error('Method '+ method +' does not exist on jQuery.sketchable');
|
||||
$.error('Method '+ method +' does not exist. See jQuery.sketchable("methods").');
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
|
@ -213,12 +213,12 @@
|
|||
* interactive: true,
|
||||
* mouseupMovements: false,
|
||||
* events: {
|
||||
* create: function(elem, data){},
|
||||
* init: function(elem, data){},
|
||||
* clear: function(elem, data){},
|
||||
* destroy: function(elem, data){},
|
||||
* mouseDown: function(elem, data, evt){},
|
||||
* mouseMove: function(elem, data, evt){},
|
||||
* mouseUp: function(elem, data, evt){},
|
||||
* mousedown: function(elem, data, evt){},
|
||||
* mousemove: function(elem, data, evt){},
|
||||
* mouseup: function(elem, data, evt){},
|
||||
* },
|
||||
* graphics: {
|
||||
* firstPointSize: 0,
|
||||
|
|
@ -239,12 +239,12 @@
|
|||
mouseupMovements: false,
|
||||
// Callback Event
|
||||
events: {
|
||||
// create: function(elem, data){},
|
||||
// init: function(elem, data){},
|
||||
// clear: function(elem, data){},
|
||||
// destroy: function(elem, data){},
|
||||
// mouseDown: function(elem, data, evt){},
|
||||
// mouseMove: function(elem, data, evt){},
|
||||
// mouseUp: function(elem, data, evt){},
|
||||
// mousedown: function(elem, data, evt){},
|
||||
// mousemove: function(elem, data, evt){},
|
||||
// mouseup: function(elem, data, evt){},
|
||||
},
|
||||
// TODO: add more jSketch config options
|
||||
graphics: {
|
||||
|
|
@ -281,8 +281,8 @@
|
|||
var p = getMousePos(e);
|
||||
if (data.canvas.isDrawing) data.canvas.lineTo(p.x, p.y);
|
||||
saveMousePos(data, p);
|
||||
if (typeof options.events.mouseMove === 'function') {
|
||||
options.events.mouseMove(elem, data, e);
|
||||
if (typeof options.events.mousemove === 'function') {
|
||||
options.events.mousemove(elem, data, e);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -296,8 +296,8 @@
|
|||
data.canvas.fillCircle(p.x, p.y, options.graphics.firstPointSize);
|
||||
}
|
||||
saveMousePos(data, p);
|
||||
if (typeof options.events.mouseDown === 'function') {
|
||||
options.events.mouseDown(elem, data, e);
|
||||
if (typeof options.events.mousedown === 'function') {
|
||||
options.events.mousedown(elem, data, e);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -307,8 +307,8 @@
|
|||
data.canvas.closePath();
|
||||
data.strokes.push(data.coords);
|
||||
data.coords = [];
|
||||
if (typeof options.events.mouseUp === 'function') {
|
||||
options.events.mouseUp(elem, data, e);
|
||||
if (typeof options.events.mouseup === 'function') {
|
||||
options.events.mouseup(elem, data, e);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@
|
|||
* jQuery sketchable 1.5 | Luis A. Leiva | MIT license
|
||||
* This is a jQuery plugin for the jSketch drawing class.
|
||||
*/
|
||||
(function(g){var j,e="sketchable";var b={init:function(k){j=g.extend({},g.fn.sketchable.defaults,k);return this.each(function(){var l=g(this),m=l.data(e);if(!m){var n=new jSketch(this,{fillStyle:j.graphics.fillStyle,strokeStyle:j.graphics.strokeStyle,lineWidth:j.graphics.lineWidth,});n.isDrawing=false;l.data(e,{strokes:[],coords:[],timestamp:new Date().getTime(),canvas:n});if(j.interactive){l.bind("mousedown",h);l.bind("mouseup",i);l.bind("mousemove",f);l.bind("touchstart",d);l.bind("touchend",d);l.bind("touchmove",d);this.onselectstart=function(){return false}}}if(typeof j.events.create==="function"){j.events.create(l,l.data(e))}})},strokes:function(k){if(k){return this.each(function(){var m=g(this),n=m.data(e);n.strokes=k})}else{var l=g(this).data(e);return l.strokes}},handler:function(k){return this.each(function(){var l=g(this),m=l.data(e);k(l,m)})},clear:function(){return this.each(function(){var k=g(this),l=k.data(e);l.canvas.clear();l.strokes=[];if(typeof j.events.clear==="function"){j.events.clear(k,l)}})},reset:function(k){return this.each(function(){var l=g(this),m=l.data(e);l.sketchable("destroy").sketchable(k);if(typeof j.events.reset==="function"){j.events.reset(l,m)}})},destroy:function(){return this.each(function(){var k=g(this),l=k.data(e);if(j.interactive){k.unbind("mousedown",h);k.unbind("mouseup",i);k.unbind("mousemove",f);k.unbind("touchstart",d);k.unbind("touchend",d);k.unbind("touchmove",d)}k.removeData(e);if(typeof j.events.destroy==="function"){j.events.destroy(k,l)}})}};g.fn.sketchable=function(k){if(b[k]){return b[k].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof k==="object"||!k){return b.init.apply(this,arguments)}else{g.error("Method "+k+" does not exist on jQuery.sketchable")}}return this};g.fn.sketchable.defaults={interactive:true,mouseupMovements:false,events:{},graphics:{firstPointSize:0,lineWidth:3,strokeStyle:"#F0F",fillStyle:"#F0F"}};function c(l){var k=g(l.target),m=k.offset();return{x:Math.round(l.pageX-m.left),y:Math.round(l.pageY-m.top)}}function a(k,m){var l=(new Date).getTime();k.coords.push([m.x,m.y,l,+k.canvas.isDrawing])}function f(n){var k=g(n.target),l=k.data(e);if(!j.mouseupMovements&&!l.canvas.isDrawing){return}var m=c(n);if(l.canvas.isDrawing){l.canvas.lineTo(m.x,m.y)}a(l,m);if(typeof j.events.mouseMove==="function"){j.events.mouseMove(k,l,n)}}function h(n){var k=g(n.target),l=k.data(e);l.canvas.isDrawing=true;var m=c(n);l.canvas.beginPath();if(j.graphics.firstPointSize>0){l.canvas.fillCircle(m.x,m.y,j.graphics.firstPointSize)}a(l,m);if(typeof j.events.mouseDown==="function"){j.events.mouseDown(k,l,n)}}function i(m){var k=g(m.target),l=k.data(e);l.canvas.isDrawing=false;l.canvas.closePath();l.strokes.push(l.coords);l.coords=[];if(typeof j.events.mouseUp==="function"){j.events.mouseUp(k,l,m)}}function d(l){l.preventDefault();var k=g(l.target);var n=l.originalEvent.changedTouches[0];for(var m in l){n[m]=l[m]}switch(l.type){case"touchstart":k.unbind(l.type,h);h(n);break;case"touchmove":k.unbind(l.type,f);f(n);break;case"touchend":k.unbind(l.type,i);i(n);break;default:return}}})(jQuery);
|
||||
(function(g){var j,e="sketchable";var b={init:function(k){j=g.extend({},g.fn.sketchable.defaults,k);return this.each(function(){var l=g(this),m=l.data(e);if(!m){var n=new jSketch(this,{fillStyle:j.graphics.fillStyle,strokeStyle:j.graphics.strokeStyle,lineWidth:j.graphics.lineWidth,});n.isDrawing=false;l.data(e,{strokes:[],coords:[],timestamp:new Date().getTime(),canvas:n});if(j.interactive){l.bind("mousedown",h);l.bind("mouseup",i);l.bind("mousemove",f);l.bind("touchstart",d);l.bind("touchend",d);l.bind("touchmove",d);this.onselectstart=function(){return false}}}if(typeof j.events.init==="function"){j.events.init(l,l.data(e))}})},strokes:function(k){if(k){return this.each(function(){var m=g(this),n=m.data(e);n.strokes=k})}else{var l=g(this).data(e);return l.strokes}},handler:function(k){return this.each(function(){var l=g(this),m=l.data(e);k(l,m)})},clear:function(){return this.each(function(){var k=g(this),l=k.data(e);l.canvas.clear();l.strokes=[];if(typeof j.events.clear==="function"){j.events.clear(k,l)}})},reset:function(k){return this.each(function(){var l=g(this),m=l.data(e);l.sketchable("destroy").sketchable(k);if(typeof j.events.reset==="function"){j.events.reset(l,m)}})},destroy:function(){return this.each(function(){var k=g(this),l=k.data(e);if(j.interactive){k.unbind("mousedown",h);k.unbind("mouseup",i);k.unbind("mousemove",f);k.unbind("touchstart",d);k.unbind("touchend",d);k.unbind("touchmove",d)}k.removeData(e);if(typeof j.events.destroy==="function"){j.events.destroy(k,l)}})}};g.fn.sketchable=function(k){if(b[k]){return b[k].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof k==="object"||!k){return b.init.apply(this,arguments)}else{g.error("Method "+k+' does not exist. See jQuery.sketchable("methods").')}}return this};g.fn.sketchable.defaults={interactive:true,mouseupMovements:false,events:{},graphics:{firstPointSize:0,lineWidth:3,strokeStyle:"#F0F",fillStyle:"#F0F"}};function c(l){var k=g(l.target),m=k.offset();return{x:Math.round(l.pageX-m.left),y:Math.round(l.pageY-m.top)}}function a(k,m){var l=(new Date).getTime();k.coords.push([m.x,m.y,l,+k.canvas.isDrawing])}function f(n){var k=g(n.target),l=k.data(e);if(!j.mouseupMovements&&!l.canvas.isDrawing){return}var m=c(n);if(l.canvas.isDrawing){l.canvas.lineTo(m.x,m.y)}a(l,m);if(typeof j.events.mousemove==="function"){j.events.mousemove(k,l,n)}}function h(n){var k=g(n.target),l=k.data(e);l.canvas.isDrawing=true;var m=c(n);l.canvas.beginPath();if(j.graphics.firstPointSize>0){l.canvas.fillCircle(m.x,m.y,j.graphics.firstPointSize)}a(l,m);if(typeof j.events.mousedown==="function"){j.events.mousedown(k,l,n)}}function i(m){var k=g(m.target),l=k.data(e);l.canvas.isDrawing=false;l.canvas.closePath();l.strokes.push(l.coords);l.coords=[];if(typeof j.events.mouseup==="function"){j.events.mouseup(k,l,m)}}function d(l){l.preventDefault();var k=g(l.target);var n=l.originalEvent.changedTouches[0];for(var m in l){n[m]=l[m]}switch(l.type){case"touchstart":k.unbind(l.type,h);h(n);break;case"touchmove":k.unbind(l.type,f);f(n);break;case"touchend":k.unbind(l.type,i);i(n);break;default:return}}})(jQuery);
|
||||
Loading…
Reference in New Issue