Add support in whitelist and remapElements() for <a> elements
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1307 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
@@ -27,13 +27,13 @@ var isOpera = !!window.opera,
|
||||
support = {},
|
||||
|
||||
// this defines which elements and attributes that we support
|
||||
// TODO: add <a> elements to this
|
||||
// TODO: add <marker> to this and marker attributes
|
||||
// TODO: add <mask> to this
|
||||
// TODO: add <pattern> to this
|
||||
// TODO: add <symbol> to this
|
||||
// TODO: add <tspan> to this
|
||||
svgWhiteList = {
|
||||
"a": ["clip-path", "clip-rule", "fill", "fill-opacity", "fill-rule", "filter", "id", "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", "opacity", "r", "requiredFeatures", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform"],
|
||||
"clipPath": ["clipPathUnits", "id"],
|
||||
"defs": [],
|
||||
@@ -1205,16 +1205,18 @@ function BatchCommand(text) {
|
||||
// <circle fill="url('someFile.svg#foo')" /> or
|
||||
// <circle fill='url("someFile.svg#foo")' />
|
||||
this.getUrlFromAttr = function(attrVal) {
|
||||
// url("#somegrad")
|
||||
if (attrVal.indexOf('url("') == 0) {
|
||||
return attrVal.substring(5,attrVal.indexOf('"',6));
|
||||
}
|
||||
// url('#somegrad')
|
||||
else if (attrVal.indexOf("url('") == 0) {
|
||||
return attrVal.substring(5,attrVal.indexOf("'",6));
|
||||
}
|
||||
else if (attrVal.indexOf("url(") == 0) {
|
||||
return attrVal.substring(4,attrVal.indexOf(')'));
|
||||
if (attrVal) {
|
||||
// url("#somegrad")
|
||||
if (attrVal.indexOf('url("') == 0) {
|
||||
return attrVal.substring(5,attrVal.indexOf('"',6));
|
||||
}
|
||||
// url('#somegrad')
|
||||
else if (attrVal.indexOf("url('") == 0) {
|
||||
return attrVal.substring(5,attrVal.indexOf("'",6));
|
||||
}
|
||||
else if (attrVal.indexOf("url(") == 0) {
|
||||
return attrVal.substring(4,attrVal.indexOf(')'));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
@@ -1783,7 +1785,7 @@ function BatchCommand(text) {
|
||||
initial["transform"] = start_transform ? start_transform : "";
|
||||
|
||||
// if it's a group, we have special processing to flatten transforms
|
||||
if (selected.tagName == "g") {
|
||||
if (selected.tagName == "g" || selected.tagName == "a") {
|
||||
var box = canvas.getBBox(selected),
|
||||
oldcenter = {x: box.x+box.width/2, y: box.y+box.height/2},
|
||||
newcenter = transformPoint(box.x+box.width/2, box.y+box.height/2,
|
||||
@@ -3356,7 +3358,13 @@ function BatchCommand(text) {
|
||||
start_transform = null;
|
||||
};
|
||||
|
||||
$(container).mousedown(mouseDown).mousemove(mouseMove);
|
||||
// prevent links from being followed in the canvas
|
||||
var handleLinkInCanvas = function(e) {
|
||||
e.preventDefault();
|
||||
return false;
|
||||
};
|
||||
|
||||
$(container).mousedown(mouseDown).mousemove(mouseMove).click(handleLinkInCanvas);
|
||||
$(window).mouseup(mouseUp);
|
||||
|
||||
$(container).bind("mousewheel DOMMouseScroll", function(e){
|
||||
@@ -6527,7 +6535,7 @@ function BatchCommand(text) {
|
||||
// "fill", "fill-opacity", "fill-rule", "stroke", "stroke-dasharray", "stroke-dashoffset",
|
||||
// "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity",
|
||||
// "stroke-width"
|
||||
// and then for each child, if they do not have the attribute (or the value is 'inherit'?)
|
||||
// and then for each child, if they do not have the attribute (or the value is 'inherit')
|
||||
// then set the child's attribute
|
||||
|
||||
// TODO: get the group's opacity and propagate it down to the children (multiply it
|
||||
|
||||
@@ -25,7 +25,9 @@
|
||||
|
||||
var svgCanvas = new SvgCanvas(document.getElementById("svgcanvas")),
|
||||
svgroot = document.getElementById("svgroot"),
|
||||
svgdoc = svgroot.documentElement;
|
||||
svgdoc = svgroot.documentElement,
|
||||
svgns = "http://www.w3.org/2000/svg",
|
||||
xlinkns = "http://www.w3.org/1999/xlink";
|
||||
|
||||
module("Basic Module");
|
||||
|
||||
@@ -123,8 +125,17 @@
|
||||
var u = document.getElementById("the-use"),
|
||||
fu = document.getElementById("foreign-use");
|
||||
|
||||
equals(true, (u && u.nodeName == "use"), "Did not import <use> element");
|
||||
equals(null, fu, "Imported a <use> that references a foreign element");
|
||||
equals((u && u.nodeName == "use"), true, "Did not import <use> element");
|
||||
equals((fu && !fu.getAttributeNS(xlinkns,"href")), true, "Did not remove reference to foreign element in <use>");
|
||||
});
|
||||
|
||||
test("Test getUrlFromAttr", function() {
|
||||
expect(4);
|
||||
|
||||
equals(svgCanvas.getUrlFromAttr("url(#foo)"), "#foo");
|
||||
equals(svgCanvas.getUrlFromAttr("url(somefile.svg#foo)"), "somefile.svg#foo");
|
||||
equals(svgCanvas.getUrlFromAttr("url('#foo')"), "#foo");
|
||||
equals(svgCanvas.getUrlFromAttr('url("#foo")'), "#foo");
|
||||
});
|
||||
|
||||
// This test shows that an element with an invalid attribute is still parsed in properly
|
||||
|
||||
Reference in New Issue
Block a user