mirror of
https://github.com/konvajs/konva.git
synced 2025-09-23 20:53:42 +08:00
removed createAttrs method and cleaned up init logic
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
Kinetic.Util.addMethods(Kinetic.Group, {
|
Kinetic.Util.addMethods(Kinetic.Group, {
|
||||||
___init: function(config) {
|
___init: function(config) {
|
||||||
this.nodeType = 'Group';
|
this.nodeType = 'Group';
|
||||||
this.createAttrs();
|
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Container.call(this, config);
|
Kinetic.Container.call(this, config);
|
||||||
}
|
}
|
||||||
|
@@ -5,7 +5,6 @@
|
|||||||
Kinetic.Util.addMethods(Kinetic.Layer, {
|
Kinetic.Util.addMethods(Kinetic.Layer, {
|
||||||
___init: function(config) {
|
___init: function(config) {
|
||||||
this.nodeType = 'Layer';
|
this.nodeType = 'Layer';
|
||||||
this.createAttrs();
|
|
||||||
this.canvas = new Kinetic.SceneCanvas();
|
this.canvas = new Kinetic.SceneCanvas();
|
||||||
this.hitCanvas = new Kinetic.HitCanvas();
|
this.hitCanvas = new Kinetic.HitCanvas();
|
||||||
// call super constructor
|
// call super constructor
|
||||||
|
@@ -37,6 +37,7 @@
|
|||||||
_init: function(config) {
|
_init: function(config) {
|
||||||
this._id = Kinetic.Global.idCounter++;
|
this._id = Kinetic.Global.idCounter++;
|
||||||
this.eventListeners = {};
|
this.eventListeners = {};
|
||||||
|
this.attrs = {};
|
||||||
this.setAttrs(config);
|
this.setAttrs(config);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
@@ -238,13 +239,6 @@
|
|||||||
getAttrs: function() {
|
getAttrs: function() {
|
||||||
return this.attrs || {};
|
return this.attrs || {};
|
||||||
},
|
},
|
||||||
createAttrs: function() {
|
|
||||||
if(this.attrs === undefined) {
|
|
||||||
this.attrs = {};
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set multiple attrs at once using an object literal
|
* set multiple attrs at once using an object literal
|
||||||
* @method
|
* @method
|
||||||
|
@@ -37,7 +37,6 @@
|
|||||||
this.colorKey = key;
|
this.colorKey = key;
|
||||||
shapes[key] = this;
|
shapes[key] = this;
|
||||||
|
|
||||||
this.createAttrs();
|
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Node.call(this, config);
|
Kinetic.Node.call(this, config);
|
||||||
|
|
||||||
|
@@ -38,7 +38,6 @@
|
|||||||
|
|
||||||
Kinetic.Util.addMethods(Kinetic.Stage, {
|
Kinetic.Util.addMethods(Kinetic.Stage, {
|
||||||
___init: function(config) {
|
___init: function(config) {
|
||||||
this.createAttrs();
|
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Container.call(this, config);
|
Kinetic.Container.call(this, config);
|
||||||
this.nodeType = STAGE;
|
this.nodeType = STAGE;
|
||||||
|
@@ -58,7 +58,6 @@
|
|||||||
____init: function(config) {
|
____init: function(config) {
|
||||||
var that = this;
|
var that = this;
|
||||||
|
|
||||||
this.createAttrs();
|
|
||||||
this.className = LABEL;
|
this.className = LABEL;
|
||||||
Kinetic.Group.call(this, config);
|
Kinetic.Group.call(this, config);
|
||||||
|
|
||||||
@@ -173,7 +172,6 @@
|
|||||||
|
|
||||||
Kinetic.Tag.prototype = {
|
Kinetic.Tag.prototype = {
|
||||||
___init: function(config) {
|
___init: function(config) {
|
||||||
this.createAttrs();
|
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
this.className = 'Tag';
|
this.className = 'Tag';
|
||||||
},
|
},
|
||||||
|
@@ -26,8 +26,6 @@
|
|||||||
|
|
||||||
Kinetic.RegularPolygon.prototype = {
|
Kinetic.RegularPolygon.prototype = {
|
||||||
___init: function(config) {
|
___init: function(config) {
|
||||||
this.createAttrs();
|
|
||||||
|
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
this.className = 'RegularPolygon';
|
this.className = 'RegularPolygon';
|
||||||
|
@@ -28,8 +28,6 @@
|
|||||||
|
|
||||||
Kinetic.Star.prototype = {
|
Kinetic.Star.prototype = {
|
||||||
___init: function(config) {
|
___init: function(config) {
|
||||||
this.createAttrs();
|
|
||||||
|
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
this.className = 'Star';
|
this.className = 'Star';
|
||||||
|
@@ -42,8 +42,6 @@
|
|||||||
Kinetic.TextPath.prototype = {
|
Kinetic.TextPath.prototype = {
|
||||||
___init: function(config) {
|
___init: function(config) {
|
||||||
var that = this;
|
var that = this;
|
||||||
|
|
||||||
this.createAttrs();
|
|
||||||
this.dummyCanvas = document.createElement('canvas');
|
this.dummyCanvas = document.createElement('canvas');
|
||||||
this.dataArray = [];
|
this.dataArray = [];
|
||||||
|
|
||||||
|
@@ -27,7 +27,6 @@
|
|||||||
Kinetic.Blob.prototype = {
|
Kinetic.Blob.prototype = {
|
||||||
___init: function(config) {
|
___init: function(config) {
|
||||||
var that = this;
|
var that = this;
|
||||||
this.createAttrs();
|
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
this.className = 'Blob';
|
this.className = 'Blob';
|
||||||
|
@@ -37,7 +37,6 @@
|
|||||||
|
|
||||||
Kinetic.Circle.prototype = {
|
Kinetic.Circle.prototype = {
|
||||||
___init: function(config) {
|
___init: function(config) {
|
||||||
this.createAttrs();
|
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
this.className = CIRCLE;
|
this.className = CIRCLE;
|
||||||
|
@@ -18,8 +18,6 @@
|
|||||||
|
|
||||||
Kinetic.Ellipse.prototype = {
|
Kinetic.Ellipse.prototype = {
|
||||||
___init: function(config) {
|
___init: function(config) {
|
||||||
this.createAttrs();
|
|
||||||
|
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
this.className = ELLIPSE;
|
this.className = ELLIPSE;
|
||||||
|
@@ -37,8 +37,6 @@
|
|||||||
|
|
||||||
Kinetic.Line.prototype = {
|
Kinetic.Line.prototype = {
|
||||||
___init: function(config) {
|
___init: function(config) {
|
||||||
this.createAttrs();
|
|
||||||
|
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
this.className = 'Line';
|
this.className = 'Line';
|
||||||
|
@@ -23,8 +23,6 @@
|
|||||||
|
|
||||||
Kinetic.Polygon.prototype = {
|
Kinetic.Polygon.prototype = {
|
||||||
___init: function(config) {
|
___init: function(config) {
|
||||||
this.createAttrs();
|
|
||||||
|
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
this.className = 'Polygon';
|
this.className = 'Polygon';
|
||||||
|
@@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
Kinetic.Rect.prototype = {
|
Kinetic.Rect.prototype = {
|
||||||
___init: function(config) {
|
___init: function(config) {
|
||||||
this.createAttrs();
|
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
this.className = 'Rect';
|
this.className = 'Rect';
|
||||||
},
|
},
|
||||||
|
@@ -27,7 +27,6 @@
|
|||||||
Kinetic.Spline.prototype = {
|
Kinetic.Spline.prototype = {
|
||||||
___init: function(config) {
|
___init: function(config) {
|
||||||
var that = this;
|
var that = this;
|
||||||
this.createAttrs();
|
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
this.className = 'Spline';
|
this.className = 'Spline';
|
||||||
|
@@ -72,8 +72,6 @@
|
|||||||
|
|
||||||
Kinetic.Sprite.prototype = {
|
Kinetic.Sprite.prototype = {
|
||||||
___init: function(config) {
|
___init: function(config) {
|
||||||
this.createAttrs();
|
|
||||||
|
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
this.className = 'Sprite';
|
this.className = 'Sprite';
|
||||||
|
@@ -68,12 +68,13 @@
|
|||||||
Kinetic.Text.prototype = {
|
Kinetic.Text.prototype = {
|
||||||
___init: function(config) {
|
___init: function(config) {
|
||||||
var that = this;
|
var that = this;
|
||||||
this.createAttrs();
|
|
||||||
|
|
||||||
// since width and height work a bit different for Text,
|
if (config.width === undefined) {
|
||||||
// we need to default the values here
|
config.width = AUTO;
|
||||||
this.attrs.width = AUTO;
|
}
|
||||||
this.attrs.height = AUTO;
|
if (config.height === undefined) {
|
||||||
|
config.height = AUTO;
|
||||||
|
}
|
||||||
|
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
|
@@ -27,8 +27,6 @@
|
|||||||
|
|
||||||
Kinetic.Wedge.prototype = {
|
Kinetic.Wedge.prototype = {
|
||||||
___init: function(config) {
|
___init: function(config) {
|
||||||
this.createAttrs();
|
|
||||||
|
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
this.className = 'Wedge';
|
this.className = 'Wedge';
|
||||||
|
@@ -54,7 +54,7 @@ Test.Modules.Text = {
|
|||||||
group.add(text);
|
group.add(text);
|
||||||
layer.add(group);
|
layer.add(group);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
test(text.getClassName() === 'Text', 'getClassName should be Text');
|
test(text.getClassName() === 'Text', 'getClassName should be Text');
|
||||||
},
|
},
|
||||||
'text getters and setters': function(containerId) {
|
'text getters and setters': function(containerId) {
|
||||||
@@ -98,7 +98,6 @@ Test.Modules.Text = {
|
|||||||
|
|
||||||
test(text.getX() === stage.getWidth() / 2, 'text box x should be in center of stage');
|
test(text.getX() === stage.getWidth() / 2, 'text box x should be in center of stage');
|
||||||
test(text.getY() === stage.getHeight() / 2, 'text box y should be in center of stage');
|
test(text.getY() === stage.getHeight() / 2, 'text box y should be in center of stage');
|
||||||
|
|
||||||
test(text.getText() === 'Hello World!', 'text should be Hello World!');
|
test(text.getText() === 'Hello World!', 'text should be Hello World!');
|
||||||
test(text.getFontSize() == 50, 'font size should 50');
|
test(text.getFontSize() == 50, 'font size should 50');
|
||||||
test(text.getFontFamily() == 'Calibri', 'font family should be Calibri');
|
test(text.getFontFamily() == 'Calibri', 'font family should be Calibri');
|
||||||
@@ -112,7 +111,6 @@ Test.Modules.Text = {
|
|||||||
test(text.getPadding() === 10, 'padding should be 10');
|
test(text.getPadding() === 10, 'padding should be 10');
|
||||||
test(text.getShadowColor() === 'black', 'text box shadow color should be black');
|
test(text.getShadowColor() === 'black', 'text box shadow color should be black');
|
||||||
test(text.getDraggable() === true, 'text should be draggable');
|
test(text.getDraggable() === true, 'text should be draggable');
|
||||||
|
|
||||||
test(text.getWidth() === 400, 'box width should be 400');
|
test(text.getWidth() === 400, 'box width should be 400');
|
||||||
test(text.getHeight() === 100, 'box height should be 100');
|
test(text.getHeight() === 100, 'box height should be 100');
|
||||||
test(text.getTextWidth() > 0, 'text width should be greater than 0');
|
test(text.getTextWidth() > 0, 'text width should be greater than 0');
|
||||||
@@ -164,7 +162,7 @@ Test.Modules.Text = {
|
|||||||
height: 200
|
height: 200
|
||||||
});
|
});
|
||||||
var layer = new Kinetic.Layer();
|
var layer = new Kinetic.Layer();
|
||||||
|
|
||||||
var rect = new Kinetic.Rect({
|
var rect = new Kinetic.Rect({
|
||||||
x: 10,
|
x: 10,
|
||||||
y: 10,
|
y: 10,
|
||||||
@@ -204,14 +202,14 @@ Test.Modules.Text = {
|
|||||||
width: 50,
|
width: 50,
|
||||||
duration: 20
|
duration: 20
|
||||||
});
|
});
|
||||||
|
|
||||||
rect.transitionTo({
|
rect.transitionTo({
|
||||||
width: 50,
|
width: 50,
|
||||||
duration: 20
|
duration: 20
|
||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
'text multi line with shadows': function(containerId) {
|
'text multi line with shadows': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
@@ -271,15 +269,15 @@ Test.Modules.Text = {
|
|||||||
|
|
||||||
var width = text.getWidth();
|
var width = text.getWidth();
|
||||||
var height = text.getHeight();
|
var height = text.getHeight();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
layer.add(text);
|
layer.add(text);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
text.setFontSize(30);
|
text.setFontSize(30);
|
||||||
layer.draw();
|
layer.draw();
|
||||||
|
|
||||||
//console.log(text.getHeight() + ',' + height);
|
//console.log(text.getHeight() + ',' + height);
|
||||||
|
|
||||||
test(text.getWidth() > width, 'text box width should have increased.');
|
test(text.getWidth() > width, 'text box width should have increased.');
|
||||||
|
Reference in New Issue
Block a user