standardized init method names with underscores

This commit is contained in:
Eric Rowell
2013-07-22 21:41:41 -07:00
parent ecdd5cc59a
commit 9324c366ea
24 changed files with 201 additions and 209 deletions

View File

@@ -1,6 +1,6 @@
(function() {
Kinetic.Util.addMethods(Kinetic.Container, {
_containerInit: function(config) {
__init: function(config) {
this.children = new Kinetic.Collection();
Kinetic.Node.call(this, config);
},

View File

@@ -8,93 +8,93 @@
y: 0
},
node: null,
// methods
_drag: function(evt) {
var dd = Kinetic.DD,
var dd = Kinetic.DD,
node = dd.node;
if(node) {
var pos = node.getStage().getPointerPosition();
var dbf = node.getDragBoundFunc();
var newNodePos = {
x: pos.x - dd.offset.x,
y: pos.y - dd.offset.y
};
if(dbf !== undefined) {
newNodePos = dbf.call(node, newNodePos, evt);
}
node.setAbsolutePosition(newNodePos);
if(!dd.isDragging) {
dd.isDragging = true;
node.fire('dragstart', evt, true);
}
// execute ondragmove if defined
node.fire('dragmove', evt, true);
}
},
_endDragBefore: function(evt) {
var dd = Kinetic.DD,
var dd = Kinetic.DD,
node = dd.node,
nodeType, layer;
if(node) {
nodeType = node.nodeType,
layer = node.getLayer();
dd.anim.stop();
// only fire dragend event if the drag and drop
// operation actually started.
// operation actually started.
if(dd.isDragging) {
dd.isDragging = false;
if (evt) {
evt.dragEndNode = node;
}
}
}
delete dd.node;
(layer || node).draw();
}
},
_endDragAfter: function(evt) {
evt = evt || {};
var dragEndNode = evt.dragEndNode;
if (evt && dragEndNode) {
dragEndNode.fire('dragend', evt, true);
dragEndNode.fire('dragend', evt, true);
}
}
};
// Node extenders
/**
* initiate drag and drop
* @method
* @memberof Kinetic.Node.prototype
*/
Kinetic.Node.prototype.startDrag = function() {
var dd = Kinetic.DD,
that = this,
var dd = Kinetic.DD,
that = this,
stage = this.getStage(),
layer = this.getLayer(),
layer = this.getLayer(),
pos = stage.getPointerPosition(),
m = this.getTransform().getTranslation(),
m = this.getTransform().getTranslation(),
ap = this.getAbsolutePosition();
if(pos) {
if (dd.node) {
dd.node.stopDrag();
dd.node.stopDrag();
}
dd.node = this;
dd.offset.x = pos.x - ap.x;
dd.offset.y = pos.y - ap.y;
@@ -102,7 +102,7 @@
dd.anim.start();
}
};
/**
* stop drag and drop
* @method
@@ -114,7 +114,7 @@
dd._endDragBefore(evt);
dd._endDragAfter(evt);
};
/**
* set draggable
* @method
@@ -135,9 +135,9 @@
if(dd.node && dd.node._id === this._id) {
this.stopDrag();
}
}
origDestroy.call(this);
origDestroy.call(this);
};
/**
@@ -180,7 +180,7 @@
}
}
};
Kinetic.Node.prototype._dragCleanup = function() {
this.off('mousedown.kinetic');
this.off('touchstart.kinetic');
@@ -205,7 +205,7 @@
*/
Kinetic.Node.addGetter(Kinetic.Node, 'draggable', false);
/**
* get draggable
* @name getDraggable
@@ -220,21 +220,13 @@
* @memberof Kinetic.Node.prototype
*/
/**
* alias of getDraggable
* @name isDraggable
* @method
* @memberof Kinetic.Node.prototype
*/
Kinetic.Node.prototype.isDraggable = Kinetic.Node.prototype.getDraggable;
var html = document.getElementsByTagName('html')[0];
html.addEventListener('mouseup', Kinetic.DD._endDragBefore, true);
html.addEventListener('touchend', Kinetic.DD._endDragBefore, true);
html.addEventListener('mouseup', Kinetic.DD._endDragAfter, false);
html.addEventListener('touchend', Kinetic.DD._endDragAfter, false);
})();

