mirror of
https://github.com/konvajs/konva.git
synced 2026-03-03 16:58:33 +08:00
added Global.addMethods() method and defined core constructors in Global
This commit is contained in:
@@ -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();
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -36,7 +36,30 @@ 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
|
||||
|
||||
@@ -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);
|
||||
})();
|
||||
|
||||
28
src/Layer.js
28
src/Layer.js
@@ -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
|
||||
|
||||
@@ -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 = {};
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user