added new fire() method which fires synthetic events and custom events. Simulate() now simulates user events with event bubbling

This commit is contained in:
Eric Rowell
2012-11-03 17:19:21 -07:00
parent df829e1e89
commit 0748692c1d
8 changed files with 108 additions and 76 deletions

View File

@@ -25,4 +25,4 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
var Kinetic={};Kinetic.Filters={},Kinetic.Plugins={},Kinetic.Global={BUBBLE_WHITELIST:["mousedown","mousemove","mouseup","mouseover","mouseout","mouseenter","mouseleave","click","dblclick","touchstart","touchmove","touchend","tap","dbltap","dragstart","dragmove","dragend"],BUFFER_WHITELIST:["fill","stroke","textFill","textStroke"],BUFFER_BLACKLIST:["shadow"],stages:[],idCounter:0,tempNodes:{},shapes:{},warn:function(a){console&&console.warn&&console.warn("Kinetic warning: "+a)},extend:function(a,b){for(var c in b.prototype)c in a.prototype||(a.prototype[c]=b.prototype[c])},_pullNodes:function(a){var b=this.tempNodes;for(var c in b){var d=b[c];d.getStage()!==undefined&&d.getStage()._id===a._id&&(a._addId(d),a._addName(d),this._removeTempNode(d))}},_addTempNode:function(a){this.tempNodes[a._id]=a},_removeTempNode:function(a){delete this.tempNodes[a._id]}};
var Kinetic={};Kinetic.Filters={},Kinetic.Plugins={},Kinetic.Global={BUFFER_WHITELIST:["fill","stroke","textFill","textStroke"],BUFFER_BLACKLIST:["shadow"],stages:[],idCounter:0,tempNodes:{},shapes:{},warn:function(a){console&&console.warn&&console.warn("Kinetic warning: "+a)},extend:function(a,b){for(var c in b.prototype)c in a.prototype||(a.prototype[c]=b.prototype[c])},_pullNodes:function(a){var b=this.tempNodes;for(var c in b){var d=b[c];d.getStage()!==undefined&&d.getStage()._id===a._id&&(a._addId(d),a._addName(d),this._removeTempNode(d))}},_addTempNode:function(a){this.tempNodes[a._id]=a},_removeTempNode:function(a){delete this.tempNodes[a._id]}};

File diff suppressed because one or more lines are too long

View File

@@ -29,7 +29,6 @@ var Kinetic = {};
Kinetic.Filters = {};
Kinetic.Plugins = {};
Kinetic.Global = {
BUBBLE_WHITELIST: ['mousedown', 'mousemove', 'mouseup', 'mouseover', 'mouseout', 'mouseenter', 'mouseleave', 'click', 'dblclick', 'touchstart', 'touchmove', 'touchend', 'tap', 'dbltap', 'dragstart', 'dragmove', 'dragend'],
BUFFER_WHITELIST: ['fill', 'stroke', 'textFill', 'textStroke'],
BUFFER_BLACKLIST: ['shadow'],
stages: [],
@@ -1680,15 +1679,25 @@ Kinetic.Node.prototype = {
}
},
/**
* simulate event
* simulate event with event bubbling
* @name simulate
* @methodOf Kinetic.Node.prototype
* @param {String} eventType
* @param {Object} event attribute
* @param {EventObject} evt event object
*/
simulate: function(eventType, evt) {
this._handleEvent(eventType, evt || {});
},
/**
* synthetically fire an event.  The event object will not bubble up the Node tree.  You can also pass in custom properties
* @name fire
* @methodOf Kinetic.Node.prototype
* @param {String} eventType
* @param {Object} obj optional object which can be used to pass parameters
*/
fire: function(eventType, obj) {
this._executeHandlers(eventType, obj || {});
},
/**
* get absolute transform of the node which takes into
* account its parent transforms
@@ -1993,14 +2002,11 @@ Kinetic.Node.prototype = {
if(okayToRun) {
if(el[eventType]) {
var events = el[eventType];
for(var i = 0; i < events.length; i++) {
events[i].handler.apply(this, [evt]);
}
this.fire(eventType, evt);
}
// simulate event bubbling
if(Kinetic.Global.BUBBLE_WHITELIST.indexOf(eventType) >= 0 && !evt.cancelBubble && this.parent) {
if(!evt.cancelBubble && this.parent) {
if(compareShape && compareShape.parent) {
this._handleEvent.call(this.parent, eventType, evt, compareShape.parent);
}
@@ -2010,6 +2016,12 @@ Kinetic.Node.prototype = {
}
}
},
_executeHandlers: function(eventType, evt) {
var events = this.eventListeners[eventType];
for(var i = 0; i < events.length; i++) {
events[i].handler.apply(this, [evt]);
}
},
_shouldDraw: function(canvas) {
return (this.isVisible() && (!canvas || canvas.name !== 'buffer' || this.getListening()));
}

File diff suppressed because one or more lines are too long