diff options
author | wout <wout@impinc.co.uk> | 2014-06-11 15:27:07 +0200 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-06-11 15:27:07 +0200 |
commit | e3a0f3a887a398a87356f63253830e1baf67823e (patch) | |
tree | d2b13c0dc0b4d40270cda7e1968860325d6c49b8 /src | |
parent | 791f4368403571d5e824d91f3562c63baae356a8 (diff) | |
download | svg.js-e3a0f3a887a398a87356f63253830e1baf67823e.tar.gz svg.js-e3a0f3a887a398a87356f63253830e1baf67823e.zip |
Bumped to version 1.0.0-rc.7
Look at change log for full overview of changes.
Diffstat (limited to 'src')
-rwxr-xr-x | src/element.js | 4 | ||||
-rwxr-xr-x | src/event.js | 31 | ||||
-rwxr-xr-x | src/pointarray.js | 2 | ||||
-rwxr-xr-x | src/regex.js | 3 | ||||
-rwxr-xr-x | src/svg.js | 6 | ||||
-rwxr-xr-x | src/text.js | 19 |
6 files changed, 39 insertions, 26 deletions
diff --git a/src/element.js b/src/element.js index 9c52dd0..e63b57e 100755 --- a/src/element.js +++ b/src/element.js @@ -293,8 +293,8 @@ SVG.Element = SVG.invent({ s = s.split(';') /* apply every definition individually */ - for (v = 0; v < s.length; v++) { - v = s[v].split(':') + for (var i = 0; i < s.length; i++) { + v = s[i].split(':') this.style(v[0].replace(/\s+/g, ''), v[1]) } } else { diff --git a/src/event.js b/src/event.js index 73e3ba5..885eab8 100755 --- a/src/event.js +++ b/src/event.js @@ -1,8 +1,4 @@ -// ### Manage events on elements - -// rect.click(function() { -// this.fill({ color: '#f06' }) -// }) +// Add events to elements ;[ 'click' , 'dblclick' , 'mousedown' @@ -31,20 +27,23 @@ }) +// Initialize events stack +SVG.events = {} + +// Event constructor +SVG.registerEvent = function(event) { + if (!SVG.events[event]) + SVG.events[event] = new Event(event) +} + // Add event binder in the SVG namespace SVG.on = function(node, event, listener) { - if (node.addEventListener) - node.addEventListener(event, listener, false) - else - node.attachEvent('on' + event, listener) + node.addEventListener(event, listener.bind(node.instance || node), false) } // Add event unbinder in the SVG namespace SVG.off = function(node, event, listener) { - if (node.removeEventListener) - node.removeEventListener(event, listener, false) - else - node.detachEvent('on' + event, listener) + node.removeEventListener(event, listener.bind(node.instance || node), false) } // @@ -61,4 +60,10 @@ SVG.extend(SVG.Element, { return this } + // Fire given event +, fire: function(event) { + this.node.dispatchEvent(SVG.events[event]) + + return this + } })
\ No newline at end of file diff --git a/src/pointarray.js b/src/pointarray.js index 16f3283..e246adf 100755 --- a/src/pointarray.js +++ b/src/pointarray.js @@ -69,7 +69,7 @@ SVG.extend(SVG.PointArray, { /* recalculate position of all points according to new size */ for (i = this.value.length - 1; i >= 0; i--) { this.value[i][0] = ((this.value[i][0] - box.x) * width) / box.width + box.x - this.value[i][1] = ((this.value[i][1] - box.y) * height) / box.height + box.x + this.value[i][1] = ((this.value[i][1] - box.y) * height) / box.height + box.y } return this diff --git a/src/regex.js b/src/regex.js index c78d9f3..433952b 100755 --- a/src/regex.js +++ b/src/regex.js @@ -30,4 +30,7 @@ SVG.regex = { /* test for image url */ , isImage: /\.(jpg|jpeg|png|gif)(\?[^=]+.*)?/i + /* test for namespaced event */ +, isEvent: /^[\w]+:[\w]+$/ + }
\ No newline at end of file @@ -1,6 +1,6 @@ // The main wrapping element -this.SVG = function(element) { +var SVG = this.SVG = function(element) { if (SVG.supported) { element = new SVG.Doc(element) @@ -65,7 +65,7 @@ SVG.get = function(id) { SVG.prepare = function(element) { /* select document body and create invisible svg element */ var body = document.getElementsByTagName('body')[0] - , draw = (body ? new SVG.Doc(body) : element.nested()).size(2, 2) + , draw = (body ? new SVG.Doc(body) : element.nested()).size(2, 0) , path = SVG.create('path') /* insert parsers */ @@ -86,4 +86,4 @@ SVG.supported = (function() { !! document.createElementNS(SVG.ns,'svg').createSVGRect })() -if (!SVG.supported) return false
\ No newline at end of file +if (!SVG.supported) return false diff --git a/src/text.js b/src/text.js index 170b9de..1d05362 100755 --- a/src/text.js +++ b/src/text.js @@ -31,13 +31,14 @@ SVG.Text = SVG.invent({ } // Move over y-axis , y: function(y) { - var o = this.attr('y') - this.bbox().y + var oy = this.attr('y') + , o = typeof oy === 'number' ? oy - this.bbox().y : 0 /* act as getter */ if (y == null) - return this.attr('y') - o + return typeof oy === 'number' ? oy - o : oy - return this.attr('y', y + o) + return this.attr('y', typeof y === 'number' ? y + o : y) } // Move center over x-axis , cx: function(x) { @@ -50,7 +51,7 @@ SVG.Text = SVG.invent({ // Set the text content , text: function(text) { /* act as getter */ - if (!text) return this.content + if (typeof text === 'undefined') return this.content /* remove existing content */ this.clear().build(true) @@ -61,7 +62,7 @@ SVG.Text = SVG.invent({ } else { /* store text and make sure text is not blank */ - text = (this.content = (SVG.regex.isBlank.test(text) ? 'text' : text)).split('\n') + text = (this.content = text).split('\n') /* build new lines */ for (var i = 0, il = text.length; i < il; i++) @@ -88,14 +89,14 @@ SVG.Text = SVG.invent({ } // Rebuild appearance type , rebuild: function(rebuild) { - var self = this - /* store new rebuild flag if given */ if (typeof rebuild == 'boolean') this._rebuild = rebuild /* define position of all lines */ if (this._rebuild) { + var self = this + this.lines.each(function() { if (this.newLined) { if (!this.textPath) @@ -103,6 +104,8 @@ SVG.Text = SVG.invent({ this.attr('dy', self._leading * new SVG.Number(self.attr('font-size'))) } }) + + this.fire('rebuild') } return this @@ -216,3 +219,5 @@ SVG.extend(SVG.Text, SVG.TSpan, { } }) +// Register rebuild event +SVG.registerEvent('rebuild') |