added support for event bubble cancelation

This commit is contained in:
Eric Rowell
2012-03-17 14:35:34 -07:00
parent a9601fadc2
commit fafb5db93f
11 changed files with 460 additions and 455 deletions

View File

@@ -158,8 +158,7 @@ Kinetic.GlobalObject = {
this.isAnimating = true;
that._animationLoop();
}
else
if(this.isAnimating && !this._isaCanvasAnimating()) {
else if(this.isAnimating && !this._isaCanvasAnimating()) {
this.isAnimating = false;
this.frame.lastTime = 0;
}

View File

@@ -541,15 +541,11 @@ Kinetic.Node.prototype = {
}
}
if(obj.parent.className !== 'Stage') {
// simulate event bubbling
if(!evt.cancelBubble && obj.parent.className !== 'Stage') {
handle(obj.parent);
}
}
/*
* simulate bubbling by handling node events
* first, followed by group events, followed
* by layer events
*/
handle(this);
}
};

View File

@@ -16,8 +16,7 @@ Kinetic.Shape = function(config) {
if(config.stroke === undefined) {
config.stroke = 'black';
}
else
if(config.strokeWidth === undefined) {
else if(config.strokeWidth === undefined) {
config.strokeWidth = 2;
}
}

View File

@@ -285,8 +285,7 @@ Kinetic.Stage.prototype = {
return true;
}
// handle onmouseup & onclick
else
if(this.mouseUp) {
else if(this.mouseUp) {
this.mouseUp = false;
shape._handleEvents('onmouseup', evt);
@@ -312,8 +311,7 @@ Kinetic.Stage.prototype = {
}
// handle touchstart
else
if(this.touchStart) {
else if(this.touchStart) {
this.touchStart = false;
shape._handleEvents('touchstart', evt);
@@ -333,23 +331,20 @@ Kinetic.Stage.prototype = {
}
// handle touchend
else
if(this.touchEnd) {
else if(this.touchEnd) {
this.touchEnd = false;
shape._handleEvents('touchend', evt);
return true;
}
// handle touchmove
else
if(!isDragging && el.touchmove) {
else if(!isDragging && el.touchmove) {
shape._handleEvents('touchmove', evt);
return true;
}
//this condition is used to identify a new target shape.
else
if(!isDragging && (!this.targetShape || (!this.targetFound && shape.id !== this.targetShape.id))) {
else if(!isDragging && (!this.targetShape || (!this.targetFound && shape.id !== this.targetShape.id))) {
/*
* check if old target has an onmouseout event listener
*/
@@ -370,15 +365,13 @@ Kinetic.Stage.prototype = {
}
// handle onmousemove
else
if(!isDragging) {
else if(!isDragging) {
shape._handleEvents('onmousemove', evt);
return true;
}
}
// handle mouseout condition
else
if(!isDragging && this.targetShape && this.targetShape.id === shape.id) {
else if(!isDragging && this.targetShape && this.targetShape.id === shape.id) {
this.targetShape = undefined;
shape._handleEvents('onmouseout', evt);
return true;
@@ -402,7 +395,7 @@ Kinetic.Stage.prototype = {
}
}
else {
this._traverseChildren(child);
this._traverseChildren(child, evt);
}
}

View File

@@ -41,4 +41,4 @@ Kinetic.Polygon.prototype = {
};
// extend Shape
Kinetic.GlobalObject.extend(Kinetic.Polygon, Kinetic.Shape);
Kinetic.GlobalObject.extend(Kinetic.Polygon, Kinetic.Shape);

View File

@@ -70,4 +70,4 @@ Kinetic.RegularPolygon.prototype = {
};
// extend Shape
Kinetic.GlobalObject.extend(Kinetic.RegularPolygon, Kinetic.Shape);
Kinetic.GlobalObject.extend(Kinetic.RegularPolygon, Kinetic.Shape);

View File

@@ -70,4 +70,4 @@ Kinetic.Star.prototype = {
}
};
// extend Shape
Kinetic.GlobalObject.extend(Kinetic.Star, Kinetic.Shape);
Kinetic.GlobalObject.extend(Kinetic.Star, Kinetic.Shape);

View File

@@ -15,8 +15,7 @@ Kinetic.Text = function(config) {
if(config.textStroke === undefined) {
config.textStroke = 'black';
}
else
if(config.textStrokeWidth === undefined) {
else if(config.textStrokeWidth === undefined) {
config.textStrokeWidth = 2;
}
}
@@ -80,8 +79,7 @@ Kinetic.Text = function(config) {
if(this.textStroke === undefined) {
this.textStroke = 'black';
}
else
if(this.textStrokeWidth === undefined) {
else if(this.textStrokeWidth === undefined) {
this.textStrokeWidth = 2;
}
context.lineWidth = this.textStrokeWidth;