mirror of
https://github.com/konvajs/konva.git
synced 2025-10-15 12:34:52 +08:00
converting arguments object into true array for setters, restored the original underscore.js methods, and moved radius conversion logic from the setAttrs method to a radiusChange event listener in Ellipse
This commit is contained in:
@@ -140,12 +140,10 @@ Kinetic.GlobalObject = {
|
||||
return !!(obj && obj.constructor && obj.call && obj.apply);
|
||||
},
|
||||
_isArray: function(obj) {
|
||||
return obj.length !== undefined;
|
||||
//return Object.prototype.toString.call(obj) == '[object Array]';
|
||||
return Object.prototype.toString.call(obj) == '[object Array]';
|
||||
},
|
||||
_isObject: function(obj) {
|
||||
return ( typeof obj == 'object');
|
||||
//return obj === Object(obj);
|
||||
return (obj !== undefined && obj.constructor == Object);
|
||||
},
|
||||
_isNumber: function(obj) {
|
||||
return Object.prototype.toString.call(obj) == '[object Number]';
|
||||
|
25
src/Node.js
25
src/Node.js
@@ -229,21 +229,6 @@ Kinetic.Node.prototype = {
|
||||
that._setAttr(obj[key], 'x', pos.x);
|
||||
that._setAttr(obj[key], 'y', pos.y);
|
||||
break;
|
||||
case 'radius':
|
||||
/*
|
||||
* root attr radius should be an object
|
||||
* while all other radius attrs should be
|
||||
* a number
|
||||
*/
|
||||
if(level > 0) {
|
||||
that._setAttr(obj, key, val);
|
||||
}
|
||||
else {
|
||||
var pos = go._getXY(val);
|
||||
that._setAttr(obj[key], 'x', pos.x);
|
||||
that._setAttr(obj[key], 'y', pos.y);
|
||||
}
|
||||
break;
|
||||
case 'scale':
|
||||
var pos = go._getXY(val);
|
||||
that._setAttr(obj[key], 'x', pos.x);
|
||||
@@ -363,7 +348,7 @@ Kinetic.Node.prototype = {
|
||||
*/
|
||||
setScale: function() {
|
||||
this.setAttrs({
|
||||
scale: arguments
|
||||
scale: Array.prototype.slice.call(arguments)
|
||||
});
|
||||
},
|
||||
/**
|
||||
@@ -371,7 +356,7 @@ Kinetic.Node.prototype = {
|
||||
* @param {Object} point
|
||||
*/
|
||||
setPosition: function() {
|
||||
var pos = Kinetic.GlobalObject._getXY(arguments);
|
||||
var pos = Kinetic.GlobalObject._getXY(Array.prototype.slice.call(arguments));
|
||||
this.setAttrs(pos);
|
||||
},
|
||||
/**
|
||||
@@ -395,7 +380,7 @@ Kinetic.Node.prototype = {
|
||||
* y property
|
||||
*/
|
||||
setAbsolutePosition: function() {
|
||||
var pos = Kinetic.GlobalObject._getXY(arguments);
|
||||
var pos = Kinetic.GlobalObject._getXY(Array.prototype.slice.call(arguments));
|
||||
/*
|
||||
* save rotation and scale and
|
||||
* then remove them from the transform
|
||||
@@ -438,7 +423,7 @@ Kinetic.Node.prototype = {
|
||||
* move node by an amount
|
||||
*/
|
||||
move: function() {
|
||||
var pos = Kinetic.GlobalObject._getXY(arguments);
|
||||
var pos = Kinetic.GlobalObject._getXY(Array.prototype.slice.call(arguments));
|
||||
|
||||
var x = this.getX();
|
||||
var y = this.getY();
|
||||
@@ -618,7 +603,7 @@ Kinetic.Node.prototype = {
|
||||
*/
|
||||
setOffset: function() {
|
||||
this.setAttrs({
|
||||
offset: arguments
|
||||
offset: Array.prototype.slice.call(arguments)
|
||||
});
|
||||
},
|
||||
/**
|
||||
|
@@ -242,7 +242,7 @@ Kinetic.Shape.prototype = {
|
||||
var appliedShadow = false;
|
||||
var context = this.getContext();
|
||||
context.save();
|
||||
var a = arguments;
|
||||
var a = Array.prototype.slice.call(arguments);
|
||||
|
||||
if(a.length === 5 || a.length === 9) {
|
||||
if(!this.appliedShadow) {
|
||||
@@ -261,7 +261,7 @@ Kinetic.Shape.prototype = {
|
||||
context.restore();
|
||||
|
||||
if(appliedShadow) {
|
||||
this.drawImage.apply(this, arguments);
|
||||
this.drawImage.apply(this, a);
|
||||
}
|
||||
},
|
||||
/**
|
||||
@@ -330,7 +330,7 @@ Kinetic.Shape.prototype = {
|
||||
* element is the y component
|
||||
*/
|
||||
intersects: function() {
|
||||
var pos = Kinetic.GlobalObject._getXY(arguments);
|
||||
var pos = Kinetic.GlobalObject._getXY(Array.prototype.slice.call(arguments));
|
||||
var stage = this.getStage();
|
||||
|
||||
if(this.attrs.detectionType === 'path') {
|
||||
|
@@ -93,7 +93,7 @@ Kinetic.Stage.prototype = {
|
||||
*/
|
||||
setSize: function() {
|
||||
// set stage dimensions
|
||||
var size = Kinetic.GlobalObject._getSize(arguments);
|
||||
var size = Kinetic.GlobalObject._getSize(Array.prototype.slice.call(arguments));
|
||||
this.setAttrs(size);
|
||||
},
|
||||
/**
|
||||
@@ -295,7 +295,7 @@ Kinetic.Stage.prototype = {
|
||||
* @param {Object} point
|
||||
*/
|
||||
getIntersections: function() {
|
||||
var pos = Kinetic.GlobalObject._getXY(arguments);
|
||||
var pos = Kinetic.GlobalObject._getXY(Array.prototype.slice.call(arguments));
|
||||
var arr = [];
|
||||
var shapes = this.get('Shape');
|
||||
|
||||
|
@@ -34,8 +34,14 @@ Kinetic.Ellipse = function(config) {
|
||||
};
|
||||
// call super constructor
|
||||
Kinetic.Shape.apply(this, [config]);
|
||||
};
|
||||
|
||||
this._convertRadius();
|
||||
|
||||
var that = this;
|
||||
this.on('radiusChange', function() {
|
||||
that._convertRadius();
|
||||
});
|
||||
};
|
||||
// Circle backwards compatibility
|
||||
Kinetic.Circle = Kinetic.Ellipse;
|
||||
|
||||
@@ -52,9 +58,24 @@ Kinetic.Ellipse.prototype = {
|
||||
*/
|
||||
setRadius: function() {
|
||||
this.setAttrs({
|
||||
radius: arguments
|
||||
radius: Array.prototype.slice.call(arguments)
|
||||
});
|
||||
}
|
||||
},
|
||||
/**
|
||||
* converts numeric radius into an object
|
||||
*/
|
||||
_convertRadius: function() {
|
||||
var go = Kinetic.GlobalObject;
|
||||
var radius = this.getRadius();
|
||||
// if radius is already an object then return
|
||||
if(go._isObject(radius)) {
|
||||
return false;
|
||||
}
|
||||
var pos = go._getXY(radius);
|
||||
this.setAttrs({
|
||||
radius: pos
|
||||
});
|
||||
}
|
||||
};
|
||||
// extend Shape
|
||||
Kinetic.GlobalObject.extend(Kinetic.Ellipse, Kinetic.Shape);
|
||||
|
@@ -56,7 +56,7 @@ Kinetic.Image.prototype = {
|
||||
* set width and height
|
||||
*/
|
||||
setSize: function() {
|
||||
var size = Kinetic.GlobalObject._getSize(arguments);
|
||||
var size = Kinetic.GlobalObject._getSize(Array.prototype.slice.call(arguments));
|
||||
this.setAttrs(size);
|
||||
},
|
||||
/**
|
||||
@@ -73,7 +73,7 @@ Kinetic.Image.prototype = {
|
||||
*/
|
||||
setCrop: function() {
|
||||
this.setAttrs({
|
||||
crop: arguments
|
||||
crop: Array.prototype.slice.call(arguments)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@@ -64,7 +64,6 @@ Kinetic.Path = function(config) {
|
||||
this.dataArray = this.getDataArray();
|
||||
|
||||
this.on('dataChange', function() {
|
||||
console.log('changed')
|
||||
that.dataArray = that.getDataArray();
|
||||
});
|
||||
};
|
||||
|
@@ -51,7 +51,7 @@ Kinetic.Rect.prototype = {
|
||||
* set width and height
|
||||
*/
|
||||
setSize: function() {
|
||||
var size = Kinetic.GlobalObject._getSize(arguments);
|
||||
var size = Kinetic.GlobalObject._getSize(Array.prototype.slice.call(arguments));
|
||||
this.setAttrs(size);
|
||||
},
|
||||
/**
|
||||
|
@@ -29,6 +29,12 @@ Kinetic.Sprite = function(config) {
|
||||
};
|
||||
// call super constructor
|
||||
Kinetic.Shape.apply(this, [config]);
|
||||
|
||||
var that = this;
|
||||
this.on('animationChange', function() {
|
||||
// reset index when animation changes
|
||||
that.setIndex(0);
|
||||
});
|
||||
};
|
||||
/*
|
||||
* Sprite methods
|
||||
|
Reference in New Issue
Block a user