bug fix: ellipse radius change no longer fires duplicate attr change event

This commit is contained in:
Eric Rowell
2012-07-01 15:30:51 -07:00
parent 31566bff13
commit caae5a5155
4 changed files with 43 additions and 20 deletions

10
dist/kinetic-core.js vendored
View File

@@ -3433,10 +3433,12 @@ Kinetic.Ellipse.prototype = {
if(go._isObject(radius)) { if(go._isObject(radius)) {
return false; return false;
} }
var pos = go._getXY(radius);
this.setAttrs({ /*
radius: pos * directly set radius attr to avoid
}); * duplicate attr change event
*/
this.attrs.radius = go._getXY(radius);
} }
}; };
// extend Shape // extend Shape

File diff suppressed because one or more lines are too long

View File

@@ -56,10 +56,12 @@ Kinetic.Ellipse.prototype = {
if(go._isObject(radius)) { if(go._isObject(radius)) {
return false; return false;
} }
var pos = go._getXY(radius);
this.setAttrs({ /*
radius: pos * directly set radius attr to avoid
}); * duplicate attr change event
*/
this.attrs.radius = go._getXY(radius);
} }
}; };
// extend Shape // extend Shape

View File

@@ -3131,20 +3131,37 @@ Test.prototype.tests = {
} }
}); });
var circle = new Kinetic.Ellipse({
x: stage.getWidth() / 2,
y: stage.getHeight() / 2,
radius: [70, 35],
fill: 'green',
stroke: 'black',
strokeWidth: 4
});
layer.add(circle);
layer.add(rect); layer.add(rect);
stage.add(layer); stage.add(layer);
var widthChanged = false; var widthChanged = 0;
var shadowChanged = false; var shadowChanged = 0;
var radiusChanged = 0;
rect.on('widthChange', function() { rect.on('widthChange', function() {
widthChanged = true; widthChanged++;
}); });
rect.on('shadowChange', function() { rect.on('shadowChange', function() {
shadowChanged = true; shadowChanged++;
}); });
circle.on('radiusChange', function() {
radiusChanged++;
});
circle.setRadius(70, 20);
rect.setSize(210); rect.setSize(210);
rect.setShadow({ rect.setShadow({
offset: { offset: {
@@ -3152,8 +3169,10 @@ Test.prototype.tests = {
} }
}); });
test(widthChanged, 'width change event was not fired'); test(widthChanged === 1, 'width change event was not fired correctly');
test(shadowChanged, 'shadow change event not fired'); test(shadowChanged === 1, 'shadow change event not fired correctly');
test(radiusChanged === 1, 'radius change event was not fired correctly');
}, },
'NODE - test setting shadow offset': function(containerId) { 'NODE - test setting shadow offset': function(containerId) {
var stage = new Kinetic.Stage({ var stage = new Kinetic.Stage({