diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 8ca6b69e..8410c8d8 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -27,13 +27,13 @@ var isOpera = !!window.opera, support = {}, // this defines which elements and attributes that we support -// TODO: add elements to this // TODO: add to this and marker attributes // TODO: add to this // TODO: add to this // TODO: add to this // TODO: add 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) { // or // 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 diff --git a/test/test1.html b/test/test1.html index 341f4a58..bebac9e3 100644 --- a/test/test1.html +++ b/test/test1.html @@ -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 element"); - equals(null, fu, "Imported a that references a foreign element"); + equals((u && u.nodeName == "use"), true, "Did not import element"); + equals((fu && !fu.getAttributeNS(xlinkns,"href")), true, "Did not remove reference to foreign element in "); + }); + + 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