refactored Image event bindings and fixed radial gradient bug

This commit is contained in:
Eric Rowell 2012-06-24 13:39:36 -07:00
parent a8c09516ba
commit 3b6dffe6e1
5 changed files with 21 additions and 29 deletions

18
dist/kinetic-core.js vendored
View File

@ -2937,7 +2937,7 @@ Kinetic.Shape.prototype = {
context.fill();
}
// radial gradient
else if(s.radius && e.radius) {
else if((s.radius || s.radius === 0) && (e.radius || e.radius === 0)) {
var context = this.getContext();
var grd = context.createRadialGradient(s.x, s.y, s.radius, e.x, e.y, e.radius);
var colorStops = fill.colorStops;
@ -3479,18 +3479,10 @@ Kinetic.Image = function(config) {
Kinetic.Rect.apply(this, [config]);
// update attrs when one of the following changes
this.on('widthChange', function() {
this._setAttrs();
});
this.on('heightChange', function() {
this._setAttrs();
});
this.on('imageChange', function() {
this._setAttrs();
});
this.on('cropChange', function() {
this._setAttrs();
});
this.on('widthChange', this._setAttrs);
this.on('heightChange', this._setAttrs);
this.on('imageChange', this._setAttrs);
this.on('cropChange', this._setAttrs);
this._setAttrs();
};

File diff suppressed because one or more lines are too long

View File

@ -136,7 +136,7 @@ Kinetic.Shape.prototype = {
context.fill();
}
// radial gradient
else if(s.radius && e.radius) {
else if((s.radius || s.radius === 0) && (e.radius || e.radius === 0)) {
var context = this.getContext();
var grd = context.createRadialGradient(s.x, s.y, s.radius, e.x, e.y, e.radius);
var colorStops = fill.colorStops;

View File

@ -14,18 +14,10 @@ Kinetic.Image = function(config) {
Kinetic.Rect.apply(this, [config]);
// update attrs when one of the following changes
this.on('widthChange', function() {
this._setAttrs();
});
this.on('heightChange', function() {
this._setAttrs();
});
this.on('imageChange', function() {
this._setAttrs();
});
this.on('cropChange', function() {
this._setAttrs();
});
this.on('widthChange', this._setAttrs);
this.on('heightChange', this._setAttrs);
this.on('imageChange', this._setAttrs);
this.on('cropChange', this._setAttrs);
this._setAttrs();
};

View File

@ -1808,7 +1808,9 @@ Test.prototype.tests = {
width: 578,
height: 200
});
var layer = new Kinetic.Layer();
var layer = new Kinetic.Layer({
throttle: 999
});
darth = new Kinetic.Image({
x: 200,
y: 60,
@ -1823,6 +1825,12 @@ Test.prototype.tests = {
layer.add(darth);
stage.add(layer);
darth.setHeight(200);
layer.draw();
darth.setHeight(100);
layer.draw();
test(darth.getX() === 200, 'x should be 200');
test(darth.getY() === 60, 'y should be 60');
test(darth.getWidth() === 100, 'width should be 100');