Skip to content

Commit

Permalink
Update ID in animateMotion ‘begin’ attribute. Fixes svg#373
Browse files Browse the repository at this point in the history
  • Loading branch information
GreLI committed Jun 21, 2015
1 parent b5d4166 commit 20e2a30
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
25 changes: 14 additions & 11 deletions plugins/cleanupIDs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ exports.params = {
var referencesProps = require('./_collections').referencesProps,
regReferencesUrl = /^url\(("|')?#(.+?)\1\)$/,
regReferencesHref = /^#(.+?)$/,
regReferencesBegin = /^(\w+?)\./,
styleOrScript = ['style', 'script'],
generateIDchars = [
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
Expand Down Expand Up @@ -83,15 +84,14 @@ exports.fn = function(data, params) {
}

// save IDs href references
else if (attr.name === 'xlink:href') {
match = attr.value.match(regReferencesHref);

if (match) {
if (referencesIDs[idPrefix + match[1]]) {
referencesIDs[idPrefix + match[1]].push(attr);
} else {
referencesIDs[idPrefix + match[1]] = [attr];
}
else if (
attr.name === 'xlink:href' && (match = attr.value.match(regReferencesHref)) ||
attr.name === 'begin' && (match = attr.value.match(regReferencesBegin))
) {
if (referencesIDs[idPrefix + match[1]]) {
referencesIDs[idPrefix + match[1]].push(attr);
} else {
referencesIDs[idPrefix + match[1]] = [attr];
}
}
});
Expand Down Expand Up @@ -126,13 +126,16 @@ exports.fn = function(data, params) {
IDs[k].attr('id').value = currentIDstring;

referencesIDs[k].forEach(function(attr) {
attr.value = attr.value.replace('#' + k.replace(idPrefix, ''), '#' + currentIDstring);
k = k.replace(idPrefix, '');
attr.value = attr.value
.replace('#' + k, '#' + currentIDstring)
.replace(k + '.', currentIDstring + '.');
});

}

// don't remove referenced IDs
delete IDs[k];
delete IDs[idPrefix + k];

}
}
Expand Down
8 changes: 8 additions & 0 deletions test/plugins/cleanupIDs.01.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 20e2a30

Please sign in to comment.