From 69da2d385450daa158d75ebe59449cc044ec8022 Mon Sep 17 00:00:00 2001 From: wout Date: Wed, 3 Sep 2014 12:15:16 +0200 Subject: Firefox fixes and event specs --- src/boxes.js | 10 ++++++---- src/event.js | 17 ++++++++++++++--- src/matrix.js | 2 +- 3 files changed, 21 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/boxes.js b/src/boxes.js index 2c5cd8b..0b90f60 100755 --- a/src/boxes.js +++ b/src/boxes.js @@ -5,17 +5,19 @@ SVG.BBox = SVG.invent({ if (element) { var box - // find native bbox - if (element.node.getBBox) + // yes this is ugly, but Firefox can be a bitch when it comes to elements that are not yet rendered + try { + // find native bbox box = element.node.getBBox() - // mimic bbox - else + } catch(e) { + // mimic bbox box = { x: element.node.clientLeft , y: element.node.clientTop , width: element.node.clientWidth , height: element.node.clientHeight } + } // plain x and y this.x = box.x diff --git a/src/event.js b/src/event.js index 6108155..3f7e656 100755 --- a/src/event.js +++ b/src/event.js @@ -39,15 +39,26 @@ SVG.registerEvent = function(event) { // Add event binder in the SVG namespace SVG.on = function(node, event, listener) { + // create listener var l = listener.bind(node.instance || node) - SVG.listeners[listener] = l + + // ensure node reference + SVG.listeners[node] = SVG.listeners[node] || {} + + // reference listener + SVG.listeners[node][listener] = l + + // add listener node.addEventListener(event, l, false) } // Add event unbinder in the SVG namespace SVG.off = function(node, event, listener) { - node.removeEventListener(event, SVG.listeners[listener], false) - delete SVG.listeners[listener] + // remove listener + node.removeEventListener(event, SVG.listeners[node][listener], false) + + // remove listener reference + delete SVG.listeners[node][listener] } // diff --git a/src/matrix.js b/src/matrix.js index d1757f3..cbd053f 100644 --- a/src/matrix.js +++ b/src/matrix.js @@ -15,7 +15,7 @@ SVG.Matrix = SVG.invent({ // merge source for (i = abcdef.length - 1; i >= 0; i--) - this[abcdef[i]] = typeof source[abcdef[i]] === 'number' ? + this[abcdef[i]] = source && typeof source[abcdef[i]] === 'number' ? source[abcdef[i]] : base[abcdef[i]] } -- cgit v1.2.3