created a proper utility function that handles defaults. Integrating the ntew get() method fixes a shadowBlur issue. fixed #587

This commit is contained in:
Eric Rowell
2013-08-28 09:48:42 -07:00
parent 188bf2d8d0
commit 2f0c889b1e
3 changed files with 35 additions and 9 deletions

View File

@@ -455,20 +455,24 @@
} }
}, },
_applyShadow: function(shape) { _applyShadow: function(shape) {
var context = this.context; var context = this.context,
util, absOpacity, color, blur, offset, shadowOpacity;
if(shape.hasShadow() && shape.getShadowEnabled()) { if(shape.hasShadow() && shape.getShadowEnabled()) {
var aa = shape.getAbsoluteOpacity(); util = Kinetic.Util;
// defaults absOpacity = shape.getAbsoluteOpacity();
var color = shape.getShadowColor() || 'black'; color = util.get(shape.getShadowColor(), 'black');
var blur = shape.getShadowBlur() || 5; blur = util.get(shape.getShadowBlur(), 5);
var offset = shape.getShadowOffset() || { shadowOpacity = util.get(shape.getShadowOpacity(), 0);
offset = util.get(shape.getShadowOffset(), {
x: 0, x: 0,
y: 0 y: 0
}; });
if(shape.getShadowOpacity()) { if(shadowOpacity) {
context.globalAlpha = shape.getShadowOpacity() * aa; context.globalAlpha = shadowOpacity * absOpacity;
} }
context.shadowColor = color; context.shadowColor = color;
context.shadowBlur = blur; context.shadowBlur = blur;
context.shadowOffsetX = offset.x; context.shadowOffsetX = offset.x;

View File

@@ -598,6 +598,19 @@
} }
return HASH + randColor; return HASH + randColor;
}, },
/**
* return value with default fallback
* @method
* @memberof Kinetic.Util.prototype
*/
get: function(val, def) {
if (val === undefined) {
return def;
}
else {
return val;
}
},
/** /**
* get RGB components of a color * get RGB components of a color
* @method * @method

View File

@@ -0,0 +1,9 @@
Test.Modules.UTIL = {
'util get()': function(containerId) {
var get = Kinetic.Util.get;
test(get(1, 2) === 1, 'get() should return 1');
test(get(0, 2) === 0, 'get() should return 0');
test(get(undefined, {foo:'bar'}).foo === 'bar', 'get() should return bar');
}
};