Uniquify IDs in SVG-Edit

Since we can have several SVG-Edit graphics
on a page, SVG-Edit should assign unique IDs
to elements, and do so in a fashion that survives
re-editing.

To do this, we use a nonce, and record its value in
a custom se:nonce attribute on the <svg> element.
(Is there a better way?). 

Also, preserve the custom se:connector attribute for
later editing purposes.
This commit is contained in:
Jacques Distler 2010-02-25 02:25:16 -06:00
parent c4003f79b3
commit aa0a151ba4
4 changed files with 34 additions and 8 deletions

View file

@ -12,7 +12,10 @@ $(function() {
svgCanvas.addExtension("Arrows", function(S) {
var svgcontent = S.svgcontent,
addElem = S.addSvgElementFromJson,
nonce = S.nonce,
selElems;
svgCanvas.bind('setarrownonce', setArrowNonce);
var lang_list = {
"en":[
@ -23,10 +26,20 @@ $(function() {
]
};
var prefix = 'se_arrow_';
var arrowprefix = prefix + nonce + '_';
var pathdata = {
fw: {d:"m0,0l10,5l-10,5l5,-5l-5,-5z", refx:8, id:"se_arrow_fw"},
bk: {d:"m10,0l-10,5l10,5l-5,-5l5,-5z", refx:2, id:"se_arrow_bk"}
fw: {d:"m0,0l10,5l-10,5l5,-5l-5,-5z", refx:8, id: arrowprefix + 'fw'},
bk: {d:"m10,0l-10,5l10,5l-5,-5l5,-5z", refx:2, id: arrowprefix + 'bk'}
}
function setArrowNonce(window, n) {
arrowprefix = prefix + n + '_';
pathdata.fw.id = arrowprefix + 'fw';
pathdata.bk.id = arrowprefix + 'bk';
}
function getLinked(elem, attr) {
var str = elem.getAttribute(attr);
if(!str) return null;
@ -77,7 +90,7 @@ $(function() {
function addMarker(dir, type, id) {
// TODO: Make marker (or use?) per arrow type, since refX can be different
id = id || 'se_arrow_' + dir;
id = id || arrowprefix + dir;
var marker = S.getElem(id);
@ -174,7 +187,7 @@ $(function() {
var last_id = marker.id;
var dir = last_id.indexOf('_fw') !== -1?'fw':'bk';
new_marker = addMarker(dir, type, 'se_arrow_' + dir + all_markers.length);
new_marker = addMarker(dir, type, arrowprefix + dir + all_markers.length);
$(new_marker).children().attr('fill', color);
}