diff options
author | wout <wout@impinc.co.uk> | 2014-09-05 14:45:27 +0200 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-09-05 14:45:27 +0200 |
commit | 04c734f0fc6c03c20d471c560f2ad8dba3d65b83 (patch) | |
tree | 212e8aeafd7f5d4a6ff81284eea3de4babf0b638 /src | |
parent | 9a0c9eb2e73a9ca941a043802143dbb568b4a609 (diff) | |
download | svg.js-04c734f0fc6c03c20d471c560f2ad8dba3d65b83.tar.gz svg.js-04c734f0fc6c03c20d471c560f2ad8dba3d65b83.zip |
Bumped to version 1.0.0
Diffstat (limited to 'src')
-rwxr-xr-x | src/element.js | 8 | ||||
-rwxr-xr-x | src/event.js | 55 | ||||
-rw-r--r-- | src/polyfill.js | 14 | ||||
-rwxr-xr-x | src/rbox.js | 4 |
4 files changed, 68 insertions, 13 deletions
diff --git a/src/element.js b/src/element.js index b12947b..8c4166d 100755 --- a/src/element.js +++ b/src/element.js @@ -144,11 +144,11 @@ SVG.Element = SVG.invent({ } else if (v == null) { /* act as a getter if the first and only argument is not an object */ - v = this.node.getAttribute(a) + v = this.node.attributes[a] return v == null ? SVG.defaults.attrs[a] : - SVG.regex.isNumber.test(v) ? - parseFloat(v) : v + SVG.regex.isNumber.test(v.nodeValue) ? + parseFloat(v.nodeValue) : v.nodeValue } else if (a == 'style') { /* redirect to the style method */ @@ -389,7 +389,7 @@ SVG.Element = SVG.invent({ } // Get referenced element form attribute value , reference: function(attr) { - return SVG.get(this.attr(attr)) + return SVG.get(this.attr()[attr]) } // Private: find svg parent by instance , _parent: function(parent) { diff --git a/src/event.js b/src/event.js index 8430fa0..63764ed 100755 --- a/src/event.js +++ b/src/event.js @@ -6,8 +6,8 @@ , 'mouseover' , 'mouseout' , 'mousemove' - , 'mouseenter' - , 'mouseleave' + // , 'mouseenter' -> not supported by IE + // , 'mouseleave' -> not supported by IE , 'touchstart' , 'touchmove' , 'touchleave' @@ -34,20 +34,54 @@ SVG.listeners = {} // Event constructor SVG.registerEvent = function(event) { if (!SVG.events[event]) - SVG.events[event] = new Event(event) + SVG.events[event] = new CustomEvent(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 reference objects + SVG.listeners[node] = SVG.listeners[node] || {} + SVG.listeners[node][event] = SVG.listeners[node][event] || {} + + // reference listener + SVG.listeners[node][event][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] + if (listener) { + // remove listener reference + if (SVG.listeners[node] && SVG.listeners[node][event]) { + // remove listener + node.removeEventListener(event, SVG.listeners[node][event][listener], false) + + delete SVG.listeners[node][event][listener] + } + + } else if (event) { + // remove all listeners for the event + if (SVG.listeners[node][event]) { + for (listener in SVG.listeners[node][event]) + SVG.off(node, event, listener) + + delete SVG.listeners[node][event] + } + + } else { + // remove all listeners on a given node + if (SVG.listeners[node]) { + for (event in SVG.listeners[node]) + SVG.off(node, event) + + delete SVG.listeners[node] + } + } } // @@ -65,9 +99,16 @@ SVG.extend(SVG.Element, { return this } // Fire given event -, fire: function(event) { +, fire: function(event, data) { + // Add detail data to event + SVG.events[event].detail = data + + // Dispatch event this.node.dispatchEvent(SVG.events[event]) + // Remove detail + delete SVG.events[event].detail + return this } })
\ No newline at end of file diff --git a/src/polyfill.js b/src/polyfill.js new file mode 100644 index 0000000..3a3c25c --- /dev/null +++ b/src/polyfill.js @@ -0,0 +1,14 @@ +// Add CustomEvent to IE9 and IE10 +if (typeof CustomEvent !== 'function') { + // Code from: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent + function CustomEvent (event, options) { + options = options || { bubbles: false, cancelable: false, detail: undefined } + var e = document.createEvent('CustomEvent') + e.initCustomEvent(event, options.bubbles, options.cancelable, options.detail) + return e + } + + CustomEvent.prototype = window.Event.prototype + + window.CustomEvent = CustomEvent +}
\ No newline at end of file diff --git a/src/rbox.js b/src/rbox.js index 54e08cb..2fc093b 100755 --- a/src/rbox.js +++ b/src/rbox.js @@ -47,8 +47,8 @@ SVG.RBox = function(element) { this.height = box.height /= zoom /* offset by window scroll position, because getBoundingClientRect changes when window is scrolled */ - this.x += window.scrollX; - this.y += window.scrollY; + this.x += typeof window.scrollX === 'number' ? window.scrollX : window.pageXOffset + this.y += typeof window.scrollY === 'number' ? window.scrollY : window.pageYOffset /* add center, right and bottom */ boxProperties(this) |