View File

@@ -25,14 +25,14 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
/**
* @namespace Kinetic
*/
var Kinetic = {};
var Kinetic = {};
(function() {
Kinetic.version = '@@version';
/**
/**
* @namespace Filters
* @memberof Kinetic
*/
@@ -48,7 +48,7 @@ var Kinetic = {};
* @@nodeParams
*/
Kinetic.Node = function(config) {
this._nodeInit(config);
this._init(config);
};
/**
@@ -74,12 +74,12 @@ var Kinetic = {};
* context.quadraticCurveTo(300, 100, 260, 170);<br>
* context.closePath();<br>
* canvas.fillStroke(this);<br>
* }<br>
* }<br>
*});
*/
Kinetic.Shape = function(config) {
this._initShape(config);
};
this.__init(config);
};
/**
* Container constructor.&nbsp; Containers are used to contain nodes or other containers
@@ -92,7 +92,7 @@ var Kinetic = {};
* @@containerParams
*/
Kinetic.Container = function(config) {
this._containerInit(config);
this.__init(config);
};
/**
@@ -112,7 +112,7 @@ var Kinetic = {};
* });
*/
Kinetic.Stage = function(config) {
this._initStage(config);
this.___init(config);
};
/**
@@ -130,7 +130,7 @@ var Kinetic = {};
* var layer = new Kinetic.Layer();
*/
Kinetic.Layer = function(config) {
this._initLayer(config);
this.___init(config);
};
/**
@@ -145,10 +145,10 @@ var Kinetic = {};
* var group = new Kinetic.Group();
*/
Kinetic.Group = function(config) {
this._initGroup(config);
};
this.___init(config);
};
/**
/**
* @namespace Global
* @memberof Kinetic
*/
@@ -166,13 +166,13 @@ var Kinetic = {};
* @memberof Kinetic.Global
*/
isDragging: function() {
var dd = Kinetic.DD;
var dd = Kinetic.DD;
// if DD is not included with the build, then
// drag and drop is not even possible
if (!dd) {
return false;
}
}
// if DD is included with the build
else {
return dd.isDragging;
@@ -185,13 +185,13 @@ var Kinetic = {};
* @memberof Kinetic.Global
*/
isDragReady: function() {
var dd = Kinetic.DD;
var dd = Kinetic.DD;
// if DD is not included with the build, then
// drag and drop is not even possible
if (!dd) {
return false;
}
}
// if DD is included with the build
else {
return !!dd.node;

View File

@@ -1,6 +1,6 @@
(function() {
Kinetic.Util.addMethods(Kinetic.Group, {
_initGroup: function(config) {
___init: function(config) {
this.nodeType = 'Group';
this.createAttrs();
// call super constructor

View File

@@ -3,7 +3,7 @@
var HASH = '#';
Kinetic.Util.addMethods(Kinetic.Layer, {
_initLayer: function(config) {
___init: function(config) {
this.nodeType = 'Layer';
this.createAttrs();
this.canvas = new Kinetic.SceneCanvas();

View File

@@ -34,7 +34,7 @@
CHILDREN = 'children';
Kinetic.Util.addMethods(Kinetic.Node, {
_nodeInit: function(config) {
_init: function(config) {
this._id = Kinetic.Global.idCounter++;
this.eventListeners = {};
this.setAttrs(config);

View File

@@ -16,7 +16,7 @@
}
Kinetic.Util.addMethods(Kinetic.Shape, {
_initShape: function(config) {
__init: function(config) {
this.nodeType = 'Shape';
this._fillFunc = _fillFunc;
this._strokeFunc = _strokeFunc;

View File

@@ -37,7 +37,7 @@
}
Kinetic.Util.addMethods(Kinetic.Stage, {
_initStage: function(config) {
___init: function(config) {
this.createAttrs();
// call super constructor
Kinetic.Container.call(this, config);

View File

@@ -8,12 +8,12 @@
DOWN = 'down',
LEFT = 'left',
LABEL = 'Label',
// cached variables
attrChangeListLen = ATTR_CHANGE_LIST.length;
/**
* Label constructor.&nbsp; Labels are groups that contain a Text and Tag shape
* Label constructor.&nbsp; Labels are groups that contain a Text and Tag shape
* @constructor
* @memberof Kinetic
* @param {Object} config
@@ -51,16 +51,16 @@
* }));
*/
Kinetic.Label = function(config) {
this._initLabel(config);
this.____init(config);
};
Kinetic.Label.prototype = {
_initLabel: function(config) {
____init: function(config) {
var that = this;
this.createAttrs();
this.className = LABEL;
Kinetic.Group.call(this, config);
Kinetic.Group.call(this, config);
this.on('add', function(evt) {
that._addListeners(evt.child);
@@ -76,7 +76,7 @@
*/
getText: function() {
return this.get('Text')[0];
},
},
/**
* get Tag shape for the label. You need to access the Tag shape in order to update
* the pointer properties and the corner radius
@@ -93,11 +93,11 @@
var func = function(){
that._sync();
};
// update text data for certain attr changes
for(n = 0; n < attrChangeListLen; n++) {
context.on(ATTR_CHANGE_LIST[n] + CHANGE_KINETIC, func);
}
}
},
getWidth: function() {
return this.getText().getWidth();
@@ -112,11 +112,11 @@
if (text && tag) {
width = text.getWidth(),
height = text.getHeight(),
height = text.getHeight(),
pointerDirection = tag.getPointerDirection(),
pointerWidth = tag.getPointerWidth(),
pointerHeight = tag.getPointerHeight(),
x = 0,
x = 0,
y = 0;
switch(pointerDirection) {
@@ -137,13 +137,13 @@
y = height / 2;
break;
}
tag.setAttrs({
x: -1 * x,
y: -1 * y,
width: width,
height: height
});
});
text.setAttrs({
x: -1 * x,
@@ -152,12 +152,12 @@
}
}
};
Kinetic.Util.extend(Kinetic.Label, Kinetic.Group);
/**
* Tag constructor.&nbsp; A Tag can be configured
* to have a pointer element that points up, right, down, or left
* to have a pointer element that points up, right, down, or left
* @constructor
* @memberof Kinetic
* @param {Object} config
@@ -165,14 +165,14 @@
* is none. When a pointer is present, the positioning of the label is relative to the tip of the pointer.
* @param {Number} [config.pointerWidth]
* @param {Number} [config.pointerHeight]
* @param {Number} [config.cornerRadius]
*/
* @param {Number} [config.cornerRadius]
*/
Kinetic.Tag = function(config) {
this._initTag(config);
this.___init(config);
};
Kinetic.Tag.prototype = {
_initTag: function(config) {
___init: function(config) {
this.createAttrs();
Kinetic.Shape.call(this, config);
this.className = 'Tag';
@@ -186,45 +186,45 @@
pointerWidth = this.getPointerWidth(),
pointerHeight = this.getPointerHeight(),
cornerRadius = this.getCornerRadius();
context.beginPath();
context.moveTo(0,0);
if (pointerDirection === UP) {
context.lineTo((width - pointerWidth)/2, 0);
context.lineTo(width/2, -1 * pointerHeight);
context.lineTo((width + pointerWidth)/2, 0);
}
context.lineTo(width, 0);
if (pointerDirection === RIGHT) {
context.lineTo(width, (height - pointerHeight)/2);
context.lineTo(width + pointerWidth, height/2);
context.lineTo(width, (height + pointerHeight)/2);
}
context.lineTo(width, height);
if (pointerDirection === DOWN) {
context.lineTo((width + pointerWidth)/2, height);
context.lineTo(width/2, height + pointerHeight);
context.lineTo((width - pointerWidth)/2, height);
context.lineTo((width - pointerWidth)/2, height);
}
context.lineTo(0, height);
if (pointerDirection === LEFT) {
context.lineTo(0, (height + pointerHeight)/2);
context.lineTo(-1 * pointerWidth, height/2);
context.lineTo(0, (height - pointerHeight)/2);
}
}
context.closePath();
canvas.fillStroke(this);
}
};
Kinetic.Util.extend(Kinetic.Tag, Kinetic.Shape);
Kinetic.Node.addGetterSetter(Kinetic.Tag, 'pointerDirection', NONE);
@@ -234,7 +234,7 @@
* @method
* @memberof Kinetic.Tag.prototype
* @param {String} pointerDirection can be up, right, down, left, or none. The
* default is none
* default is none
*/
/**
@@ -247,15 +247,15 @@
Kinetic.Node.addGetterSetter(Kinetic.Tag, 'pointerWidth', 0);
/**
* set pointer width
* set pointer width
* @name setPointerWidth
* @method
* @memberof Kinetic.Tag.prototype
* @param {Number} pointerWidth
* @param {Number} pointerWidth
*/
/**
* get pointer width
* get pointer width
* @name getPointerWidth
* @method
* @memberof Kinetic.Tag.prototype
@@ -264,7 +264,7 @@
Kinetic.Node.addGetterSetter(Kinetic.Tag, 'pointerHeight', 0);
/**
* set pointer height
* set pointer height
* @name setPointerHeight
* @method
* @memberof Kinetic.Tag.prototype
@@ -272,7 +272,7 @@
*/
/**
* get pointer height
* get pointer height
* @name getPointerHeight
* @method
* @memberof Kinetic.Tag.prototype

View File

@@ -19,11 +19,11 @@
* });
*/
Kinetic.Path = function(config) {
this._initPath(config);
this.___init(config);
};
Kinetic.Path.prototype = {
_initPath: function(config) {
___init: function(config) {
this.dataArray = [];
var that = this;
@@ -262,7 +262,7 @@
// Move var from within the switch to up here (jshint)
var prevCmd, ctlPtx, ctlPty; // Ss, Tt
var rx, ry, psi, fa, fs, x1, y1; // Aa
// convert l, H, h, V, and v to L
switch (c) {

View File

@@ -21,11 +21,11 @@
* });
*/
Kinetic.RegularPolygon = function(config) {
this._initRegularPolygon(config);
this.___init(config);
};
Kinetic.RegularPolygon.prototype = {
_initRegularPolygon: function(config) {
___init: function(config) {
this.createAttrs();
// call super constructor
@@ -34,8 +34,8 @@
this._setDrawFuncs();
},
drawFunc: function(canvas) {
var context = canvas.getContext(),
sides = this.attrs.sides,
var context = canvas.getContext(),
sides = this.attrs.sides,
radius = this.attrs.radius,
n, x, y;

View File

@@ -23,11 +23,11 @@
* });
*/
Kinetic.Star = function(config) {
this._initStar(config);
this.___init(config);
};
Kinetic.Star.prototype = {
_initStar: function(config) {
___init: function(config) {
this.createAttrs();
// call super constructor

View File

@@ -29,9 +29,9 @@
* });
*/
Kinetic.TextPath = function(config) {
this._initTextPath(config);
this.___init(config);
};
function _fillFunc(context) {
context.fillText(this.partialText, 0, 0);
}
@@ -40,13 +40,13 @@
}
Kinetic.TextPath.prototype = {
_initTextPath: function(config) {
___init: function(config) {
var that = this;
this.createAttrs();
this.dummyCanvas = document.createElement('canvas');
this.dataArray = [];
// call super constructor
Kinetic.Shape.call(this, config);
@@ -89,7 +89,7 @@
context.translate(p0.x, p0.y);
context.rotate(glyphInfo[i].rotation);
this.partialText = glyphInfo[i].text;
canvas.fillStroke(this);
context.restore();
@@ -317,7 +317,7 @@
// map TextPath methods to Text
Kinetic.TextPath.prototype._getContextFont = Kinetic.Text.prototype._getContextFont;
Kinetic.Util.extend(Kinetic.TextPath, Kinetic.Shape);
// add setters and getters
@@ -371,7 +371,7 @@
* @method
* @memberof Kinetic.TextPath.prototype
*/
Kinetic.Node.addGetter(Kinetic.TextPath, 'text', EMPTY_STRING);
/**

View File

@@ -21,11 +21,11 @@
* });
*/
Kinetic.Blob = function(config) {
this._initBlob(config);
this.___init(config);
};
Kinetic.Blob.prototype = {
_initBlob: function(config) {
___init: function(config) {
var that = this;
this.createAttrs();
// call super constructor
@@ -40,9 +40,9 @@
this._setAllPoints();
},
drawFunc: function(canvas) {
var points = this.getPoints(),
length = points.length,
context = canvas.getContext(),
var points = this.getPoints(),
length = points.length,
context = canvas.getContext(),
tension = this.getTension(),
ap, len, n, point;
@@ -57,7 +57,7 @@
while(n < len-1) {
context.bezierCurveTo(ap[n].x, ap[n++].y, ap[n].x, ap[n++].y, ap[n].x, ap[n++].y);
}
}
}
// no tension
else {
@@ -71,11 +71,11 @@
canvas.fillStroke(this);
},
_setAllPoints: function() {
var points = this.getPoints(),
length = points.length,
tension = this.getTension(),
var points = this.getPoints(),
length = points.length,
tension = this.getTension(),
util = Kinetic.Util,
firstControlPoints = util._getControlPoints(points[length - 1], points[0], points[1], tension),
firstControlPoints = util._getControlPoints(points[length - 1], points[0], points[1], tension),
lastControlPoints = util._getControlPoints(points[length - 2], points[length - 1], points[0], tension);
this.allPoints = Kinetic.Util._expandPoints(this.getPoints(), this.getTension());

View File

@@ -32,11 +32,11 @@
* });
*/
Kinetic.Circle = function(config) {
this._initCircle(config);
this.___init(config);
};
Kinetic.Circle.prototype = {
_initCircle: function(config) {
___init: function(config) {
this.createAttrs();
// call super constructor
Kinetic.Shape.call(this, config);

View File

@@ -13,11 +13,11 @@
* {{NodeParams}}
*/
Kinetic.Ellipse = function(config) {
this._initEllipse(config);
this.___init(config);
};
Kinetic.Ellipse.prototype = {
_initEllipse: function(config) {
___init: function(config) {
this.createAttrs();
// call super constructor

View File

@@ -3,7 +3,7 @@
var IMAGE = 'Image',
CROP = 'crop',
SET = 'set';
/**
* Image constructor
* @constructor
@@ -28,23 +28,23 @@
* imageObj.src = '/path/to/image.jpg'
*/
Kinetic.Image = function(config) {
this._initImage(config);
this.___init(config);
};
Kinetic.Image.prototype = {
_initImage: function(config) {
___init: function(config) {
var that = this;
// call super constructor
Kinetic.Shape.call(this, config);
this.className = IMAGE;
this._setDrawFuncs();
},
drawFunc: function(canvas) {
var width = this.getWidth(),
height = this.getHeight(),
params,
that = this,
var width = this.getWidth(),
height = this.getHeight(),
params,
that = this,
context = canvas.getContext(),
crop = this.getCrop(),
cropX, cropY, cropWidth, cropHeight, image;
@@ -93,9 +93,9 @@
}
},
drawHitFunc: function(canvas) {
var width = this.getWidth(),
height = this.getHeight(),
imageHitRegion = this.imageHitRegion,
var width = this.getWidth(),
height = this.getHeight(),
imageHitRegion = this.imageHitRegion,
context = canvas.getContext();
if(imageHitRegion) {
@@ -125,7 +125,7 @@
}
else {
filterCanvas = this.filterCanvas = new Kinetic.SceneCanvas({
width: width,
width: width,
height: height
});
}
@@ -167,7 +167,7 @@
pos = Kinetic.Util._getXY(config),
size = Kinetic.Util._getSize(config),
both = Kinetic.Util._merge(pos, size);
this._setAttr(CROP, Kinetic.Util._merge(both, this.getCrop()));
},
/**
@@ -189,14 +189,14 @@
context = canvas.getContext(),
image = this.getImage(),
imageData, data, rgbColorKey, i, n;
context.drawImage(image, 0, 0);
try {
imageData = context.getImageData(0, 0, width, height);
data = imageData.data;
rgbColorKey = Kinetic.Util._hexToRgb(this.colorKey);
// replace non transparent pixels with color key
for(i = 0, n = data.length; i < n; i += 4) {
if (data[i + 3] > 0) {
@@ -226,8 +226,8 @@
delete this.imageHitRegion;
},
getWidth: function() {
var image = this.getImage();
return this.attrs.width || (image ? image.width : 0);
var image = this.getImage();
return this.attrs.width || (image ? image.width : 0);
},
getHeight: function() {
var image = this.getImage();
@@ -253,7 +253,7 @@
Kinetic.Node.addFilterSetter = function(constructor, attr) {
var that = this,
method = SET + Kinetic.Util._capitalize(attr);
constructor.prototype[method] = function(val) {
this._setAttr(attr, val);
this._applyFilter = true;
@@ -277,7 +277,7 @@
* @method
* @memberof Kinetic.Image.prototype
*/
Kinetic.Node.addGetter(Kinetic.Image, 'crop');
/**

View File

@@ -32,11 +32,11 @@
* });
*/
Kinetic.Line = function(config) {
this._initLine(config);
this.___init(config);
};
Kinetic.Line.prototype = {
_initLine: function(config) {
___init: function(config) {
this.createAttrs();
// call super constructor
@@ -45,8 +45,8 @@
this._setDrawFuncs();
},
drawFunc: function(canvas) {
var points = this.getPoints(),
length = points.length,
var points = this.getPoints(),
length = points.length,
context = canvas.getContext(),
n, point;

View File

@@ -18,11 +18,11 @@
* });
*/
Kinetic.Polygon = function(config) {
this._initPolygon(config);
this.___init(config);
};
Kinetic.Polygon.prototype = {
_initPolygon: function(config) {
___init: function(config) {
this.createAttrs();
// call super constructor

View File

@@ -18,11 +18,11 @@
* });
*/
Kinetic.Rect = function(config) {
this._initRect(config);
this.___init(config);
};
Kinetic.Rect.prototype = {
_initRect: function(config) {
___init: function(config) {
this.createAttrs();
Kinetic.Shape.call(this, config);
this.className = 'Rect';
@@ -30,12 +30,12 @@
},
drawFunc: function(canvas) {
var context = canvas.getContext(),
cornerRadius = this.getCornerRadius(),
width = this.getWidth(),
cornerRadius = this.getCornerRadius(),
width = this.getWidth(),
height = this.getHeight();
context.beginPath();
if(!cornerRadius) {
// simple rect - don't bother doing all that complicated maths stuff.
context.rect(0, 0, width, height);

View File

@@ -21,11 +21,11 @@
* });
*/
Kinetic.Spline = function(config) {
this._initSpline(config);
this.___init(config);
};
Kinetic.Spline.prototype = {
_initSpline: function(config) {
___init: function(config) {
var that = this;
this.createAttrs();
// call super constructor
@@ -40,9 +40,9 @@
this._setAllPoints();
},
drawFunc: function(canvas) {
var points = this.getPoints(),
length = points.length,
context = canvas.getContext(),
var points = this.getPoints(),
length = points.length,
context = canvas.getContext(),
tension = this.getTension(),
ap, len, n, point;

View File

@@ -61,19 +61,19 @@
* animation: 'idle',<br>
* animations: animations,<br>
* frameRate: 7,<br>
* index: 0<br>
* index: 0<br>
* });<br>
* };<br>
* imageObj.src = '/path/to/image.jpg'
*/
Kinetic.Sprite = function(config) {
this._initSprite(config);
this.___init(config);
};
Kinetic.Sprite.prototype = {
_initSprite: function(config) {
___init: function(config) {
this.createAttrs();
// call super constructor
Kinetic.Shape.call(this, config);
this.className = 'Sprite';
@@ -87,10 +87,10 @@
});
},
drawFunc: function(canvas) {
var anim = this.getAnimation(),
index = this.getIndex(),
f = this.getAnimations()[anim][index],
context = canvas.getContext(),
var anim = this.getAnimation(),
index = this.getIndex(),
f = this.getAnimations()[anim][index],
context = canvas.getContext(),
image = this.getImage();
if(image) {
@@ -98,9 +98,9 @@
}
},
drawHitFunc: function(canvas) {
var anim = this.getAnimation(),
index = this.getIndex(),
f = this.getAnimations()[anim][index],
var anim = this.getAnimation(),
index = this.getIndex(),
f = this.getAnimations()[anim][index],
context = canvas.getContext();
context.beginPath();
@@ -161,9 +161,9 @@
var index = this.getIndex(),
animation = this.getAnimation(),
animations = this.getAnimations(),
anim = animations[animation],
anim = animations[animation],
len = anim.length;
if(index < len - 1) {
this.setIndex(index + 1);
}
@@ -212,11 +212,11 @@
Kinetic.Node.addGetterSetter(Kinetic.Sprite, 'image');
/**
* set image
* set image
* @name setImage
* @method
* @memberof Kinetic.Sprite.prototype
* @param {Image} image
* @param {Image} image
*/
/**

View File

@@ -1,18 +1,18 @@
(function() {
// constants
var AUTO = 'auto',
var AUTO = 'auto',
CALIBRI = 'Calibri',
CANVAS = 'canvas',
CANVAS = 'canvas',
CENTER = 'center',
CHANGE_KINETIC = 'Change.kinetic',
CONTEXT_2D = '2d',
DASH = '-',
EMPTY_STRING = '',
EMPTY_STRING = '',
LEFT = 'left',
NEW_LINE = '\n',
TEXT = 'text',
TEXT_UPPER = 'Text',
TOP = 'top',
TEXT_UPPER = 'Text',
TOP = 'top',
MIDDLE = 'middle',
NORMAL = 'normal',
PX_SPACE = 'px ',
@@ -22,7 +22,7 @@
CHAR = 'char',
NONE = 'none',
ATTR_CHANGE_LIST = ['fontFamily', 'fontSize', 'fontStyle', 'padding', 'align', 'lineHeight', 'text', 'width', 'height', 'wrap'],
// cached variables
attrChangeListLen = ATTR_CHANGE_LIST.length,
dummyContext = document.createElement(CANVAS).getContext(CONTEXT_2D);
@@ -56,7 +56,7 @@
* });
*/
Kinetic.Text = function(config) {
this._initText(config);
this.___init(config);
};
function _fillFunc(context) {
context.fillText(this.partialText, 0, 0);
@@ -66,15 +66,15 @@
}
Kinetic.Text.prototype = {
_initText: function(config) {
___init: function(config) {
var that = this;
this.createAttrs();
// since width and height work a bit different for Text,
// we need to default the values here
this.attrs.width = AUTO;
this.attrs.height = AUTO;
// call super constructor
Kinetic.Shape.call(this, config);
@@ -91,13 +91,13 @@
this._setTextData();
},
drawFunc: function(canvas) {
var context = canvas.getContext(),
p = this.getPadding(),
var context = canvas.getContext(),
p = this.getPadding(),
fontStyle = this.getFontStyle(),
fontSize = this.getFontSize(),
fontFamily = this.getFontFamily(),
textHeight = this.getTextHeight(),
lineHeightPx = this.getLineHeight() * textHeight,
lineHeightPx = this.getLineHeight() * textHeight,
textArr = this.textArr,
textArrLen = textArr.length,
totalWidth = this.getWidth();
@@ -132,8 +132,8 @@
context.restore();
},
drawHitFunc: function(canvas) {
var context = canvas.getContext(),
width = this.getWidth(),
var context = canvas.getContext(),
width = this.getWidth(),
height = this.getHeight();
context.beginPath();
@@ -190,7 +190,7 @@
context.save();
context.font = this._getContextFont();
metrics = context.measureText(text);
context.restore();
return {
@@ -231,7 +231,7 @@
var line = lines[i],
lineWidth = this._getTextWidth(line);
if (fixedWidth && lineWidth > maxWidth) {
/*
/*
* if width is fixed and line does not fit entirely
* break the line into multiple fitting lines
*/
@@ -315,7 +315,7 @@
}
};
Kinetic.Util.extend(Kinetic.Text, Kinetic.Shape);
// add getters setters
Kinetic.Node.addGetterSetter(Kinetic.Text, 'fontFamily', CALIBRI);
@@ -444,7 +444,7 @@
* @method
* @memberof Kinetic.Text.prototype
*/
Kinetic.Node.addSetter(Kinetic.Text, 'width');
/**
@@ -455,7 +455,7 @@
* @param {Number|String} width default is auto
*/
Kinetic.Node.addSetter(Kinetic.Text, 'height');
Kinetic.Node.addSetter(Kinetic.Text, 'height');
/**
* set height

View File

@@ -22,11 +22,11 @@
* });
*/
Kinetic.Wedge = function(config) {
this._initWedge(config);
this.___init(config);
};
Kinetic.Wedge.prototype = {
_initWedge: function(config) {
___init: function(config) {
this.createAttrs();
// call super constructor