From 9d44834148ea6837e7882fd96afbb9867769bee3 Mon Sep 17 00:00:00 2001 From: Jason Follas Date: Thu, 22 Mar 2012 08:59:29 -0400 Subject: [PATCH] - 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 --- src/Stage.js | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/Stage.js b/src/Stage.js index 25e0a454..466dd0aa 100644 --- a/src/Stage.js +++ b/src/Stage.js @@ -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 {String} mimeType (optional) + * @param {Number} arg2 (optional) */ - toDataURL: function(callback) { + toDataURL: function(callback, mimeType, arg2) { var bufferLayer = this.bufferLayer; var bufferContext = bufferLayer.getContext(); var layers = this.children; @@ -180,7 +184,7 @@ Kinetic.Stage.prototype = { addLayer(n); } else { - callback(bufferLayer.getCanvas().toDataURL()); + callback(bufferLayer.getCanvas().toDataURL(mimeType, arg2)); } }; imageObj.src = dataURL; @@ -417,18 +421,20 @@ Kinetic.Stage.prototype = { // propapgate backwards through children for(var i = children.length - 1; i >= 0; i--) { var child = children[i]; - if(child.className === 'Shape') { - var exit = this._detectEvent(child, evt); - if(exit) { - return true; - } - } - else { - var exit = this._traverseChildren(child, evt); - if(exit) { - return true; - } - } + if (child.isListening) { + if(child.className === 'Shape') { + var exit = this._detectEvent(child, evt); + if(exit) { + return true; + } + } + else { + var exit = this._traverseChildren(child, evt); + if(exit) { + return true; + } + } + } } return false; @@ -533,8 +539,8 @@ Kinetic.Stage.prototype = { * @param {Event} evt */ _setMousePosition: function(evt) { - var mouseX = evt.clientX - this._getContainerPosition().left + window.pageXOffset; - var mouseY = evt.clientY - this._getContainerPosition().top + window.pageYOffset; + var mouseX = evt.offsetX || (evt.clientX - this._getContainerPosition().left + window.pageXOffset); + var mouseY = evt.offsetY || (evt.clientY - this._getContainerPosition().top + window.pageYOffset); this.mousePos = { x: mouseX, y: mouseY