mirror of https://github.com/luileito/jsketch.git
Enforce single quotes
This commit is contained in:
parent
fad61979e4
commit
1cef44c5e5
|
|
@ -17,7 +17,7 @@
|
||||||
*/
|
*/
|
||||||
;(function($){
|
;(function($){
|
||||||
// Custom namespace ID.
|
// Custom namespace ID.
|
||||||
var _ns = "sketchable";
|
var _ns = 'sketchable';
|
||||||
/**
|
/**
|
||||||
* jQuery sketchable plugin API.
|
* jQuery sketchable plugin API.
|
||||||
* @namespace methods
|
* @namespace methods
|
||||||
|
|
@ -40,12 +40,12 @@
|
||||||
if (!data) {
|
if (!data) {
|
||||||
// Attach event listeners.
|
// Attach event listeners.
|
||||||
if (options.interactive) {
|
if (options.interactive) {
|
||||||
elem.bind("mousedown", mousedownHandler);
|
elem.bind('mousedown', mousedownHandler);
|
||||||
elem.bind("mousemove", mousemoveHandler);
|
elem.bind('mousemove', mousemoveHandler);
|
||||||
elem.bind("mouseup", mouseupHandler);
|
elem.bind('mouseup', mouseupHandler);
|
||||||
elem.bind("touchstart", touchdownHandler);
|
elem.bind('touchstart', touchdownHandler);
|
||||||
elem.bind("touchmove", touchmoveHandler);
|
elem.bind('touchmove', touchmoveHandler);
|
||||||
elem.bind("touchend", touchupHandler);
|
elem.bind('touchend', touchupHandler);
|
||||||
// Fix Chrome "bug".
|
// Fix Chrome "bug".
|
||||||
this.onselectstart = function(){ return false };
|
this.onselectstart = function(){ return false };
|
||||||
}
|
}
|
||||||
|
|
@ -174,12 +174,12 @@
|
||||||
return this.each(function(){
|
return this.each(function(){
|
||||||
var elem = $(this), data = elem.data(_ns) || {}, options = data.options;
|
var elem = $(this), data = elem.data(_ns) || {}, options = data.options;
|
||||||
if (options.interactive) {
|
if (options.interactive) {
|
||||||
elem.unbind("mouseup", mouseupHandler);
|
elem.unbind('mouseup', mouseupHandler);
|
||||||
elem.unbind("mousemove", mousemoveHandler);
|
elem.unbind('mousemove', mousemoveHandler);
|
||||||
elem.unbind("mousedown", mousedownHandler);
|
elem.unbind('mousedown', mousedownHandler);
|
||||||
elem.unbind("touchstart", touchdownHandler);
|
elem.unbind('touchstart', touchdownHandler);
|
||||||
elem.unbind("touchmove", touchmoveHandler);
|
elem.unbind('touchmove', touchmoveHandler);
|
||||||
elem.unbind("touchend", touchupHandler);
|
elem.unbind('touchend', touchupHandler);
|
||||||
}
|
}
|
||||||
elem.removeData(_ns);
|
elem.removeData(_ns);
|
||||||
|
|
||||||
|
|
@ -209,7 +209,7 @@
|
||||||
$.fn.sketchable = function(method) {
|
$.fn.sketchable = function(method) {
|
||||||
// These "magic" keywords return internal plugin methods,
|
// These "magic" keywords return internal plugin methods,
|
||||||
// so that they can be easily extended/overriden.
|
// so that they can be easily extended/overriden.
|
||||||
if ("methods functions hooks".split(" ").indexOf(method) > -1) {
|
if ('methods functions hooks'.split(' ').indexOf(method) > -1) {
|
||||||
return methods;
|
return methods;
|
||||||
} else if (methods[method]) {
|
} else if (methods[method]) {
|
||||||
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
|
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
|
||||||
|
|
@ -247,8 +247,8 @@
|
||||||
* lineWidth: 3,
|
* lineWidth: 3,
|
||||||
* strokeStyle: '#F0F',
|
* strokeStyle: '#F0F',
|
||||||
* fillStyle: '#F0F',
|
* fillStyle: '#F0F',
|
||||||
* lineCap: "round",
|
* lineCap: 'round',
|
||||||
* lineJoin: "round",
|
* lineJoin: 'round',
|
||||||
* miterLimit: 10
|
* miterLimit: 10
|
||||||
* }
|
* }
|
||||||
* });
|
* });
|
||||||
|
|
@ -279,8 +279,8 @@
|
||||||
lineWidth: 3,
|
lineWidth: 3,
|
||||||
strokeStyle: '#F0F',
|
strokeStyle: '#F0F',
|
||||||
fillStyle: '#F0F',
|
fillStyle: '#F0F',
|
||||||
lineCap: "round",
|
lineCap: 'round',
|
||||||
lineJoin: "round",
|
lineJoin: 'round',
|
||||||
miterLimit: 10
|
miterLimit: 10
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -292,7 +292,7 @@
|
||||||
if (!options) options = elem.data(_ns).options;
|
if (!options) options = elem.data(_ns).options;
|
||||||
if (options.cssCursors) {
|
if (options.cssCursors) {
|
||||||
// Visually indicate whether this element is interactive or not.
|
// Visually indicate whether this element is interactive or not.
|
||||||
elem[0].style.cursor = options.interactive ? "pointer" : "not-allowed";
|
elem[0].style.cursor = options.interactive ? 'pointer' : 'not-allowed';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -140,8 +140,8 @@
|
||||||
* @memberOf MementoCanvas
|
* @memberOf MementoCanvas
|
||||||
*/
|
*/
|
||||||
this.init = function() {
|
this.init = function() {
|
||||||
$(document).off("keypress", keyManager);
|
$(document).off('keypress', keyManager);
|
||||||
$(document).on("keypress", keyManager);
|
$(document).on('keypress', keyManager);
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* Destroy instance.
|
* Destroy instance.
|
||||||
|
|
@ -149,14 +149,14 @@
|
||||||
* @memberOf MementoCanvas
|
* @memberOf MementoCanvas
|
||||||
*/
|
*/
|
||||||
this.destroy = function() {
|
this.destroy = function() {
|
||||||
$(document).off("keypress", keyManager);
|
$(document).off('keypress', keyManager);
|
||||||
this.reset();
|
this.reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Bind plugin extension ////////////////////////////////////////////////////
|
// Bind plugin extension ////////////////////////////////////////////////////
|
||||||
var namespace = "sketchable";
|
var namespace = 'sketchable';
|
||||||
var plugin = $.fn.sketchable;
|
var plugin = $.fn.sketchable;
|
||||||
var availMethods = plugin('methods');
|
var availMethods = plugin('methods');
|
||||||
|
|
||||||
|
|
@ -200,7 +200,7 @@
|
||||||
|
|
||||||
// Event order matters.
|
// Event order matters.
|
||||||
// Init must go first, since it's called when instantiating the plugin.
|
// Init must go first, since it's called when instantiating the plugin.
|
||||||
var events = 'init mouseup clear destroy'.split(" ");
|
var events = 'init mouseup clear destroy'.split(' ');
|
||||||
for (var i = 0; i < events.length; i++) {
|
for (var i = 0; i < events.length; i++) {
|
||||||
override(events[i]);
|
override(events[i]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
29
jsketch.js
29
jsketch.js
|
|
@ -1,5 +1,5 @@
|
||||||
/*!
|
/*!
|
||||||
* jSketch 0.8 | Luis A. Leiva | MIT license
|
* jSketch 0.9 | Luis A. Leiva | MIT license
|
||||||
* A simple JavaScript library for drawing facilities on HTML5 canvas.
|
* A simple JavaScript library for drawing facilities on HTML5 canvas.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
|
|
@ -8,8 +8,7 @@
|
||||||
* such as function chainability and old-school AS3-like notation.
|
* such as function chainability and old-school AS3-like notation.
|
||||||
* @name jSketch
|
* @name jSketch
|
||||||
* @class
|
* @class
|
||||||
* @version 0.8
|
* @version 0.9
|
||||||
* @date 9 Jul 2014
|
|
||||||
* @author Luis A. Leiva
|
* @author Luis A. Leiva
|
||||||
* @license MIT license
|
* @license MIT license
|
||||||
* @example
|
* @example
|
||||||
|
|
@ -60,10 +59,10 @@
|
||||||
* @memberof jSketch
|
* @memberof jSketch
|
||||||
*/
|
*/
|
||||||
context: function(elem) {
|
context: function(elem) {
|
||||||
if (elem === null) throw("No canvas element specified.");
|
if (elem === null) throw('No canvas element specified.');
|
||||||
// Save shortcuts: canvas (DOM elem) & graphics (2D canvas context).
|
// Save shortcuts: canvas (DOM elem) & graphics (2D canvas context).
|
||||||
this.canvas = elem;
|
this.canvas = elem;
|
||||||
this.graphics = elem.getContext("2d");
|
this.graphics = elem.getContext('2d');
|
||||||
// Always allow chainability.
|
// Always allow chainability.
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
@ -289,7 +288,7 @@
|
||||||
*/
|
*/
|
||||||
strokeCircle: function(x,y, radius) {
|
strokeCircle: function(x,y, radius) {
|
||||||
this.graphics.beginPath();
|
this.graphics.beginPath();
|
||||||
this.graphics.arc(x,y, radius, 0, Math.PI * 2, false);
|
this.graphics.arc(x,y, radius, 0, 2*Math.PI, false);
|
||||||
this.graphics.stroke();
|
this.graphics.stroke();
|
||||||
this.graphics.closePath();
|
this.graphics.closePath();
|
||||||
return this;
|
return this;
|
||||||
|
|
@ -304,7 +303,7 @@
|
||||||
*/
|
*/
|
||||||
fillCircle: function(x,y, radius) {
|
fillCircle: function(x,y, radius) {
|
||||||
this.graphics.beginPath();
|
this.graphics.beginPath();
|
||||||
this.graphics.arc(x,y, radius, 0, Math.PI * 2, false);
|
this.graphics.arc(x,y, radius, 0, 2*Math.PI, false);
|
||||||
this.graphics.fill();
|
this.graphics.fill();
|
||||||
this.graphics.closePath();
|
this.graphics.closePath();
|
||||||
return this;
|
return this;
|
||||||
|
|
@ -313,10 +312,16 @@
|
||||||
* Experimental.
|
* Experimental.
|
||||||
* @ignore
|
* @ignore
|
||||||
*/
|
*/
|
||||||
radialCircle: function(x,y,radius,glowSize,color1,color2) {
|
radialCircle: function(x,y, radius, glowSize, colors) {
|
||||||
var g = this.graphics.createRadialGradient(x,y, radius, x,y, glowSize || 5);
|
var g = this.graphics.createRadialGradient(x,y, radius, x,y, glowSize || 5);
|
||||||
g.addColorStop(0, color1 || this.graphics.fillStyle);
|
if (colors.constructor.name !== 'array') {
|
||||||
g.addColorStop(1, color2 || 'white');
|
colors = [this.graphics.fillStyle, 'white'];
|
||||||
|
} else {
|
||||||
|
for (var s = 0; s < colors.length; s++) {
|
||||||
|
var color = colors[i];
|
||||||
|
g.addColorStop(i, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
this.beginFill(g).fillCircle(x,y, radius).endFill();
|
this.beginFill(g).fillCircle(x,y, radius).endFill();
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
@ -348,7 +353,7 @@
|
||||||
*/
|
*/
|
||||||
eraser: function(brushSize) {
|
eraser: function(brushSize) {
|
||||||
if (typeof brushSize === 'undefined') brushSize = 15;
|
if (typeof brushSize === 'undefined') brushSize = 15;
|
||||||
this.graphics.globalCompositeOperation = "destination-out";
|
this.graphics.globalCompositeOperation = 'destination-out';
|
||||||
this.lineStyle(null, brushSize);
|
this.lineStyle(null, brushSize);
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
@ -360,7 +365,7 @@
|
||||||
*/
|
*/
|
||||||
pencil: function(brushSize) {
|
pencil: function(brushSize) {
|
||||||
if (typeof brushSize === 'undefined') brushSize = 2;
|
if (typeof brushSize === 'undefined') brushSize = 2;
|
||||||
this.graphics.globalCompositeOperation = "source-over";
|
this.graphics.globalCompositeOperation = 'source-over';
|
||||||
this.lineStyle(null, brushSize);
|
this.lineStyle(null, brushSize);
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
*/
|
*/
|
||||||
;(function(window){
|
;(function(window){
|
||||||
// Custom namespace ID.
|
// Custom namespace ID.
|
||||||
var _ns = "sketchable";
|
var _ns = 'sketchable';
|
||||||
/**
|
/**
|
||||||
* Creates a <tt>sketchable</tt> instance.
|
* Creates a <tt>sketchable</tt> instance.
|
||||||
* This is a plugin for the <tt>jSketch</tt> drawing class.
|
* This is a plugin for the <tt>jSketch</tt> drawing class.
|
||||||
|
|
@ -66,18 +66,18 @@
|
||||||
if (!data) {
|
if (!data) {
|
||||||
// Attach event listeners.
|
// Attach event listeners.
|
||||||
if (options.interactive) {
|
if (options.interactive) {
|
||||||
Event.add(elem, "mousedown", mousedownHandler);
|
Event.add(elem, 'mousedown', mousedownHandler);
|
||||||
Event.add(elem, "mousemove", mousemoveHandler);
|
Event.add(elem, 'mousemove', mousemoveHandler);
|
||||||
Event.add(elem, "mouseup", mouseupHandler);
|
Event.add(elem, 'mouseup', mouseupHandler);
|
||||||
Event.add(elem, "touchstart", touchdownHandler);
|
Event.add(elem, 'touchstart', touchdownHandler);
|
||||||
Event.add(elem, "touchmove", touchmoveHandler);
|
Event.add(elem, 'touchmove', touchmoveHandler);
|
||||||
Event.add(elem, "touchend", touchupHandler);
|
Event.add(elem, 'touchend', touchupHandler);
|
||||||
// Fix Chrome "bug".
|
// Fix Chrome "bug".
|
||||||
this.onselectstart = function(){ return false };
|
this.onselectstart = function(){ return false };
|
||||||
}
|
}
|
||||||
if (options.cssCursors) {
|
if (options.cssCursors) {
|
||||||
// Visually indicate whether this element is interactive or not.
|
// Visually indicate whether this element is interactive or not.
|
||||||
elem.style.cursor = options.interactive ? "pointer" : "not-allowed";
|
elem.style.cursor = options.interactive ? 'pointer' : 'not-allowed';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var sketch = new jSketch(elem, options.graphics);
|
var sketch = new jSketch(elem, options.graphics);
|
||||||
|
|
@ -196,12 +196,12 @@
|
||||||
destroy: function() {
|
destroy: function() {
|
||||||
var elem = this.elem, data = dataBind(elem)[_ns], options = data.options;
|
var elem = this.elem, data = dataBind(elem)[_ns], options = data.options;
|
||||||
if (options.interactive) {
|
if (options.interactive) {
|
||||||
Event.remove(elem, "mouseup", mouseupHandler);
|
Event.remove(elem, 'mouseup', mouseupHandler);
|
||||||
Event.remove(elem, "mousemove", mousemoveHandler);
|
Event.remove(elem, 'mousemove', mousemoveHandler);
|
||||||
Event.remove(elem, "mousedown", mousedownHandler);
|
Event.remove(elem, 'mousedown', mousedownHandler);
|
||||||
Event.remove(elem, "touchstart", touchdownHandler);
|
Event.remove(elem, 'touchstart', touchdownHandler);
|
||||||
Event.remove(elem, "touchmove", touchmoveHandler);
|
Event.remove(elem, 'touchmove', touchmoveHandler);
|
||||||
Event.remove(elem, "touchend", touchupHandler);
|
Event.remove(elem, 'touchend', touchupHandler);
|
||||||
}
|
}
|
||||||
dataBind(elem)[_ns] = null;
|
dataBind(elem)[_ns] = null;
|
||||||
|
|
||||||
|
|
@ -239,8 +239,8 @@
|
||||||
* lineWidth: 3,
|
* lineWidth: 3,
|
||||||
* strokeStyle: '#F0F',
|
* strokeStyle: '#F0F',
|
||||||
* fillStyle: '#F0F',
|
* fillStyle: '#F0F',
|
||||||
* lineCap: "round",
|
* lineCap: 'round',
|
||||||
* lineJoin: "round",
|
* lineJoin: 'round',
|
||||||
* miterLimit: 10
|
* miterLimit: 10
|
||||||
* }
|
* }
|
||||||
* });
|
* });
|
||||||
|
|
@ -271,8 +271,8 @@
|
||||||
lineWidth: 3,
|
lineWidth: 3,
|
||||||
strokeStyle: '#F0F',
|
strokeStyle: '#F0F',
|
||||||
fillStyle: '#F0F',
|
fillStyle: '#F0F',
|
||||||
lineCap: "round",
|
lineCap: 'round',
|
||||||
lineJoin: "round",
|
lineJoin: 'round',
|
||||||
miterLimit: 10
|
miterLimit: 10
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -131,8 +131,8 @@
|
||||||
* @memberOf MementoCanvas
|
* @memberOf MementoCanvas
|
||||||
*/
|
*/
|
||||||
this.init = function() {
|
this.init = function() {
|
||||||
Event.remove(document, "keypress", keyManager);
|
Event.remove(document, 'keypress', keyManager);
|
||||||
Event.add(document, "keypress", keyManager);
|
Event.add(document, 'keypress', keyManager);
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* Destroy instance.
|
* Destroy instance.
|
||||||
|
|
@ -140,14 +140,14 @@
|
||||||
* @memberOf MementoCanvas
|
* @memberOf MementoCanvas
|
||||||
*/
|
*/
|
||||||
this.destroy = function() {
|
this.destroy = function() {
|
||||||
Event.remove(document, "keypress", keyManager);
|
Event.remove(document, 'keypress', keyManager);
|
||||||
this.reset();
|
this.reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Bind plugin extension ////////////////////////////////////////////////////
|
// Bind plugin extension ////////////////////////////////////////////////////
|
||||||
var namespace = "sketchable";
|
var namespace = 'sketchable';
|
||||||
var availMethods = Sketchable.fn;
|
var availMethods = Sketchable.fn;
|
||||||
var defaults = Sketchable.fn.defaults;
|
var defaults = Sketchable.fn.defaults;
|
||||||
|
|
||||||
|
|
@ -191,7 +191,7 @@
|
||||||
|
|
||||||
// Event order matters.
|
// Event order matters.
|
||||||
// Init must go first, since it's called when instantiating the plugin.
|
// Init must go first, since it's called when instantiating the plugin.
|
||||||
var events = 'init mouseup clear destroy'.split(" ");
|
var events = 'init mouseup clear destroy'.split(' ');
|
||||||
for (var i = 0; i < events.length; i++) {
|
for (var i = 0; i < events.length; i++) {
|
||||||
override(events[i]);
|
override(events[i]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue