JSCS changes; Prepare for JSCS ignore support; down to 51 failures

This commit is contained in:
kangax 2014-08-03 16:47:27 +02:00
parent 922caa74c2
commit 818ab118b3
35 changed files with 312 additions and 119 deletions

View file

@ -71,7 +71,9 @@ fabric.BaseBrush = fabric.util.createClass(/** @lends fabric.BaseBrush.prototype
* @private
*/
_setShadow: function() {
if (!this.shadow) return;
if (!this.shadow) {
return;
}
var ctx = this.canvas.contextTop;

View file

@ -339,7 +339,9 @@
* @param {fabric.Object} target
*/
_shouldCenterTransform: function (e, target) {
if (!target) return;
if (!target) {
return;
}
var t = this._currentTransform,
centerTransform;
@ -403,7 +405,9 @@
* @param {fabric.Object} target
*/
_setupCurrentTransform: function (e, target) {
if (!target) return;
if (!target) {
return;
}
var pointer = this.getPointer(e),
corner = target._findTargetCorner(this.getPointer(e, true)),
@ -472,7 +476,9 @@
lockScalingX = target.get('lockScalingX'),
lockScalingY = target.get('lockScalingY');
if (lockScalingX && lockScalingY) return;
if (lockScalingX && lockScalingY) {
return;
}
// Get the constraint point
var constraintPosition = target.translateToOriginPoint(target.getCenterPoint(), t.originX, t.originY),
@ -623,7 +629,9 @@
var t = this._currentTransform;
if (t.target.get('lockRotation')) return;
if (t.target.get('lockRotation')) {
return;
}
var lastAngle = atan2(t.ey - t.top, t.ex - t.left),
curAngle = atan2(y - t.top, x - t.left),
@ -722,7 +730,9 @@
* @param {Boolean} skipGroup when true, group is skipped and only objects are traversed through
*/
findTarget: function (e, skipGroup) {
if (this.skipTargetFind) return;
if (this.skipTargetFind) {
return;
}
if (this._isLastRenderedObject(e)) {
return this.lastRenderedObjectWithControlsAboveOverlay;
@ -1102,7 +1112,9 @@
*/
_drawObjectsControls: function(ctx) {
for (var i = 0, len = this._objects.length; i < len; ++i) {
if (!this._objects[i] || !this._objects[i].active) continue;
if (!this._objects[i] || !this._objects[i].active) {
continue;
}
this._objects[i]._renderControls(ctx);
this.lastRenderedObjectWithControlsAboveOverlay = this._objects[i];
}

View file

@ -394,7 +394,9 @@
*/
fabric.Color.sourceFromHsl = function(color) {
var match = color.match(Color.reHSLa);
if (!match) return;
if (!match) {
return;
}
var h = (((parseFloat(match[1]) % 360) + 360) % 360) / 360,
s = parseFloat(match[2]) / (/%$/.test(match[2]) ? 100 : 1),

View file

@ -38,12 +38,12 @@
var context = canvasEl.getContext('2d'),
imageData = context.getImageData(0, 0, canvasEl.width, canvasEl.height),
data = imageData.data,
tr, tg, tb,
r, g, b,
source,
tr, tg, tb,
r, g, b,
source,
isImage = false;
if(this.image){
if (this.image) {
// Blend images
isImage = true;
@ -51,12 +51,13 @@
_el.width = this.image.width;
_el.height = this.image.height;
var _tmp_canvas = new fabric.StaticCanvas(_el);
_tmp_canvas.add(this.image);
var context2 = _tmp_canvas.getContext('2d');
source = context2.getImageData(0, 0, _tmp_canvas.width, _tmp_canvas.height).data;
} else {
// Blend color
var tmpCanvas = new fabric.StaticCanvas(_el);
tmpCanvas.add(this.image);
var context2 = tmpCanvas.getContext('2d');
source = context2.getImageData(0, 0, tmpCanvas.width, tmpCanvas.height).data;
}
else {
// Blend color
source = new fabric.Color(this.color).getSource();
tr = source[0] * this.alpha;
@ -70,22 +71,22 @@
g = data[i + 1];
b = data[i + 2];
if(isImage){
if (isImage) {
tr = source[i] * this.alpha;
tg = source[i + 1] * this.alpha;
tb = source[i + 2] * this.alpha;
}
switch(this.mode){
switch (this.mode) {
case 'multiply':
data[i] = r * tr / 255;
data[i + 1] = g * tg / 255;
data[i + 2] = b * tb / 255;
break;
case 'screen':
data[i] = 1 - (1-r) * (1-tr);
data[i + 1] = 1 - (1-g) * (1-tg);
data[i + 2] = 1 - (1-b) * (1-tb);
data[i] = 1 - (1 - r) * (1 - tr);
data[i + 1] = 1 - (1 - g) * (1 - tg);
data[i + 2] = 1 - (1 - b) * (1 - tb);
break;
case 'add':
data[i] = Math.min(255, r + tr);

View file

@ -125,7 +125,9 @@
scx = sx + cx - halfSide;
/* jshint maxdepth:5 */
if (scy < 0 || scy > sh || scx < 0 || scx > sw) continue;
if (scy < 0 || scy > sh || scx < 0 || scx > sw) {
continue;
}
var srcOff = (scy * sw + scx) * 4,
wt = weights[cy * side + cx];

View file

@ -41,7 +41,9 @@
* @param {Object} canvasEl Canvas element to apply filter to
*/
applyTo: function(canvasEl) {
if (!this.mask) return;
if (!this.mask) {
return;
}
var context = canvasEl.getContext('2d'),
imageData = context.getImageData(0, 0, canvasEl.width, canvasEl.height),

View file

@ -165,6 +165,7 @@
if (this.type === 'linear') {
markup = [
//jscs:disable validateIndentation
'<linearGradient ',
'id="SVGID_', this.id,
'" gradientUnits="', this.gradientUnits,
@ -173,10 +174,12 @@
'" x2="', coords.x2,
'" y2="', coords.y2,
'">'
//jscs:enable validateIndentation
];
}
else if (this.type === 'radial') {
markup = [
//jscs:disable validateIndentation
'<radialGradient ',
'id="SVGID_', this.id,
'" gradientUnits="', this.gradientUnits,
@ -186,16 +189,19 @@
'" fx="', coords.x1,
'" fy="', coords.y1,
'">'
//jscs:enable validateIndentation
];
}
for (var i = 0; i < this.colorStops.length; i++) {
markup.push(
//jscs:disable validateIndentation
'<stop ',
'offset="', (this.colorStops[i].offset * 100) + '%',
'" style="stop-color:', this.colorStops[i].color,
(this.colorStops[i].opacity ? ';stop-opacity: ' + this.colorStops[i].opacity : ';'),
'"/>'
//jscs:enable validateIndentation
);
}
@ -213,7 +219,9 @@
toLive: function(ctx) {
var gradient;
if (!this.type) return;
if (!this.type) {
return;
}
if (this.type === 'linear') {
gradient = ctx.createLinearGradient(

View file

@ -1,12 +1,12 @@
/**
* Wrapper around `console.log` (when available)
* @param {Any} values Values to log
* @param {Any} [values] Values to log
*/
fabric.log = function() { };
/**
* Wrapper around `console.warn` (when available)
* @param {Any} Values to log as a warning
* @param {Any} [values] Values to log as a warning
*/
fabric.warn = function() { };

View file

@ -119,8 +119,8 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prototype */ {
/**
* Animates object's properties
* @param {String|Object} property to animate (if string) or properties to animate (if object)
* @param {Number|Object} value to animate property to (if string was given first) or options object
* @param {String|Object} property Property to animate (if string) or properties to animate (if object)
* @param {Number|Object} value Value to animate property to (if string was given first) or options object
* @return {fabric.Object} thisArg
* @tutorial {@link http://fabricjs.com/fabric-intro-part-2/#animation}
* @chainable
@ -208,11 +208,15 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
else {
_this.set(property, value);
}
if (skipCallbacks) return;
if (skipCallbacks) {
return;
}
options.onChange && options.onChange();
},
onComplete: function() {
if (skipCallbacks) return;
if (skipCallbacks) {
return;
}
_this.setCoords();
options.onComplete && options.onComplete();

View file

@ -379,7 +379,9 @@
// accept only left clicks
var isLeftClick = 'which' in e ? e.which === 1 : e.button === 1;
if (!isLeftClick && !fabric.isTouchSupported) return;
if (!isLeftClick && !fabric.isTouchSupported) {
return;
}
if (this.isDrawingMode) {
this._onMouseDownInDrawingMode(e);
@ -387,7 +389,9 @@
}
// ignore if some object is being transformed at this moment
if (this._currentTransform) return;
if (this._currentTransform) {
return;
}
var target = this.findTarget(e),
pointer = this.getPointer(e, true);

View file

@ -70,7 +70,9 @@
lockScalingX = target.get('lockScalingX'),
lockScalingY = target.get('lockScalingY');
if (lockScalingX && lockScalingY) return;
if (lockScalingX && lockScalingY) {
return;
}
target._scaling = true;
@ -97,7 +99,9 @@
_rotateObjectByAngle: function(curAngle) {
var t = this._currentTransform;
if (t.target.get('lockRotation')) return;
if (t.target.get('lockRotation')) {
return;
}
t.target.angle = radiansToDegrees(degreesToRadians(curAngle) + t.theta);
}
});

View file

@ -156,7 +156,9 @@
for (var i = this._objects.length; i--; ) {
currentObject = this._objects[i];
if (!currentObject || !currentObject.selectable || !currentObject.visible) continue;
if (!currentObject || !currentObject.selectable || !currentObject.visible) {
continue;
}
if (currentObject.intersectsWithRect(selectionX1Y1, selectionX2Y2) ||
currentObject.isContainedWithinRect(selectionX1Y1, selectionX2Y2) ||
@ -167,7 +169,9 @@
group.push(currentObject);
// only add one object if it's a click
if (isClick) break;
if (isClick) {
break;
}
}
}

View file

@ -39,7 +39,9 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
* });
*/
loadFromJSON: function (json, callback, reviver) {
if (!json) return;
if (!json) {
return;
}
// serialize if it wasn't already
var serialized = (typeof json === 'string')

View file

@ -71,6 +71,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
*/
_createTextCharBg: function(styleDecl, lineLeftOffset, lineTopOffset, heightOfLine, charWidth, charOffset) {
return [
//jscs:disable validateIndentation
'<rect fill="', styleDecl.textBackgroundColor,
'" transform="translate(',
-this.width / 2, ' ',
@ -80,6 +81,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
'" width="', charWidth,
'" height="', heightOfLine,
'"></rect>'
//jscs:enable validateIndentation
].join('');
},
@ -96,6 +98,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
}, styleDecl));
return [
//jscs:disable validateIndentation
'<tspan x="', lineLeftOffset + charOffset, '" ',
yProp, '="', lineTopOffset, '" ',
@ -108,6 +111,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
fabric.util.string.escapeXml(_char),
'</tspan>'
//jscs:enable validateIndentation
].join('');
}
});

View file

@ -61,11 +61,12 @@
* @private
*/
_tick: function() {
if (this._abortCursorAnimation) {
return;
}
var _this = this;
if (this._abortCursorAnimation) return;
this.animate('_currentCursorOpacity', 1, {
duration: this.cursorDuration,
@ -88,7 +89,9 @@
* @private
*/
_onTickComplete: function() {
if (this._abortCursorAnimation) return;
if (this._abortCursorAnimation) {
return;
}
var _this = this;
if (this._cursorTimeout1) {
@ -315,7 +318,9 @@
* @chainable
*/
enterEditing: function() {
if (this.isEditing || !this.editable) return;
if (this.isEditing || !this.editable) {
return;
}
this.exitEditingOnOthers();
@ -364,7 +369,9 @@
* @private
*/
_updateTextarea: function() {
if (!this.hiddenTextarea) return;
if (!this.hiddenTextarea) {
return;
}
this.hiddenTextarea.value = this.text;
this.hiddenTextarea.selectionStart = this.selectionStart;
@ -389,7 +396,9 @@
* @private
*/
_restoreEditingProps: function() {
if (!this._savedProps) return;
if (!this._savedProps) {
return;
}
this.hoverCursor = this._savedProps.overCursor;
this.hasControls = this._savedProps.hasControls;
@ -575,7 +584,9 @@
insertStyleObjects: function(_chars, isEndOfLine, styles) {
// short-circuit
if (this.isEmptyStyles()) return;
if (this.isEmptyStyles()) {
return;
}
var cursorLocation = this.get2DCursorLocation(),
lineIndex = cursorLocation.lineIndex,

View file

@ -112,7 +112,9 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
*/
initMousemoveHandler: function() {
this.on('mousemove', function(options) {
if (!this.__isMousedown || !this.isEditing) return;
if (!this.__isMousedown || !this.isEditing) {
return;
}
var newSelectionStart = this.getSelectionStartFromPointer(options.e);
@ -143,7 +145,9 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
initMouseupHandler: function() {
this.on('mouseup', function(options) {
this.__isMousedown = false;
if (this._isObjectMoved(options.e)) return;
if (this._isObjectMoved(options.e)) {
return;
}
if (this.__lastSelected) {
this.enterEditing();

View file

@ -53,7 +53,9 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
* @param {Event} e Event object
*/
onKeyDown: function(e) {
if (!this.isEditing) return;
if (!this.isEditing) {
return;
}
if (e.keyCode in this._keysMap) {
this[this._keysMap[e.keyCode]](e);
@ -442,7 +444,9 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
* @param {Event} e Event object
*/
moveCursorLeft: function(e) {
if (this.selectionStart === 0 && this.selectionEnd === 0) return;
if (this.selectionStart === 0 && this.selectionEnd === 0) {
return;
}
this.abortCursorAnimation();
this._currentCursorOpacity = 1;
@ -528,7 +532,9 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
* @param {Event} e Event object
*/
moveCursorRight: function(e) {
if (this.selectionStart >= this.text.length && this.selectionEnd >= this.text.length) return;
if (this.selectionStart >= this.text.length && this.selectionEnd >= this.text.length) {
return;
}
this.abortCursorAnimation();
this._currentCursorOpacity = 1;

View file

@ -1,7 +1,9 @@
(function(){
var degreesToRadians = fabric.util.degreesToRadians,
//jscs:disable requireCamelCaseOrUpperCaseIdentifiers
isVML = function() { return typeof G_vmlCanvasManager !== 'undefined'; };
//jscs:enable requireCamelCaseOrUpperCaseIdentifiers
fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prototype */ {
@ -262,7 +264,9 @@
* @chainable
*/
drawBorders: function(ctx) {
if (!this.hasBorders) return this;
if (!this.hasBorders) {
return this;
}
var padding = this.padding,
padding2 = padding * 2,
@ -337,7 +341,9 @@
* @chainable
*/
drawControls: function(ctx) {
if (!this.hasControls) return this;
if (!this.hasControls) {
return this;
}
var size = this.cornerSize,
size2 = size / 2,

View file

@ -6,7 +6,9 @@
* @param {Function} handler
*/
function _removeEventListener(eventName, handler) {
if (!this.__eventListeners[eventName]) return;
if (!this.__eventListeners[eventName]) {
return;
}
if (handler) {
fabric.util.removeFromArray(this.__eventListeners[eventName], handler);
@ -57,7 +59,9 @@
* @chainable
*/
function stopObserving(eventName, handler) {
if (!this.__eventListeners) return;
if (!this.__eventListeners) {
return;
}
// remove all key/value pairs (event name -> event handler)
if (arguments.length === 0) {
@ -86,10 +90,15 @@
* @chainable
*/
function fire(eventName, options) {
if (!this.__eventListeners) return;
if (!this.__eventListeners) {
return;
}
var listenersForEvent = this.__eventListeners[eventName];
if (!listenersForEvent) return;
if (!listenersForEvent) {
return;
}
for (var i = 0, len = listenersForEvent.length; i < len; i++) {
// avoiding try/catch for perf. reasons
listenersForEvent[i].call(this, options || { });

View file

@ -101,9 +101,13 @@
function _setStrokeFillOpacity(attributes) {
for (var attr in colorAttributes) {
if (!attributes[attr] || typeof attributes[colorAttributes[attr]] === 'undefined') continue;
if (!attributes[attr] || typeof attributes[colorAttributes[attr]] === 'undefined') {
continue;
}
if (attributes[attr].indexOf('url(') === 0) continue;
if (attributes[attr].indexOf('url(') === 0) {
continue;
}
var color = new fabric.Color(attributes[attr]);
attributes[attr] = color.setAlpha(toFixed(color.getAlpha() * attributes[colorAttributes[attr]], 2)).toRgba();
@ -271,7 +275,9 @@
// TODO: support non-px font size
var match = value.match(/(normal|italic)?\s*(normal|small-caps)?\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\s*(\d+)px(?:\/(normal|[\d\.]+))?\s+(.*)/);
if (!match) return;
if (!match) {
return;
}
var fontStyle = match[1],
// font variant is not used
@ -324,7 +330,9 @@
function parseStyleObject(style, oStyle) {
var attr, value;
for (var prop in style) {
if (typeof style[prop] === 'undefined') continue;
if (typeof style[prop] === 'undefined') {
continue;
}
attr = normalizeAttr(prop.toLowerCase());
value = normalizeValue(attr, style[prop]);
@ -343,7 +351,7 @@
*/
function getGlobalStylesForElement(element) {
var styles = { };
for (var rule in fabric.cssRules) {
if (elementMatchesRule(element, rule.split(' '))) {
for (var property in fabric.cssRules[rule]) {
@ -419,7 +427,9 @@
for (var j = 0, attrs = el.attributes, l = attrs.length; j < l; j++) {
var attr = attrs.item(j);
if (attr.nodeName === 'x' || attr.nodeName === 'y' || attr.nodeName === 'xlink:href') continue;
if (attr.nodeName === 'x' || attr.nodeName === 'y' || attr.nodeName === 'xlink:href') {
continue;
}
if (attr.nodeName === 'transform') {
currentTrans = currentTrans + ' ' + attr.nodeValue;
@ -441,7 +451,9 @@
*/
function addSvgTransform(doc, matrix) {
matrix[3] = matrix[0] = (matrix[0] > matrix[3] ? matrix[3] : matrix[0]);
if (!(matrix[0] !== 1 || matrix[3] !== 1 || matrix[4] !== 0 || matrix[5] !== 0)) return;
if (!(matrix[0] !== 1 || matrix[3] !== 1 || matrix[4] !== 0 || matrix[5] !== 0)) {
return;
}
// default is to preserve aspect ratio
// preserveAspectRatio attribute to be implemented
var el = doc.ownerDocument.createElement('g');
@ -490,7 +502,9 @@
}
return function(doc, callback, reviver) {
if (!doc) return;
if (!doc) {
return;
}
var startTime = new Date();
parseUseDirectives(doc);
@ -626,7 +640,9 @@
for (var i = instances.length; i--; ) {
var instanceFillValue = instances[i].get('fill');
if (!(/^url\(/).test(instanceFillValue)) continue;
if (!(/^url\(/).test(instanceFillValue)) {
continue;
}
var gradientId = instanceFillValue.slice(5, instanceFillValue.length - 1);
@ -756,7 +772,9 @@
parsePointsAttribute: function(points) {
// points attribute is required and must not be empty
if (!points) return null;
if (!points) {
return null;
}
// replace commas with whitespace and remove bookending whitespace
points = points.replace(/,/g, ' ').trim();
@ -858,7 +876,9 @@
//IE chokes on DOCTYPE
xml.loadXML(r.responseText.replace(/<!DOCTYPE[\s\S]*?(\[[\s\S]*\])*?>/i,''));
}
if (!xml || !xml.documentElement) return;
if (!xml || !xml.documentElement) {
return;
}
fabric.parseSVGDocument(xml.documentElement, function (results, options) {
svgCache.set(url, {
@ -907,23 +927,29 @@
var markup = '';
for (var i = 0, len = objects.length; i < len; i++) {
if (objects[i].type !== 'text' || !objects[i].path) continue;
if (objects[i].type !== 'text' || !objects[i].path) {
continue;
}
markup += [
//jscs:disable validateIndentation
'@font-face {',
'font-family: ', objects[i].fontFamily, '; ',
'src: url(\'', objects[i].path, '\')',
'}'
//jscs:enable validateIndentation
].join('');
}
if (markup) {
markup = [
//jscs:disable validateIndentation
'<style type="text/css">',
'<![CDATA[',
markup,
']]>',
'</style>'
//jscs:enable validateIndentation
].join('');
}

View file

@ -99,7 +99,9 @@
*/
render: function(ctx, noTransform) {
// do not use `get` for perf. reasons
if (this.rx === 0 || this.ry === 0) return;
if (this.rx === 0 || this.ry === 0) {
return;
}
return this.callSuper('render', ctx, noTransform);
},

View file

@ -115,8 +115,8 @@
addWithUpdate: function(object) {
this._restoreObjectsState();
if (object) {
this._objects.push(object);
object.group = this;
this._objects.push(object);
object.group = this;
}
// since _restoreObjectsState set objects inactive
this.forEachObject(this._setObjectActive, this);
@ -218,7 +218,9 @@
*/
render: function(ctx) {
// do not render if object is not visible
if (!this.visible) return;
if (!this.visible) {
return;
}
ctx.save();
this.clipTo && fabric.util.clipContext(this, ctx);
@ -252,7 +254,9 @@
var originalHasRotatingPoint = object.hasRotatingPoint;
// do not render if object is not visible
if (!object.visible) return;
if (!object.visible) {
return;
}
object.hasRotatingPoint = false;
@ -475,9 +479,11 @@
*/
toSVG: function(reviver) {
var markup = [
//jscs:disable validateIndentation
'<g ',
'transform="', this.getSvgTransform(),
'">'
//jscs:enable validateIndentation
];
for (var i = 0, len = this._objects.length; i < len; i++) {

View file

@ -119,7 +119,9 @@
*/
render: function(ctx, noTransform) {
// do not render if object is not visible
if (!this.visible) return;
if (!this.visible) {
return;
}
ctx.save();
var m = this.transformMatrix,

View file

@ -201,7 +201,9 @@
* Returns true if object has no styling
*/
isEmptyStyles: function() {
if (!this.styles) return true;
if (!this.styles) {
return true;
}
var obj = this.styles;
for (var p1 in obj) {
@ -313,7 +315,9 @@
* Renders cursor or selection (depending on what exists)
*/
renderCursorOrSelection: function() {
if (!this.active) return;
if (!this.active) {
return;
}
var chars = this.text.split(''),
boundaries;
@ -729,7 +733,9 @@
fontSize = (styleDeclaration ? styleDeclaration.fontSize : null) || this.fontSize;
if (!textDecoration) return;
if (!textDecoration) {
return;
}
if (textDecoration.indexOf('underline') > -1) {
this._renderCharDecorationAtOffset(
@ -800,7 +806,9 @@
* @param {Array} textLines Array of all text lines
*/
_renderTextLinesBackground: function(ctx, textLines) {
if (!this.textBackgroundColor && !this.styles) return;
if (!this.textBackgroundColor && !this.styles) {
return;
}
ctx.save();
@ -1101,7 +1109,9 @@
* @private
*/
_renderTextBoxBackground: function(ctx) {
if (!this.backgroundColor) return;
if (!this.backgroundColor) {
return;
}
ctx.save();
ctx.fillStyle = this.backgroundColor;

View file

@ -164,7 +164,9 @@
cp.x,
cp.y
);
if (!this.transformMatrix) ctx.translate(-this.group.width / 2, -this.group.height / 2);
if (!this.transformMatrix) {
ctx.translate(-this.group.width / 2, -this.group.height / 2);
}
}
if (!this.strokeDashArray || this.strokeDashArray && supportsLineDash) {

View file

@ -708,7 +708,9 @@
* @param {Object} [options] Options object
*/
_initClipping: function(options) {
if (!options.clipTo || typeof options.clipTo !== 'string') return;
if (!options.clipTo || typeof options.clipTo !== 'string') {
return;
}
var functionBody = fabric.util.getFunctionBody(options.clipTo);
if (typeof functionBody !== 'undefined') {
@ -932,8 +934,9 @@
* @return {Boolean} flipY value // TODO
*/
getViewportTransform: function() {
if (this.canvas && this.canvas.viewportTransform)
if (this.canvas && this.canvas.viewportTransform) {
return this.canvas.viewportTransform;
}
return [1, 0, 0, 1, 0, 0];
},
@ -944,7 +947,9 @@
*/
render: function(ctx, noTransform) {
// do not render if width/height are zeros or object is not visible
if (this.width === 0 || this.height === 0 || !this.visible) return;
if (this.width === 0 || this.height === 0 || !this.visible) {
return;
}
ctx.save();
@ -1036,7 +1041,9 @@
* @param {CanvasRenderingContext2D} ctx Context to render on
*/
_setShadow: function(ctx) {
if (!this.shadow) return;
if (!this.shadow) {
return;
}
ctx.shadowColor = this.shadow.color;
ctx.shadowBlur = this.shadow.blur;
@ -1049,7 +1056,9 @@
* @param {CanvasRenderingContext2D} ctx Context to render on
*/
_removeShadow: function(ctx) {
if (!this.shadow) return;
if (!this.shadow) {
return;
}
ctx.shadowColor = '';
ctx.shadowBlur = ctx.shadowOffsetX = ctx.shadowOffsetY = 0;
@ -1060,7 +1069,9 @@
* @param {CanvasRenderingContext2D} ctx Context to render on
*/
_renderFill: function(ctx) {
if (!this.fill) return;
if (!this.fill) {
return;
}
if (this.fill.toLive) {
ctx.save();
@ -1087,7 +1098,9 @@
* @param {CanvasRenderingContext2D} ctx Context to render on
*/
_renderStroke: function(ctx) {
if (!this.stroke || this.strokeWidth === 0) return;
if (!this.stroke || this.strokeWidth === 0) {
return;
}
ctx.save();
if (this.strokeDashArray) {

View file

@ -94,7 +94,9 @@
// one of commands (m,M,l,L,q,Q,c,C,etc.) followed by non-command characters (i.e. command values)
: path.match && path.match(/[mzlhvcsqta][^mzlhvcsqta]*/gi);
if (!this.path) return;
if (!this.path) {
return;
}
if (!fromArray) {
this.path = this._parsePath();
@ -455,12 +457,14 @@
*/
render: function(ctx, noTransform) {
// do not render if object is not visible
if (!this.visible) return;
if (!this.visible) {
return;
}
ctx.save();
if (noTransform) {
ctx.translate(-this.width/2, -this.height/2);
}
ctx.translate(-this.width/2, -this.height/2);
}
var m = this.transformMatrix;
if (m) {
@ -541,6 +545,7 @@
var path = chunks.join(' ');
markup.push(
//jscs:disable validateIndentation
'<g transform="', (this.group ? '' : this.getSvgTransform()), '">',
'<path ',
'd="', path,
@ -549,6 +554,7 @@
'" stroke-linecap="round" ',
'/>',
'</g>'
//jscs:enable validateIndentation
);
return reviver ? reviver(markup.join('')) : markup.join('');

View file

@ -72,7 +72,9 @@
*/
render: function(ctx) {
// do not render if object is not visible
if (!this.visible) return;
if (!this.visible) {
return;
}
ctx.save();
@ -148,10 +150,12 @@
toSVG: function(reviver) {
var objects = this.getObjects(),
markup = [
//jscs:disable validateIndentation
'<g ',
'style="', this.getSvgStyles(), '" ',
'transform="', this.getSvgTransform(), '" ',
'>'
//jscs:enable validateIndentation
];
for (var i = 0, len = objects.length; i < len; i++) {

View file

@ -67,7 +67,9 @@
this.minX = minX;
this.minY = minY;
if (skipOffset) return;
if (skipOffset) {
return;
}
var halfWidth = this.width / 2 + this.minX,
halfHeight = this.height / 2 + this.minY;

View file

@ -326,7 +326,9 @@
* @private
*/
_initDimensions: function() {
if (this.__skipDimension) return;
if (this.__skipDimension) {
return;
}
var canvasEl = fabric.util.createCanvasElement();
this._render(canvasEl.getContext('2d'));
},
@ -550,7 +552,9 @@
* @param {Array} textLines Array of all text lines
*/
_renderTextFill: function(ctx, textLines) {
if (!this.fill && !this._skipFillStrokeCheck) return;
if (!this.fill && !this._skipFillStrokeCheck) {
return;
}
this._boundaries = [ ];
var lineHeights = 0;
@ -576,7 +580,9 @@
* @param {Array} textLines Array of all text lines
*/
_renderTextStroke: function(ctx, textLines) {
if ((!this.stroke || this.strokeWidth === 0) && !this._skipFillStrokeCheck) return;
if ((!this.stroke || this.strokeWidth === 0) && !this._skipFillStrokeCheck) {
return;
}
var lineHeights = 0;
@ -626,7 +632,9 @@
* @param {CanvasRenderingContext2D} ctx Context to render on
*/
_renderTextBoxBackground: function(ctx) {
if (!this.backgroundColor) return;
if (!this.backgroundColor) {
return;
}
ctx.save();
ctx.fillStyle = this.backgroundColor;
@ -647,7 +655,9 @@
* @param {Array} textLines Array of all text lines
*/
_renderTextLinesBackground: function(ctx, textLines) {
if (!this.textBackgroundColor) return;
if (!this.textBackgroundColor) {
return;
}
ctx.save();
ctx.fillStyle = this.textBackgroundColor;
@ -703,7 +713,9 @@
* @param {Array} textLines Array of all text lines
*/
_renderTextDecoration: function(ctx, textLines) {
if (!this.textDecoration) return;
if (!this.textDecoration) {
return;
}
// var halfOfVerticalBox = this.originY === 'top' ? 0 : this._getTextHeight(ctx, textLines) / 2;
var halfOfVerticalBox = this._getTextHeight(ctx, textLines) / 2,
@ -754,13 +766,16 @@
*/
render: function(ctx, noTransform) {
// do not render if object is not visible
if (!this.visible) return;
if (!this.visible) {
return;
}
ctx.save();
this._transform(ctx, noTransform);
var m = this.transformMatrix;
var isInPathGroup = this.group && this.group.type === 'path-group';
var m = this.transformMatrix,
isInPathGroup = this.group && this.group.type === 'path-group';
if (isInPathGroup) {
ctx.translate(-this.group.width/2, -this.group.height/2);
}
@ -931,7 +946,9 @@
lineTopOffsetMultiplier++;
}
if (!this.textBackgroundColor || !this._boundaries) continue;
if (!this.textBackgroundColor || !this._boundaries) {
continue;
}
this._setSVGTextLineBg(textBgRects, i, textLeftOffset, lineHeight);
}
@ -1087,14 +1104,14 @@
options.originX = 'left';
}
var text = new fabric.Text(element.textContent, options);
var text = new fabric.Text(element.textContent, options),
/*
Adjust positioning:
x/y attributes in SVG correspond to the bottom-left corner of text bounding box
top/left properties in Fabric correspond to center point of text bounding box
*/
offX = 0;
/*
Adjust positioning:
x/y attributes in SVG correspond to the bottom-left corner of text bounding box
top/left properties in Fabric correspond to center point of text bounding box
*/
var offX = 0;
if (text.originX === 'left') {
offX = text.getWidth() / 2;
}

View file

@ -59,9 +59,11 @@ fabric.util.object.extend(fabric.Text.prototype, {
// Cufon doesn't play nice with textDecoration=underline if element doesn't have a parent
container.appendChild(el);
//jscs:disable requireCamelCaseOrUpperCaseIdentifiers
if (typeof G_vmlCanvasManager === 'undefined') {
el.innerHTML = this.text;
}
//jscs:enable requireCamelCaseOrUpperCaseIdentifiers
else {
// IE 7 & 8 drop newlines and white space on text nodes
// see: http://web.student.tuwien.ac.at/~e0226430/innerHtmlQuirk.html

View file

@ -421,7 +421,9 @@
this.width = this.width || parseInt(this.lowerCanvasEl.width, 10) || 0;
this.height = this.height || parseInt(this.lowerCanvasEl.height, 10) || 0;
if (!this.lowerCanvasEl.style) return;
if (!this.lowerCanvasEl.style) {
return;
}
this.lowerCanvasEl.width = this.width;
this.lowerCanvasEl.height = this.height;
@ -468,7 +470,7 @@
/**
* Sets width of this canvas instance
* @param {Number|String} width value to set width to
* @param {Number|String} value Value to set width to
* @param {Object} [options] Options object
* @param {Boolean} [options.backstoreOnly=false] Set the given dimensions only as canvas backstore dimensions
* @param {Boolean} [options.cssOnly=false] Set the given dimensions only as css dimensions
@ -481,7 +483,7 @@
/**
* Sets height of this canvas instance
* @param {Number|String} height value to set height to
* @param {Number|String} value Value to set height to
* @param {Object} [options] Options object
* @param {Boolean} [options.backstoreOnly=false] Set the given dimensions only as canvas backstore dimensions
* @param {Boolean} [options.cssOnly=false] Set the given dimensions only as css dimensions
@ -693,14 +695,18 @@
* @private
*/
_draw: function (ctx, object) {
if (!object) return;
if (!object) {
return;
}
ctx.save();
var v = this.viewportTransform;
ctx.transform(v[0], v[1], v[2], v[3], v[4], v[5]);
object.render(ctx);
ctx.restore();
if (!this.controlsAboveOverlay) object._renderControls(ctx);
if (!this.controlsAboveOverlay) {
object._renderControls(ctx);
}
},
/**

View file

@ -276,7 +276,9 @@
if (loading) {
if (typeof this.readyState === 'string' &&
this.readyState !== 'loaded' &&
this.readyState !== 'complete') return;
this.readyState !== 'complete') {
return;
}
loading = false;
callback(e || fabric.window.event);
scriptEl = scriptEl.onload = scriptEl.onreadystatechange = null;

View file

@ -215,7 +215,9 @@
* @private
*/
function find(array, byProperty, condition) {
if (!array || array.length === 0) return;
if (!array || array.length === 0) {
return;
}
var i = array.length - 1,
result = byProperty ? array[i][byProperty] : array[i];

View file

@ -387,9 +387,11 @@
*/
createCanvasElement: function(canvasEl) {
canvasEl || (canvasEl = fabric.document.createElement('canvas'));
//jscs:disable requireCamelCaseOrUpperCaseIdentifiers
if (!canvasEl.getContext && typeof G_vmlCanvasManager !== 'undefined') {
G_vmlCanvasManager.initElement(canvasEl);
}
//jscs:enable requireCamelCaseOrUpperCaseIdentifiers
return canvasEl;
},
@ -557,7 +559,9 @@
for (var i = 3, l = imageData.data.length; i < l; i += 4) {
var temp = imageData.data[i];
_isTransparent = temp <= 0;
if (_isTransparent === false) break; // Stop if colour found
if (_isTransparent === false) {
break; // Stop if colour found
}
}
imageData = null;