JSDoc + JSCS tweaks - Part 2

This commit is contained in:
Stefan Kienzle 2014-07-18 11:16:23 +02:00
parent 61853dd275
commit 6b5f049bb0
13 changed files with 119 additions and 106 deletions

View file

@ -52,7 +52,8 @@
},
/**
* @param {Object} pointer
* @private
* @param {Object} pointer Actual mouse position related to the canvas.
*/
_prepareForDrawing: function(pointer) {
@ -66,18 +67,15 @@
/**
* @private
* @param {fabric.Point} point
* @param {fabric.Point} point Point to be added to points array
*/
_addPoint: function(point) {
this._points.push(point);
},
/**
* Clear points array and set contextTop canvas
* style.
*
* Clear points array and set contextTop canvas style.
* @private
*
*/
_reset: function() {
this._points.length = 0;
@ -88,9 +86,7 @@
/**
* @private
*
* @param point {pointer} (fabric.util.pointer) actual mouse position
* related to the canvas.
* @param {Object} pointer Actual mouse position related to the canvas.
*/
_captureDrawingPath: function(pointer) {
var pointerPoint = new fabric.Point(pointer.x, pointer.y);
@ -99,19 +95,18 @@
/**
* Draw a smooth path on the topCanvas using quadraticCurveTo
*
* @private
*/
_render: function() {
var ctx = this.canvas.contextTop;
var v = this.canvas.viewportTransform;
var ctx = this.canvas.contextTop,
v = this.canvas.viewportTransform,
p1 = this._points[0],
p2 = this._points[1];
ctx.save();
ctx.transform(v[0], v[1], v[2], v[3], v[4], v[5]);
ctx.beginPath();
var p1 = this._points[0],
p2 = this._points[1];
//if we only have 2 points in the path and they are the same
//it means that the user only clicked the canvas without moving the mouse
//then we should be drawing a dot. A path isn't drawn between two identical dots
@ -141,19 +136,18 @@
/**
* Return an SVG path based on our captured points and their bounding box
*
* @private
*/
_getSVGPathData: function() {
this.box = this.getPathBoundingBox(this._points);
return this.convertPointsToSVGPath(
this._points, this.box.minx, this.box.maxx, this.box.miny, this.box.maxy);
this._points, this.box.minX, this.box.minY);
},
/**
* Returns bounding box of a path based on given points
* @param {Array} points
* @return {Object} object with minx, miny, maxx, maxy
* @param {Array} points Array of points
* @return {Object} Object with minX, minY, maxX, maxY
*/
getPathBoundingBox: function(points) {
var xBounds = [],
@ -179,19 +173,21 @@
yBounds.push(p1.y);
return {
minx: utilMin(xBounds),
miny: utilMin(yBounds),
maxx: utilMax(xBounds),
maxy: utilMax(yBounds)
minX: utilMin(xBounds),
minY: utilMin(yBounds),
maxX: utilMax(xBounds),
maxY: utilMax(yBounds)
};
},
/**
* Converts points to SVG path
* @param {Array} points Array of points
* @param {Number} minX
* @param {Number} minY
* @return {String} SVG path
*/
convertPointsToSVGPath: function(points, minX, maxX, minY) {
convertPointsToSVGPath: function(points, minX, minY) {
var path = [],
p1 = new fabric.Point(points[0].x - minX, points[0].y - minY),
p2 = new fabric.Point(points[1].x - minX, points[1].y - minY);
@ -215,7 +211,7 @@
/**
* Creates fabric.Path object to add on canvas
* @param {String} pathData Path data
* @return {fabric.Path} path to add on canvas
* @return {fabric.Path} Path to add on canvas
*/
createPath: function(pathData) {
var path = new fabric.Path(pathData);
@ -237,7 +233,6 @@
* On mouseup after drawing the path on contextTop canvas
* we use the points captured to create an new fabric path object
* and add it to the fabric canvas.
*
*/
_finalizeAndAddPath: function() {
var ctx = this.canvas.contextTop;

View file

@ -123,6 +123,10 @@ fabric.SprayBrush = fabric.util.createClass( fabric.BaseBrush, /** @lends fabric
this.canvas.renderAll();
},
/**
* @private
* @param {Array} rects
*/
_getOptimizedRects: function(rects) {
// avoid creating duplicate rects at the same coordinates
@ -185,7 +189,7 @@ fabric.SprayBrush = fabric.util.createClass( fabric.BaseBrush, /** @lends fabric
else {
width = this.dotWidth;
}
var point = new fabric.Point(x, y);
point.width = width;

View file

@ -98,8 +98,8 @@
* @param {Event} [e] Event object fired on Event.js gesture
* @param {Event} [self] Inner Event object
*/
_onGesture: function(e, s) {
this.__onTransformGesture && this.__onTransformGesture(e, s);
_onGesture: function(e, self) {
this.__onTransformGesture && this.__onTransformGesture(e, self);
},
/**
@ -107,8 +107,8 @@
* @param {Event} [e] Event object fired on Event.js drag
* @param {Event} [self] Inner Event object
*/
_onDrag: function(e, s) {
this.__onDrag && this.__onDrag(e, s);
_onDrag: function(e, self) {
this.__onDrag && this.__onDrag(e, self);
},
/**
@ -116,8 +116,8 @@
* @param {Event} [e] Event object fired on Event.js wheel event
* @param {Event} [self] Inner Event object
*/
_onMouseWheel: function(e, s) {
this.__onMouseWheel && this.__onMouseWheel(e, s);
_onMouseWheel: function(e, self) {
this.__onMouseWheel && this.__onMouseWheel(e, self);
},
/**
@ -125,8 +125,8 @@
* @param {Event} [e] Event object fired on Event.js orientation change
* @param {Event} [self] Inner Event object
*/
_onOrientationChange: function(e,s) {
this.__onOrientationChange && this.__onOrientationChange(e,s);
_onOrientationChange: function(e,self) {
this.__onOrientationChange && this.__onOrientationChange(e,self);
},
/**
@ -134,8 +134,8 @@
* @param {Event} [e] Event object fired on Event.js shake
* @param {Event} [self] Inner Event object
*/
_onShake: function(e,s) {
this.__onShake && this.__onShake(e,s);
_onShake: function(e, self) {
this.__onShake && this.__onShake(e,self);
},
/**

View file

@ -9,8 +9,8 @@
* Method that defines actions when an Event.js gesture is detected on an object. Currently only supports
* 2 finger gestures.
*
* @param e Event object by Event.js
* @param self Event proxy object by Event.js
* @param {Event} e Event object by Event.js
* @param {Event} self Event proxy object by Event.js
*/
__onTransformGesture: function(e, self) {
@ -31,8 +31,8 @@
/**
* Method that defines actions when an Event.js drag is detected.
*
* @param e Event object by Event.js
* @param self Event proxy object by Event.js
* @param {Event} e Event object by Event.js
* @param {Event} self Event proxy object by Event.js
*/
__onDrag: function(e, self) {
this.fire('touch:drag', { e: e, self: self });
@ -41,8 +41,8 @@
/**
* Method that defines actions when an Event.js orientation event is detected.
*
* @param e Event object by Event.js
* @param self Event proxy object by Event.js
* @param {Event} e Event object by Event.js
* @param {Event} self Event proxy object by Event.js
*/
__onOrientationChange: function(e, self) {
this.fire('touch:orientation', { e: e, self: self });
@ -51,8 +51,8 @@
/**
* Method that defines actions when an Event.js shake event is detected.
*
* @param e Event object by Event.js
* @param self Event proxy object by Event.js
* @param {Event} e Event object by Event.js
* @param {Event} self Event proxy object by Event.js
*/
__onShake: function(e, self) {
this.fire('touch:shake', { e: e, self: self });
@ -60,8 +60,8 @@
/**
* Scales an object by a factor
* @param s {Number} The scale factor to apply to the current scale level
* @param by {String} Either 'x' or 'y' - specifies dimension constraint by which to scale an object.
* @param {Number} s The scale factor to apply to the current scale level
* @param {String} by Either 'x' or 'y' - specifies dimension constraint by which to scale an object.
* When not provided, an object is scaled by both dimensions equally
*/
_scaleObjectBy: function(s, by) {
@ -92,7 +92,7 @@
/**
* Rotates object by an angle
* @param curAngle {Number} the angle of rotation in degrees
* @param {Number} curAngle The angle of rotation in degrees
*/
_rotateObjectByAngle: function(curAngle) {
var t = this._currentTransform;

View file

@ -216,7 +216,8 @@
/**
* Find new selection index representing start of current line according to current selection index
* @param {Number} current selection index
* @param {Number} startFrom Current selection index
* @return {Number} New selection index
*/
findLineBoundaryLeft: function(startFrom) {
var offset = 0, index = startFrom - 1;
@ -231,7 +232,8 @@
/**
* Find new selection index representing end of current line according to current selection index
* @param {Number} current selection index
* @param {Number} startFrom Current selection index
* @return {Number} New selection index
*/
findLineBoundaryRight: function(startFrom) {
var offset = 0, index = startFrom;
@ -264,6 +266,7 @@
* Finds index corresponding to beginning or end of a word
* @param {Number} selectionStart Index of a character
* @param {Number} direction: 1 or -1
* @return {Number} Index of the beginning or end of a word
*/
searchWordBoundary: function(selectionStart, direction) {
var index = this._reSpace.test(this.text.charAt(selectionStart)) ? selectionStart - 1 : selectionStart,

View file

@ -155,7 +155,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
/**
* Changes cursor location in a text depending on passed pointer (x/y) object
* @param {Object} pointer Pointer object with x and y numeric properties
* @param {Event} e Event object
*/
setCursorByClick: function(e) {
var newSelectionStart = this.getSelectionStartFromPointer(e);
@ -178,7 +178,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
/**
* @private
* @param {Event} e Event object
* @param {Object} Object with x/y corresponding to local offset (according to object rotation)
* @return {Object} Coordinates of a pointer (x, y)
*/
_getLocalRotatedPointer: function(e) {
var pointer = this.canvas.getPointer(e),
@ -198,7 +198,6 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
* @return {Number} Index of a character
*/
getSelectionStartFromPointer: function(e) {
var mouseOffset = this._getLocalRotatedPointer(e),
textLines = this.text.split(this._reNewline),
prevWidth = 0,

View file

@ -110,7 +110,8 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
// Check for backward compatibility with old browsers
if (clipboardData) {
copiedText = clipboardData.getData('text');
} else {
}
else {
copiedText = this.copiedText;
}
@ -135,6 +136,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
/**
* @private
* @param {Event} e Event object
* @return {Object} Clipboard data object
*/
_getClipboardData: function(e) {
return e && (e.clipboardData || fabric.window.clipboardData);
@ -156,10 +158,11 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
/**
* Gets start offset of a selection
* @param {Event} e Event object
* @param {Boolean} isRight
* @return {Number}
*/
getDownCursorOffset: function(e, isRight) {
var selectionProp = isRight ? this.selectionEnd : this.selectionStart,
textLines = this.text.split(this._reNewline),
_char,
@ -202,7 +205,6 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
* @private
*/
_getIndexOnNextLine: function(cursorLocation, textOnNextLine, widthOfCharsOnSameLineBeforeCursor, textLines) {
var lineIndex = cursorLocation.lineIndex + 1,
widthOfNextLine = this._getWidthOfLine(this.ctx, lineIndex, textLines),
lineLeftOffset = this._getLineLeftOffset(widthOfNextLine),
@ -245,7 +247,6 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
* @param {Event} e Event object
*/
moveCursorDown: function(e) {
this.abortCursorAnimation();
this._currentCursorOpacity = 1;
@ -266,7 +267,6 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
* @param {Number} offset
*/
moveCursorDownWithoutShift: function(offset) {
this._selectionDirection = 'right';
this.selectionStart += offset;
@ -281,7 +281,6 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
* @param {Number} offset
*/
moveCursorDownWithShift: function(offset) {
if (this._selectionDirection === 'left' && (this.selectionStart !== this.selectionEnd)) {
this.selectionStart += offset;
this._selectionDirection = 'left';
@ -297,8 +296,12 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
}
},
/**
* @param {Event} e Event object
* @param {Boolean} isRight
* @return {Number}
*/
getUpCursorOffset: function(e, isRight) {
var selectionProp = isRight ? this.selectionEnd : this.selectionStart,
cursorLocation = this.get2DCursorLocation(selectionProp);
@ -564,7 +567,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
/**
* Moves cursor right without keeping selection
* @param {Event} e
* @param {Event} e Event object
*/
moveCursorRightWithoutShift: function(e) {
this._selectionDirection = 'right';
@ -584,6 +587,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
/**
* Inserts a character where cursor is (replacing selection if one exists)
* @param {Event} e Event object
*/
removeChars: function(e) {
if (this.selectionStart === this.selectionEnd) {
@ -610,6 +614,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
/**
* @private
* @param {Event} e Event object
*/
_removeCharsNearCursor: function(e) {
if (this.selectionStart !== 0) {

View file

@ -253,7 +253,7 @@
/**
* Scales an object (equally by x and y)
* @param value {Number} scale factor
* @param {Number} value Scale factor
* @return {fabric.Object} thisArg
* @chainable
*/
@ -274,7 +274,7 @@
/**
* Scales an object to a given width, with respect to bounding box (scaling by x/y equally)
* @param value {Number} new width value
* @param {Number} value New width value
* @return {fabric.Object} thisArg
* @chainable
*/
@ -286,7 +286,7 @@
/**
* Scales an object to a given height, with respect to bounding box (scaling by x/y equally)
* @param value {Number} new height value
* @param {Number} value New height value
* @return {fabric.Object} thisArg
* @chainable
*/
@ -302,24 +302,24 @@
* @chainable
*/
setCoords: function() {
var strokeWidth = this.strokeWidth > 1 ? this.strokeWidth : 0,
theta = degreesToRadians(this.angle),
vpt = this.getViewportTransform();
var f = function (p) {
return fabric.util.transformPoint(p, vpt);
};
var w = this.width,
vpt = this.getViewportTransform(),
f = function (p) {
return fabric.util.transformPoint(p, vpt);
},
w = this.width,
h = this.height,
capped = this.strokeLineCap === "round" || this.strokeLineCap === "square",
vLine = this.type === "line" && this.width === 1,
hLine = this.type === "line" && this.height === 1,
strokeW = (capped && hLine) || this.type !== "line",
strokeH = (capped && vLine) || this.type !== "line";
capped = this.strokeLineCap === 'round' || this.strokeLineCap === 'square',
vLine = this.type === 'line' && this.width === 1,
hLine = this.type === 'line' && this.height === 1,
strokeW = (capped && hLine) || this.type !== 'line',
strokeH = (capped && vLine) || this.type !== 'line';
if (vLine) {
w = strokeWidth;
} else if (hLine) {
}
else if (hLine) {
h = strokeWidth;
}
if (strokeW) {
@ -361,11 +361,12 @@
mt = f(_mt),
mr = f(new fabric.Point(_tr.x - (wh.y/2 * sinTh), _tr.y + (wh.y/2 * cosTh))),
mb = f(new fabric.Point(_bl.x + (wh.x/2 * cosTh), _bl.y + (wh.x/2 * sinTh))),
mtr = f(new fabric.Point(_mt.x, _mt.y));
mtr = f(new fabric.Point(_mt.x, _mt.y)),
// padding
var padX = Math.cos(_angle + theta) * this.padding * Math.sqrt(2),
// padding
padX = Math.cos(_angle + theta) * this.padding * Math.sqrt(2),
padY = Math.sin(_angle + theta) * this.padding * Math.sqrt(2);
tl = tl.add(new fabric.Point(-padX, -padY));
tr = tr.add(new fabric.Point(padY, -padX));
br = br.add(new fabric.Point(padX, padY));

View file

@ -281,14 +281,15 @@
var w = this.getWidth(),
h = this.getHeight(),
strokeWidth = this.strokeWidth > 1 ? this.strokeWidth : 0,
capped = this.strokeLineCap === "round" || this.strokeLineCap === "square",
vLine = this.type === "line" && this.width === 1,
hLine = this.type === "line" && this.height === 1,
strokeW = (capped && hLine) || this.type !== "line",
strokeH = (capped && vLine) || this.type !== "line";
capped = this.strokeLineCap === 'round' || this.strokeLineCap === 'square',
vLine = this.type === 'line' && this.width === 1,
hLine = this.type === 'line' && this.height === 1,
strokeW = (capped && hLine) || this.type !== 'line',
strokeH = (capped && vLine) || this.type !== 'line';
if (vLine) {
w = strokeWidth / scaleX;
} else if (hLine) {
}
else if (hLine) {
h = strokeWidth / scaleY;
}
if (strokeW) {
@ -348,14 +349,16 @@
strokeWidth = this.strokeWidth > 1 ? this.strokeWidth : 0,
w = this.width,
h = this.height,
capped = this.strokeLineCap === "round" || this.strokeLineCap === "square",
vLine = this.type === "line" && this.width === 1,
hLine = this.type === "line" && this.height === 1,
strokeW = (capped && hLine) || this.type !== "line",
strokeH = (capped && vLine) || this.type !== "line";
capped = this.strokeLineCap === 'round' || this.strokeLineCap === 'square',
vLine = this.type === 'line' && this.width === 1,
hLine = this.type === 'line' && this.height === 1,
strokeW = (capped && hLine) || this.type !== 'line',
strokeH = (capped && vLine) || this.type !== 'line';
if (vLine) {
w = strokeWidth;
} else if (hLine) {
}
else if (hLine) {
h = strokeWidth;
}
if (strokeW) {

View file

@ -36,7 +36,7 @@
/**
* Translates the coordinates from center to origin coordinates (based on the object's dimensions)
* @param {fabric.Point} point The point which corresponds to center of the object
* @param {fabric.Point} center The point which corresponds to center of the object
* @param {String} originX Horizontal origin: 'left', 'center' or 'right'
* @param {String} originY Vertical origin: 'top', 'center' or 'bottom'
* @return {fabric.Point}
@ -146,7 +146,7 @@
/**
* Sets the position of the object taking into consideration the object's origin
* @param {fabric.Point} point The new position of the object
* @param {fabric.Point} pos The new position of the object
* @param {String} originX Horizontal origin: 'left', 'center' or 'right'
* @param {String} originY Vertical origin: 'top', 'center' or 'bottom'
* @return {void}

View file

@ -682,6 +682,7 @@
/**
* @private
* @param {Object} [options] Options object
*/
_initGradient: function(options) {
if (options.fill && options.fill.colorStops && !(options.fill instanceof fabric.Gradient)) {
@ -691,6 +692,7 @@
/**
* @private
* @param {Object} [options] Options object
*/
_initPattern: function(options) {
if (options.fill && options.fill.source && !(options.fill instanceof fabric.Pattern)) {
@ -703,6 +705,7 @@
/**
* @private
* @param {Object} [options] Options object
*/
_initClipping: function(options) {
if (!options.clipTo || typeof options.clipTo !== 'string') return;
@ -752,7 +755,6 @@
* @return {Object} Object representation of an instance
*/
toObject: function(propertiesToInclude) {
var NUM_FRACTION_DIGITS = fabric.Object.NUM_FRACTION_DIGITS,
object = {
@ -1006,17 +1008,17 @@
* @param {Boolean} [noTransform] When true, context is not transformed
*/
_renderControls: function(ctx, noTransform) {
var v = this.getViewportTransform();
var vpt = this.getViewportTransform();
ctx.save();
if (this.active && !noTransform) {
var center;
if (this.group) {
center = fabric.util.transformPoint(this.group.getCenterPoint(), v);
center = fabric.util.transformPoint(this.group.getCenterPoint(), vpt);
ctx.translate(center.x, center.y);
ctx.rotate(degreesToRadians(this.group.angle));
}
center = fabric.util.transformPoint(this.getCenterPoint(), v, null != this.group);
center = fabric.util.transformPoint(this.getCenterPoint(), vpt, null != this.group);
if (this.group) {
center.x *= this.group.scaleX;
center.y *= this.group.scaleY;

View file

@ -135,7 +135,7 @@
/**
* Returns "folded" (reduced) result of iterating over elements in an array
* @param {Function} fn Callback to invoke for each element
* @param {Object} [context] Context to invoke callback in
* @param {Object} [initial] Object to use as the first argument to the first call of the callback
* @return {Any}
*/
Array.prototype.reduce = function(fn /*, initial*/) {

View file

@ -144,19 +144,19 @@
switch (unit[0]) {
case 'mm':
return number * fabric.DPI / 25.4;
break;
case 'cm':
return number * fabric.DPI / 2.54;
break;
case 'in':
return number * fabric.DPI;
break;
case 'pt':
return number * fabric.DPI / 72; // or * 4 / 3
break;
case 'pc':
return number * fabric.DPI / 72 * 12; // or * 16
break;
return number * fabric.DPI / 72 * 12; // or * 16
default:
return number;
}
@ -253,7 +253,8 @@
* @memberOf fabric.util
* @param {Array} objects Objects to enliven
* @param {Function} callback Callback to invoke when all objects are created
* @param {Function} Method for further parsing of object elements,
* @param {String} namespace Namespace to get klass "Class" object from
* @param {Function} reviver Method for further parsing of object elements,
* called after each fabric object created.
*/
enlivenObjects: function(objects, callback, namespace, reviver) {