- Added check for child.isListening in _traverseChildren() to handle case when a node overlaps another and you don't want to handle events for the topmost node.

- Added support for event.offsetX/offsetY in _setMousePosition to work around a Kinetic bug observed in Windows 8/Internet Explorer 10
- Added MIME type support to toDataURL() so that additional image formats can be generated in accordance to the spec
This commit is contained in:
Jason Follas 2012-03-22 08:59:29 -04:00
parent afad713df3
commit 9d44834148

View File

@ -162,10 +162,14 @@ Kinetic.Stage.prototype = {
} }
}, },
/** /**
* creates a composite data URL and passes it to a callback * Creates a composite data URL and passes it to a callback. If MIME type is not
* specified, then "image/png" will result. For "image/jpeg", specify a quality
* level as arg2 (range 0.0 - 1.0)
* @param {function} callback * @param {function} callback
* @param {String} mimeType (optional)
* @param {Number} arg2 (optional)
*/ */
toDataURL: function(callback) { toDataURL: function(callback, mimeType, arg2) {
var bufferLayer = this.bufferLayer; var bufferLayer = this.bufferLayer;
var bufferContext = bufferLayer.getContext(); var bufferContext = bufferLayer.getContext();
var layers = this.children; var layers = this.children;
@ -180,7 +184,7 @@ Kinetic.Stage.prototype = {
addLayer(n); addLayer(n);
} }
else { else {
callback(bufferLayer.getCanvas().toDataURL()); callback(bufferLayer.getCanvas().toDataURL(mimeType, arg2));
} }
}; };
imageObj.src = dataURL; imageObj.src = dataURL;
@ -417,18 +421,20 @@ Kinetic.Stage.prototype = {
// propapgate backwards through children // propapgate backwards through children
for(var i = children.length - 1; i >= 0; i--) { for(var i = children.length - 1; i >= 0; i--) {
var child = children[i]; var child = children[i];
if(child.className === 'Shape') { if (child.isListening) {
var exit = this._detectEvent(child, evt); if(child.className === 'Shape') {
if(exit) { var exit = this._detectEvent(child, evt);
return true; if(exit) {
} return true;
} }
else { }
var exit = this._traverseChildren(child, evt); else {
if(exit) { var exit = this._traverseChildren(child, evt);
return true; if(exit) {
} return true;
} }
}
}
} }
return false; return false;
@ -533,8 +539,8 @@ Kinetic.Stage.prototype = {
* @param {Event} evt * @param {Event} evt
*/ */
_setMousePosition: function(evt) { _setMousePosition: function(evt) {
var mouseX = evt.clientX - this._getContainerPosition().left + window.pageXOffset; var mouseX = evt.offsetX || (evt.clientX - this._getContainerPosition().left + window.pageXOffset);
var mouseY = evt.clientY - this._getContainerPosition().top + window.pageYOffset; var mouseY = evt.offsetY || (evt.clientY - this._getContainerPosition().top + window.pageYOffset);
this.mousePos = { this.mousePos = {
x: mouseX, x: mouseX,
y: mouseY y: mouseY