diff --git a/dist/kinetic-core.js b/dist/kinetic-core.js index 3018c9cf..e59abed2 100644 --- a/dist/kinetic-core.js +++ b/dist/kinetic-core.js @@ -432,14 +432,14 @@ requestAnimFrame = (function(callback) { /////////////////////////////////////////////////////////////////////// // Node /////////////////////////////////////////////////////////////////////// +/** + * Node constructor.  Nodes are entities that can be transformed, layered, + * and have events bound to them. They are the building blocks of a KineticJS + * application + * @constructor + * @param {Object} config + */ Kinetic.Node = Kinetic.Class.extend({ - /** - * Node constructor.  Nodes are entities that can be transformed, layered, - * and have events bound to them. They are the building blocks of a KineticJS - * application - * @constructor - * @param {Object} config - */ init: function(config) { this.defaultNodeAttrs = { visible: true, @@ -501,6 +501,8 @@ Kinetic.Node = Kinetic.Class.extend({ * of event types delimmited by a space to bind multiple events at once * such as 'mousedown mouseup mousemove'. include a namespace to bind an * event by name such as 'click.foobar'. + * @name on + * @methodOf Kinetic.Node.prototype * @param {String} typesStr * @param {Function} handler */ @@ -534,6 +536,8 @@ Kinetic.Node = Kinetic.Class.extend({ * bindings at once such as 'mousedown mouseup mousemove'. * include a namespace to remove an event binding by name * such as 'click.foobar'. + * @name off + * @methodOf Kinetic.Node.prototype * @param {String} typesStr */ off: function(typesStr) { @@ -567,12 +571,16 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * get attrs + * @name getAttrs + * @methodOf Kinetic.Node.prototype */ getAttrs: function() { return this.attrs; }, /** * set default attrs + * @name setDefaultAttrs + * @methodOf Kinetic.Node.prototype * @param {Object} confic */ setDefaultAttrs: function(config) { @@ -598,6 +606,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * set attrs + * @name setAttrs + * @methodOf Kinetic.Node.prototype * @param {Object} config */ setAttrs: function(config) { @@ -690,6 +700,8 @@ Kinetic.Node = Kinetic.Class.extend({ * determine if shape is visible or not. Shape is visible only * if it's visible and all of its ancestors are visible. If one ancestor * is invisible, this means that the shape is also invisible + * @name isVisible + * @methodOf Kinetic.Node.prototype */ isVisible: function() { if(this.attrs.visible && this.getParent() && !this.getParent().isVisible()) { @@ -699,6 +711,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * show node + * @name show + * @methodOf Kinetic.Node.prototype */ show: function() { this.setAttrs({ @@ -707,6 +721,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * hide node + * @name hide + * @methodOf Kinetic.Node.prototype */ hide: function() { this.setAttrs({ @@ -715,6 +731,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * get zIndex + * @name getZIndex + * @methodOf Kinetic.Node.prototype */ getZIndex: function() { return this.index; @@ -722,6 +740,8 @@ Kinetic.Node = Kinetic.Class.extend({ /** * get absolute z-index by taking into account * all parent and sibling indices + * @name getAbsoluteZIndex + * @methodOf Kinetic.Node.prototype */ getAbsoluteZIndex: function() { var level = this.getLevel(); @@ -755,6 +775,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * get node level in node tree + * @name getLevel + * @methodOf Kinetic.Node.prototype */ getLevel: function() { var level = 0; @@ -767,6 +789,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * set node position + * @name setPosition + * @methodOf Kinetic.Node.prototype * @param {Object} point */ setPosition: function() { @@ -775,6 +799,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * get node position relative to container + * @name getPosition + * @methodOf Kinetic.Node.prototype */ getPosition: function() { return { @@ -784,12 +810,16 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * get absolute position relative to stage + * @name getAbsolutePosition + * @methodOf Kinetic.Node.prototype */ getAbsolutePosition: function() { return this.getAbsoluteTransform().getTranslation(); }, /** * set absolute position relative to stage + * @name setAbsolutePosition + * @methodOf Kinetic.Node.prototype * @param {Object} pos object containing an x and * y property */ @@ -835,6 +865,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * move node by an amount + * @name move + * @methodOf Kinetic.Node.prototype */ move: function() { var pos = Kinetic.Type._getXY(Array.prototype.slice.call(arguments)); @@ -857,12 +889,16 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * get rotation in degrees + * @name getRotationDeg + * @methodOf Kinetic.Node.prototype */ getRotationDeg: function() { return this.attrs.rotation * 180 / Math.PI; }, /** * rotate node by an amount in radians + * @name rotate + * @methodOf Kinetic.Node.prototype * @param {Number} theta */ rotate: function(theta) { @@ -872,6 +908,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * rotate node by an amount in degrees + * @name rotateDeg + * @methodOf Kinetic.Node.prototype * @param {Number} deg */ rotateDeg: function(deg) { @@ -881,6 +919,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * move node to top + * @name moveToTop + * @methodOf Kinetic.Node.prototype */ moveToTop: function() { var index = this.index; @@ -890,6 +930,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * move node up + * @name moveUp + * @methodOf Kinetic.Node.prototype */ moveUp: function() { var index = this.index; @@ -899,6 +941,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * move node down + * @name moveDown + * @methodOf Kinetic.Node.prototype */ moveDown: function() { var index = this.index; @@ -910,6 +954,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * move node to bottom + * @name moveToBottom + * @methodOf Kinetic.Node.prototype */ moveToBottom: function() { var index = this.index; @@ -919,6 +965,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * set zIndex + * @name setZIndex + * @methodOf Kinetic.Node.prototype * @param {int} zIndex */ setZIndex: function(zIndex) { @@ -929,6 +977,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * get absolute alpha + * @name getAbsoluteAlpha + * @methodOf Kinetic.Node.prototype */ getAbsoluteAlpha: function() { var absAlpha = 1; @@ -942,6 +992,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * determine if node is currently in drag and drop mode + * @name isDragging + * @methodOf Kinetic.Node.prototype */ isDragging: function() { var go = Kinetic.Global; @@ -949,6 +1001,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * move node to another container + * @name moveTo + * @methodOf Kinetic.Node.prototype * @param {Container} newContainer */ moveTo: function(newContainer) { @@ -965,12 +1019,16 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * get parent container + * @name getParent + * @methodOf Kinetic.Node.prototype */ getParent: function() { return this.parent; }, /** - * get layer associated to node + * get layer that contains the node + * @name getLayer + * @methodOf Kinetic.Node.prototype */ getLayer: function() { if(this.nodeType === 'Layer') { @@ -981,7 +1039,9 @@ Kinetic.Node = Kinetic.Class.extend({ } }, /** - * get stage associated to node + * get stage that contains the node + * @name getStage + * @methodOf Kinetic.Node.prototype */ getStage: function() { if(this.nodeType !== 'Stage' && this.getParent()) { @@ -996,6 +1056,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * simulate event + * @name simulate + * @methodOf Kinetic.Node.prototype * @param {String} eventType */ simulate: function(eventType) { @@ -1005,6 +1067,8 @@ Kinetic.Node = Kinetic.Class.extend({ * transition node to another state. Any property that can accept a real * number can be transitioned, including x, y, rotation, alpha, strokeWidth, * radius, scale.x, scale.y, offset.x, offset.y, etc. + * @name transitionTo + * @methodOf Kinetic.Node.prototype * @param {Object} config * @config {Number} [duration] duration that the transition runs in seconds * @config {String} [easing] easing function. can be linear, ease-in, ease-out, ease-in-out, @@ -1072,6 +1136,8 @@ Kinetic.Node = Kinetic.Class.extend({ /** * get transform of the node while taking into * account the transforms of its parents + * @name getAbsoluteTransform + * @methodOf Kinetic.Node.prototype */ getAbsoluteTransform: function() { // absolute transform @@ -1098,6 +1164,8 @@ Kinetic.Node = Kinetic.Class.extend({ /** * get transform of the node while not taking * into account the transforms of its parents + * @name getTransform + * @methodOf Kinetic.Node.prototype */ getTransform: function() { var m = new Kinetic.Transform(); @@ -1116,6 +1184,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * clone node + * @name clone + * @methodOf Kinetic.Node.prototype * @param {Object} config used to override cloned * attrs */ @@ -1451,23 +1521,29 @@ Kinetic.Node.addSetters(Kinetic.Node, ['rotationDeg']); /////////////////////////////////////////////////////////////////////// // Container /////////////////////////////////////////////////////////////////////// +/** + * Container constructor.  Containers are used to contain nodes or other containers + * @constructor + * @augments Kinetic.Node + * @param {Object} config + */ Kinetic.Container = Kinetic.Node.extend({ - /** - * Container constructor.  Containers are used to contain nodes or other containers - * @constructor - */ init: function(config) { this.children = []; this._super(config); }, /** * get children + * @name getChildren + * @methodOf Kinetic.Container.prototype */ getChildren: function() { return this.children; }, /** * remove all children + * @name removeChildren + * @methodOf Kinetic.Container.prototype */ removeChildren: function() { while(this.children.length > 0) { @@ -1476,6 +1552,8 @@ Kinetic.Container = Kinetic.Node.extend({ }, /** * add node to container + * @name add + * @methodOf Kinetic.Container.prototype * @param {Node} child */ add: function(child) { @@ -1512,6 +1590,8 @@ Kinetic.Container = Kinetic.Node.extend({ }, /** * remove child from container + * @name remove + * @methodOf Kinetic.Container.prototype * @param {Node} child */ remove: function(child) { @@ -1554,6 +1634,8 @@ Kinetic.Container = Kinetic.Node.extend({ * ex: * var node = stage.get('#foo'); // selects node with id foo * var nodes = layer.get('.bar'); // selects nodes with name bar inside layer + * @name get + * @methodOf Kinetic.Container.prototype * @param {String} selector */ get: function(selector) { @@ -1586,6 +1668,8 @@ Kinetic.Container = Kinetic.Node.extend({ /** * determine if node is an ancestor * of descendant + * @name isAncestorOf + * @methodOf Kinetic.Container.prototype * @param {Kinetic.Node} node */ isAncestorOf: function(node) { @@ -1605,6 +1689,8 @@ Kinetic.Container = Kinetic.Node.extend({ }, /** * get shapes that intersect a point + * @name getIntersections + * @methodOf Kinetic.Container.prototype * @param {Object} point */ getIntersections: function() { @@ -1692,17 +1778,17 @@ Kinetic.Container = Kinetic.Node.extend({ /////////////////////////////////////////////////////////////////////// // Stage /////////////////////////////////////////////////////////////////////// +/** + * Stage constructor. A stage is used to contain multiple layers and handle + * animations + * @constructor + * @augments Kinetic.Container + * @augments Kinetic.Node + * @param {String|DomElement} cont Container id or DOM element + * @param {int} width + * @param {int} height + */ Kinetic.Stage = Kinetic.Container.extend({ - /** - * Stage constructor. A stage is used to contain multiple layers and handle - * animations - * @constructor - * @augments Kinetic.Container - * @augments Kinetic.Node - * @param {String|DomElement} cont Container id or DOM element - * @param {int} width - * @param {int} height - */ init: function(config) { this.setDefaultAttrs({ width: 400, @@ -1741,6 +1827,8 @@ Kinetic.Stage = Kinetic.Container.extend({ }, /** * sets onFrameFunc for animation + * @name onFrame + * @methodOf Kinetic.Stage.prototype * @param {function} func */ onFrame: function(func) { @@ -1750,6 +1838,8 @@ Kinetic.Stage = Kinetic.Container.extend({ }, /** * start animation + * @name start + * @methodOf Kinetic.Stage.prototype */ start: function() { if(!this.animRunning) { @@ -1761,6 +1851,8 @@ Kinetic.Stage = Kinetic.Container.extend({ }, /** * stop animation + * @name stop + * @methodOf Kinetic.Stage.prototype */ stop: function() { Kinetic.Animation._removeAnimation(this.anim); @@ -1768,12 +1860,16 @@ Kinetic.Stage = Kinetic.Container.extend({ }, /** * draw children + * @name draw + * @methodOf Kinetic.Stage.prototype */ draw: function() { this._drawChildren(); }, /** * set stage size + * @name setSize + * @methodOf Kinetic.Stage.prototype */ setSize: function() { // set stage dimensions @@ -1782,6 +1878,8 @@ Kinetic.Stage = Kinetic.Container.extend({ }, /** * return stage size + * @name getSize + * @methodOf Kinetic.Stage.prototype */ getSize: function() { return { @@ -1791,6 +1889,8 @@ Kinetic.Stage = Kinetic.Container.extend({ }, /** * clear all layers + * @name clear + * @methodOf Kinetic.Stage.prototype */ clear: function() { var layers = this.children; @@ -1802,6 +1902,8 @@ Kinetic.Stage = Kinetic.Container.extend({ * Creates a composite data URL and passes it to a callback. If MIME type is not * specified, then "image/png" will result. For "image/jpeg", specify a quality * level as quality (range 0.0 - 1.0) + * @name toDataURL + * @methodOf Kinetic.Stage.prototype * @param {function} callback * @param {String} mimeType (optional) * @param {Number} quality (optional) @@ -1840,6 +1942,8 @@ Kinetic.Stage = Kinetic.Container.extend({ }, /** * serialize stage and children as a JSON object + * @name toJSON + * @methodOf Kinetic.Stage.prototype */ toJSON: function() { var type = Kinetic.Type; @@ -1876,6 +1980,8 @@ Kinetic.Stage = Kinetic.Container.extend({ }, /** * reset stage to default state + * @name reset + * @methodOf Kinetic.Stage.prototype */ reset: function() { // remove children @@ -1892,6 +1998,8 @@ Kinetic.Stage = Kinetic.Container.extend({ * event handlers (it probably does), then you need to select the appropriate * shapes after loading the stage and set these properties via on(), setDrawFunc(), * and setImage() + * @name load + * @methodOf Kinetic.Stage.prototype * @param {String} JSON string */ load: function(json) { @@ -1935,6 +2043,8 @@ Kinetic.Stage = Kinetic.Container.extend({ }, /** * get mouse position for desktop apps + * @name getMousePosition + * @methodOf Kinetic.Stage.prototype * @param {Event} evt */ getMousePosition: function(evt) { @@ -1942,6 +2052,8 @@ Kinetic.Stage = Kinetic.Container.extend({ }, /** * get touch position for mobile apps + * @name getTouchPosition + * @methodOf Kinetic.Stage.prototype * @param {Event} evt */ getTouchPosition: function(evt) { @@ -1949,6 +2061,8 @@ Kinetic.Stage = Kinetic.Container.extend({ }, /** * get user position (mouse position or touch position) + * @name getUserPosition + * @methodOf Kinetic.Stage.prototype * @param {Event} evt */ getUserPosition: function(evt) { @@ -1956,18 +2070,16 @@ Kinetic.Stage = Kinetic.Container.extend({ }, /** * get container DOM element + * @name getContainer + * @methodOf Kinetic.Stage.prototype */ getContainer: function() { return this.attrs.container; }, - /** - * get content DOM element - */ - getContent: function() { - return this.content; - }, /** * get stage + * @name getStage + * @methodOf Kinetic.Stage.prototype */ getStage: function() { return this; @@ -1975,6 +2087,8 @@ Kinetic.Stage = Kinetic.Container.extend({ /** * get stage DOM node, which is a div element * with the class name "kineticjs-content" + * @name getDOM + * @methodOf Kinetic.Stage.prototype */ getDOM: function() { return this.content; @@ -2694,15 +2808,14 @@ Kinetic.Node.addGettersSetters(Kinetic.Stage, ['width', 'height', 'throttle']); /////////////////////////////////////////////////////////////////////// // Layer /////////////////////////////////////////////////////////////////////// +/** + * Layer constructor. Layers are tied to their own canvas element and are used + * to contain groups or shapes + * @constructor + * @augments Kinetic.Container + * @param {Object} config + */ Kinetic.Layer = Kinetic.Container.extend({ - /** - * Layer constructor. Layers are tied to their own canvas element and are used - * to contain groups or shapes - * @constructor - * @augments Kinetic.Container - * @augments Kinetic.Node - * @param {Object} config - */ init: function(config) { this.setDefaultAttrs({ throttle: 80, @@ -2724,6 +2837,8 @@ Kinetic.Layer = Kinetic.Container.extend({ /** * draw children nodes. this includes any groups * or shapes + * @name draw + * @methodOf Kinetic.Layer.prototype */ draw: function() { var throttle = this.attrs.throttle; @@ -2756,12 +2871,16 @@ Kinetic.Layer = Kinetic.Container.extend({ }, /** * set before draw function handler + * @name beforeDraw + * @methodOf Kinetic.Layer.prototype */ beforeDraw: function(func) { this.beforeDrawFunc = func; }, /** * set after draw function handler + * @name afterDraw + * @methodOf Kinetic.Layer.prototype */ afterDraw: function(func) { this.afterDrawFunc = func; @@ -2771,6 +2890,8 @@ Kinetic.Layer = Kinetic.Container.extend({ * a layer does not remove its children. The nodes within * the layer will be redrawn whenever the .draw() method * is used again. + * @name clear + * @methodOf Kinetic.Layer.prototype */ clear: function() { var context = this.getContext(); @@ -2779,12 +2900,16 @@ Kinetic.Layer = Kinetic.Container.extend({ }, /** * get layer canvas + * @name getCanvas + * @methodOf Kinetic.Layer.prototype */ getCanvas: function() { return this.canvas; }, /** * get layer context + * @name getContext + * @methodOf Kinetic.Layer.prototype */ getContext: function() { return this.context; @@ -2856,14 +2981,13 @@ Kinetic.Node.addGettersSetters(Kinetic.Layer, ['clearBeforeDraw', 'throttle']); /////////////////////////////////////////////////////////////////////// // Group /////////////////////////////////////////////////////////////////////// +/** + * Group constructor. Groups are used to contain shapes or other groups. + * @constructor + * @augments Kinetic.Container + * @param {Object} config + */ Kinetic.Group = Kinetic.Container.extend({ - /** - * Group constructor. Groups are used to contain shapes or other groups. - * @constructor - * @augments Kinetic.Container - * @augments Kinetic.Node - * @param {Object} config - */ init: function(config) { this.nodeType = 'Group'; @@ -2880,23 +3004,23 @@ Kinetic.Group = Kinetic.Container.extend({ /////////////////////////////////////////////////////////////////////// // Shape /////////////////////////////////////////////////////////////////////// +/** + * Shape constructor. Shapes are used to objectify drawing bits of a KineticJS + * application + * @constructor + * @augments Kinetic.Node + * @param {Object} config + * @config {String|Object} [fill] can be a string color, a linear gradient object, a radial + * gradient object, or a pattern object. + * @config {String} [stroke] stroke color + * @config {Number} [strokeWidth] stroke width + * @config {String} [lineJoin] line join can be "miter", "round", or "bevel". The default + * is "miter" + * @config {Object} [shadow] shadow object + * @config {String} [detectionType] shape detection type. Can be "path" or "pixel". + * The default is "path" because it performs better + */ Kinetic.Shape = Kinetic.Node.extend({ - /** - * Shape constructor. Shapes are used to objectify drawing bits of a KineticJS - * application - * @constructor - * @augments Kinetic.Node - * @param {Object} config - * @config {String|Object} [fill] can be a string color, a linear gradient object, a radial - * gradient object, or a pattern object. - * @config {String} [stroke] stroke color - * @config {Number} [strokeWidth] stroke width - * @config {String} [lineJoin] line join can be "miter", "round", or "bevel". The default - * is "miter" - * @config {Object} [shadow] shadow object - * @config {String} [detectionType] shape detection type. Can be "path" or "pixel". - * The default is "path" because it performs better - */ init: function(config) { this.setDefaultAttrs({ detectionType: 'path' @@ -2915,12 +3039,16 @@ Kinetic.Shape = Kinetic.Node.extend({ * user created layer that contains the shape. When the event detection * engine is determining whether or not an event has occured on that shape, * .getContext() returns the context of the invisible path layer. + * @name getContext + * @methodOf Kinetic.Shape.prototype */ getContext: function() { return this.tempLayer.getContext(); }, /** * get shape temp layer canvas + * @name getCanvas + * @methodOf Kinetic.Shape.prototype */ getCanvas: function() { return this.tempLayer.getCanvas(); @@ -2928,6 +3056,8 @@ Kinetic.Shape = Kinetic.Node.extend({ /** * helper method to stroke the shape and apply * shadows if needed + * @name stroke + * @methodOf Kinetic.Shape.prototype */ stroke: function() { var go = Kinetic.Global; @@ -2956,6 +3086,8 @@ Kinetic.Shape = Kinetic.Node.extend({ /** * helper method to fill the shape with a color, linear gradient, * radial gradient, or pattern, and also apply shadows if needed + * @name fill + * @methodOf Kinetic.Shape.prototype * */ fill: function() { var appliedShadow = false; @@ -3040,6 +3172,8 @@ Kinetic.Shape = Kinetic.Node.extend({ /** * helper method to fill text and appy shadows if needed * @param {String} text + * @name fillText + * @methodOf Kinetic.Shape.prototype */ fillText: function(text) { var appliedShadow = false; @@ -3061,9 +3195,9 @@ Kinetic.Shape = Kinetic.Node.extend({ /** * helper method to stroke text and apply shadows * if needed + * @name strokeText + * @methodOf Kinetic.Shape.prototype * @param {String} text - * @param {Number} x - * @param {Number} y */ strokeText: function(text) { var appliedShadow = false; @@ -3094,6 +3228,8 @@ Kinetic.Shape = Kinetic.Node.extend({ /** * helper method to draw an image and apply * a shadow if neede + * @name drawImage + * @methodOf Kinetic.Shape.prototype */ drawImage: function() { var appliedShadow = false; @@ -3124,6 +3260,8 @@ Kinetic.Shape = Kinetic.Node.extend({ /** * helper method to set the line join of a shape * based on the lineJoin property + * @name applyLineJoin + * @methodOf Kinetic.Shape.prototype */ applyLineJoin: function() { var context = this.getContext(); @@ -3340,13 +3478,13 @@ Kinetic.Node.addGettersSetters(Kinetic.Shape, ['fill', 'stroke', 'lineJoin', 'st /////////////////////////////////////////////////////////////////////// // Rect /////////////////////////////////////////////////////////////////////// +/** + * Rect constructor + * @constructor + * @augments Kinetic.Shape + * @param {Object} config + */ Kinetic.Rect = Kinetic.Shape.extend({ - /** - * Rect constructor - * @constructor - * @augments Kinetic.Shape - * @param {Object} config - */ init: function(config) { this.setDefaultAttrs({ width: 0, @@ -3385,6 +3523,8 @@ Kinetic.Rect = Kinetic.Shape.extend({ }, /** * set width and height + * @name setSize + * @methodOf Kinetic.Rect.prototype */ setSize: function() { var size = Kinetic.Type._getSize(Array.prototype.slice.call(arguments)); @@ -3392,6 +3532,8 @@ Kinetic.Rect = Kinetic.Shape.extend({ }, /** * return rect size + * @name getSize + * @methodOf Kinetic.Rect.prototype */ getSize: function() { return { @@ -3445,13 +3587,13 @@ Kinetic.Node.addGettersSetters(Kinetic.Rect, ['width', 'height', 'cornerRadius'] /////////////////////////////////////////////////////////////////////// // Ellipse /////////////////////////////////////////////////////////////////////// +/** + * Ellipse constructor + * @constructor + * @augments Kinetic.Shape + * @param {Object} config + */ Kinetic.Ellipse = Kinetic.Shape.extend({ - /** - * Ellipse constructor - * @constructor - * @augments Kinetic.Shape - * @param {Object} config - */ init: function(config) { this.setDefaultAttrs({ radius: { @@ -3514,6 +3656,8 @@ Kinetic.Node.addGettersSetters(Kinetic.Ellipse, ['radius']); /** * set radius + * @name setRadius + * @methodOf Kinetic.Ellipse.prototype * @param {Number|Object|Array} radius * radius can be a number, in which the ellipse becomes a circle, * it can be an object with an x and y component, or it @@ -3531,13 +3675,13 @@ Kinetic.Node.addGettersSetters(Kinetic.Ellipse, ['radius']); /////////////////////////////////////////////////////////////////////// // Image /////////////////////////////////////////////////////////////////////// +/** + * Image constructor + * @constructor + * @augments Kinetic.Shape + * @param {Object} config + */ Kinetic.Image = Kinetic.Shape.extend({ - /** - * Image constructor - * @constructor - * @augments Kinetic.Shape - * @param {Object} config - */ init: function(config) { this.shapeType = "Image"; config.drawFunc = function() { @@ -3572,6 +3716,8 @@ Kinetic.Image = Kinetic.Shape.extend({ }, /** * set width and height + * @name setSize + * @methodOf Kinetic.Image.prototype */ setSize: function() { var size = Kinetic.GlobalObject._getSize(Array.prototype.slice.call(arguments)); @@ -3579,6 +3725,8 @@ Kinetic.Image = Kinetic.Shape.extend({ }, /** * return image size + * @name getSize + * @methodOf Kinetic.Image.prototype */ getSize: function() { return { @@ -3645,13 +3793,13 @@ Kinetic.Node.addGettersSetters(Kinetic.Image, ['height', 'width', 'image', 'crop /////////////////////////////////////////////////////////////////////// // Sprite /////////////////////////////////////////////////////////////////////// +/** + * Sprite constructor + * @constructor + * @augments Kinetic.Shape + * @param {Object} config + */ Kinetic.Sprite = Kinetic.Shape.extend({ - /** - * Sprite constructor - * @constructor - * @augments Kinetic.Shape - * @param {Object} config - */ init: function(config) { this.setDefaultAttrs({ index: 0, @@ -3683,6 +3831,8 @@ Kinetic.Sprite = Kinetic.Shape.extend({ }, /** * start sprite animation + * @name start + * @methodOf Kinetic.Sprite.prototype */ start: function() { var that = this; @@ -3712,7 +3862,7 @@ Kinetic.Sprite = Kinetic.Shape.extend({ ka._addAnimation(this.anim); this.interval = setInterval(function() { - var index = that.attrs.index; + var index = that.attrs.index; that._updateIndex(); if(that.afterFrameFunc && index === that.afterFrameIndex) { that.afterFrameFunc(); @@ -3723,6 +3873,8 @@ Kinetic.Sprite = Kinetic.Shape.extend({ }, /** * stop sprite animation + * @name stop + * @methodOf Kinetic.Sprite.prototype */ stop: function() { var ka = Kinetic.Animation; @@ -3734,6 +3886,8 @@ Kinetic.Sprite = Kinetic.Shape.extend({ }, /** * set after frame event handler + * @name afterFrame + * @methodOf Kinetic.Sprite.prototype * @param {Integer} index frame index * @param {Function} func function to be executed after frame has been drawn */ @@ -3797,13 +3951,13 @@ Kinetic.Node.addGettersSetters(Kinetic.Sprite, ['animation', 'animations', 'inde /////////////////////////////////////////////////////////////////////// // Polygon /////////////////////////////////////////////////////////////////////// +/** + * Polygon constructor.  Polygons are defined by an array of points + * @constructor + * @augments Kinetic.Shape + * @param {Object} config + */ Kinetic.Polygon = Kinetic.Shape.extend({ - /** - * Polygon constructor.  Polygons are defined by an array of points - * @constructor - * @augments Kinetic.Shape - * @param {Object} config - */ init: function(config) { this.setDefaultAttrs({ points: [] @@ -3845,13 +3999,13 @@ Kinetic.Node.addGettersSetters(Kinetic.Polygon, ['points']); /////////////////////////////////////////////////////////////////////// // RegularPolygon /////////////////////////////////////////////////////////////////////// +/** + * RegularPolygon constructor.  Examples include triangles, squares, pentagons, hexagons, etc. + * @constructor + * @augments Kinetic.Shape + * @param {Object} config + */ Kinetic.RegularPolygon = Kinetic.Shape.extend({ - /** - * RegularPolygon constructor.  Examples include triangles, squares, pentagons, hexagons, etc. - * @constructor - * @augments Kinetic.Shape - * @param {Object} config - */ init: function(config) { this.setDefaultAttrs({ radius: 0, @@ -3908,13 +4062,13 @@ Kinetic.Node.addGettersSetters(Kinetic.RegularPolygon, ['radius', 'sides']); /////////////////////////////////////////////////////////////////////// // Star /////////////////////////////////////////////////////////////////////// +/** + * Star constructor + * @constructor + * @augments Kinetic.Shape + * @param {Object} config + */ Kinetic.Star = Kinetic.Shape.extend({ - /** - * Star constructor - * @constructor - * @augments Kinetic.Shape - * @param {Object} config - */ init: function(config) { this.setDefaultAttrs({ numPoints: 0, @@ -4091,30 +4245,38 @@ Kinetic.Text = Kinetic.Shape.extend({ that._setTextData(); }, - /** - * get text width in pixels - */ - getTextWidth: function() { - return this.textWidth; - }, - /** - * get text height in pixels - */ - getTextHeight: function() { - return this.textHeight; - }, /** * get box width + * @name getBoxWidth + * @methodOf Kinetic.Text.prototype */ getBoxWidth: function() { return this.attrs.width === 'auto' ? this.getTextWidth() + this.attrs.padding * 2 : this.attrs.width; }, /** * get box height + * @name getBoxHeight + * @methodOf Kinetic.Text.prototype */ getBoxHeight: function() { return this.attrs.height === 'auto' ? (this.getTextHeight() * this.textArr.length * this.attrs.lineHeight) + this.attrs.padding * 2 : this.attrs.height; }, + /** + * get text width in pixels + * @name getTextWidth + * @methodOf Kinetic.Text.prototype + */ + getTextWidth: function() { + return this.textWidth; + }, + /** + * get text height in pixels + * @name getTextHeight + * @methodOf Kinetic.Text.prototype + */ + getTextHeight: function() { + return this.textHeight; + }, _getTextSize: function(text) { var dummyCanvas = this.dummyCanvas; var context = dummyCanvas.getContext('2d'); @@ -4369,13 +4531,13 @@ Kinetic.Node.addGettersSetters(Kinetic.Text, ['fontFamily', 'fontSize', 'fontSty /////////////////////////////////////////////////////////////////////// // Line /////////////////////////////////////////////////////////////////////// +/** + * Line constructor.  Lines are defined by an array of points + * @constructor + * @augments Kinetic.Shape + * @param {Object} config + */ Kinetic.Line = Kinetic.Shape.extend({ - /** - * Line constructor.  Lines are defined by an array of points - * @constructor - * @augments Kinetic.Shape - * @param {Object} config - */ init: function(config) { this.setDefaultAttrs({ points: [], @@ -4516,14 +4678,14 @@ Kinetic.Node.addGettersSetters(Kinetic.Line, ['dashArray', 'lineCap', 'points']) /////////////////////////////////////////////////////////////////////// // SVG Path /////////////////////////////////////////////////////////////////////// +/** + * Path constructor. + * @author Jason Follas + * @constructor + * @augments Kinetic.Shape + * @param {Object} config + */ Kinetic.Path = Kinetic.Shape.extend({ - /** - * Path constructor. - * @author Jason Follas - * @constructor - * @augments Kinetic.Shape - * @param {Object} config - */ init: function(config) { this.shapeType = "Path"; this.dataArray = []; @@ -4577,10 +4739,10 @@ Kinetic.Path = Kinetic.Shape.extend({ // call super constructor this._super(config); - this.dataArray = this.getDataArray(); + this.dataArray = this._getDataArray(); this.on('dataChange', function() { - that.dataArray = that.getDataArray(); + that.dataArray = that._getDataArray(); }); }, /** @@ -4589,7 +4751,7 @@ Kinetic.Path = Kinetic.Shape.extend({ * L data for the purpose of high performance Path * rendering */ - getDataArray: function() { + _getDataArray: function() { // Path Data Segment must begin with a moveTo //m (x y)+ Relative moveTo (subsequent points are treated as lineTo) @@ -4915,9 +5077,7 @@ Kinetic.Node.addGettersSetters(Kinetic.Path, ['data']); * class. */ -/** - * Matrix object - */ + Kinetic.Transform = function() { this.m = [1, 0, 0, 1, 0, 0]; } @@ -5066,6 +5226,8 @@ Kinetic.Transition = function(node, config) { Kinetic.Transition.prototype = { /** * start transition + * @name start + * @methodOf Kinetic.Transition.prototype */ start: function() { for(var n = 0; n < this.tweens.length; n++) { @@ -5074,6 +5236,8 @@ Kinetic.Transition.prototype = { }, /** * stop transition + * @name stop + * @methodOf Kinetic.Transition.prototype */ stop: function() { for(var n = 0; n < this.tweens.length; n++) { @@ -5082,6 +5246,8 @@ Kinetic.Transition.prototype = { }, /** * resume transition + * @name resume + * @methodOf Kinetic.Transition.prototype */ resume: function() { for(var n = 0; n < this.tweens.length; n++) { @@ -5122,9 +5288,6 @@ Kinetic.Transition.prototype = { * an animation of a single Node property. A Transition is a set of * multiple tweens */ -/** - * Tween constructor - */ Kinetic.Tween = function(obj, propFunc, func, begin, finish, duration) { this._listeners = []; this.addListener(this); diff --git a/dist/kinetic-core.min.js b/dist/kinetic-core.min.js index 29caa96b..9ee4b5bc 100644 --- a/dist/kinetic-core.min.js +++ b/dist/kinetic-core.min.js @@ -24,5 +24,5 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. - */;Kinetic.Class=function(){},Kinetic.Class.extend=function(c){function g(){!a&&this.init&&this.init.apply(this,arguments)}var d=this.prototype;a=!0;var e=new this;a=!1;for(var f in c)e[f]=typeof c[f]=="function"&&typeof d[f]=="function"&&b.test(c[f])?function(a,b){return function(){var c=this._super;this._super=d[a];var e=b.apply(this,arguments);return this._super=c,e}}(f,c[f]):c[f];return g.prototype=e,g.prototype.constructor=g,g.extend=arguments.callee,g}}(),Kinetic.Animation={animations:[],animIdCounter:0,animRunning:!1,frame:{time:0,timeDiff:0,lastTime:0},_addAnimation:function(a){a.id=this.animIdCounter++,this.animations.push(a)},_removeAnimation:function(a){var b=a.id,c=this.animations;for(var d=0;d0){this._updateFrameObject(),this._runFrames();var a=this;requestAnimFrame(function(){a._animationLoop()})}else this.animRunning=!1,this.frame.lastTime=0},_handleAnimation:function(){var a=this;this.animRunning?this.frame.lastTime=0:(this.animRunning=!0,a._animationLoop())}},requestAnimFrame=function(a){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){window.setTimeout(a,1e3/60)}}(),Kinetic.Node=Kinetic.Class.extend({init:function(a){this.defaultNodeAttrs={visible:!0,listening:!0,name:undefined,alpha:1,x:0,y:0,scale:{x:1,y:1},rotation:0,offset:{x:0,y:0},dragConstraint:"none",dragBounds:{},draggable:!1},this.setDefaultAttrs(this.defaultNodeAttrs),this.eventListeners={},this.setAttrs(a),this.on("draggableChange.kinetic",function(){if(this.attrs.draggable)this._listenDrag();else{this._dragCleanup();var a=this.getStage(),b=Kinetic.Global;a&&b.drag.node&&b.drag.node._id===this._id&&a._endDrag()}}),this.simulate("draggableChange")},on:function(a,b){var c=a.split(" ");for(var d=0;d1?g[1]:"";this.eventListeners[h]||(this.eventListeners[h]=[]),this.eventListeners[h].push({name:i,handler:b})}},off:function(a){var b=a.split(" ");for(var c=0;c1){var h=f[1];for(var i=0;i0&&f[0].getLevel()<=a&&e(f)}var a=this.getLevel(),b=this.getStage(),c=this,d=0;return c.nodeType!=="Stage"&&e(c.getStage().getChildren()),d},getLevel:function(){var a=0,b=this.parent;while(b)a++,b=b.parent;return a},setPosition:function(){var a=Kinetic.Type._getXY(Array.prototype.slice.call(arguments));this.setAttrs(a)},getPosition:function(){return{x:this.attrs.x,y:this.attrs.y}},getAbsolutePosition:function(){return this.getAbsoluteTransform().getTranslation()},setAbsolutePosition:function(){var a=Kinetic.Type._getXY(Array.prototype.slice.call(arguments)),b=this.attrs.rotation,c={x:this.attrs.scale.x,y:this.attrs.scale.y},d={x:this.attrs.offset.x,y:this.attrs.offset.y};this.attrs.rotation=0,this.attrs.scale={x:1,y:1};var e=this.getAbsoluteTransform();e.invert(),e.translate(a.x,a.y),a={x:this.attrs.x+e.getTranslation().x,y:this.attrs.y+e.getTranslation().y},this.setPosition(a.x,a.y),this.rotate(b),this.attrs.scale={x:c.x,y:c.y}},move:function(){var a=Kinetic.Type._getXY(Array.prototype.slice.call(arguments)),b=this.getX(),c=this.getY();a.x!==undefined&&(b+=a.x),a.y!==undefined&&(c+=a.y),this.setAttrs({x:b,y:c})},getRotationDeg:function(){return this.attrs.rotation*180/Math.PI},rotate:function(a){this.setAttrs({rotation:this.getRotation()+a})},rotateDeg:function(a){this.setAttrs({rotation:this.getRotation()+a*Math.PI/180})},moveToTop:function(){var a=this.index;this.parent.children.splice(a,1),this.parent.children.push(this),this.parent._setChildrenIndices()},moveUp:function(){var a=this.index;this.parent.children.splice(a,1),this.parent.children.splice(a+1,0,this),this.parent._setChildrenIndices()},moveDown:function(){var a=this.index;a>0&&(this.parent.children.splice(a,1),this.parent.children.splice(a-1,0,this),this.parent._setChildrenIndices())},moveToBottom:function(){var a=this.index;this.parent.children.splice(a,1),this.parent.children.unshift(this),this.parent._setChildrenIndices()},setZIndex:function(a){var b=this.index;this.parent.children.splice(b,1),this.parent.children.splice(a,0,this),this.parent._setChildrenIndices()},getAbsoluteAlpha:function(){var a=1,b=this;while(b.nodeType!=="Stage")a*=b.attrs.alpha,b=b.parent;return a},isDragging:function(){var a=Kinetic.Global;return a.drag.node!==undefined&&a.drag.node._id===this._id&&a.drag.moving},moveTo:function(a){var b=this.parent;b.children.splice(this.index,1),b._setChildrenIndices(),a.children.push(this),this.index=a.children.length-1,this.parent=a,a._setChildrenIndices()},getParent:function(){return this.parent},getLayer:function(){return this.nodeType==="Layer"?this:this.getParent().getLayer()},getStage:function(){return this.nodeType!=="Stage"&&this.getParent()?this.getParent().getStage():this.nodeType==="Stage"?this:undefined},simulate:function(a){this._handleEvent(a,{})},transitionTo:function(a){var b=Kinetic.Animation;this.transAnim&&(b._removeAnimation(this.transAnim),this.transAnim=null);var c=this.nodeType==="Stage"?this:this.getLayer(),d=this,e=new Kinetic.Transition(this,a),f={func:function(){e._onEnterFrame()},node:c};return this.transAnim=f,b._addAnimation(f),e.onFinished=function(){b._removeAnimation(f),d.transAnim=null,a.callback!==undefined&&a.callback(),f.node.draw()},e.start(),b._handleAnimation(),e},getAbsoluteTransform:function(){var a=new Kinetic.Transform,b=[],c=this.parent;b.unshift(this);while(c)b.unshift(c),c=c.parent;for(var d=0;d=0&&!b.cancelBubble&&this.parent&&this._handleEvent.call(this.parent,a,b)}}}),Kinetic.Node.addSetters=function(constructor,a){for(var b=0;b0)this.remove(this.children[0])},add:function(a){a._id=Kinetic.Global.idCounter++,a.index=this.children.length,a.parent=this,this.children.push(a);var b=a.getStage();if(b===undefined){var c=Kinetic.Global;c.tempNodes.push(a)}else{b._addId(a),b._addName(a);var c=Kinetic.Global;c._pullNodes(b)}return this._add!==undefined&&this._add(a),this},remove:function(a){if(a&&a.index!==undefined&&this.children[a.index]._id==a._id){var b=this.getStage();b!==undefined&&(b._removeId(a),b._removeName(a));var c=Kinetic.Global;for(var d=0;d0)a.remove(a.children[0]);this._remove!==undefined&&this._remove(a)}return this},get:function(a){var b=this.getStage(),c,d=a.slice(1);if(a.charAt(0)==="#")c=b.ids[d]!==undefined?[b.ids[d]]:[];else{if(a.charAt(0)!==".")return a==="Shape"||a==="Group"||a==="Layer"?this._getNodes(a):!1;c=b.names[d]!==undefined?b.names[d]:[]}var e=[];for(var f=0;f=0;d--){var e=c[d];if(e.getListening())if(e.nodeType==="Shape"){var f=this._detectEvent(e,b);if(f)return!0}else{var f=this._traverseChildren(e,b);if(f)return!0}}return!1},_handleStageEvent:function(a){var b=new Date,c=b.getTime();this.lastEventTime=c;var d=Kinetic.Global;a||(a=window.event),this._setMousePosition(a),this._setTouchPosition(a),this.pathLayer.clear(),this.targetFound=!1;var e=!1;for(var f=this.children.length-1;f>=0;f--){var g=this.children[f];if(g.isVisible()&&f>=0&&g.getListening()&&this._traverseChildren(g,a)){e=!0;break}}!e&&this.mouseoutShape&&(this.mouseoutShape._handleEvent("mouseout",a),this.mouseoutShape=undefined)},_bindContentEvents:function(){var a=Kinetic.Global,b=this,c=["mousedown","mousemove","mouseup","mouseover","mouseout","touchstart","touchmove","touchend"];for(var d=0;d=f||b>200)this.mouseDown=!1,this.mouseUp=!1,this.mouseMove=!0,this._handleStageEvent(a);this._startDrag(a)},_mousedown:function(a){this.mouseDown=!0,this.mouseUp=!1,this.mouseMove=!1,this._handleStageEvent(a),this.attrs.draggable&&this._initDrag()},_mouseup:function(a){this.mouseDown=!1,this.mouseUp=!0,this.mouseMove=!1,this._handleStageEvent(a),this.clickStart=!1,this._endDrag(a)},_touchstart:function(a){a.preventDefault(),this.touchStart=!0,this.touchEnd=!1,this.touchMove=!1,this._handleStageEvent(a),this.attrs.draggable&&this._initDrag()},_touchend:function(a){this.touchStart=!1,this.touchEnd=!0,this.touchMove=!1,this._handleStageEvent(a),this.tapStart=!1,this._endDrag(a)},_touchmove:function(a){var b=this,c=this.attrs.throttle,d=new Date,e=d.getTime(),f=e-this.lastEventTime,g=1e3/c;if(f>=g||c>200)a.preventDefault(),b.touchEnd=!1,b.touchMove=!0,b._handleStageEvent(a);this._startDrag(a)},_setMousePosition:function(a){var b=a.offsetX||a.clientX-this._getContentPosition().left+window.pageXOffset,c=a.offsetY||a.clientY-this._getContentPosition().top+window.pageYOffset;this.mousePos={x:b,y:c}},_setTouchPosition:function(a){if(a.touches!==undefined&&a.touches.length===1){var b=a.touches[0],c=b.clientX-this._getContentPosition().left+window.pageXOffset,d=b.clientY-this._getContentPosition().top+window.pageYOffset;this.touchPos={x:c,y:d}}},_getContentPosition:function(){var a=this.content,b=0,c=0;while(a&&a.tagName!=="BODY")b+=a.offsetTop-a.scrollTop,c+=a.offsetLeft-a.scrollLeft,a=a.offsetParent;return{top:b,left:c}},_modifyPathContext:function(a){a.stroke=function(){},a.fill=function(){},a.fillRect=function(b,c,d,e){a.rect(b,c,d,e)},a.strokeRect=function(b,c,d,e){a.rect(b,c,d,e)},a.drawImage=function(){},a.fillText=function(){},a.strokeText=function(){}},_endDrag:function(a){var b=Kinetic.Global;b.drag.node&&b.drag.moving&&(b.drag.moving=!1,b.drag.node._handleEvent("dragend",a)),b.drag.node=undefined},_startDrag:function(a){var b=this,c=Kinetic.Global,d=c.drag.node;if(d){var e=b.getUserPosition(),f=d.attrs.dragConstraint,g=d.attrs.dragBounds,h={x:d.attrs.x,y:d.attrs.y},i={x:e.x-c.drag.offset.x,y:e.y-c.drag.offset.y};g.left!==undefined&&i.xg.right&&(i.x=g.right),g.top!==undefined&&i.yg.bottom&&(i.y=g.bottom),d.setAbsolutePosition(i),f==="horizontal"?d.attrs.y=h.y:f==="vertical"&&(d.attrs.x=h.x),c.drag.node.nodeType==="Stage"?c.drag.node.draw():c.drag.node.getLayer().draw(),c.drag.moving||(c.drag.moving=!0,c.drag.node._handleEvent("dragstart",a)),c.drag.node._handleEvent("dragmove",a)}},_buildDOM:function(){this.content=document.createElement("div"),this.content.style.position="relative",this.content.style.display="inline-block",this.content.className="kineticjs-content",this.attrs.container.appendChild(this.content),this.bufferLayer=new Kinetic.Layer({name:"bufferLayer"}),this.pathLayer=new Kinetic.Layer({name:"pathLayer"}),this.bufferLayer.parent=this,this.pathLayer.parent=this,this._modifyPathContext(this.pathLayer.context),this.bufferLayer.getCanvas().style.display="none",this.pathLayer.getCanvas().style.display="none",this.bufferLayer.canvas.className="kineticjs-buffer-layer",this.content.appendChild(this.bufferLayer.canvas),this.pathLayer.canvas.className="kineticjs-path-layer",this.content.appendChild(this.pathLayer.canvas),this.setSize(this.attrs.width,this.attrs.height),this._resizeDOM()},_addId:function(a){a.attrs.id!==undefined&&(this.ids[a.attrs.id]=a)},_removeId:function(a){a.attrs.id!==undefined&&delete this.ids[a.attrs.id]},_addName:function(a){var b=a.attrs.name;b!==undefined&&(this.names[b]===undefined&&(this.names[b]=[]),this.names[b].push(a))},_removeName:function(a){if(a.attrs.name!==undefined){var b=this.names[a.attrs.name];if(b!==undefined){for(var c=0;c=e||a>200)this._draw(),this.drawTimeout!==undefined&&(clearTimeout(this.drawTimeout),this.drawTimeout=undefined);else if(this.drawTimeout===undefined){var f=this;this.drawTimeout=setTimeout(function(){f.draw()},17)}},beforeDraw:function(a){this.beforeDrawFunc=a},afterDraw:function(a){this.afterDrawFunc=a},clear:function(){var a=this.getContext(),b=this.getCanvas();a.clearRect(0,0,b.width,b.height)},getCanvas:function(){return this.canvas},getContext:function(){return this.context},_draw:function(){var a=new Date,b=a.getTime();this.lastDrawTime=b,this.beforeDrawFunc!==undefined&&this.beforeDrawFunc.call(this),this.attrs.clearBeforeDraw&&this.clear(),this.isVisible()&&(this.attrs.drawFunc!==undefined&&this.attrs.drawFunc.call(this),this._drawChildren()),this.afterDrawFunc!==undefined&&this.afterDrawFunc.call(this)}}),Kinetic.Node.addGettersSetters(Kinetic.Layer,["clearBeforeDraw","throttle"]),Kinetic.Group=Kinetic.Container.extend({init:function(a){this.nodeType="Group",this._super(a)},draw:function(){this.attrs.visible&&this._drawChildren()}}),Kinetic.Shape=Kinetic.Node.extend({init:function(a){this.setDefaultAttrs({detectionType:"path"}),this.data=[],this.nodeType="Shape",this.appliedShadow=!1,this._super(a)},getContext:function(){return this.tempLayer.getContext()},getCanvas:function(){return this.tempLayer.getCanvas()},stroke:function(){var a=Kinetic.Global,b=!1,c=this.getContext();if(this.attrs.stroke||this.attrs.strokeWidth){c.save(),this.attrs.shadow&&!this.appliedShadow&&(b=this._applyShadow());var d=this.attrs.stroke?this.attrs.stroke:"black",e=this.attrs.strokeWidth?this.attrs.strokeWidth:2;c.lineWidth=e,c.strokeStyle=d,c.stroke(),c.restore()}b&&this.stroke()},fill:function(){var a=!1,b=this.getContext();b.save();var c=this.attrs.fill;if(c){this.attrs.shadow&&!this.appliedShadow&&(a=this._applyShadow());var d=c.start,e=c.end,f=null;if(typeof c=="string")f=this.attrs.fill,b.fillStyle=f,b.fill();else if(c.image){var g=c.repeat?c.repeat:"repeat";f=b.createPattern(c.image,g),b.save(),c.scale&&b.scale(c.scale.x,c.scale.y),c.offset&&b.translate(c.offset.x,c.offset.y),b.fillStyle=f,b.fill(),b.restore()}else if(!d.radius&&!e.radius){var b=this.getContext(),h=b.createLinearGradient(d.x,d.y,e.x,e.y),i=c.colorStops;for(var j=0;j0&&d&&(this.attrs.height==="auto"||e*(c+1)this.attrs.width-this.attrs.padding*2){if(f==0)break;var i=h.lastIndexOf(" "),j=h.lastIndexOf("-"),k=Math.max(i,j);if(k>=0){g=a.splice(0,1+k).join("");break}g=a.splice(0,f).join("");break}f++,f===a.length&&(g=a.splice(0,f).join(""))}this.textWidth=Math.max(this.textWidth,this._getTextSize(g).width),g!==undefined&&(b.push(g),d=!0),c++}this.textArr=b}}),Kinetic.Node.addGettersSetters(Kinetic.Text,["fontFamily","fontSize","fontStyle","textFill","textStroke","textStrokeWidth","padding","align","lineHeight","text","width","height","cornerRadius","fill","stroke","strokeWidth","shadow"]),Kinetic.Line=Kinetic.Shape.extend({init:function(a){this.setDefaultAttrs({points:[],lineCap:"butt",dashArray:[],detectionType:"pixel"}),this.shapeType="Line",a.drawFunc=function(){var a=this.getContext(),b={};a.beginPath(),a.moveTo(this.attrs.points[0].x,this.attrs.points[0].y);for(var c=1;c0){var f=this.attrs.points[c-1].x,g=this.attrs.points[c-1].y;this._dashedLine(f,g,d,e,this.attrs.dashArray)}else a.lineTo(d,e)}!this.attrs.lineCap||(a.lineCap=this.attrs.lineCap),this.stroke()},this._super(a)},_dashedLine:function(a,b,c,d,e){var f=this.getContext(),g=e.length,h=c-a,i=d-b,j=h>i,k=j?i/h:h/i;k>9999?k=9999:k<-9999&&(k=-9999);var l=Math.sqrt(h*h+i*i),m=0,n=!0;while(l>=.1&&m<1e4){var o=e[m++%g];o===0&&(o=.001),o>l&&(o=l);var p=Math.sqrt(o*o/(1+k*k));j?(a+=h<0&&i<0?p*-1:p,b+=h<0&&i<0?k*p*-1:k*p):(a+=h<0&&i<0?k*p*-1:k*p,b+=h<0&&i<0?p*-1:p),f[n?"lineTo":"moveTo"](a,b),l-=o,n=!n}f.moveTo(c,d)}}),Kinetic.Node.addGettersSetters(Kinetic.Line,["dashArray","lineCap","points"]),Kinetic.Path=Kinetic.Shape.extend({init:function(a){this.shapeType="Path",this.dataArray=[];var b=this;a.drawFunc=function(){var a=this.getContext(),b=this.dataArray;a.beginPath();for(var c=0;ci?h:i,o=h>i?1:h/i,p=h>i?i/h:1;a.translate(f,g),a.rotate(l),a.scale(o,p),a.arc(0,0,n,j,j+k,1-m),a.scale(1/o,1/p),a.rotate(-l),a.translate(-f,-g);break;case"z":a.closePath()}}this.fill(),this.stroke()},this._super(a),this.dataArray=this.getDataArray(),this.on("dataChange",function(){b.dataArray=b.getDataArray()})},getDataArray:function(){var a=this.attrs.data;if(!this.attrs.data)return[];var b=["m","M","l","L","v","V","h","H","z","Z","c","C","q","Q","t","T","s","S","a","A"];a=a.replace(new RegExp(" ","g"),",");for(var c=0;c0&&j[0]===""&&j.shift();for(var k=0;k0){if(isNaN(j[0]))break;var l=undefined,m=[];switch(i){case"l":f+=j.shift(),g+=j.shift(),l="L",m.push(f,g);break;case"L":f=j.shift(),g=j.shift(),m.push(f,g);break;case"m":f+=j.shift(),g+=j.shift(),l="M",m.push(f,g),i="l";break;case"M":f=j.shift(),g=j.shift(),l="M",m.push(f,g),i="L";break;case"h":f+=j.shift(),l="L",m.push(f,g);break;case"H":f=j.shift(),l="L",m.push(f,g);break;case"v":g+=j.shift(),l="L",m.push(f,g);break;case"V":g=j.shift(),l="L",m.push(f,g);break;case"C":m.push(j.shift(),j.shift(),j.shift(),j.shift()),f=j.shift(),g=j.shift(),m.push(f,g);break;case"c":m.push(f+j.shift(),g+j.shift(),f+j.shift(),g+j.shift()),f+=j.shift(),g+=j.shift(),l="C",m.push(f,g);break;case"S":var n=f,o=g,p=e[e.length-1];p.command==="C"&&(n=f+(f-p.points[2]),o=g+(g-p.points[3])),m.push(n,o,j.shift(),j.shift()),f=j.shift(),g=j.shift(),l="C",m.push(f,g);break;case"s":var n=f,o=g,p=e[e.length-1];p.command==="C"&&(n=f+(f-p.points[2]),o=g+(g-p.points[3])),m.push(n,o,f+j.shift(),g+j.shift()),f+=j.shift(),g+=j.shift(),l="C",m.push(f,g);break;case"Q":m.push(j.shift(),j.shift()),f=j.shift(),g=j.shift(),m.push(f,g);break;case"q":m.push(f+j.shift(),g+j.shift()),f+=j.shift(),g+=j.shift(),l="Q",m.push(f,g);break;case"T":var n=f,o=g,p=e[e.length-1];p.command==="Q"&&(n=f+(f-p.points[0]),o=g+(g-p.points[1])),f=j.shift(),g=j.shift(),l="Q",m.push(n,o,f,g);break;case"t":var n=f,o=g,p=e[e.length-1];p.command==="Q"&&(n=f+(f-p.points[0]),o=g+(g-p.points[1])),f+=j.shift(),g+=j.shift(),l="Q",m.push(n,o,f,g);break;case"A":var q=j.shift(),r=j.shift(),s=j.shift(),t=j.shift(),u=j.shift(),v=f,w=g;f=j.shift(),g=j.shift(),l="A",m=this._convertEndpointToCenterParameterization(v,w,f,g,t,u,q,r,s);break;case"a":var q=j.shift(),r=j.shift(),s=j.shift(),t=j.shift(),u=j.shift(),v=f,w=g;f+=j.shift(),g+=j.shift(),l="A",m=this._convertEndpointToCenterParameterization(v,w,f,g,t,u,q,r,s)}e.push({command:l||i,points:m})}(i==="z"||i==="Z")&&e.push({command:"z",points:[]})}return e},_convertEndpointToCenterParameterization:function(a,b,c,d,e,f,g,h,i){var j=i*(Math.PI/180),k=Math.cos(j)*(a-c)/2+Math.sin(j)*(b-d)/2,l=-1*Math.sin(j)*(a-c)/2+Math.cos(j)*(b-d)/2,m=k*k/(g*g)+l*l/(h*h);m>1&&(g*=Math.sqrt(m),h*=Math.sqrt(m));var n=Math.sqrt((g*g*h*h-g*g*l*l-h*h*k*k)/(g*g*l*l+h*h*k*k));e==f&&(n*=-1),isNaN(n)&&(n=0);var o=n*g*l/h,p=n*-h*k/g,q=(a+c)/2+Math.cos(j)*o-Math.sin(j)*p,r=(b+d)/2+Math.sin(j)*o+Math.cos(j)*p,s=function(a){return Math.sqrt(a[0]*a[0]+a[1]*a[1])},t=function(a,b){return(a[0]*b[0]+a[1]*b[1])/(s(a)*s(b))},u=function(a,b){return(a[0]*b[1]=1&&(y=0),f==0&&y>0&&(y-=2*Math.PI),f==1&&y<0&&(y+=2*Math.PI),[q,r,g,h,v,y,j,f]}}),Kinetic.Node.addGettersSetters(Kinetic.Path,["data"]),Kinetic.Transform=function(){this.m=[1,0,0,1,0,0]},Kinetic.Transform.prototype={translate:function(a,b){this.m[4]+=this.m[0]*a+this.m[2]*b,this.m[5]+=this.m[1]*a+this.m[3]*b},scale:function(a,b){this.m[0]*=a,this.m[1]*=a,this.m[2]*=b,this.m[3]*=b},rotate:function(a){var b=Math.cos(a),c=Math.sin(a),d=this.m[0]*b+this.m[2]*c,e=this.m[1]*b+this.m[3]*c,f=this.m[0]*-c+this.m[2]*b,g=this.m[1]*-c+this.m[3]*b;this.m[0]=d,this.m[1]=e,this.m[2]=f,this.m[3]=g},getTranslation:function(){return{x:this.m[4],y:this.m[5]}},multiply:function(a){var b=this.m[0]*a.m[0]+this.m[2]*a.m[1],c=this.m[1]*a.m[0]+this.m[3]*a.m[1],d=this.m[0]*a.m[2]+this.m[2]*a.m[3],e=this.m[1]*a.m[2]+this.m[3]*a.m[3],f=this.m[0]*a.m[4]+this.m[2]*a.m[5]+this.m[4],g=this.m[1]*a.m[4]+this.m[3]*a.m[5]+this.m[5];this.m[0]=b,this.m[1]=c,this.m[2]=d,this.m[3]=e,this.m[4]=f,this.m[5]=g},invert:function(){var a=1/(this.m[0]*this.m[3]-this.m[1]*this.m[2]),b=this.m[3]*a,c=-this.m[1]*a,d=-this.m[2]*a,e=this.m[0]*a,f=a*(this.m[2]*this.m[5]-this.m[3]*this.m[4]),g=a*(this.m[1]*this.m[4]-this.m[0]*this.m[5]);this.m[0]=b,this.m[1]=c,this.m[2]=d,this.m[3]=e,this.m[4]=f,this.m[5]=g},getMatrix:function(){return this.m}},Kinetic.Transition=function(a,b){function d(a,b,e,f){for(var g in a)g!=="duration"&&g!=="easing"&&g!=="callback"&&(Kinetic.Type._isObject(a[g])?(e[g]={},d(a[g],b[g],e[g],f)):c._add(c._getTween(b,g,a[g],e,f)))}this.node=a,this.config=b,this.tweens=[];var c=this,e={};d(b,a.attrs,e,e);var f=0;for(var g=0;g=c.tweens.length&&c.onFinished()}}},Kinetic.Transition.prototype={start:function(){for(var a=0;athis.getDuration()?this.looping?(this.rewind(a-this._duration),this.update(),this.broadcastMessage("onLooped",{target:this,type:"onLooped"})):(this._time=this._duration,this.update(),this.stop(),this.broadcastMessage("onFinished",{target:this,type:"onFinished"})):a<0?(this.rewind(),this.update()):(this._time=a,this.update())},getTime:function(){return this._time},setDuration:function(a){this._duration=a===null||a<=0?1e5:a},getDuration:function(){return this._duration},setPosition:function(a){this.prevPos=this._pos,this.propFunc(a),this._pos=a,this.broadcastMessage("onChanged",{target:this,type:"onChanged"})},getPosition:function(a){return a===undefined&&(a=this._time),this.func(a,this.begin,this._change,this._duration)},setFinish:function(a){this._change=a-this.begin},getFinish:function(){return this.begin+this._change},start:function(){this.rewind(),this.startEnterFrame(),this.broadcastMessage("onStarted",{target:this,type:"onStarted"})},rewind:function(a){this.stop(),this._time=a===undefined?0:a,this.fixTime(),this.update()},fforward:function(){this._time=this._duration,this.fixTime(),this.update()},update:function(){this.setPosition(this.getPosition(this._time))},startEnterFrame:function(){this.stopEnterFrame(),this.isPlaying=!0,this.onEnterFrame()},onEnterFrame:function(){this.isPlaying&&this.nextFrame()},nextFrame:function(){this.setTime((this.getTimer()-this._startTime)/1e3)},stop:function(){this.stopEnterFrame(),this.broadcastMessage("onStopped",{target:this,type:"onStopped"})},stopEnterFrame:function(){this.isPlaying=!1},continueTo:function(a,b){this.begin=this._pos,this.setFinish(a),this._duration!==undefined&&this.setDuration(b),this.start()},resume:function(){this.fixTime(),this.startEnterFrame(),this.broadcastMessage("onResumed",{target:this,type:"onResumed"})},yoyo:function(){this.continueTo(this.begin,this._time)},addListener:function(a){return this.removeListener(a),this._listeners.push(a)},removeListener:function(a){var b=this._listeners,c=b.length;while(c--)if(b[c]==a)return b.splice(c,1),!0;return!1},broadcastMessage:function(){var a=[];for(var b=0;b0){this._updateFrameObject(),this._runFrames();var a=this;requestAnimFrame(function(){a._animationLoop()})}else this.animRunning=!1,this.frame.lastTime=0},_handleAnimation:function(){var a=this;this.animRunning?this.frame.lastTime=0:(this.animRunning=!0,a._animationLoop())}},requestAnimFrame=function(a){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){window.setTimeout(a,1e3/60)}}(),Kinetic.Node=Kinetic.Class.extend({init:function(a){this.defaultNodeAttrs={visible:!0,listening:!0,name:undefined,alpha:1,x:0,y:0,scale:{x:1,y:1},rotation:0,offset:{x:0,y:0},dragConstraint:"none",dragBounds:{},draggable:!1},this.setDefaultAttrs(this.defaultNodeAttrs),this.eventListeners={},this.setAttrs(a),this.on("draggableChange.kinetic",function(){if(this.attrs.draggable)this._listenDrag();else{this._dragCleanup();var a=this.getStage(),b=Kinetic.Global;a&&b.drag.node&&b.drag.node._id===this._id&&a._endDrag()}}),this.simulate("draggableChange")},on:function(a,b){var c=a.split(" ");for(var d=0;d1?g[1]:"";this.eventListeners[h]||(this.eventListeners[h]=[]),this.eventListeners[h].push({name:i,handler:b})}},off:function(a){var b=a.split(" ");for(var c=0;c1){var h=f[1];for(var i=0;i0&&f[0].getLevel()<=a&&e(f)}var a=this.getLevel(),b=this.getStage(),c=this,d=0;return c.nodeType!=="Stage"&&e(c.getStage().getChildren()),d},getLevel:function(){var a=0,b=this.parent;while(b)a++,b=b.parent;return a},setPosition:function(){var a=Kinetic.Type._getXY(Array.prototype.slice.call(arguments));this.setAttrs(a)},getPosition:function(){return{x:this.attrs.x,y:this.attrs.y}},getAbsolutePosition:function(){return this.getAbsoluteTransform().getTranslation()},setAbsolutePosition:function(){var a=Kinetic.Type._getXY(Array.prototype.slice.call(arguments)),b=this.attrs.rotation,c={x:this.attrs.scale.x,y:this.attrs.scale.y},d={x:this.attrs.offset.x,y:this.attrs.offset.y};this.attrs.rotation=0,this.attrs.scale={x:1,y:1};var e=this.getAbsoluteTransform();e.invert(),e.translate(a.x,a.y),a={x:this.attrs.x+e.getTranslation().x,y:this.attrs.y+e.getTranslation().y},this.setPosition(a.x,a.y),this.rotate(b),this.attrs.scale={x:c.x,y:c.y}},move:function(){var a=Kinetic.Type._getXY(Array.prototype.slice.call(arguments)),b=this.getX(),c=this.getY();a.x!==undefined&&(b+=a.x),a.y!==undefined&&(c+=a.y),this.setAttrs({x:b,y:c})},getRotationDeg:function(){return this.attrs.rotation*180/Math.PI},rotate:function(a){this.setAttrs({rotation:this.getRotation()+a})},rotateDeg:function(a){this.setAttrs({rotation:this.getRotation()+a*Math.PI/180})},moveToTop:function(){var a=this.index;this.parent.children.splice(a,1),this.parent.children.push(this),this.parent._setChildrenIndices()},moveUp:function(){var a=this.index;this.parent.children.splice(a,1),this.parent.children.splice(a+1,0,this),this.parent._setChildrenIndices()},moveDown:function(){var a=this.index;a>0&&(this.parent.children.splice(a,1),this.parent.children.splice(a-1,0,this),this.parent._setChildrenIndices())},moveToBottom:function(){var a=this.index;this.parent.children.splice(a,1),this.parent.children.unshift(this),this.parent._setChildrenIndices()},setZIndex:function(a){var b=this.index;this.parent.children.splice(b,1),this.parent.children.splice(a,0,this),this.parent._setChildrenIndices()},getAbsoluteAlpha:function(){var a=1,b=this;while(b.nodeType!=="Stage")a*=b.attrs.alpha,b=b.parent;return a},isDragging:function(){var a=Kinetic.Global;return a.drag.node!==undefined&&a.drag.node._id===this._id&&a.drag.moving},moveTo:function(a){var b=this.parent;b.children.splice(this.index,1),b._setChildrenIndices(),a.children.push(this),this.index=a.children.length-1,this.parent=a,a._setChildrenIndices()},getParent:function(){return this.parent},getLayer:function(){return this.nodeType==="Layer"?this:this.getParent().getLayer()},getStage:function(){return this.nodeType!=="Stage"&&this.getParent()?this.getParent().getStage():this.nodeType==="Stage"?this:undefined},simulate:function(a){this._handleEvent(a,{})},transitionTo:function(a){var b=Kinetic.Animation;this.transAnim&&(b._removeAnimation(this.transAnim),this.transAnim=null);var c=this.nodeType==="Stage"?this:this.getLayer(),d=this,e=new Kinetic.Transition(this,a),f={func:function(){e._onEnterFrame()},node:c};return this.transAnim=f,b._addAnimation(f),e.onFinished=function(){b._removeAnimation(f),d.transAnim=null,a.callback!==undefined&&a.callback(),f.node.draw()},e.start(),b._handleAnimation(),e},getAbsoluteTransform:function(){var a=new Kinetic.Transform,b=[],c=this.parent;b.unshift(this);while(c)b.unshift(c),c=c.parent;for(var d=0;d=0&&!b.cancelBubble&&this.parent&&this._handleEvent.call(this.parent,a,b)}}}),Kinetic.Node.addSetters=function(constructor,a){for(var b=0;b0)this.remove(this.children[0])},add:function(a){a._id=Kinetic.Global.idCounter++,a.index=this.children.length,a.parent=this,this.children.push(a);var b=a.getStage();if(b===undefined){var c=Kinetic.Global;c.tempNodes.push(a)}else{b._addId(a),b._addName(a);var c=Kinetic.Global;c._pullNodes(b)}return this._add!==undefined&&this._add(a),this},remove:function(a){if(a&&a.index!==undefined&&this.children[a.index]._id==a._id){var b=this.getStage();b!==undefined&&(b._removeId(a),b._removeName(a));var c=Kinetic.Global;for(var d=0;d0)a.remove(a.children[0]);this._remove!==undefined&&this._remove(a)}return this},get:function(a){var b=this.getStage(),c,d=a.slice(1);if(a.charAt(0)==="#")c=b.ids[d]!==undefined?[b.ids[d]]:[];else{if(a.charAt(0)!==".")return a==="Shape"||a==="Group"||a==="Layer"?this._getNodes(a):!1;c=b.names[d]!==undefined?b.names[d]:[]}var e=[];for(var f=0;f=0;d--){var e=c[d];if(e.getListening())if(e.nodeType==="Shape"){var f=this._detectEvent(e,b);if(f)return!0}else{var f=this._traverseChildren(e,b);if(f)return!0}}return!1},_handleStageEvent:function(a){var b=new Date,c=b.getTime();this.lastEventTime=c;var d=Kinetic.Global;a||(a=window.event),this._setMousePosition(a),this._setTouchPosition(a),this.pathLayer.clear(),this.targetFound=!1;var e=!1;for(var f=this.children.length-1;f>=0;f--){var g=this.children[f];if(g.isVisible()&&f>=0&&g.getListening()&&this._traverseChildren(g,a)){e=!0;break}}!e&&this.mouseoutShape&&(this.mouseoutShape._handleEvent("mouseout",a),this.mouseoutShape=undefined)},_bindContentEvents:function(){var a=Kinetic.Global,b=this,c=["mousedown","mousemove","mouseup","mouseover","mouseout","touchstart","touchmove","touchend"];for(var d=0;d=f||b>200)this.mouseDown=!1,this.mouseUp=!1,this.mouseMove=!0,this._handleStageEvent(a);this._startDrag(a)},_mousedown:function(a){this.mouseDown=!0,this.mouseUp=!1,this.mouseMove=!1,this._handleStageEvent(a),this.attrs.draggable&&this._initDrag()},_mouseup:function(a){this.mouseDown=!1,this.mouseUp=!0,this.mouseMove=!1,this._handleStageEvent(a),this.clickStart=!1,this._endDrag(a)},_touchstart:function(a){a.preventDefault(),this.touchStart=!0,this.touchEnd=!1,this.touchMove=!1,this._handleStageEvent(a),this.attrs.draggable&&this._initDrag()},_touchend:function(a){this.touchStart=!1,this.touchEnd=!0,this.touchMove=!1,this._handleStageEvent(a),this.tapStart=!1,this._endDrag(a)},_touchmove:function(a){var b=this,c=this.attrs.throttle,d=new Date,e=d.getTime(),f=e-this.lastEventTime,g=1e3/c;if(f>=g||c>200)a.preventDefault(),b.touchEnd=!1,b.touchMove=!0,b._handleStageEvent(a);this._startDrag(a)},_setMousePosition:function(a){var b=a.offsetX||a.clientX-this._getContentPosition().left+window.pageXOffset,c=a.offsetY||a.clientY-this._getContentPosition().top+window.pageYOffset;this.mousePos={x:b,y:c}},_setTouchPosition:function(a){if(a.touches!==undefined&&a.touches.length===1){var b=a.touches[0],c=b.clientX-this._getContentPosition().left+window.pageXOffset,d=b.clientY-this._getContentPosition().top+window.pageYOffset;this.touchPos={x:c,y:d}}},_getContentPosition:function(){var a=this.content,b=0,c=0;while(a&&a.tagName!=="BODY")b+=a.offsetTop-a.scrollTop,c+=a.offsetLeft-a.scrollLeft,a=a.offsetParent;return{top:b,left:c}},_modifyPathContext:function(a){a.stroke=function(){},a.fill=function(){},a.fillRect=function(b,c,d,e){a.rect(b,c,d,e)},a.strokeRect=function(b,c,d,e){a.rect(b,c,d,e)},a.drawImage=function(){},a.fillText=function(){},a.strokeText=function(){}},_endDrag:function(a){var b=Kinetic.Global;b.drag.node&&b.drag.moving&&(b.drag.moving=!1,b.drag.node._handleEvent("dragend",a)),b.drag.node=undefined},_startDrag:function(a){var b=this,c=Kinetic.Global,d=c.drag.node;if(d){var e=b.getUserPosition(),f=d.attrs.dragConstraint,g=d.attrs.dragBounds,h={x:d.attrs.x,y:d.attrs.y},i={x:e.x-c.drag.offset.x,y:e.y-c.drag.offset.y};g.left!==undefined&&i.xg.right&&(i.x=g.right),g.top!==undefined&&i.yg.bottom&&(i.y=g.bottom),d.setAbsolutePosition(i),f==="horizontal"?d.attrs.y=h.y:f==="vertical"&&(d.attrs.x=h.x),c.drag.node.nodeType==="Stage"?c.drag.node.draw():c.drag.node.getLayer().draw(),c.drag.moving||(c.drag.moving=!0,c.drag.node._handleEvent("dragstart",a)),c.drag.node._handleEvent("dragmove",a)}},_buildDOM:function(){this.content=document.createElement("div"),this.content.style.position="relative",this.content.style.display="inline-block",this.content.className="kineticjs-content",this.attrs.container.appendChild(this.content),this.bufferLayer=new Kinetic.Layer({name:"bufferLayer"}),this.pathLayer=new Kinetic.Layer({name:"pathLayer"}),this.bufferLayer.parent=this,this.pathLayer.parent=this,this._modifyPathContext(this.pathLayer.context),this.bufferLayer.getCanvas().style.display="none",this.pathLayer.getCanvas().style.display="none",this.bufferLayer.canvas.className="kineticjs-buffer-layer",this.content.appendChild(this.bufferLayer.canvas),this.pathLayer.canvas.className="kineticjs-path-layer",this.content.appendChild(this.pathLayer.canvas),this.setSize(this.attrs.width,this.attrs.height),this._resizeDOM()},_addId:function(a){a.attrs.id!==undefined&&(this.ids[a.attrs.id]=a)},_removeId:function(a){a.attrs.id!==undefined&&delete this.ids[a.attrs.id]},_addName:function(a){var b=a.attrs.name;b!==undefined&&(this.names[b]===undefined&&(this.names[b]=[]),this.names[b].push(a))},_removeName:function(a){if(a.attrs.name!==undefined){var b=this.names[a.attrs.name];if(b!==undefined){for(var c=0;c=e||a>200)this._draw(),this.drawTimeout!==undefined&&(clearTimeout(this.drawTimeout),this.drawTimeout=undefined);else if(this.drawTimeout===undefined){var f=this;this.drawTimeout=setTimeout(function(){f.draw()},17)}},beforeDraw:function(a){this.beforeDrawFunc=a},afterDraw:function(a){this.afterDrawFunc=a},clear:function(){var a=this.getContext(),b=this.getCanvas();a.clearRect(0,0,b.width,b.height)},getCanvas:function(){return this.canvas},getContext:function(){return this.context},_draw:function(){var a=new Date,b=a.getTime();this.lastDrawTime=b,this.beforeDrawFunc!==undefined&&this.beforeDrawFunc.call(this),this.attrs.clearBeforeDraw&&this.clear(),this.isVisible()&&(this.attrs.drawFunc!==undefined&&this.attrs.drawFunc.call(this),this._drawChildren()),this.afterDrawFunc!==undefined&&this.afterDrawFunc.call(this)}}),Kinetic.Node.addGettersSetters(Kinetic.Layer,["clearBeforeDraw","throttle"]),Kinetic.Group=Kinetic.Container.extend({init:function(a){this.nodeType="Group",this._super(a)},draw:function(){this.attrs.visible&&this._drawChildren()}}),Kinetic.Shape=Kinetic.Node.extend({init:function(a){this.setDefaultAttrs({detectionType:"path"}),this.data=[],this.nodeType="Shape",this.appliedShadow=!1,this._super(a)},getContext:function(){return this.tempLayer.getContext()},getCanvas:function(){return this.tempLayer.getCanvas()},stroke:function(){var a=Kinetic.Global,b=!1,c=this.getContext();if(this.attrs.stroke||this.attrs.strokeWidth){c.save(),this.attrs.shadow&&!this.appliedShadow&&(b=this._applyShadow());var d=this.attrs.stroke?this.attrs.stroke:"black",e=this.attrs.strokeWidth?this.attrs.strokeWidth:2;c.lineWidth=e,c.strokeStyle=d,c.stroke(),c.restore()}b&&this.stroke()},fill:function(){var a=!1,b=this.getContext();b.save();var c=this.attrs.fill;if(c){this.attrs.shadow&&!this.appliedShadow&&(a=this._applyShadow());var d=c.start,e=c.end,f=null;if(typeof c=="string")f=this.attrs.fill,b.fillStyle=f,b.fill();else if(c.image){var g=c.repeat?c.repeat:"repeat";f=b.createPattern(c.image,g),b.save(),c.scale&&b.scale(c.scale.x,c.scale.y),c.offset&&b.translate(c.offset.x,c.offset.y),b.fillStyle=f,b.fill(),b.restore()}else if(!d.radius&&!e.radius){var b=this.getContext(),h=b.createLinearGradient(d.x,d.y,e.x,e.y),i=c.colorStops;for(var j=0;j0&&d&&(this.attrs.height==="auto"||e*(c+1)this.attrs.width-this.attrs.padding*2){if(f==0)break;var i=h.lastIndexOf(" "),j=h.lastIndexOf("-"),k=Math.max(i,j);if(k>=0){g=a.splice(0,1+k).join("");break}g=a.splice(0,f).join("");break}f++,f===a.length&&(g=a.splice(0,f).join(""))}this.textWidth=Math.max(this.textWidth,this._getTextSize(g).width),g!==undefined&&(b.push(g),d=!0),c++}this.textArr=b}}),Kinetic.Node.addGettersSetters(Kinetic.Text,["fontFamily","fontSize","fontStyle","textFill","textStroke","textStrokeWidth","padding","align","lineHeight","text","width","height","cornerRadius","fill","stroke","strokeWidth","shadow"]),Kinetic.Line=Kinetic.Shape.extend({init:function(a){this.setDefaultAttrs({points:[],lineCap:"butt",dashArray:[],detectionType:"pixel"}),this.shapeType="Line",a.drawFunc=function(){var a=this.getContext(),b={};a.beginPath(),a.moveTo(this.attrs.points[0].x,this.attrs.points[0].y);for(var c=1;c0){var f=this.attrs.points[c-1].x,g=this.attrs.points[c-1].y;this._dashedLine(f,g,d,e,this.attrs.dashArray)}else a.lineTo(d,e)}!this.attrs.lineCap||(a.lineCap=this.attrs.lineCap),this.stroke()},this._super(a)},_dashedLine:function(a,b,c,d,e){var f=this.getContext(),g=e.length,h=c-a,i=d-b,j=h>i,k=j?i/h:h/i;k>9999?k=9999:k<-9999&&(k=-9999);var l=Math.sqrt(h*h+i*i),m=0,n=!0;while(l>=.1&&m<1e4){var o=e[m++%g];o===0&&(o=.001),o>l&&(o=l);var p=Math.sqrt(o*o/(1+k*k));j?(a+=h<0&&i<0?p*-1:p,b+=h<0&&i<0?k*p*-1:k*p):(a+=h<0&&i<0?k*p*-1:k*p,b+=h<0&&i<0?p*-1:p),f[n?"lineTo":"moveTo"](a,b),l-=o,n=!n}f.moveTo(c,d)}}),Kinetic.Node.addGettersSetters(Kinetic.Line,["dashArray","lineCap","points"]),Kinetic.Path=Kinetic.Shape.extend({init:function(a){this.shapeType="Path",this.dataArray=[];var b=this;a.drawFunc=function(){var a=this.getContext(),b=this.dataArray;a.beginPath();for(var c=0;ci?h:i,o=h>i?1:h/i,p=h>i?i/h:1;a.translate(f,g),a.rotate(l),a.scale(o,p),a.arc(0,0,n,j,j+k,1-m),a.scale(1/o,1/p),a.rotate(-l),a.translate(-f,-g);break;case"z":a.closePath()}}this.fill(),this.stroke()},this._super(a),this.dataArray=this._getDataArray(),this.on("dataChange",function(){b.dataArray=b._getDataArray()})},_getDataArray:function(){var a=this.attrs.data;if(!this.attrs.data)return[];var b=["m","M","l","L","v","V","h","H","z","Z","c","C","q","Q","t","T","s","S","a","A"];a=a.replace(new RegExp(" ","g"),",");for(var c=0;c0&&j[0]===""&&j.shift();for(var k=0;k0){if(isNaN(j[0]))break;var l=undefined,m=[];switch(i){case"l":f+=j.shift(),g+=j.shift(),l="L",m.push(f,g);break;case"L":f=j.shift(),g=j.shift(),m.push(f,g);break;case"m":f+=j.shift(),g+=j.shift(),l="M",m.push(f,g),i="l";break;case"M":f=j.shift(),g=j.shift(),l="M",m.push(f,g),i="L";break;case"h":f+=j.shift(),l="L",m.push(f,g);break;case"H":f=j.shift(),l="L",m.push(f,g);break;case"v":g+=j.shift(),l="L",m.push(f,g);break;case"V":g=j.shift(),l="L",m.push(f,g);break;case"C":m.push(j.shift(),j.shift(),j.shift(),j.shift()),f=j.shift(),g=j.shift(),m.push(f,g);break;case"c":m.push(f+j.shift(),g+j.shift(),f+j.shift(),g+j.shift()),f+=j.shift(),g+=j.shift(),l="C",m.push(f,g);break;case"S":var n=f,o=g,p=e[e.length-1];p.command==="C"&&(n=f+(f-p.points[2]),o=g+(g-p.points[3])),m.push(n,o,j.shift(),j.shift()),f=j.shift(),g=j.shift(),l="C",m.push(f,g);break;case"s":var n=f,o=g,p=e[e.length-1];p.command==="C"&&(n=f+(f-p.points[2]),o=g+(g-p.points[3])),m.push(n,o,f+j.shift(),g+j.shift()),f+=j.shift(),g+=j.shift(),l="C",m.push(f,g);break;case"Q":m.push(j.shift(),j.shift()),f=j.shift(),g=j.shift(),m.push(f,g);break;case"q":m.push(f+j.shift(),g+j.shift()),f+=j.shift(),g+=j.shift(),l="Q",m.push(f,g);break;case"T":var n=f,o=g,p=e[e.length-1];p.command==="Q"&&(n=f+(f-p.points[0]),o=g+(g-p.points[1])),f=j.shift(),g=j.shift(),l="Q",m.push(n,o,f,g);break;case"t":var n=f,o=g,p=e[e.length-1];p.command==="Q"&&(n=f+(f-p.points[0]),o=g+(g-p.points[1])),f+=j.shift(),g+=j.shift(),l="Q",m.push(n,o,f,g);break;case"A":var q=j.shift(),r=j.shift(),s=j.shift(),t=j.shift(),u=j.shift(),v=f,w=g;f=j.shift(),g=j.shift(),l="A",m=this._convertEndpointToCenterParameterization(v,w,f,g,t,u,q,r,s);break;case"a":var q=j.shift(),r=j.shift(),s=j.shift(),t=j.shift(),u=j.shift(),v=f,w=g;f+=j.shift(),g+=j.shift(),l="A",m=this._convertEndpointToCenterParameterization(v,w,f,g,t,u,q,r,s)}e.push({command:l||i,points:m})}(i==="z"||i==="Z")&&e.push({command:"z",points:[]})}return e},_convertEndpointToCenterParameterization:function(a,b,c,d,e,f,g,h,i){var j=i*(Math.PI/180),k=Math.cos(j)*(a-c)/2+Math.sin(j)*(b-d)/2,l=-1*Math.sin(j)*(a-c)/2+Math.cos(j)*(b-d)/2,m=k*k/(g*g)+l*l/(h*h);m>1&&(g*=Math.sqrt(m),h*=Math.sqrt(m));var n=Math.sqrt((g*g*h*h-g*g*l*l-h*h*k*k)/(g*g*l*l+h*h*k*k));e==f&&(n*=-1),isNaN(n)&&(n=0);var o=n*g*l/h,p=n*-h*k/g,q=(a+c)/2+Math.cos(j)*o-Math.sin(j)*p,r=(b+d)/2+Math.sin(j)*o+Math.cos(j)*p,s=function(a){return Math.sqrt(a[0]*a[0]+a[1]*a[1])},t=function(a,b){return(a[0]*b[0]+a[1]*b[1])/(s(a)*s(b))},u=function(a,b){return(a[0]*b[1]=1&&(y=0),f==0&&y>0&&(y-=2*Math.PI),f==1&&y<0&&(y+=2*Math.PI),[q,r,g,h,v,y,j,f]}}),Kinetic.Node.addGettersSetters(Kinetic.Path,["data"]),Kinetic.Transform=function(){this.m=[1,0,0,1,0,0]},Kinetic.Transform.prototype={translate:function(a,b){this.m[4]+=this.m[0]*a+this.m[2]*b,this.m[5]+=this.m[1]*a+this.m[3]*b},scale:function(a,b){this.m[0]*=a,this.m[1]*=a,this.m[2]*=b,this.m[3]*=b},rotate:function(a){var b=Math.cos(a),c=Math.sin(a),d=this.m[0]*b+this.m[2]*c,e=this.m[1]*b+this.m[3]*c,f=this.m[0]*-c+this.m[2]*b,g=this.m[1]*-c+this.m[3]*b;this.m[0]=d,this.m[1]=e,this.m[2]=f,this.m[3]=g},getTranslation:function(){return{x:this.m[4],y:this.m[5]}},multiply:function(a){var b=this.m[0]*a.m[0]+this.m[2]*a.m[1],c=this.m[1]*a.m[0]+this.m[3]*a.m[1],d=this.m[0]*a.m[2]+this.m[2]*a.m[3],e=this.m[1]*a.m[2]+this.m[3]*a.m[3],f=this.m[0]*a.m[4]+this.m[2]*a.m[5]+this.m[4],g=this.m[1]*a.m[4]+this.m[3]*a.m[5]+this.m[5];this.m[0]=b,this.m[1]=c,this.m[2]=d,this.m[3]=e,this.m[4]=f,this.m[5]=g},invert:function(){var a=1/(this.m[0]*this.m[3]-this.m[1]*this.m[2]),b=this.m[3]*a,c=-this.m[1]*a,d=-this.m[2]*a,e=this.m[0]*a,f=a*(this.m[2]*this.m[5]-this.m[3]*this.m[4]),g=a*(this.m[1]*this.m[4]-this.m[0]*this.m[5]);this.m[0]=b,this.m[1]=c,this.m[2]=d,this.m[3]=e,this.m[4]=f,this.m[5]=g},getMatrix:function(){return this.m}},Kinetic.Transition=function(a,b){function d(a,b,e,f){for(var g in a)g!=="duration"&&g!=="easing"&&g!=="callback"&&(Kinetic.Type._isObject(a[g])?(e[g]={},d(a[g],b[g],e[g],f)):c._add(c._getTween(b,g,a[g],e,f)))}this.node=a,this.config=b,this.tweens=[];var c=this,e={};d(b,a.attrs,e,e);var f=0;for(var g=0;g=c.tweens.length&&c.onFinished()}}},Kinetic.Transition.prototype={start:function(){for(var a=0;athis.getDuration()?this.looping?(this.rewind(a-this._duration),this.update(),this.broadcastMessage("onLooped",{target:this,type:"onLooped"})):(this._time=this._duration,this.update(),this.stop(),this.broadcastMessage("onFinished",{target:this,type:"onFinished"})):a<0?(this.rewind(),this.update()):(this._time=a,this.update())},getTime:function(){return this._time},setDuration:function(a){this._duration=a===null||a<=0?1e5:a},getDuration:function(){return this._duration},setPosition:function(a){this.prevPos=this._pos,this.propFunc(a),this._pos=a,this.broadcastMessage("onChanged",{target:this,type:"onChanged"})},getPosition:function(a){return a===undefined&&(a=this._time),this.func(a,this.begin,this._change,this._duration)},setFinish:function(a){this._change=a-this.begin},getFinish:function(){return this.begin+this._change},start:function(){this.rewind(),this.startEnterFrame(),this.broadcastMessage("onStarted",{target:this,type:"onStarted"})},rewind:function(a){this.stop(),this._time=a===undefined?0:a,this.fixTime(),this.update()},fforward:function(){this._time=this._duration,this.fixTime(),this.update()},update:function(){this.setPosition(this.getPosition(this._time))},startEnterFrame:function(){this.stopEnterFrame(),this.isPlaying=!0,this.onEnterFrame()},onEnterFrame:function(){this.isPlaying&&this.nextFrame()},nextFrame:function(){this.setTime((this.getTimer()-this._startTime)/1e3)},stop:function(){this.stopEnterFrame(),this.broadcastMessage("onStopped",{target:this,type:"onStopped"})},stopEnterFrame:function(){this.isPlaying=!1},continueTo:function(a,b){this.begin=this._pos,this.setFinish(a),this._duration!==undefined&&this.setDuration(b),this.start()},resume:function(){this.fixTime(),this.startEnterFrame(),this.broadcastMessage("onResumed",{target:this,type:"onResumed"})},yoyo:function(){this.continueTo(this.begin,this._time)},addListener:function(a){return this.removeListener(a),this._listeners.push(a)},removeListener:function(a){var b=this._listeners,c=b.length;while(c--)if(b[c]==a)return b.splice(c,1),!0;return!1},broadcastMessage:function(){var a=[];for(var b=0;b 0) { @@ -26,6 +32,8 @@ Kinetic.Container = Kinetic.Node.extend({ }, /** * add node to container + * @name add + * @methodOf Kinetic.Container.prototype * @param {Node} child */ add: function(child) { @@ -62,6 +70,8 @@ Kinetic.Container = Kinetic.Node.extend({ }, /** * remove child from container + * @name remove + * @methodOf Kinetic.Container.prototype * @param {Node} child */ remove: function(child) { @@ -104,6 +114,8 @@ Kinetic.Container = Kinetic.Node.extend({ * ex: * var node = stage.get('#foo'); // selects node with id foo * var nodes = layer.get('.bar'); // selects nodes with name bar inside layer + * @name get + * @methodOf Kinetic.Container.prototype * @param {String} selector */ get: function(selector) { @@ -136,6 +148,8 @@ Kinetic.Container = Kinetic.Node.extend({ /** * determine if node is an ancestor * of descendant + * @name isAncestorOf + * @methodOf Kinetic.Container.prototype * @param {Kinetic.Node} node */ isAncestorOf: function(node) { @@ -155,6 +169,8 @@ Kinetic.Container = Kinetic.Node.extend({ }, /** * get shapes that intersect a point + * @name getIntersections + * @methodOf Kinetic.Container.prototype * @param {Object} point */ getIntersections: function() { diff --git a/src/Group.js b/src/Group.js index 3d9d577a..7de7f3e1 100644 --- a/src/Group.js +++ b/src/Group.js @@ -1,14 +1,13 @@ /////////////////////////////////////////////////////////////////////// // Group /////////////////////////////////////////////////////////////////////// +/** + * Group constructor. Groups are used to contain shapes or other groups. + * @constructor + * @augments Kinetic.Container + * @param {Object} config + */ Kinetic.Group = Kinetic.Container.extend({ - /** - * Group constructor. Groups are used to contain shapes or other groups. - * @constructor - * @augments Kinetic.Container - * @augments Kinetic.Node - * @param {Object} config - */ init: function(config) { this.nodeType = 'Group'; diff --git a/src/Layer.js b/src/Layer.js index c296b1b4..baaa3889 100644 --- a/src/Layer.js +++ b/src/Layer.js @@ -1,15 +1,14 @@ /////////////////////////////////////////////////////////////////////// // Layer /////////////////////////////////////////////////////////////////////// +/** + * Layer constructor. Layers are tied to their own canvas element and are used + * to contain groups or shapes + * @constructor + * @augments Kinetic.Container + * @param {Object} config + */ Kinetic.Layer = Kinetic.Container.extend({ - /** - * Layer constructor. Layers are tied to their own canvas element and are used - * to contain groups or shapes - * @constructor - * @augments Kinetic.Container - * @augments Kinetic.Node - * @param {Object} config - */ init: function(config) { this.setDefaultAttrs({ throttle: 80, @@ -31,6 +30,8 @@ Kinetic.Layer = Kinetic.Container.extend({ /** * draw children nodes. this includes any groups * or shapes + * @name draw + * @methodOf Kinetic.Layer.prototype */ draw: function() { var throttle = this.attrs.throttle; @@ -63,12 +64,16 @@ Kinetic.Layer = Kinetic.Container.extend({ }, /** * set before draw function handler + * @name beforeDraw + * @methodOf Kinetic.Layer.prototype */ beforeDraw: function(func) { this.beforeDrawFunc = func; }, /** * set after draw function handler + * @name afterDraw + * @methodOf Kinetic.Layer.prototype */ afterDraw: function(func) { this.afterDrawFunc = func; @@ -78,6 +83,8 @@ Kinetic.Layer = Kinetic.Container.extend({ * a layer does not remove its children. The nodes within * the layer will be redrawn whenever the .draw() method * is used again. + * @name clear + * @methodOf Kinetic.Layer.prototype */ clear: function() { var context = this.getContext(); @@ -86,12 +93,16 @@ Kinetic.Layer = Kinetic.Container.extend({ }, /** * get layer canvas + * @name getCanvas + * @methodOf Kinetic.Layer.prototype */ getCanvas: function() { return this.canvas; }, /** * get layer context + * @name getContext + * @methodOf Kinetic.Layer.prototype */ getContext: function() { return this.context; diff --git a/src/Node.js b/src/Node.js index fd25d5f2..9d138d39 100644 --- a/src/Node.js +++ b/src/Node.js @@ -1,14 +1,14 @@ /////////////////////////////////////////////////////////////////////// // Node /////////////////////////////////////////////////////////////////////// +/** + * Node constructor.  Nodes are entities that can be transformed, layered, + * and have events bound to them. They are the building blocks of a KineticJS + * application + * @constructor + * @param {Object} config + */ Kinetic.Node = Kinetic.Class.extend({ - /** - * Node constructor.  Nodes are entities that can be transformed, layered, - * and have events bound to them. They are the building blocks of a KineticJS - * application - * @constructor - * @param {Object} config - */ init: function(config) { this.defaultNodeAttrs = { visible: true, @@ -70,6 +70,8 @@ Kinetic.Node = Kinetic.Class.extend({ * of event types delimmited by a space to bind multiple events at once * such as 'mousedown mouseup mousemove'. include a namespace to bind an * event by name such as 'click.foobar'. + * @name on + * @methodOf Kinetic.Node.prototype * @param {String} typesStr * @param {Function} handler */ @@ -103,6 +105,8 @@ Kinetic.Node = Kinetic.Class.extend({ * bindings at once such as 'mousedown mouseup mousemove'. * include a namespace to remove an event binding by name * such as 'click.foobar'. + * @name off + * @methodOf Kinetic.Node.prototype * @param {String} typesStr */ off: function(typesStr) { @@ -136,12 +140,16 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * get attrs + * @name getAttrs + * @methodOf Kinetic.Node.prototype */ getAttrs: function() { return this.attrs; }, /** * set default attrs + * @name setDefaultAttrs + * @methodOf Kinetic.Node.prototype * @param {Object} confic */ setDefaultAttrs: function(config) { @@ -167,6 +175,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * set attrs + * @name setAttrs + * @methodOf Kinetic.Node.prototype * @param {Object} config */ setAttrs: function(config) { @@ -259,6 +269,8 @@ Kinetic.Node = Kinetic.Class.extend({ * determine if shape is visible or not. Shape is visible only * if it's visible and all of its ancestors are visible. If one ancestor * is invisible, this means that the shape is also invisible + * @name isVisible + * @methodOf Kinetic.Node.prototype */ isVisible: function() { if(this.attrs.visible && this.getParent() && !this.getParent().isVisible()) { @@ -268,6 +280,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * show node + * @name show + * @methodOf Kinetic.Node.prototype */ show: function() { this.setAttrs({ @@ -276,6 +290,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * hide node + * @name hide + * @methodOf Kinetic.Node.prototype */ hide: function() { this.setAttrs({ @@ -284,6 +300,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * get zIndex + * @name getZIndex + * @methodOf Kinetic.Node.prototype */ getZIndex: function() { return this.index; @@ -291,6 +309,8 @@ Kinetic.Node = Kinetic.Class.extend({ /** * get absolute z-index by taking into account * all parent and sibling indices + * @name getAbsoluteZIndex + * @methodOf Kinetic.Node.prototype */ getAbsoluteZIndex: function() { var level = this.getLevel(); @@ -324,6 +344,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * get node level in node tree + * @name getLevel + * @methodOf Kinetic.Node.prototype */ getLevel: function() { var level = 0; @@ -336,6 +358,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * set node position + * @name setPosition + * @methodOf Kinetic.Node.prototype * @param {Object} point */ setPosition: function() { @@ -344,6 +368,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * get node position relative to container + * @name getPosition + * @methodOf Kinetic.Node.prototype */ getPosition: function() { return { @@ -353,12 +379,16 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * get absolute position relative to stage + * @name getAbsolutePosition + * @methodOf Kinetic.Node.prototype */ getAbsolutePosition: function() { return this.getAbsoluteTransform().getTranslation(); }, /** * set absolute position relative to stage + * @name setAbsolutePosition + * @methodOf Kinetic.Node.prototype * @param {Object} pos object containing an x and * y property */ @@ -404,6 +434,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * move node by an amount + * @name move + * @methodOf Kinetic.Node.prototype */ move: function() { var pos = Kinetic.Type._getXY(Array.prototype.slice.call(arguments)); @@ -426,12 +458,16 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * get rotation in degrees + * @name getRotationDeg + * @methodOf Kinetic.Node.prototype */ getRotationDeg: function() { return this.attrs.rotation * 180 / Math.PI; }, /** * rotate node by an amount in radians + * @name rotate + * @methodOf Kinetic.Node.prototype * @param {Number} theta */ rotate: function(theta) { @@ -441,6 +477,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * rotate node by an amount in degrees + * @name rotateDeg + * @methodOf Kinetic.Node.prototype * @param {Number} deg */ rotateDeg: function(deg) { @@ -450,6 +488,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * move node to top + * @name moveToTop + * @methodOf Kinetic.Node.prototype */ moveToTop: function() { var index = this.index; @@ -459,6 +499,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * move node up + * @name moveUp + * @methodOf Kinetic.Node.prototype */ moveUp: function() { var index = this.index; @@ -468,6 +510,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * move node down + * @name moveDown + * @methodOf Kinetic.Node.prototype */ moveDown: function() { var index = this.index; @@ -479,6 +523,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * move node to bottom + * @name moveToBottom + * @methodOf Kinetic.Node.prototype */ moveToBottom: function() { var index = this.index; @@ -488,6 +534,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * set zIndex + * @name setZIndex + * @methodOf Kinetic.Node.prototype * @param {int} zIndex */ setZIndex: function(zIndex) { @@ -498,6 +546,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * get absolute alpha + * @name getAbsoluteAlpha + * @methodOf Kinetic.Node.prototype */ getAbsoluteAlpha: function() { var absAlpha = 1; @@ -511,6 +561,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * determine if node is currently in drag and drop mode + * @name isDragging + * @methodOf Kinetic.Node.prototype */ isDragging: function() { var go = Kinetic.Global; @@ -518,6 +570,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * move node to another container + * @name moveTo + * @methodOf Kinetic.Node.prototype * @param {Container} newContainer */ moveTo: function(newContainer) { @@ -534,12 +588,16 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * get parent container + * @name getParent + * @methodOf Kinetic.Node.prototype */ getParent: function() { return this.parent; }, /** - * get layer associated to node + * get layer that contains the node + * @name getLayer + * @methodOf Kinetic.Node.prototype */ getLayer: function() { if(this.nodeType === 'Layer') { @@ -550,7 +608,9 @@ Kinetic.Node = Kinetic.Class.extend({ } }, /** - * get stage associated to node + * get stage that contains the node + * @name getStage + * @methodOf Kinetic.Node.prototype */ getStage: function() { if(this.nodeType !== 'Stage' && this.getParent()) { @@ -565,6 +625,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * simulate event + * @name simulate + * @methodOf Kinetic.Node.prototype * @param {String} eventType */ simulate: function(eventType) { @@ -574,6 +636,8 @@ Kinetic.Node = Kinetic.Class.extend({ * transition node to another state. Any property that can accept a real * number can be transitioned, including x, y, rotation, alpha, strokeWidth, * radius, scale.x, scale.y, offset.x, offset.y, etc. + * @name transitionTo + * @methodOf Kinetic.Node.prototype * @param {Object} config * @config {Number} [duration] duration that the transition runs in seconds * @config {String} [easing] easing function. can be linear, ease-in, ease-out, ease-in-out, @@ -641,6 +705,8 @@ Kinetic.Node = Kinetic.Class.extend({ /** * get transform of the node while taking into * account the transforms of its parents + * @name getAbsoluteTransform + * @methodOf Kinetic.Node.prototype */ getAbsoluteTransform: function() { // absolute transform @@ -667,6 +733,8 @@ Kinetic.Node = Kinetic.Class.extend({ /** * get transform of the node while not taking * into account the transforms of its parents + * @name getTransform + * @methodOf Kinetic.Node.prototype */ getTransform: function() { var m = new Kinetic.Transform(); @@ -685,6 +753,8 @@ Kinetic.Node = Kinetic.Class.extend({ }, /** * clone node + * @name clone + * @methodOf Kinetic.Node.prototype * @param {Object} config used to override cloned * attrs */ diff --git a/src/Shape.js b/src/Shape.js index 335ecd78..f59828b7 100644 --- a/src/Shape.js +++ b/src/Shape.js @@ -1,23 +1,23 @@ /////////////////////////////////////////////////////////////////////// // Shape /////////////////////////////////////////////////////////////////////// +/** + * Shape constructor. Shapes are used to objectify drawing bits of a KineticJS + * application + * @constructor + * @augments Kinetic.Node + * @param {Object} config + * @config {String|Object} [fill] can be a string color, a linear gradient object, a radial + * gradient object, or a pattern object. + * @config {String} [stroke] stroke color + * @config {Number} [strokeWidth] stroke width + * @config {String} [lineJoin] line join can be "miter", "round", or "bevel". The default + * is "miter" + * @config {Object} [shadow] shadow object + * @config {String} [detectionType] shape detection type. Can be "path" or "pixel". + * The default is "path" because it performs better + */ Kinetic.Shape = Kinetic.Node.extend({ - /** - * Shape constructor. Shapes are used to objectify drawing bits of a KineticJS - * application - * @constructor - * @augments Kinetic.Node - * @param {Object} config - * @config {String|Object} [fill] can be a string color, a linear gradient object, a radial - * gradient object, or a pattern object. - * @config {String} [stroke] stroke color - * @config {Number} [strokeWidth] stroke width - * @config {String} [lineJoin] line join can be "miter", "round", or "bevel". The default - * is "miter" - * @config {Object} [shadow] shadow object - * @config {String} [detectionType] shape detection type. Can be "path" or "pixel". - * The default is "path" because it performs better - */ init: function(config) { this.setDefaultAttrs({ detectionType: 'path' @@ -36,12 +36,16 @@ Kinetic.Shape = Kinetic.Node.extend({ * user created layer that contains the shape. When the event detection * engine is determining whether or not an event has occured on that shape, * .getContext() returns the context of the invisible path layer. + * @name getContext + * @methodOf Kinetic.Shape.prototype */ getContext: function() { return this.tempLayer.getContext(); }, /** * get shape temp layer canvas + * @name getCanvas + * @methodOf Kinetic.Shape.prototype */ getCanvas: function() { return this.tempLayer.getCanvas(); @@ -49,6 +53,8 @@ Kinetic.Shape = Kinetic.Node.extend({ /** * helper method to stroke the shape and apply * shadows if needed + * @name stroke + * @methodOf Kinetic.Shape.prototype */ stroke: function() { var go = Kinetic.Global; @@ -77,6 +83,8 @@ Kinetic.Shape = Kinetic.Node.extend({ /** * helper method to fill the shape with a color, linear gradient, * radial gradient, or pattern, and also apply shadows if needed + * @name fill + * @methodOf Kinetic.Shape.prototype * */ fill: function() { var appliedShadow = false; @@ -161,6 +169,8 @@ Kinetic.Shape = Kinetic.Node.extend({ /** * helper method to fill text and appy shadows if needed * @param {String} text + * @name fillText + * @methodOf Kinetic.Shape.prototype */ fillText: function(text) { var appliedShadow = false; @@ -182,9 +192,9 @@ Kinetic.Shape = Kinetic.Node.extend({ /** * helper method to stroke text and apply shadows * if needed + * @name strokeText + * @methodOf Kinetic.Shape.prototype * @param {String} text - * @param {Number} x - * @param {Number} y */ strokeText: function(text) { var appliedShadow = false; @@ -215,6 +225,8 @@ Kinetic.Shape = Kinetic.Node.extend({ /** * helper method to draw an image and apply * a shadow if neede + * @name drawImage + * @methodOf Kinetic.Shape.prototype */ drawImage: function() { var appliedShadow = false; @@ -245,6 +257,8 @@ Kinetic.Shape = Kinetic.Node.extend({ /** * helper method to set the line join of a shape * based on the lineJoin property + * @name applyLineJoin + * @methodOf Kinetic.Shape.prototype */ applyLineJoin: function() { var context = this.getContext(); diff --git a/src/Stage.js b/src/Stage.js index 38c52b80..c255fb1b 100644 --- a/src/Stage.js +++ b/src/Stage.js @@ -1,17 +1,17 @@ /////////////////////////////////////////////////////////////////////// // Stage /////////////////////////////////////////////////////////////////////// +/** + * Stage constructor. A stage is used to contain multiple layers and handle + * animations + * @constructor + * @augments Kinetic.Container + * @augments Kinetic.Node + * @param {String|DomElement} cont Container id or DOM element + * @param {int} width + * @param {int} height + */ Kinetic.Stage = Kinetic.Container.extend({ - /** - * Stage constructor. A stage is used to contain multiple layers and handle - * animations - * @constructor - * @augments Kinetic.Container - * @augments Kinetic.Node - * @param {String|DomElement} cont Container id or DOM element - * @param {int} width - * @param {int} height - */ init: function(config) { this.setDefaultAttrs({ width: 400, @@ -50,6 +50,8 @@ Kinetic.Stage = Kinetic.Container.extend({ }, /** * sets onFrameFunc for animation + * @name onFrame + * @methodOf Kinetic.Stage.prototype * @param {function} func */ onFrame: function(func) { @@ -59,6 +61,8 @@ Kinetic.Stage = Kinetic.Container.extend({ }, /** * start animation + * @name start + * @methodOf Kinetic.Stage.prototype */ start: function() { if(!this.animRunning) { @@ -70,6 +74,8 @@ Kinetic.Stage = Kinetic.Container.extend({ }, /** * stop animation + * @name stop + * @methodOf Kinetic.Stage.prototype */ stop: function() { Kinetic.Animation._removeAnimation(this.anim); @@ -77,12 +83,16 @@ Kinetic.Stage = Kinetic.Container.extend({ }, /** * draw children + * @name draw + * @methodOf Kinetic.Stage.prototype */ draw: function() { this._drawChildren(); }, /** * set stage size + * @name setSize + * @methodOf Kinetic.Stage.prototype */ setSize: function() { // set stage dimensions @@ -91,6 +101,8 @@ Kinetic.Stage = Kinetic.Container.extend({ }, /** * return stage size + * @name getSize + * @methodOf Kinetic.Stage.prototype */ getSize: function() { return { @@ -100,6 +112,8 @@ Kinetic.Stage = Kinetic.Container.extend({ }, /** * clear all layers + * @name clear + * @methodOf Kinetic.Stage.prototype */ clear: function() { var layers = this.children; @@ -111,6 +125,8 @@ Kinetic.Stage = Kinetic.Container.extend({ * Creates a composite data URL and passes it to a callback. If MIME type is not * specified, then "image/png" will result. For "image/jpeg", specify a quality * level as quality (range 0.0 - 1.0) + * @name toDataURL + * @methodOf Kinetic.Stage.prototype * @param {function} callback * @param {String} mimeType (optional) * @param {Number} quality (optional) @@ -149,6 +165,8 @@ Kinetic.Stage = Kinetic.Container.extend({ }, /** * serialize stage and children as a JSON object + * @name toJSON + * @methodOf Kinetic.Stage.prototype */ toJSON: function() { var type = Kinetic.Type; @@ -185,6 +203,8 @@ Kinetic.Stage = Kinetic.Container.extend({ }, /** * reset stage to default state + * @name reset + * @methodOf Kinetic.Stage.prototype */ reset: function() { // remove children @@ -201,6 +221,8 @@ Kinetic.Stage = Kinetic.Container.extend({ * event handlers (it probably does), then you need to select the appropriate * shapes after loading the stage and set these properties via on(), setDrawFunc(), * and setImage() + * @name load + * @methodOf Kinetic.Stage.prototype * @param {String} JSON string */ load: function(json) { @@ -244,6 +266,8 @@ Kinetic.Stage = Kinetic.Container.extend({ }, /** * get mouse position for desktop apps + * @name getMousePosition + * @methodOf Kinetic.Stage.prototype * @param {Event} evt */ getMousePosition: function(evt) { @@ -251,6 +275,8 @@ Kinetic.Stage = Kinetic.Container.extend({ }, /** * get touch position for mobile apps + * @name getTouchPosition + * @methodOf Kinetic.Stage.prototype * @param {Event} evt */ getTouchPosition: function(evt) { @@ -258,6 +284,8 @@ Kinetic.Stage = Kinetic.Container.extend({ }, /** * get user position (mouse position or touch position) + * @name getUserPosition + * @methodOf Kinetic.Stage.prototype * @param {Event} evt */ getUserPosition: function(evt) { @@ -265,18 +293,16 @@ Kinetic.Stage = Kinetic.Container.extend({ }, /** * get container DOM element + * @name getContainer + * @methodOf Kinetic.Stage.prototype */ getContainer: function() { return this.attrs.container; }, - /** - * get content DOM element - */ - getContent: function() { - return this.content; - }, /** * get stage + * @name getStage + * @methodOf Kinetic.Stage.prototype */ getStage: function() { return this; @@ -284,6 +310,8 @@ Kinetic.Stage = Kinetic.Container.extend({ /** * get stage DOM node, which is a div element * with the class name "kineticjs-content" + * @name getDOM + * @methodOf Kinetic.Stage.prototype */ getDOM: function() { return this.content; diff --git a/src/Transition.js b/src/Transition.js index a2e7efc6..9f04f8bd 100644 --- a/src/Transition.js +++ b/src/Transition.js @@ -48,6 +48,8 @@ Kinetic.Transition = function(node, config) { Kinetic.Transition.prototype = { /** * start transition + * @name start + * @methodOf Kinetic.Transition.prototype */ start: function() { for(var n = 0; n < this.tweens.length; n++) { @@ -56,6 +58,8 @@ Kinetic.Transition.prototype = { }, /** * stop transition + * @name stop + * @methodOf Kinetic.Transition.prototype */ stop: function() { for(var n = 0; n < this.tweens.length; n++) { @@ -64,6 +68,8 @@ Kinetic.Transition.prototype = { }, /** * resume transition + * @name resume + * @methodOf Kinetic.Transition.prototype */ resume: function() { for(var n = 0; n < this.tweens.length; n++) { diff --git a/src/shapes/Ellipse.js b/src/shapes/Ellipse.js index 891526fd..1dc385b9 100644 --- a/src/shapes/Ellipse.js +++ b/src/shapes/Ellipse.js @@ -1,13 +1,13 @@ /////////////////////////////////////////////////////////////////////// // Ellipse /////////////////////////////////////////////////////////////////////// +/** + * Ellipse constructor + * @constructor + * @augments Kinetic.Shape + * @param {Object} config + */ Kinetic.Ellipse = Kinetic.Shape.extend({ - /** - * Ellipse constructor - * @constructor - * @augments Kinetic.Shape - * @param {Object} config - */ init: function(config) { this.setDefaultAttrs({ radius: { @@ -70,6 +70,8 @@ Kinetic.Node.addGettersSetters(Kinetic.Ellipse, ['radius']); /** * set radius + * @name setRadius + * @methodOf Kinetic.Ellipse.prototype * @param {Number|Object|Array} radius * radius can be a number, in which the ellipse becomes a circle, * it can be an object with an x and y component, or it diff --git a/src/shapes/Image.js b/src/shapes/Image.js index ef267bb6..0a26022d 100644 --- a/src/shapes/Image.js +++ b/src/shapes/Image.js @@ -1,13 +1,13 @@ /////////////////////////////////////////////////////////////////////// // Image /////////////////////////////////////////////////////////////////////// +/** + * Image constructor + * @constructor + * @augments Kinetic.Shape + * @param {Object} config + */ Kinetic.Image = Kinetic.Shape.extend({ - /** - * Image constructor - * @constructor - * @augments Kinetic.Shape - * @param {Object} config - */ init: function(config) { this.shapeType = "Image"; config.drawFunc = function() { @@ -42,6 +42,8 @@ Kinetic.Image = Kinetic.Shape.extend({ }, /** * set width and height + * @name setSize + * @methodOf Kinetic.Image.prototype */ setSize: function() { var size = Kinetic.GlobalObject._getSize(Array.prototype.slice.call(arguments)); @@ -49,6 +51,8 @@ Kinetic.Image = Kinetic.Shape.extend({ }, /** * return image size + * @name getSize + * @methodOf Kinetic.Image.prototype */ getSize: function() { return { diff --git a/src/shapes/Line.js b/src/shapes/Line.js index d16ebe03..a01ffc57 100644 --- a/src/shapes/Line.js +++ b/src/shapes/Line.js @@ -1,13 +1,13 @@ /////////////////////////////////////////////////////////////////////// // Line /////////////////////////////////////////////////////////////////////// +/** + * Line constructor.  Lines are defined by an array of points + * @constructor + * @augments Kinetic.Shape + * @param {Object} config + */ Kinetic.Line = Kinetic.Shape.extend({ - /** - * Line constructor.  Lines are defined by an array of points - * @constructor - * @augments Kinetic.Shape - * @param {Object} config - */ init: function(config) { this.setDefaultAttrs({ points: [], diff --git a/src/shapes/Path.js b/src/shapes/Path.js index f0c46f62..4fcf9c89 100644 --- a/src/shapes/Path.js +++ b/src/shapes/Path.js @@ -1,14 +1,14 @@ /////////////////////////////////////////////////////////////////////// // SVG Path /////////////////////////////////////////////////////////////////////// +/** + * Path constructor. + * @author Jason Follas + * @constructor + * @augments Kinetic.Shape + * @param {Object} config + */ Kinetic.Path = Kinetic.Shape.extend({ - /** - * Path constructor. - * @author Jason Follas - * @constructor - * @augments Kinetic.Shape - * @param {Object} config - */ init: function(config) { this.shapeType = "Path"; this.dataArray = []; @@ -62,10 +62,10 @@ Kinetic.Path = Kinetic.Shape.extend({ // call super constructor this._super(config); - this.dataArray = this.getDataArray(); + this.dataArray = this._getDataArray(); this.on('dataChange', function() { - that.dataArray = that.getDataArray(); + that.dataArray = that._getDataArray(); }); }, /** @@ -74,7 +74,7 @@ Kinetic.Path = Kinetic.Shape.extend({ * L data for the purpose of high performance Path * rendering */ - getDataArray: function() { + _getDataArray: function() { // Path Data Segment must begin with a moveTo //m (x y)+ Relative moveTo (subsequent points are treated as lineTo) diff --git a/src/shapes/Polygon.js b/src/shapes/Polygon.js index 3969ead6..f6cd3436 100644 --- a/src/shapes/Polygon.js +++ b/src/shapes/Polygon.js @@ -1,13 +1,13 @@ /////////////////////////////////////////////////////////////////////// // Polygon /////////////////////////////////////////////////////////////////////// +/** + * Polygon constructor.  Polygons are defined by an array of points + * @constructor + * @augments Kinetic.Shape + * @param {Object} config + */ Kinetic.Polygon = Kinetic.Shape.extend({ - /** - * Polygon constructor.  Polygons are defined by an array of points - * @constructor - * @augments Kinetic.Shape - * @param {Object} config - */ init: function(config) { this.setDefaultAttrs({ points: [] diff --git a/src/shapes/Rect.js b/src/shapes/Rect.js index b09cb8f5..dbcb4a5f 100644 --- a/src/shapes/Rect.js +++ b/src/shapes/Rect.js @@ -1,13 +1,13 @@ /////////////////////////////////////////////////////////////////////// // Rect /////////////////////////////////////////////////////////////////////// +/** + * Rect constructor + * @constructor + * @augments Kinetic.Shape + * @param {Object} config + */ Kinetic.Rect = Kinetic.Shape.extend({ - /** - * Rect constructor - * @constructor - * @augments Kinetic.Shape - * @param {Object} config - */ init: function(config) { this.setDefaultAttrs({ width: 0, @@ -46,6 +46,8 @@ Kinetic.Rect = Kinetic.Shape.extend({ }, /** * set width and height + * @name setSize + * @methodOf Kinetic.Rect.prototype */ setSize: function() { var size = Kinetic.Type._getSize(Array.prototype.slice.call(arguments)); @@ -53,6 +55,8 @@ Kinetic.Rect = Kinetic.Shape.extend({ }, /** * return rect size + * @name getSize + * @methodOf Kinetic.Rect.prototype */ getSize: function() { return { diff --git a/src/shapes/RegularPolygon.js b/src/shapes/RegularPolygon.js index 6d1ec168..d9083a62 100644 --- a/src/shapes/RegularPolygon.js +++ b/src/shapes/RegularPolygon.js @@ -1,13 +1,13 @@ /////////////////////////////////////////////////////////////////////// // RegularPolygon /////////////////////////////////////////////////////////////////////// +/** + * RegularPolygon constructor.  Examples include triangles, squares, pentagons, hexagons, etc. + * @constructor + * @augments Kinetic.Shape + * @param {Object} config + */ Kinetic.RegularPolygon = Kinetic.Shape.extend({ - /** - * RegularPolygon constructor.  Examples include triangles, squares, pentagons, hexagons, etc. - * @constructor - * @augments Kinetic.Shape - * @param {Object} config - */ init: function(config) { this.setDefaultAttrs({ radius: 0, diff --git a/src/shapes/Sprite.js b/src/shapes/Sprite.js index 910b55b7..b17e3f55 100644 --- a/src/shapes/Sprite.js +++ b/src/shapes/Sprite.js @@ -1,13 +1,13 @@ /////////////////////////////////////////////////////////////////////// // Sprite /////////////////////////////////////////////////////////////////////// +/** + * Sprite constructor + * @constructor + * @augments Kinetic.Shape + * @param {Object} config + */ Kinetic.Sprite = Kinetic.Shape.extend({ - /** - * Sprite constructor - * @constructor - * @augments Kinetic.Shape - * @param {Object} config - */ init: function(config) { this.setDefaultAttrs({ index: 0, @@ -39,6 +39,8 @@ Kinetic.Sprite = Kinetic.Shape.extend({ }, /** * start sprite animation + * @name start + * @methodOf Kinetic.Sprite.prototype */ start: function() { var that = this; @@ -68,7 +70,7 @@ Kinetic.Sprite = Kinetic.Shape.extend({ ka._addAnimation(this.anim); this.interval = setInterval(function() { - var index = that.attrs.index; + var index = that.attrs.index; that._updateIndex(); if(that.afterFrameFunc && index === that.afterFrameIndex) { that.afterFrameFunc(); @@ -79,6 +81,8 @@ Kinetic.Sprite = Kinetic.Shape.extend({ }, /** * stop sprite animation + * @name stop + * @methodOf Kinetic.Sprite.prototype */ stop: function() { var ka = Kinetic.Animation; @@ -90,6 +94,8 @@ Kinetic.Sprite = Kinetic.Shape.extend({ }, /** * set after frame event handler + * @name afterFrame + * @methodOf Kinetic.Sprite.prototype * @param {Integer} index frame index * @param {Function} func function to be executed after frame has been drawn */ diff --git a/src/shapes/Star.js b/src/shapes/Star.js index 74cc1b51..a32c6129 100644 --- a/src/shapes/Star.js +++ b/src/shapes/Star.js @@ -1,13 +1,13 @@ /////////////////////////////////////////////////////////////////////// // Star /////////////////////////////////////////////////////////////////////// +/** + * Star constructor + * @constructor + * @augments Kinetic.Shape + * @param {Object} config + */ Kinetic.Star = Kinetic.Shape.extend({ - /** - * Star constructor - * @constructor - * @augments Kinetic.Shape - * @param {Object} config - */ init: function(config) { this.setDefaultAttrs({ numPoints: 0, diff --git a/src/shapes/Text.js b/src/shapes/Text.js index 7468cb1f..0be98b80 100644 --- a/src/shapes/Text.js +++ b/src/shapes/Text.js @@ -104,30 +104,38 @@ Kinetic.Text = Kinetic.Shape.extend({ that._setTextData(); }, - /** - * get text width in pixels - */ - getTextWidth: function() { - return this.textWidth; - }, - /** - * get text height in pixels - */ - getTextHeight: function() { - return this.textHeight; - }, /** * get box width + * @name getBoxWidth + * @methodOf Kinetic.Text.prototype */ getBoxWidth: function() { return this.attrs.width === 'auto' ? this.getTextWidth() + this.attrs.padding * 2 : this.attrs.width; }, /** * get box height + * @name getBoxHeight + * @methodOf Kinetic.Text.prototype */ getBoxHeight: function() { return this.attrs.height === 'auto' ? (this.getTextHeight() * this.textArr.length * this.attrs.lineHeight) + this.attrs.padding * 2 : this.attrs.height; }, + /** + * get text width in pixels + * @name getTextWidth + * @methodOf Kinetic.Text.prototype + */ + getTextWidth: function() { + return this.textWidth; + }, + /** + * get text height in pixels + * @name getTextHeight + * @methodOf Kinetic.Text.prototype + */ + getTextHeight: function() { + return this.textHeight; + }, _getTextSize: function(text) { var dummyCanvas = this.dummyCanvas; var context = dummyCanvas.getContext('2d'); diff --git a/src/util/Transform.js b/src/util/Transform.js index 0f2ed749..ad6c9ad9 100644 --- a/src/util/Transform.js +++ b/src/util/Transform.js @@ -17,9 +17,7 @@ * class. */ -/** - * Matrix object - */ + Kinetic.Transform = function() { this.m = [1, 0, 0, 1, 0, 0]; } diff --git a/src/util/Tween.js b/src/util/Tween.js index 09a5d5ae..fc942828 100644 --- a/src/util/Tween.js +++ b/src/util/Tween.js @@ -7,9 +7,6 @@ * an animation of a single Node property. A Transition is a set of * multiple tweens */ -/** - * Tween constructor - */ Kinetic.Tween = function(obj, propFunc, func, begin, finish, duration) { this._listeners = []; this.addListener(this); diff --git a/tests/js/unitTests.js b/tests/js/unitTests.js index 9ad160c4..5e91fef2 100644 --- a/tests/js/unitTests.js +++ b/tests/js/unitTests.js @@ -1440,12 +1440,12 @@ Test.prototype.tests = { stage.add(layer); test(path.getData() === 'M200,100h100v50z', 'data are incorrect'); - test(path.getDataArray().length === 4, 'data array should have 4 elements'); + test(path._getDataArray().length === 4, 'data array should have 4 elements'); path.setData('M200'); test(path.getData() === 'M200', 'data are incorrect'); - test(path.getDataArray().length === 1, 'data array should have 1 element'); + test(path._getDataArray().length === 1, 'data array should have 1 element'); path.setData('M200,100h100v50z'); @@ -1490,9 +1490,9 @@ Test.prototype.tests = { stage.add(layer); test(path.getData() === 'm200,100,100,0,0,50,z', 'data are incorrect'); - test(path.getDataArray().length === 4, 'data array should have 4 elements'); + test(path._getDataArray().length === 4, 'data array should have 4 elements'); - test(path.getDataArray()[1].command === 'L', 'second command should be an implied lineTo'); + test(path._getDataArray()[1].command === 'L', 'second command should be an implied lineTo'); }, 'SHAPE - add map path': function(containerId) { var stage = new Kinetic.Stage({ @@ -1517,7 +1517,7 @@ Test.prototype.tests = { }); if(key === 'US') - test(path.getDataArray()[0].command === 'M', 'first command should be a moveTo'); + test(path._getDataArray()[0].command === 'M', 'first command should be a moveTo'); path.on('mouseover', function() { this.setFill('red'); @@ -3009,13 +3009,13 @@ Test.prototype.tests = { layer.add(text); stage.add(layer); - + /* - text.transitionTo({ - width: 500, - duration: 10 - }); - */ + text.transitionTo({ + width: 500, + duration: 10 + }); + */ }, 'SHAPE - get shape name': function(containerId) { var stage = new Kinetic.Stage({