added Global.addMethods() method and defined core constructors in Global

This commit is contained in:
Eric Rowell
2013-05-07 23:17:57 -07:00
parent 37e49085eb
commit e2d6993c89
8 changed files with 72 additions and 57 deletions

View File

@@ -220,4 +220,24 @@
moveTo.call(this, container);
};
Kinetic.Layer.batchAnim = new Kinetic.Animation(function() {
if (this.getLayers().length === 0) {
this.stop();
}
this.setLayers([]);
});
/**
* get batch draw
* @name batchDraw
* @methodOf Kinetic.Layer.prototype
*/
Kinetic.Layer.prototype.batchDraw = function() {
var batchAnim = Kinetic.Layer.batchAnim;
batchAnim.addLayer(this);
if (!batchAnim.isRunning()) {
batchAnim.start();
}
};
})();

View File

@@ -7,11 +7,7 @@
* {{NodeParams}}
* {{ContainerParams}}
*/
Kinetic.Container = function(config) {
this._containerInit(config);
};
Kinetic.Container.prototype = {
Kinetic.Global.addMethods(Kinetic.Container, {
_containerInit: function(config) {
this.children = [];
Kinetic.Node.call(this, config);
@@ -246,7 +242,7 @@
}
}
}
};
});
Kinetic.Global.extend(Kinetic.Container, Kinetic.Node);

View File

@@ -36,8 +36,31 @@ var Kinetic = {};
* @namespace
*/
Kinetic.Filters = {};
Kinetic.DD = {};
Kinetic.Node = function(config) {
this._nodeInit(config);
};
Kinetic.Shape = function(config) {
this._initShape(config);
};
Kinetic.Container = function(config) {
this._containerInit(config);
};
Kinetic.Stage = function(config) {
this._initStage(config);
};
Kinetic.Layer = function(config) {
this._initLayer(config);
};
Kinetic.Group = function(config) {
this._initGroup(config);
};
/**
* @namespace
*/
@@ -48,6 +71,19 @@ var Kinetic = {};
names: {},
//shapes hash. rgb keys and shape values
shapes: {},
/**
* @method addMethods adds methods to a constructor prototype
* @methodOf Kinetic.Global
* @param {Function} constructor
* @param {Object} methods
*/
addMethods: function(constructor, methods) {
var key;
for (key in methods) {
constructor.prototype[key] = methods[key];
}
},
/**
* @method isDragging returns whether or not drag and drop
* is currently active

View File

@@ -7,17 +7,13 @@
* {{NodeParams}}
* {{ContainerParams}}
*/
Kinetic.Group = function(config) {
this._initGroup(config);
};
Kinetic.Group.prototype = {
Kinetic.Global.addMethods(Kinetic.Group, {
_initGroup: function(config) {
this.nodeType = 'Group';
this.createAttrs();
// call super constructor
Kinetic.Container.call(this, config);
}
};
});
Kinetic.Global.extend(Kinetic.Group, Kinetic.Container);
})();

View File

@@ -10,18 +10,7 @@
* {{NodeParams}}
* {{ContainerParams}}
*/
Kinetic.Layer = function(config) {
this._initLayer(config);
};
Kinetic.Layer.batchAnim = new Kinetic.Animation(function() {
if (this.getLayers().length === 0) {
this.stop();
}
this.setLayers([]);
});
Kinetic.Layer.prototype = {
Kinetic.Global.addMethods(Kinetic.Layer, {
_initLayer: function(config) {
this.nodeType = 'Layer';
this.createAttrs();
@@ -62,19 +51,6 @@
return null;
},
/**
* get batch draw
* @name batchDraw
* @methodOf Kinetic.Layer.prototype
*/
batchDraw: function() {
var batchAnim = Kinetic.Layer.batchAnim;
batchAnim.addLayer(this);
if (!batchAnim.isRunning()) {
batchAnim.start();
}
},
drawScene: function(canvas) {
var canvas = canvas || this.getCanvas();
@@ -208,7 +184,7 @@
stage.content.removeChild(element);
}
}
};
});
Kinetic.Global.extend(Kinetic.Layer, Kinetic.Container);
// add getters and setters

View File

@@ -40,11 +40,8 @@
* @param {Object} config
* {{NodeParams}}
*/
Kinetic.Node = function(config) {
this._nodeInit(config);
};
Kinetic.Node.prototype = {
Kinetic.Global.addMethods(Kinetic.Node, {
_nodeInit: function(config) {
this._id = Kinetic.Global.idCounter++;
this.eventListeners = {};
@@ -1007,8 +1004,8 @@
*/
draw: function() {
var evt = {
node: this
};
node: this
};
this.fire(BEFORE_DRAW, evt);
this.drawScene();
@@ -1018,7 +1015,7 @@
shouldDrawHit: function() {
return this.isVisible() && this.isListening() && !Kinetic.Global.isDragging();
}
};
});
// add getter and setter methods
Kinetic.Node.addGetterSetter = function(constructor, attr, def, isTransform) {

View File

@@ -8,9 +8,6 @@
* {{ShapeParams}}
* {{NodeParams}}
*/
Kinetic.Shape = function(config) {
this._initShape(config);
};
function _fillFunc(context) {
context.fill();
}
@@ -24,7 +21,7 @@
context.stroke();
}
Kinetic.Shape.prototype = {
Kinetic.Global.addMethods(Kinetic.Shape, {
_initShape: function(config) {
this.nodeType = 'Shape';
this._fillFunc = _fillFunc;
@@ -214,7 +211,7 @@
this.setDrawHitFunc(this.drawHitFunc);
}
}
};
});
Kinetic.Global.extend(Kinetic.Shape, Kinetic.Node);
// add getters and setters

View File

@@ -44,11 +44,8 @@
* {{NodeParams}}
* {{ContainerParams}}
*/
Kinetic.Stage = function(config) {
this._initStage(config);
};
Kinetic.Stage.prototype = {
Kinetic.Global.addMethods(Kinetic.Stage, {
_initStage: function(config) {
this.createAttrs();
// call super constructor
@@ -601,7 +598,7 @@
this.content.addEventListener(baseEvent, handler, false);
}
}
};
});
Kinetic.Global.extend(Kinetic.Stage, Kinetic.Container);
// add getters and setters