event simulation now correctly bubbles

This commit is contained in:
Eric Rowell 2012-06-08 20:57:20 -07:00
parent e7699a588f
commit 440c3ac279
4 changed files with 42 additions and 10 deletions

View File

@ -1014,10 +1014,7 @@ Kinetic.Node.prototype = {
* @param {String} eventType
*/
simulate: function(eventType) {
var el = this.eventListeners[eventType];
for(var n = 0; n < el.length; n++) {
el[n].handler.call(this);
}
this._handleEvent(eventType, {});
},
/**
* set center offset

File diff suppressed because one or more lines are too long

View File

@ -651,10 +651,7 @@ Kinetic.Node.prototype = {
* @param {String} eventType
*/
simulate: function(eventType) {
var el = this.eventListeners[eventType];
for(var n = 0; n < el.length; n++) {
el[n].handler.call(this);
}
this._handleEvent(eventType, {});
},
/**
* set center offset

View File

@ -3576,15 +3576,53 @@ Test.prototype.tests = {
circle.on('click', function() {
foo = 'bar';
/*
var evt = window.event;
var rightClick = evt.which ? evt.which == 3 : evt.button == 2;
console.log(rightClick);
*/
});
circle.simulate('click');
test(foo === 'bar', 'foo should equal bar');
},
'NODE - simulate event bubble': function(containerId) {
var stage = new Kinetic.Stage({
container: containerId,
width: 578,
height: 200
});
var layer = new Kinetic.Layer();
var circle = new Kinetic.Circle({
x: stage.getWidth() / 2,
y: stage.getHeight() / 2,
radius: 70,
fill: 'green',
stroke: 'black',
strokeWidth: 4,
name: 'myCircle'
});
stage.add(layer);
layer.add(circle);
layer.draw();
var clicks = [];
circle.on('click', function() {
clicks.push('circle');
});
layer.on('click', function() {
clicks.push('layer');
});
circle.simulate('click');
test(clicks[0] === 'circle', 'circle event should be fired first');
test(clicks[1] === 'layer', 'layer event should be fired second');
},
'STAGE - add layer then shape': function(containerId) {
var stage = new Kinetic.Stage({
container: containerId,