lots of jshinting

This commit is contained in:
Eric Rowell
2013-06-01 22:03:02 -07:00
parent 3f67cc8b60
commit 77793aed60
8 changed files with 48 additions and 38 deletions

View File

@@ -131,6 +131,9 @@ module.exports = function(grunt) {
build: ['dist/*'] build: ['dist/*']
}, },
jshint: { jshint: {
options: {
laxbreak: true
},
all: ['src/**/*.js'] all: ['src/**/*.js']
} }
}; };

View File

@@ -132,8 +132,8 @@
try { try {
return this.element.toDataURL(); return this.element.toDataURL();
} }
catch(e) { catch(err) {
Kinetic.Util.warn('Unable to get data URL. ' + e.message) Kinetic.Util.warn('Unable to get data URL. ' + err.message);
return ''; return '';
} }
} }

View File

@@ -45,7 +45,7 @@
return null; return null;
}, },
drawScene: function(canvas) { drawScene: function(canvas) {
var canvas = canvas || this.getCanvas(); canvas = canvas || this.getCanvas();
if(this.getClearBeforeDraw()) { if(this.getClearBeforeDraw()) {
canvas.clear(); canvas.clear();

View File

@@ -128,7 +128,7 @@
off: function(typesStr) { off: function(typesStr) {
var types = typesStr.split(SPACE), var types = typesStr.split(SPACE),
len = types.length, len = types.length,
n, type, event, parts, baseEvent; n, type, t, event, parts, baseEvent;
for(n = 0; n < len; n++) { for(n = 0; n < len; n++) {
type = types[n]; type = types[n];
@@ -143,8 +143,8 @@
} }
} }
else { else {
for(var type in this.eventListeners) { for(t in this.eventListeners) {
this._off(type, parts[1]); this._off(t, parts[1]);
} }
} }
} }
@@ -868,8 +868,9 @@
* is very high quality * is very high quality
*/ */
toDataURL: function(config) { toDataURL: function(config) {
var config = config || {}, config = config || {};
mimeType = config.mimeType || null,
var mimeType = config.mimeType || null,
quality = config.quality || null, quality = config.quality || null,
stage = this.getStage(), stage = this.getStage(),
x = config.x || 0, x = config.x || 0,
@@ -1317,7 +1318,7 @@
/** /**
* create node with JSON string. De-serializtion does not generate custom * create node with JSON string. De-serializtion does not generate custom
* shape drawing functions, images, or event handlers (this would make the * shape drawing functions, images, or event handlers (this would make the
* serialized object huge). If your app uses custom shapes, images, and * serialized object huge). If your app uses custom shapes, images, and
* event handlers (it probably does), then you need to select the appropriate * event handlers (it probably does), then you need to select the appropriate
* shapes after loading the stage and set these properties via on(), setDrawFunc(), * shapes after loading the stage and set these properties via on(), setDrawFunc(),
* and setImage() methods * and setImage() methods

View File

@@ -179,8 +179,9 @@
delete Kinetic.Global.shapes[this.colorKey]; delete Kinetic.Global.shapes[this.colorKey];
}, },
drawScene: function(canvas) { drawScene: function(canvas) {
canvas = canvas || this.getLayer().getCanvas();
var drawFunc = this.getDrawFunc(), var drawFunc = this.getDrawFunc(),
canvas = canvas || this.getLayer().getCanvas(),
context = canvas.getContext(); context = canvas.getContext();
if(drawFunc && this.isVisible()) { if(drawFunc && this.isVisible()) {

View File

@@ -5,7 +5,6 @@
PX = 'px', PX = 'px',
MOUSEOUT = 'mouseout', MOUSEOUT = 'mouseout',
MOUSELEAVE = 'mouseleave', MOUSELEAVE = 'mouseleave',
MOUSEOUT = 'mouseout',
MOUSEOVER = 'mouseover', MOUSEOVER = 'mouseover',
MOUSEENTER = 'mouseenter', MOUSEENTER = 'mouseenter',
MOUSEMOVE = 'mousemove', MOUSEMOVE = 'mousemove',
@@ -13,8 +12,8 @@
MOUSEUP = 'mouseup', MOUSEUP = 'mouseup',
CLICK = 'click', CLICK = 'click',
DBL_CLICK = 'dblclick', DBL_CLICK = 'dblclick',
TOUCHSTART = 'touchstart' TOUCHSTART = 'touchstart',
TOUCHEND = 'touchend' TOUCHEND = 'touchend',
TAP = 'tap', TAP = 'tap',
DBL_TAP = 'dbltap', DBL_TAP = 'dbltap',
TOUCHMOVE = 'touchmove', TOUCHMOVE = 'touchmove',
@@ -191,8 +190,9 @@
* is very high quality * is very high quality
*/ */
toDataURL: function(config) { toDataURL: function(config) {
var config = config || {}, config = config || {};
mimeType = config.mimeType || null,
var mimeType = config.mimeType || null,
quality = config.quality || null, quality = config.quality || null,
x = config.x || 0, x = config.x || 0,
y = config.y || 0, y = config.y || 0,
@@ -399,9 +399,9 @@
}, },
_mousedown: function(evt) { _mousedown: function(evt) {
this._setPointerPosition(evt); this._setPointerPosition(evt);
var go = Kinetic.Global, var go = Kinetic.Global,
obj = this.getIntersection(this.getPointerPosition()), obj = this.getIntersection(this.getPointerPosition()),
shape; shape;
if(obj && obj.shape) { if(obj && obj.shape) {
shape = obj.shape; shape = obj.shape;
@@ -448,10 +448,10 @@
this.clickStart = false; this.clickStart = false;
}, },
_touchstart: function(evt) { _touchstart: function(evt) {
this._setPointerPosition(evt); this._setPointerPosition(evt);
var go = Kinetic.Global, var go = Kinetic.Global,
obj = this.getIntersection(this.getPointerPosition()), obj = this.getIntersection(this.getPointerPosition()),
shape; shape;
if(obj && obj.shape) { if(obj && obj.shape) {
shape = obj.shape; shape = obj.shape;

View File

@@ -13,8 +13,8 @@
this[i] = args[i]; this[i] = args[i];
} }
return this; return this;
} };
Kinetic.Collection.prototype = new Array(); Kinetic.Collection.prototype = [];
/** /**
* iterate through node array and run a function for each node. * iterate through node array and run a function for each node.
* The node and index is passed into the function * The node and index is passed into the function
@@ -92,7 +92,7 @@
*/ */
Kinetic.Transform = function() { Kinetic.Transform = function() {
this.m = [1, 0, 0, 1, 0, 0]; this.m = [1, 0, 0, 1, 0, 0];
} };
Kinetic.Transform.prototype = { Kinetic.Transform.prototype = {
/** /**
@@ -449,18 +449,22 @@
* an array of point objects * an array of point objects
*/ */
_getPoints: function(arg) { _getPoints: function(arg) {
var arr = [],
n, len;
if(arg === undefined) { if(arg === undefined) {
return []; return [];
} }
len = arg.length;
// an array of arrays // an array of arrays
if(this._isArray(arg[0])) { if(this._isArray(arg[0])) {
/* /*
* convert array of arrays into an array * convert array of arrays into an array
* of objects containing x, y * of objects containing x, y
*/ */
var arr = []; for(n = 0; n < len; n++) {
for(var n = 0; n < arg.length; n++) {
arr.push({ arr.push({
x: arg[n][0], x: arg[n][0],
y: arg[n][1] y: arg[n][1]
@@ -479,8 +483,7 @@
* convert array of numbers into an array * convert array of numbers into an array
* of objects containing x, y * of objects containing x, y
*/ */
var arr = []; for(n = 0; n < len; n += 2) {
for(var n = 0; n < arg.length; n += 2) {
arr.push({ arr.push({
x: arg[n], x: arg[n],
y: arg[n + 1] y: arg[n + 1]
@@ -511,7 +514,7 @@
imageObj = new Image(); imageObj = new Image();
imageObj.onload = function() { imageObj.onload = function() {
callback(imageObj); callback(imageObj);
} };
imageObj.src = arg; imageObj.src = arg;
} }
@@ -526,7 +529,7 @@
imageObj = new Image(); imageObj = new Image();
imageObj.onload = function() { imageObj.onload = function() {
callback(imageObj); callback(imageObj);
} };
imageObj.src = dataUrl; imageObj.src = dataUrl;
} }
else { else {
@@ -587,9 +590,9 @@
else if (color.substr(0, 4) === RGB_PAREN) { else if (color.substr(0, 4) === RGB_PAREN) {
rgb = RGB_REGEX.exec(color.replace(/ /g,'')); rgb = RGB_REGEX.exec(color.replace(/ /g,''));
return { return {
r: parseInt(rgb[1]), r: parseInt(rgb[1], 10),
g: parseInt(rgb[2]), g: parseInt(rgb[2], 10),
b: parseInt(rgb[3]) b: parseInt(rgb[3], 10)
}; };
} }
// default // default

View File

@@ -37,16 +37,18 @@
// tension // tension
if(tension !== 0 && length > 2) { if(tension !== 0 && length > 2) {
var ap = this.allPoints, len = ap.length; var ap = this.allPoints,
var n = 0; len = ap.length,
n, point;
while(n < len-1) { while(n < len-1) {
context.bezierCurveTo(ap[n].x, ap[n++].y, ap[n].x, ap[n++].y, ap[n].x, ap[n++].y); context.bezierCurveTo(ap[n].x, ap[n++].y, ap[n].x, ap[n++].y, ap[n].x, ap[n++].y);
} }
} }
// no tension // no tension
else { else {
for(var n = 1; n < length; n++) { for(n = 1; n < length; n++) {
var point = points[n]; point = points[n];
context.lineTo(point.x, point.y); context.lineTo(point.x, point.y);
} }
} }