fill, stroke, and strokeWidth values of undefined, null, '', or 0 are now correctly handled

This commit is contained in:
Eric Rowell 2012-04-28 12:30:14 -07:00
parent 9f6381aef3
commit c661cff85a
3 changed files with 18 additions and 16 deletions

15
dist/kinetic-core.js vendored
View File

@ -2301,17 +2301,18 @@ Kinetic.Shape.prototype = {
fillStroke: function() {
var context = this.getContext();
if(this.attrs.fill !== undefined) {
/*
* expect that fill, stroke, and strokeWidth could be
* undfined, '', null, or 0. Use !!
*/
if(!!this.attrs.fill) {
context.fillStyle = this.attrs.fill;
context.fill();
}
var hasStroke = this.attrs.stroke !== undefined;
var hasStrokeWidth = this.attrs.strokeWidth !== undefined && this.attrs.strokeWidth !== 0;
if(hasStroke || hasStrokeWidth) {
var stroke = hasStroke ? this.attrs.stroke : 'black';
var strokeWidth = hasStrokeWidth ? this.attrs.strokeWidth : 2;
if(!!this.attrs.stroke || !!this.attrs.strokeWidth) {
var stroke = !!this.attrs.stroke ? this.attrs.stroke : 'black';
var strokeWidth = !!this.attrs.strokeWidth ? this.attrs.strokeWidth : 2;
context.lineWidth = strokeWidth;
context.strokeStyle = stroke;

File diff suppressed because one or more lines are too long

View File

@ -59,17 +59,18 @@ Kinetic.Shape.prototype = {
fillStroke: function() {
var context = this.getContext();
if(this.attrs.fill !== undefined) {
/*
* expect that fill, stroke, and strokeWidth could be
* undfined, '', null, or 0. Use !!
*/
if(!!this.attrs.fill) {
context.fillStyle = this.attrs.fill;
context.fill();
}
var hasStroke = this.attrs.stroke !== undefined;
var hasStrokeWidth = this.attrs.strokeWidth !== undefined && this.attrs.strokeWidth !== 0;
if(hasStroke || hasStrokeWidth) {
var stroke = hasStroke ? this.attrs.stroke : 'black';
var strokeWidth = hasStrokeWidth ? this.attrs.strokeWidth : 2;
if(!!this.attrs.stroke || !!this.attrs.strokeWidth) {
var stroke = !!this.attrs.stroke ? this.attrs.stroke : 'black';
var strokeWidth = !!this.attrs.strokeWidth ? this.attrs.strokeWidth : 2;
context.lineWidth = strokeWidth;
context.strokeStyle = stroke;