fixed set fill attr bug which occurred when instantiating the fill with a string color and then setting it later to a fill object such as a gradient or pattern. The fix will apply to any attr which can be a string or object

This commit is contained in:
Eric Rowell
2012-06-12 09:57:29 -07:00
parent 6d4738cd2b
commit 2455000f5c
6 changed files with 62 additions and 8 deletions

View File

@@ -144,7 +144,8 @@ Kinetic.GlobalObject = {
//return Object.prototype.toString.call(obj) == '[object Array]';
},
_isObject: function(obj) {
return obj === Object(obj);
return ( typeof obj == 'object');
//return obj === Object(obj);
},
_isNumber: function(obj) {
return Object.prototype.toString.call(obj) == '[object Number]';

View File

@@ -183,9 +183,16 @@ Kinetic.Node.prototype = {
* to the node and then traverse
*/
if(go._isObject(val) && !go._isArray(val) && !go._isElement(val) && !go._hasMethods(val)) {
if(obj[key] === undefined) {
/*
* since some properties can be strings or objects, e.g.
* fill, we need to first check that obj is an object
* before setting properties. If it's not an object,
* overwrite obj with an object literal
*/
if(!Kinetic.GlobalObject._isObject(obj[key])) {
obj[key] = {};
}
setAttrs(obj[key], val, level + 1);
}
/*

View File

@@ -104,6 +104,7 @@ Kinetic.Shape.prototype = {
context.save();
var fill = this.attrs.fill;
if(!!fill) {
if(!this.appliedShadow) {
appliedShadow = this._applyShadow();