JSCS tweaks. Down to 114 failures.

This commit is contained in:
kangax 2014-06-24 14:12:17 +02:00
parent f01d1338da
commit 492253e5ca
16 changed files with 85 additions and 79 deletions

View file

@ -7,8 +7,6 @@
"requireParenthesesAroundIIFE": true,
"requireSpacesInsideObjectBrackets": "all",
"requireCommaBeforeLineBreak": true,
"requireRightStickedOperators": ["!"],
"requireLeftStickedOperators": [","],
"requireCamelCaseOrUpperCaseIdentifiers": true,
"requireKeywordsOnNewLine": ["else"],
"requireLineFeedAtFileEnd": true,

View file

@ -144,7 +144,7 @@
this.box = this.getPathBoundingBox(this._points);
return this.convertPointsToSVGPath(
this._points, this.box.minx, this.box.maxx, this.box.miny, this.box.maxy);
},
},
/**
* Returns bounding box of a path based on given points

View file

@ -783,9 +783,8 @@
// Cache all targets where their bounding box contains point.
var target,
pointer = this.getPointer(e);
var i = this._objects.length;
pointer = this.getPointer(e),
i = this._objects.length;
while (i--) {
if (this._checkTarget(e, this._objects[i], pointer)){

View file

@ -59,10 +59,9 @@
source = new fabric.Color(this.color).getSource();
for (i = 0; i < iLen; i+=4) {
data[i] *= source[0]/255;
data[i + 1] *= source[1]/255;
data[i + 2] *= source[2]/255;
data[i] *= source[0] / 255;
data[i + 1] *= source[1] / 255;
data[i + 2] *= source[2] / 255;
}
context.putImageData(imageData, 0, 0);

View file

@ -153,7 +153,7 @@
if (e.type === 'touchstart') {
// Unbind mousedown to prevent double triggers from touch devices
removeListener(this.upperCanvasEl, 'mousedown', this._onMouseDown);
removeListener(this.upperCanvasEl, 'mousedown', this._onMouseDown);
}
else {
addListener(fabric.document, 'mouseup', this._onMouseUp);

View file

@ -108,7 +108,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
fabric.util.string.escapeXml(_char),
'</tspan>'
].join('');
].join('');
}
});
/* _TO_SVG_END_ */

View file

@ -238,10 +238,10 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
mouseOffset, prevWidth, width, charIndex + i, jlen);
}
if (mouseOffset.y < height) {
return this._getNewSelectionStartFromOffset(
mouseOffset, prevWidth, width, charIndex + i, jlen, j);
}
if (mouseOffset.y < height) {
return this._getNewSelectionStartFromOffset(
mouseOffset, prevWidth, width, charIndex + i, jlen, j);
}
}
// clicked somewhere after all chars, so set at the end

View file

@ -16,7 +16,6 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
fabric.util.addListener(this.hiddenTextarea, 'copy', this.copy.bind(this));
fabric.util.addListener(this.hiddenTextarea, 'paste', this.paste.bind(this));
if (!this._clickHandlerInitialized && this.canvas) {
fabric.util.addListener(this.canvas.upperCanvasEl, 'click', this.onClick.bind(this));
this._clickHandlerInitialized = true;
@ -88,7 +87,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
copy: function(e) {
var selectedText = this.getSelectedText(),
clipboardData = this._getClipboardData(e);
// Check for backward compatibility with old browsers
if (clipboardData) {
clipboardData.setData('text', selectedText);
@ -107,14 +106,14 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
paste: function(e) {
var copiedText = null,
clipboardData = this._getClipboardData(e);
// Check for backward compatibility with old browsers
if (clipboardData) {
copiedText = clipboardData.getData('text');
} else {
copiedText = this.copiedText;
}
if (copiedText) {
this.insertChars(copiedText);
}
@ -639,4 +638,4 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
}
}
}
});
});

View file

@ -18,7 +18,9 @@
* @return {String|Boolean} corner code (tl, tr, bl, br, etc.), or false if nothing is found
*/
_findTargetCorner: function(pointer) {
if (!this.hasControls || !this.active) return false;
if (!this.hasControls || !this.active) {
return false;
}
var ex = pointer.x,
ey = pointer.y,

View file

@ -354,8 +354,8 @@
if (ruleMatchesElement) {
for (var property in fabric.cssRules[rule]) {
var attr = normalizeAttr(property);
var value = normalizeValue(attr, fabric.cssRules[rule][property]);
var attr = normalizeAttr(property),
value = normalizeValue(attr, fabric.cssRules[rule][property]);
styles[attr] = value;
}
}
@ -480,46 +480,46 @@
* Used for caching SVG documents (loaded via `fabric.Canvas#loadSVGFromURL`)
* @namespace
*/
var svgCache = {
var svgCache = {
/**
* @param {String} name
* @param {Function} callback
*/
has: function (name, callback) {
callback(false);
},
/**
* @param {String} name
* @param {Function} callback
*/
has: function (name, callback) {
callback(false);
},
/**
* @param {String} url
* @param {Function} callback
*/
get: function () {
/* NOOP */
},
/**
* @param {String} url
* @param {Function} callback
*/
get: function () {
/* NOOP */
},
/**
* @param {String} url
* @param {Object} object
*/
set: function () {
/* NOOP */
}
};
/**
* @param {String} url
* @param {Object} object
*/
set: function () {
/* NOOP */
}
};
/**
* @private
*/
function _enlivenCachedObject(cachedObject) {
var objects = cachedObject.objects,
options = cachedObject.options;
var objects = cachedObject.objects,
options = cachedObject.options;
objects = objects.map(function (o) {
return fabric[capitalize(o.type)].fromObject(o);
});
objects = objects.map(function (o) {
return fabric[capitalize(o.type)].fromObject(o);
});
return ({ objects: objects, options: options });
return ({ objects: objects, options: options });
}
/**

View file

@ -161,22 +161,24 @@
*/
fabric.Circle.fromElement = function(element, options) {
options || (options = { });
var parsedAttributes = fabric.parseAttributes(element, fabric.Circle.ATTRIBUTE_NAMES);
if (!isValidRadius(parsedAttributes)) {
throw new Error('value of `r` attribute is required and can not be negative');
}
if (!('left' in parsedAttributes)) {
parsedAttributes.left = 0;
parsedAttributes.left = 0;
}
if (!('top' in parsedAttributes)) {
parsedAttributes.top = 0
parsedAttributes.top = 0
}
if (!('transformMatrix' in parsedAttributes)) {
parsedAttributes.left -= (options.width / 2);
parsedAttributes.top -= (options.height / 2);
}
parsedAttributes.top -= (options.height / 2);
}
var obj = new fabric.Circle(extend(parsedAttributes, options));
obj.cx = parseFloat(element.getAttribute('cx')) || 0;

View file

@ -176,10 +176,10 @@
* @param {CanvasRenderingContext2D} ctx Context to render on
*/
_renderDashedStroke: function(ctx) {
var x = -this.width/2,
y = -this.height/2,
w = this.width,
h = this.height;
var x = -this.width / 2,
y = -this.height / 2,
w = this.width,
h = this.height;
ctx.save();
this._setStrokeStyles(ctx);
@ -339,13 +339,14 @@
* @param {CanvasRenderingContext2D} ctx Context to render on
*/
_render: function(ctx) {
this._element && ctx.drawImage(
this._element,
-this.width / 2,
-this.height / 2,
this.width,
this.height
);
this._element &&
ctx.drawImage(
this._element,
-this.width / 2,
-this.height / 2,
this.width,
this.height
);
},
/**

View file

@ -923,7 +923,6 @@
}
}
return data;
},

View file

@ -42,7 +42,7 @@
else if (thArc > 0 && sweep === 0) {
thArc -= 2 * Math.PI;
}
var segments = Math.ceil(Math.abs(thArc / (Math.PI * 0.5 + 0.001))),
result = [];
@ -69,7 +69,9 @@
var px = cosTh * (ox - x) + sinTh * (oy - y),
py = cosTh * (oy - y) - sinTh * (ox - x),
pl = (px * px) / (rx * rx) + (py * py) / (ry * ry);
pl *= 0.25;
pl *= 0.25;
if (pl > 1) {
pl = Math.sqrt(pl);
rx *= pl;
@ -100,14 +102,15 @@
var sinTh0 = Math.sin(th0),
cosTh0 = Math.cos(th0),
sinTh1 = Math.sin(th1),
cosTh1 = Math.cos(th1);
var a00 = cosTh * rx,
sinTh1 = Math.sin(th1),
cosTh1 = Math.cos(th1),
a00 = cosTh * rx,
a01 = -sinTh * ry,
a10 = sinTh * rx,
a11 = cosTh * ry,
thHalf = 0.25 * (th1 - th0),
t = (8 / 3) * Math.sin(thHalf) *
Math.sin(thHalf) / Math.sin(thHalf * 2),

View file

@ -9,7 +9,9 @@
t, i, len = methodNames.length;
for (i = 0; i < len; i++) {
t = typeof object[methodNames[i]];
if (!(/^(?:function|object|unknown)$/).test(t)) return false;
if (!(/^(?:function|object|unknown)$/).test(t)) {
return false;
}
}
return true;
}

View file

@ -4,7 +4,9 @@
IS_DONTENUM_BUGGY = (function(){
for (var p in { toString: 1 }) {
if (p === 'toString') return false;
if (p === 'toString') {
return false;
}
}
return true;
})(),