Rewrote connector extension to use SVG-Edit namespace attrs instead of ids/classes, removed extendWhitelist function, moved extensions to subfolder
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1326 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
05179ee739
commit
cf84f45d60
|
@ -18,8 +18,8 @@
|
||||||
<script type="text/javascript" src="locale/locale.js"></script>
|
<script type="text/javascript" src="locale/locale.js"></script>
|
||||||
<script type="text/javascript" src="svgcanvas.js"></script>
|
<script type="text/javascript" src="svgcanvas.js"></script>
|
||||||
<script type="text/javascript" src="svg-editor.js"></script>
|
<script type="text/javascript" src="svg-editor.js"></script>
|
||||||
<script type="text/javascript" src="ext-arrows.js"></script>
|
<script type="text/javascript" src="../extensions/ext-arrows.js"></script>
|
||||||
<script type="text/javascript" src="ext-connector.js"></script>
|
<script type="text/javascript" src="../extensions/ext-connector.js"></script>
|
||||||
|
|
||||||
<!-- Release version of script tags: >
|
<!-- Release version of script tags: >
|
||||||
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
|
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
|
||||||
|
|
|
@ -31,32 +31,32 @@ var isOpera = !!window.opera,
|
||||||
// TODO: add <symbol> to this
|
// TODO: add <symbol> to this
|
||||||
// TODO: add <tspan> to this
|
// TODO: add <tspan> to this
|
||||||
svgWhiteList = {
|
svgWhiteList = {
|
||||||
"a": ["clip-path", "clip-rule", "fill", "fill-opacity", "fill-rule", "filter", "id", "mask", "opacity", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform", "xlink:href", "xlink:title"],
|
"a": ["clip-path", "clip-rule", "fill", "fill-opacity", "fill-rule", "filter", "id", "class", "mask", "opacity", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform", "xlink:href", "xlink:title"],
|
||||||
"circle": ["clip-path", "clip-rule", "cx", "cy", "fill", "fill-opacity", "fill-rule", "filter", "id", "mask", "opacity", "r", "requiredFeatures", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform"],
|
"circle": ["clip-path", "clip-rule", "cx", "cy", "fill", "fill-opacity", "fill-rule", "filter", "id", "class", "mask", "opacity", "r", "requiredFeatures", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform"],
|
||||||
"clipPath": ["clipPathUnits", "id"],
|
"clipPath": ["clipPathUnits", "id", "class"],
|
||||||
"defs": [],
|
"defs": [],
|
||||||
"desc": [],
|
"desc": [],
|
||||||
"ellipse": ["clip-path", "clip-rule", "cx", "cy", "fill", "fill-opacity", "fill-rule", "filter", "id", "mask", "opacity", "requiredFeatures", "rx", "ry", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform"],
|
"ellipse": ["clip-path", "clip-rule", "cx", "cy", "fill", "fill-opacity", "fill-rule", "filter", "id", "class", "mask", "opacity", "requiredFeatures", "rx", "ry", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform"],
|
||||||
"feGaussianBlur": ["id", "requiredFeatures", "stdDeviation"],
|
"feGaussianBlur": ["id", "class", "requiredFeatures", "stdDeviation"],
|
||||||
"filter": ["filterRes", "filterUnits", "height", "id", "primitiveUnits", "requiredFeatures", "width", "x", "xlink:href", "y"],
|
"filter": ["filterRes", "filterUnits", "height", "id", "class", "primitiveUnits", "requiredFeatures", "width", "x", "xlink:href", "y"],
|
||||||
"g": ["clip-path", "clip-rule", "id", "display", "fill", "fill-opacity", "fill-rule", "filter", "mask", "opacity", "requiredFeatures", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform"],
|
"g": ["clip-path", "clip-rule", "id", "class", "display", "fill", "fill-opacity", "fill-rule", "filter", "mask", "opacity", "requiredFeatures", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform"],
|
||||||
"image": ["clip-path", "clip-rule", "filter", "height", "id", "mask", "opacity", "requiredFeatures", "style", "systemLanguage", "transform", "width", "x", "xlink:href", "xlink:title", "y"],
|
"image": ["clip-path", "clip-rule", "filter", "height", "id", "class", "mask", "opacity", "requiredFeatures", "style", "systemLanguage", "transform", "width", "x", "xlink:href", "xlink:title", "y"],
|
||||||
"line": ["clip-path", "clip-rule", "fill", "fill-opacity", "fill-rule", "filter", "id", "marker-end", "marker-mid", "marker-start", "mask", "opacity", "requiredFeatures", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform", "x1", "x2", "y1", "y2"],
|
"line": ["clip-path", "clip-rule", "fill", "fill-opacity", "fill-rule", "filter", "id", "class", "marker-end", "marker-mid", "marker-start", "mask", "opacity", "requiredFeatures", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform", "x1", "x2", "y1", "y2"],
|
||||||
"linearGradient": ["id", "gradientTransform", "gradientUnits", "requiredFeatures", "spreadMethod", "systemLanguage", "x1", "x2", "xlink:href", "y1", "y2"],
|
"linearGradient": ["id", "class", "gradientTransform", "gradientUnits", "requiredFeatures", "spreadMethod", "systemLanguage", "x1", "x2", "xlink:href", "y1", "y2"],
|
||||||
"marker": ["id", "markerHeight", "markerUnits", "markerWidth", "orient", "preserveAspectRatio", "refX", "refY", "systemLanguage", "viewBox"],
|
"marker": ["id", "class", "markerHeight", "markerUnits", "markerWidth", "orient", "preserveAspectRatio", "refX", "refY", "systemLanguage", "viewBox"],
|
||||||
"mask": ["height", "id", "maskContentUnits", "maskUnits", "width", "x", "y"],
|
"mask": ["height", "id", "class", "maskContentUnits", "maskUnits", "width", "x", "y"],
|
||||||
"metadata": ["id"],
|
"metadata": ["id", "class"],
|
||||||
"path": ["clip-path", "clip-rule", "d", "fill", "fill-opacity", "fill-rule", "filter", "id", "marker-end", "marker-mid", "marker-start", "mask", "opacity", "requiredFeatures", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform"],
|
"path": ["clip-path", "clip-rule", "d", "fill", "fill-opacity", "fill-rule", "filter", "id", "class", "marker-end", "marker-mid", "marker-start", "mask", "opacity", "requiredFeatures", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform"],
|
||||||
"polygon": ["clip-path", "clip-rule", "id", "fill", "fill-opacity", "fill-rule", "filter", "id", "marker-end", "marker-mid", "marker-start", "mask", "opacity", "points", "requiredFeatures", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform"],
|
"polygon": ["clip-path", "clip-rule", "id", "class", "fill", "fill-opacity", "fill-rule", "filter", "id", "class", "marker-end", "marker-mid", "marker-start", "mask", "opacity", "points", "requiredFeatures", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform"],
|
||||||
"polyline": ["clip-path", "clip-rule", "id", "fill", "fill-opacity", "fill-rule", "filter", "marker-end", "marker-mid", "marker-start", "mask", "opacity", "points", "requiredFeatures", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform"],
|
"polyline": ["clip-path", "clip-rule", "id", "class", "fill", "fill-opacity", "fill-rule", "filter", "marker-end", "marker-mid", "marker-start", "mask", "opacity", "points", "requiredFeatures", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform"],
|
||||||
"radialGradient": ["id", "cx", "cy", "fx", "fy", "gradientTransform", "gradientUnits", "r", "requiredFeatures", "spreadMethod", "systemLanguage", "xlink:href"],
|
"radialGradient": ["id", "class", "cx", "cy", "fx", "fy", "gradientTransform", "gradientUnits", "r", "requiredFeatures", "spreadMethod", "systemLanguage", "xlink:href"],
|
||||||
"rect": ["clip-path", "clip-rule", "fill", "fill-opacity", "fill-rule", "filter", "height", "id", "mask", "opacity", "requiredFeatures", "rx", "ry", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform", "width", "x", "y"],
|
"rect": ["clip-path", "clip-rule", "fill", "fill-opacity", "fill-rule", "filter", "height", "id", "class", "mask", "opacity", "requiredFeatures", "rx", "ry", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform", "width", "x", "y"],
|
||||||
"stop": ["id", "offset", "requiredFeatures", "stop-color", "stop-opacity", "style", "systemLanguage"],
|
"stop": ["id", "class", "offset", "requiredFeatures", "stop-color", "stop-opacity", "style", "systemLanguage"],
|
||||||
"switch": ["id", "requiredFeatures", "systemLanguage"],
|
"switch": ["id", "class", "requiredFeatures", "systemLanguage"],
|
||||||
"svg": ["clip-path", "clip-rule", "filter", "id", "height", "mask", "requiredFeatures", "style", "systemLanguage", "transform", "viewBox", "width", "xmlns", "xmlns:xlink"],
|
"svg": ["clip-path", "clip-rule", "filter", "id", "class", "height", "mask", "requiredFeatures", "style", "systemLanguage", "transform", "viewBox", "width", "xmlns", "xmlns:xlink"],
|
||||||
"text": ["clip-path", "clip-rule", "fill", "fill-opacity", "fill-rule", "filter", "font-family", "font-size", "font-style", "font-weight", "id", "mask", "opacity", "requiredFeatures", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform", "text-anchor", "x", "xml:space", "y"],
|
"text": ["clip-path", "clip-rule", "fill", "fill-opacity", "fill-rule", "filter", "font-family", "font-size", "font-style", "font-weight", "id", "class", "mask", "opacity", "requiredFeatures", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform", "text-anchor", "x", "xml:space", "y"],
|
||||||
"title": [],
|
"title": [],
|
||||||
"use": ["clip-path", "clip-rule", "filter", "height", "id", "mask", "style", "transform", "width", "x", "xlink:href", "y"]
|
"use": ["clip-path", "clip-rule", "filter", "height", "id", "class", "mask", "style", "transform", "width", "x", "xlink:href", "y"]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
@ -876,6 +876,7 @@ function BatchCommand(text) {
|
||||||
svgns = "http://www.w3.org/2000/svg",
|
svgns = "http://www.w3.org/2000/svg",
|
||||||
xlinkns = "http://www.w3.org/1999/xlink",
|
xlinkns = "http://www.w3.org/1999/xlink",
|
||||||
xmlns = "http://www.w3.org/XML/1998/namespace",
|
xmlns = "http://www.w3.org/XML/1998/namespace",
|
||||||
|
se_ns = "http://svg-edit.googlecode.com",
|
||||||
idprefix = "svg_",
|
idprefix = "svg_",
|
||||||
svgdoc = container.ownerDocument,
|
svgdoc = container.ownerDocument,
|
||||||
svgroot = svgdoc.createElementNS(svgns, "svg");
|
svgroot = svgdoc.createElementNS(svgns, "svg");
|
||||||
|
@ -993,25 +994,7 @@ function BatchCommand(text) {
|
||||||
addSvgElementFromJson: addSvgElementFromJson,
|
addSvgElementFromJson: addSvgElementFromJson,
|
||||||
selectorManager: selectorManager,
|
selectorManager: selectorManager,
|
||||||
findDefs: findDefs,
|
findDefs: findDefs,
|
||||||
recalculateDimensions: recalculateDimensions,
|
recalculateDimensions: recalculateDimensions
|
||||||
// Probably only needed for extensions, so no need to make public?
|
|
||||||
// Also, should we prevent extensions from allowing <script> elements to be added?
|
|
||||||
extendWhitelist: function(new_data) {
|
|
||||||
$.each(new_data, function(elname, attrs) {
|
|
||||||
// add element
|
|
||||||
if(!(elname in svgWhiteList)) {
|
|
||||||
svgWhiteList[elname] = attrs;
|
|
||||||
} else {
|
|
||||||
$.each(attrs, function(i, attr) {
|
|
||||||
// add attributes
|
|
||||||
if($.inArray(attr, svgWhiteList[elname]) == -1) {
|
|
||||||
svgWhiteList[elname].push(attr);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
extensions[name] = ext;
|
extensions[name] = ext;
|
||||||
call("extension_added", ext);
|
call("extension_added", ext);
|
||||||
|
@ -1123,8 +1106,11 @@ function BatchCommand(text) {
|
||||||
if (!doc || !parent) return;
|
if (!doc || !parent) return;
|
||||||
|
|
||||||
var allowedAttrs = svgWhiteList[node.nodeName];
|
var allowedAttrs = svgWhiteList[node.nodeName];
|
||||||
|
|
||||||
// if this element is allowed
|
// if this element is allowed
|
||||||
if (allowedAttrs != undefined) {
|
if (allowedAttrs != undefined) {
|
||||||
|
var se_attrs = [];
|
||||||
|
|
||||||
var i = node.attributes.length;
|
var i = node.attributes.length;
|
||||||
while (i--) {
|
while (i--) {
|
||||||
// if the attribute is not in our whitelist, then remove it
|
// if the attribute is not in our whitelist, then remove it
|
||||||
|
@ -1136,6 +1122,11 @@ function BatchCommand(text) {
|
||||||
// "href" and that namespaceURI matches the XLINK namespace
|
// "href" and that namespaceURI matches the XLINK namespace
|
||||||
var attrName = attr.nodeName;
|
var attrName = attr.nodeName;
|
||||||
if (allowedAttrs.indexOf(attrName) == -1) {
|
if (allowedAttrs.indexOf(attrName) == -1) {
|
||||||
|
// Bypassing the whitelist to allow se: prefixes. Is there
|
||||||
|
// a more appropriate way to do this?
|
||||||
|
if(attrName.indexOf('se:') == 0) {
|
||||||
|
se_attrs.push([attrName, attr.nodeValue]);
|
||||||
|
}
|
||||||
node.removeAttribute(attrName);
|
node.removeAttribute(attrName);
|
||||||
}
|
}
|
||||||
// special handling for path d attribute
|
// special handling for path d attribute
|
||||||
|
@ -1156,6 +1147,11 @@ function BatchCommand(text) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$.each(se_attrs, function(i, attr) {
|
||||||
|
node.setAttributeNS(se_ns, attr[0], attr[1]);
|
||||||
|
});
|
||||||
|
|
||||||
// for filters, uses and gradients, ensure the xlink:href refers to a local element
|
// for filters, uses and gradients, ensure the xlink:href refers to a local element
|
||||||
var href = node.getAttributeNS(xlinkns,"href");
|
var href = node.getAttributeNS(xlinkns,"href");
|
||||||
if(href &&
|
if(href &&
|
||||||
|
@ -1283,11 +1279,14 @@ function BatchCommand(text) {
|
||||||
// keep calling it until there are none to remove
|
// keep calling it until there are none to remove
|
||||||
while (removeUnusedGrads() > 0) {};
|
while (removeUnusedGrads() > 0) {};
|
||||||
pathActions.clear(true);
|
pathActions.clear(true);
|
||||||
|
|
||||||
|
// Keep SVG-Edit comment on top
|
||||||
$.each(svgcontent.childNodes, function(i, node) {
|
$.each(svgcontent.childNodes, function(i, node) {
|
||||||
if(i && node.nodeType == 8 && node.data.indexOf('Created with') != -1) {
|
if(i && node.nodeType == 8 && node.data.indexOf('Created with') != -1) {
|
||||||
svgcontent.insertBefore(node, svgcontent.firstChild);
|
svgcontent.insertBefore(node, svgcontent.firstChild);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var output = svgToString(svgcontent, 0);
|
var output = svgToString(svgcontent, 0);
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
@ -1309,6 +1308,10 @@ function BatchCommand(text) {
|
||||||
var res = canvas.getResolution();
|
var res = canvas.getResolution();
|
||||||
out.push(' width="' + res.w + '" height="' + res.h
|
out.push(' width="' + res.w + '" height="' + res.h
|
||||||
+ '" xmlns:xlink="'+xlinkns+'" xmlns="'+svgns+'"');
|
+ '" xmlns:xlink="'+xlinkns+'" xmlns="'+svgns+'"');
|
||||||
|
if(svgcontent.getAttribute("xmlns:se")) {
|
||||||
|
// TODO: Check if any se: attributes are actually used
|
||||||
|
out.push(' xmlns:se="'+se_ns+'"');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
for (var i=attrs.length-1; i>=0; i--) {
|
for (var i=attrs.length-1; i>=0; i--) {
|
||||||
attr = attrs.item(i);
|
attr = attrs.item(i);
|
||||||
|
@ -1316,6 +1319,7 @@ function BatchCommand(text) {
|
||||||
|
|
||||||
if (attrVal != "") {
|
if (attrVal != "") {
|
||||||
if(attrVal.indexOf('pointer-events') == 0) continue;
|
if(attrVal.indexOf('pointer-events') == 0) continue;
|
||||||
|
if(attr.localName == "class" && attrVal.indexOf('se_') == 0) continue;
|
||||||
out.push(" ");
|
out.push(" ");
|
||||||
if(attr.localName == 'd') attrVal = pathActions.convertPath(elem, true);
|
if(attr.localName == 'd') attrVal = pathActions.convertPath(elem, true);
|
||||||
if(!isNaN(attrVal)) {
|
if(!isNaN(attrVal)) {
|
||||||
|
@ -1343,6 +1347,9 @@ function BatchCommand(text) {
|
||||||
else if(attr.namespaceURI == xmlns) {
|
else if(attr.namespaceURI == xmlns) {
|
||||||
out.push('xml:');
|
out.push('xml:');
|
||||||
}
|
}
|
||||||
|
else if(attr.namespaceURI == se_ns) {
|
||||||
|
out.push('se:');
|
||||||
|
}
|
||||||
out.push(attr.localName); out.push("=\"");
|
out.push(attr.localName); out.push("=\"");
|
||||||
out.push(attrVal); out.push("\"");
|
out.push(attrVal); out.push("\"");
|
||||||
}
|
}
|
||||||
|
@ -5757,6 +5764,13 @@ function BatchCommand(text) {
|
||||||
addCommandToHistory(batchCmd);
|
addCommandToHistory(batchCmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.getEditorNS = function(add) {
|
||||||
|
if(add) {
|
||||||
|
svgcontent.setAttribute('xmlns:se', se_ns);
|
||||||
|
}
|
||||||
|
return se_ns;
|
||||||
|
}
|
||||||
|
|
||||||
this.setResolution = function(x, y) {
|
this.setResolution = function(x, y) {
|
||||||
var res = canvas.getResolution();
|
var res = canvas.getResolution();
|
||||||
var w = res.w, h = res.h;
|
var w = res.w, h = res.h;
|
||||||
|
|
|
@ -91,11 +91,6 @@ $(function() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
S.extendWhitelist({
|
|
||||||
"marker": ["viewBox", "id", "refX", "refY", "markerUnits", "markerWidth", "markerHeight", "orient"],
|
|
||||||
"polyline": ["class", "marker-mid"]
|
|
||||||
});
|
|
||||||
}());
|
}());
|
||||||
|
|
||||||
return {
|
return {
|
|
@ -22,8 +22,9 @@ $(function() {
|
||||||
start_elem,
|
start_elem,
|
||||||
end_elem,
|
end_elem,
|
||||||
connections = [],
|
connections = [],
|
||||||
conn_class = "se_connect",
|
conn_sel = ".se_connector",
|
||||||
connect_str = "-SE_CONNECT-",
|
se_ns,
|
||||||
|
// connect_str = "-SE_CONNECT-",
|
||||||
selElems = [];
|
selElems = [];
|
||||||
|
|
||||||
var lang_list = {
|
var lang_list = {
|
||||||
|
@ -73,15 +74,14 @@ $(function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function findConnectors() {
|
function findConnectors() {
|
||||||
|
|
||||||
// Check if selected elements have connections
|
// Check if selected elements have connections
|
||||||
var elems = selElems;
|
var elems = selElems;
|
||||||
var i = elems.length;
|
var i = elems.length;
|
||||||
var connectors = $(svgcontent).find("." + conn_class);
|
var connectors = $(svgcontent).find(conn_sel);
|
||||||
if(!connectors.length) return;
|
if(!connectors.length) return;
|
||||||
connections = [];
|
connections = [];
|
||||||
|
|
||||||
var sel = ':not(a,g,svg,.'+conn_class+')';
|
var sel = ':not(a,g,svg,'+conn_sel+')';
|
||||||
var all_els = [];
|
var all_els = [];
|
||||||
// Get children from groups
|
// Get children from groups
|
||||||
|
|
||||||
|
@ -101,37 +101,30 @@ $(function() {
|
||||||
|
|
||||||
if(i > 1) {
|
if(i > 1) {
|
||||||
// Multiselected, so unselect connector
|
// Multiselected, so unselect connector
|
||||||
svgCanvas.removeFromSelection($("." + conn_class).toArray());
|
svgCanvas.removeFromSelection($(conn_sel).toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
while(i--) {
|
while(i--) {
|
||||||
var elem = all_els[i];
|
var elem = all_els[i];
|
||||||
if(!elem) continue;
|
if(!elem) continue;
|
||||||
if(elem.getAttribute('class') == conn_class) continue;
|
if($(elem).data('c_start')) continue;
|
||||||
var elem_id = elem.id;
|
|
||||||
connectors.each(function() {
|
connectors.each(function() {
|
||||||
var con_id = this.id;
|
var start = $(this).data("c_start");
|
||||||
if(con_id.indexOf(elem_id) != -1) {
|
var end = $(this).data("c_end");
|
||||||
var is_start = true;
|
if(start == elem.id || end == elem.id) {
|
||||||
if(con_id.indexOf(connect_str + elem_id) != -1) {
|
|
||||||
// Found connector (selected is end elem)
|
|
||||||
is_start = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var bb = svgCanvas.getStrokedBBox([elem]);
|
var bb = svgCanvas.getStrokedBBox([elem]);
|
||||||
var x = bb.x + bb.width/2;
|
var x = bb.x + bb.width/2;
|
||||||
var y = bb.y + bb.height/2;
|
var y = bb.y + bb.height/2;
|
||||||
connections.push({
|
connections.push({
|
||||||
elem: elem,
|
elem: elem,
|
||||||
connector: this,
|
connector: this,
|
||||||
is_start: is_start,
|
is_start: start == elem.id,
|
||||||
start_x: x,
|
start_x: x,
|
||||||
start_y: y
|
start_y: y
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateConnectors() {
|
function updateConnectors() {
|
||||||
|
@ -154,47 +147,42 @@ $(function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init code
|
// Do once
|
||||||
(function() {
|
(function() {
|
||||||
// var conn_tools = $('<div id="connector_panel">\
|
|
||||||
// <label><select id="connector_arrow">\
|
|
||||||
// <option id="conn_arrow_none" value="none">No arrow</option>\
|
|
||||||
// <option id="conn_arrow_arrow" value="arrow">Arrow</option>\
|
|
||||||
// </select></label></div>"').hide().appendTo("#tools_top");
|
|
||||||
//
|
|
||||||
// $('#connector_arrow').change(function() {
|
|
||||||
// switch ( this.value ) {
|
|
||||||
// case "arrow":
|
|
||||||
// addArrow();
|
|
||||||
// break;
|
|
||||||
// case "none":
|
|
||||||
// remArrow();
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
S.extendWhitelist({
|
|
||||||
"marker": ["viewBox", "id", "refX", "refY", "markerUnits", "markerWidth", "markerHeight", "orient"],
|
|
||||||
"polyline": ["class", "marker-mid"]
|
|
||||||
});
|
|
||||||
|
|
||||||
var gse = svgCanvas.groupSelectedElements;
|
var gse = svgCanvas.groupSelectedElements;
|
||||||
|
|
||||||
svgCanvas.groupSelectedElements = function() {
|
svgCanvas.groupSelectedElements = function() {
|
||||||
svgCanvas.removeFromSelection($("." + conn_class).toArray());
|
svgCanvas.removeFromSelection($(conn_sel).toArray());
|
||||||
gse();
|
gse();
|
||||||
}
|
}
|
||||||
|
|
||||||
var mse = svgCanvas.moveSelectedElements;
|
var mse = svgCanvas.moveSelectedElements;
|
||||||
|
|
||||||
svgCanvas.moveSelectedElements = function() {
|
svgCanvas.moveSelectedElements = function() {
|
||||||
svgCanvas.removeFromSelection($("." + conn_class).toArray());
|
svgCanvas.removeFromSelection($(conn_sel).toArray());
|
||||||
mse.apply(this, arguments);
|
mse.apply(this, arguments);
|
||||||
updateConnectors();
|
updateConnectors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
se_ns = svgCanvas.getEditorNS();
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
// Do on reset
|
||||||
|
function init() {
|
||||||
|
// Make sure all connectors have data set
|
||||||
|
$(svgcontent).find('*').each(function() {
|
||||||
|
var conn = this.getAttributeNS(se_ns, "connector");
|
||||||
|
if(conn) {
|
||||||
|
this.setAttribute('class', conn_sel.substr(1));
|
||||||
|
var conn_data = conn.split(' ');
|
||||||
|
$(this).data('c_start',conn_data[0])
|
||||||
|
.data('c_end',conn_data[1]);
|
||||||
|
svgCanvas.getEditorNS(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
findConnectors();
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: "Connector",
|
name: "Connector",
|
||||||
svgicons: "images/conn.svg",
|
svgicons: "images/conn.svg",
|
||||||
|
@ -249,6 +237,7 @@ $(function() {
|
||||||
cur_line = addElem({
|
cur_line = addElem({
|
||||||
"element": "polyline",
|
"element": "polyline",
|
||||||
"attr": {
|
"attr": {
|
||||||
|
"id": getNextId(),
|
||||||
"points": (x+','+y+' '+x+','+y+' '+start_x+','+start_y),
|
"points": (x+','+y+' '+x+','+y+' '+start_x+','+start_y),
|
||||||
"stroke": '#000',
|
"stroke": '#000',
|
||||||
"stroke-width": 1,
|
"stroke-width": 1,
|
||||||
|
@ -285,7 +274,7 @@ $(function() {
|
||||||
while(slen--) {
|
while(slen--) {
|
||||||
var elem = selElems[slen];
|
var elem = selElems[slen];
|
||||||
// Look for selected connector elements
|
// Look for selected connector elements
|
||||||
if(elem && elem.getAttribute('class') == conn_class) {
|
if(elem && $(elem).is(conn_sel)) {
|
||||||
// Remove the "translate" transform given to move
|
// Remove the "translate" transform given to move
|
||||||
svgCanvas.removeFromSelection([elem]);
|
svgCanvas.removeFromSelection([elem]);
|
||||||
svgCanvas.getTransformList(elem).clear();
|
svgCanvas.getTransformList(elem).clear();
|
||||||
|
@ -333,11 +322,15 @@ $(function() {
|
||||||
} else {
|
} else {
|
||||||
// Valid end element
|
// Valid end element
|
||||||
end_elem = e.target;
|
end_elem = e.target;
|
||||||
var line_id = start_elem.id + connect_str + end_elem.id;
|
var start_id = start_elem.id, end_id = end_elem.id;
|
||||||
var alt_line_id = end_elem.id + connect_str + start_elem.id;
|
var conn_str = start_id + " " + end_id;
|
||||||
|
var alt_str = end_id + " " + start_id;
|
||||||
// Don't create connector if one already exists
|
// Don't create connector if one already exists
|
||||||
if($('#'+line_id + ', #' + alt_line_id).length) {
|
var dupe = $(svgcontent).find(conn_sel).filter(function() {
|
||||||
|
var conn = this.getAttributeNS(se_ns, "connector");
|
||||||
|
if(conn == conn_str || conn == alt_str) return true;
|
||||||
|
});
|
||||||
|
if(dupe.length) {
|
||||||
$(cur_line).remove();
|
$(cur_line).remove();
|
||||||
return {
|
return {
|
||||||
keep: false,
|
keep: false,
|
||||||
|
@ -350,11 +343,15 @@ $(function() {
|
||||||
var x = bb.x + bb.width/2;
|
var x = bb.x + bb.width/2;
|
||||||
var y = bb.y + bb.height/2;
|
var y = bb.y + bb.height/2;
|
||||||
setPoint(cur_line, 'end', x, y, true);
|
setPoint(cur_line, 'end', x, y, true);
|
||||||
cur_line.id = line_id;
|
$(cur_line)
|
||||||
cur_line.setAttribute("class", conn_class);
|
.data("c_start", start_id)
|
||||||
|
.data("c_end", end_id);
|
||||||
|
se_ns = svgCanvas.getEditorNS(true);
|
||||||
|
cur_line.setAttributeNS(se_ns, "se:connector", conn_str);
|
||||||
|
cur_line.setAttribute('class', conn_sel.substr(1));
|
||||||
svgCanvas.addToSelection([cur_line]);
|
svgCanvas.addToSelection([cur_line]);
|
||||||
svgCanvas.moveToBottomSelectedElement();
|
svgCanvas.moveToBottomSelectedElement();
|
||||||
|
selManager.requestSelector(cur_line).showGrips(false);
|
||||||
started = false;
|
started = false;
|
||||||
return {
|
return {
|
||||||
keep: true,
|
keep: true,
|
||||||
|
@ -373,9 +370,8 @@ $(function() {
|
||||||
|
|
||||||
while(i--) {
|
while(i--) {
|
||||||
var elem = selElems[i];
|
var elem = selElems[i];
|
||||||
if(elem && elem.getAttribute('class') == conn_class) {
|
if(elem && $(elem).data('c_start')) {
|
||||||
selManager.requestSelector(elem).showGrips(false);
|
selManager.requestSelector(elem).showGrips(false);
|
||||||
|
|
||||||
if(opts.selectedElement && !opts.multiselected) {
|
if(opts.selectedElement && !opts.multiselected) {
|
||||||
// TODO: Set up context tools and hide most regular line tools
|
// TODO: Set up context tools and hide most regular line tools
|
||||||
showPanel(true);
|
showPanel(true);
|
||||||
|
@ -392,6 +388,7 @@ $(function() {
|
||||||
if (elem && elem.tagName == 'svg' && elem.id == "svgcontent") {
|
if (elem && elem.tagName == 'svg' && elem.id == "svgcontent") {
|
||||||
// Update svgcontent (can change on import)
|
// Update svgcontent (can change on import)
|
||||||
svgcontent = elem;
|
svgcontent = elem;
|
||||||
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateConnectors();
|
updateConnectors();
|
Loading…
Reference in New Issue