diff options
Diffstat (limited to 'src/helpers.js')
-rw-r--r-- | src/helpers.js | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/helpers.js b/src/helpers.js index 50c0330..12d17c0 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -180,9 +180,9 @@ function fullBox(b) { // Get id from reference string function idFromReference(url) { - var m = (url || '').toString().match(SVG.regex.reference) + var m = SVG.regex.reference.exec(url+'') - if (m) return m[1] + if (m) return m[3] } // creates an url reference out of nodes id @@ -197,8 +197,10 @@ function removePrefixFromReferences(node) { var v = node.attributes, match for (n = v.length - 1; n >= 0; n--) { - if(match = SVG.regex.isUrl.exec(v[n].nodeValue)) { - if(match[1] == window.location) v[n].nodeValue = 'url(#' + match[2] + ')' + if(v[n].nodeName == 'xlink:href' && (match = SVG.regex.reference.exec(v[n].nodeValue))) { + if(match[2] == window.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] + ')' } } } @@ -210,8 +212,10 @@ function addPrefixToReferences(node) { var v = node.attributes, match for (n = v.length - 1; n >= 0; n--) { - if(match = SVG.regex.isUrl.exec(v[n].nodeValue)) { - if(!match[1]) v[n].nodeValue = 'url(' + window.location + '#' + match[2] + ')' + if(v[n].nodeName == 'xlink:href' && (match = SVG.regex.reference.exec(v[n].nodeValue))) { + if(!match[2]) v[n].nodeValue = window.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] + ')' } } } |