aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/helpers.js27
-rw-r--r--src/hyperlink.js2
-rw-r--r--src/image.js2
-rw-r--r--src/regex.js2
-rw-r--r--src/textpath.js2
-rw-r--r--src/use.js2
6 files changed, 24 insertions, 13 deletions
diff --git a/src/helpers.js b/src/helpers.js
index 12d17c0..d5af263 100644
--- a/src/helpers.js
+++ b/src/helpers.js
@@ -182,12 +182,23 @@ function fullBox(b) {
function idFromReference(url) {
var m = SVG.regex.reference.exec(url+'')
- if (m) return m[3]
+ if (m && m[2] == location() && m[4]) return m[4]
+}
+
+function location() {
+ return window.location.href
+ .replace(window.location.hash, '')
}
// creates an url reference out of nodes id
function url(node) {
- return 'url(' + window.location + '#' + node.id() + ')'
+ return 'url(' + location() + '#' + node.id() + ')'
+}
+
+function link(url) {
+ var match = SVG.regex.reference.exec(url)
+ if(!url || match[2]) return url
+ return location() + (match[3] || '')
}
function removePrefixFromReferences(node) {
@@ -197,10 +208,10 @@ function removePrefixFromReferences(node) {
var v = node.attributes, match
for (n = v.length - 1; n >= 0; n--) {
- if(v[n].nodeName == 'xlink:href' && (match = SVG.regex.reference.exec(v[n].nodeValue))) {
- if(match[2] == window.location) v[n].nodeValue = '#' + (match[3] || '')
+ if(v[n].nodeName == 'href' && (match = SVG.regex.reference.exec(v[n].nodeValue))) {
+ if(match[2] == location()) v[n].nodeValue = (match[3] || '')
}else if(match = SVG.regex.reference.exec(v[n].nodeValue)) {
- if(match[1] && match[2] == window.location) v[n].nodeValue = 'url(#' + match[3] + ')'
+ if(match[1] && match[2] == location()) v[n].nodeValue = 'url(' + match[3] + ')'
}
}
}
@@ -212,10 +223,10 @@ function addPrefixToReferences(node) {
var v = node.attributes, match
for (n = v.length - 1; n >= 0; n--) {
- if(v[n].nodeName == 'xlink:href' && (match = SVG.regex.reference.exec(v[n].nodeValue))) {
- if(!match[2]) v[n].nodeValue = window.location + '#' + (match[3] || '')
+ if(v[n].nodeName == 'href' && (match = SVG.regex.reference.exec(v[n].nodeValue))) {
+ if(!match[2]) v[n].nodeValue = location() + (match[3] || '')
}else if(match = SVG.regex.reference.exec(v[n].nodeValue)) {
- if(match[1] && !match[2]) v[n].nodeValue = 'url(' + window.location + '#' + match[3] + ')'
+ if(match[1] && !match[2]) v[n].nodeValue = 'url(' + location() + match[3] + ')'
}
}
}
diff --git a/src/hyperlink.js b/src/hyperlink.js
index a967707..8cb9a4a 100644
--- a/src/hyperlink.js
+++ b/src/hyperlink.js
@@ -9,7 +9,7 @@ SVG.A = SVG.invent({
, extend: {
// Link url
to: function(url) {
- return this.attr('href', url, SVG.xlink)
+ return this.attr('href', link(url), SVG.xlink)
}
// Link show attribute
, show: function(target) {
diff --git a/src/image.js b/src/image.js
index 84063de..fa2ee13 100644
--- a/src/image.js
+++ b/src/image.js
@@ -37,7 +37,7 @@ SVG.Image = SVG.invent({
}
}, this)
- return this.attr('href', (img.src = url), SVG.xlink)
+ return this.attr('href', (img.src = link(url)), SVG.xlink)
}
}
diff --git a/src/regex.js b/src/regex.js
index 4782bda..abc3552 100644
--- a/src/regex.js
+++ b/src/regex.js
@@ -10,7 +10,7 @@ SVG.regex = {
, rgb: /rgb\((\d+),(\d+),(\d+)\)/
// Parse reference url
-, reference: /(url\()?([-\w:/.]+)?#([-\w]+)/
+, reference: /(url\()?([-\w:/.]+)?(#([-\w]+))?/
// splits a transformation chain
, transforms: /\)\s*,?\s*/
diff --git a/src/textpath.js b/src/textpath.js
index 4750310..a8192b6 100644
--- a/src/textpath.js
+++ b/src/textpath.js
@@ -24,7 +24,7 @@ SVG.TextPath = SVG.invent({
this.node.appendChild(path.node)
// link textPath to path and add content
- path.attr('href', '#' + track, SVG.xlink)
+ path.attr('href', link('#' + track), SVG.xlink)
return this
}
diff --git a/src/use.js b/src/use.js
index d3150f7..e63b9f5 100644
--- a/src/use.js
+++ b/src/use.js
@@ -10,7 +10,7 @@ SVG.Use = SVG.invent({
// Use element as a reference
element: function(element, file) {
// Set lined element
- return this.attr('href', (file || '') + '#' + element, SVG.xlink)
+ return this.attr('href', link((file || '') + '#' + element), SVG.xlink)
}
}