diff --git a/public/javascripts/page_helper.js b/public/javascripts/page_helper.js index a5562be3..ceb8f08d 100644 --- a/public/javascripts/page_helper.js +++ b/public/javascripts/page_helper.js @@ -85,8 +85,23 @@ function setupSVGedit(path){ var editor = window.open(path, 'Edit SVG graphic', 'status=1,resizable=1,scrollbars=1'); if (selected) { editor.addEventListener("load", function() { + editor.svgCanvas.setCustomHandlers({ + 'save': function(window,svg){ + window.opener.postMessage(svg, window.location.protocol + '//' + window.location.host); + window.close(); + } + }); editor.svgCanvas.setSvgString(selected); }, true); + } else { + editor.addEventListener("load", function() { + editor.svgCanvas.setCustomHandlers({ + 'save': function(window,svg){ + window.opener.postMessage(svg, window.location.protocol + '//' + window.location.host); + window.close(); + } + }); + }, true); } SVGeditButton.disabled = true; SVGeditButton.value = 'Create SVG graphic'; diff --git a/public/svg-edit/editor/svg-editor.css b/public/svg-edit/editor/svg-editor.css index 0d99975e..c2f7940a 100644 --- a/public/svg-edit/editor/svg-editor.css +++ b/public/svg-edit/editor/svg-editor.css @@ -1,4 +1,4 @@ -body { +body { background: #D8D8D8; } @@ -734,6 +734,7 @@ span.zoom_tool { #tool_docprops_back { margin-left: 1em; + overflow: auto; } #svg_docprops_container #svg_docprops_docprops, diff --git a/public/svg-edit/editor/svg-editor.html b/public/svg-edit/editor/svg-editor.html index a45097f7..123ef564 100644 --- a/public/svg-edit/editor/svg-editor.html +++ b/public/svg-edit/editor/svg-editor.html @@ -312,7 +312,10 @@ script type="text/javascript" src="locale/locale.min.js">
- +
diff --git a/public/svg-edit/editor/svg-editor.js b/public/svg-edit/editor/svg-editor.js index 837e45e0..55debeab 100644 --- a/public/svg-edit/editor/svg-editor.js +++ b/public/svg-edit/editor/svg-editor.js @@ -171,10 +171,10 @@ function svg_edit_setup() { var strokePaint = new $.jGraduate.Paint({solidColor: "000000"}); // solid black var saveHandler = function(window,svg) { + // by default, we add the XML prolog back, systems integrating SVG-edit (wikis, CMSs) + // can just provide their own custom save handler and might not want the XML prolog + svg = "\n" + svg; - window.opener.postMessage(svg, window.location.protocol + '//' + window.location.host); - return; - // Creates and opens an HTML page that provides a link to the SVG, a preview, and the markup. // Also includes warning about Mozilla bug #308590 when applicable @@ -1738,7 +1738,7 @@ function svg_edit_setup() { 'margin-top': {s: '2px', l: '4px', xl: '5px'}, 'height': {s: 'auto', l: 'auto', xl: 'auto'}, 'border': {s: '1px solid #555', l: 'auto', xl: 'auto'}, - 'font-size': {s: '.9em', l: '2em', xl: '2.5em'} + 'font-size': {s: '.9em', l: '1.2em', xl: '1.4em'} }, "#zoom_panel": { 'margin-top': {s: '3px', l: '4px', xl: '5px'} @@ -1758,10 +1758,12 @@ function svg_edit_setup() { 'line-height': {s: '18px', l: '34px', xl: '40px'}, 'margin-top': {s: '3px'} }, - "div.toolset, #tools_top label, #tools_bottom label": { + "#tools_top label, #tools_bottom label": { 'font-size': {s: '1em', l: '1.5em', xl: '2em'}, - 'margin-top': {s: '1px', l: '3px', xl: '5px'}, - 'height': {s: '25px', l: '43px', xl: '64px'} + 'height': {s: '25px', l: '42px', xl: '64px'} + }, + "div.toolset": { + 'height': {s: '25px', l: '42px', xl: '64px'} }, "#tool_bold, #tool_italic": { 'font-size': {s: '1.5em', l: '3em', xl: '4.5em'} @@ -2761,7 +2763,7 @@ function svg_edit_setup() { updateCanvas(true); }); -// var revnums = "svg-editor.js ($Rev: 1395 $) "; +// var revnums = "svg-editor.js ($Rev: 1402 $) "; // revnums += svgCanvas.getVersion(); // $('#copyright')[0].setAttribute("title", revnums); return svgCanvas; diff --git a/public/svg-edit/editor/svgcanvas.js b/public/svg-edit/editor/svgcanvas.js index 6d276968..68510b4f 100644 --- a/public/svg-edit/editor/svgcanvas.js +++ b/public/svg-edit/editor/svgcanvas.js @@ -684,7 +684,9 @@ function BatchCommand(text) { 'fill': '#FFF', 'style': 'pointer-events:none' }); - if (!window.opera) rect.setAttribute('filter', 'url(#canvashadow)'); + // Both Firefox and WebKit are too slow with this filter region (especially at higher + // zoom levels) and Opera has at least one bug +// if (!window.opera) rect.setAttribute('filter', 'url(#canvashadow)'); canvasbg.appendChild(rect); svgroot.insertBefore(canvasbg, svgcontent); }; @@ -1343,7 +1345,7 @@ function BatchCommand(text) { if(attrName.indexOf('se:') == 0) { se_attrs.push([attrName, attr.nodeValue]); } - node.removeAttribute(attrName); + node.removeAttributeNS(attrNsURI, attrLocalName); } // special handling for path d attribute if (node.nodeName == 'path' && attrName == 'd') { @@ -1528,7 +1530,7 @@ function BatchCommand(text) { var i = attrs.length; while (i--) { attr = attrs.item(i); - var attrVal = attr.nodeValue; + var attrVal = toXml(attr.nodeValue); // only serialize attributes we don't use internally if (attrVal != "" && $.inArray(attr.localName, ['width','height','xmlns','x','y','viewBox','id','overflow']) == -1) @@ -1542,7 +1544,7 @@ function BatchCommand(text) { } else { for (var i=attrs.length-1; i>=0; i--) { attr = attrs.item(i); - var attrVal = attr.nodeValue; + var attrVal = toXml(attr.nodeValue); if (attr.localName == '-moz-math-font-style') continue; if (attrVal != "") { if(attrVal.indexOf('pointer-events') == 0) continue; @@ -7721,7 +7723,7 @@ function BatchCommand(text) { // Function: getVersion // Returns a string which describes the revision number of SvgCanvas. this.getVersion = function() { - return "svgcanvas.js ($Rev: 1396 $)"; + return "svgcanvas.js ($Rev: 1404 $)"; }; this.setUiStrings = function(strs) { diff --git a/public/svg-edit/test/test1.html b/public/svg-edit/test/test1.html index e039e372..c28be868 100644 --- a/public/svg-edit/test/test1.html +++ b/public/svg-edit/test/test1.html @@ -1,7 +1,7 @@ - + @@ -172,22 +172,50 @@ ''); var attrVal = document.getElementById('se_test_elem').getAttributeNS("http://svg-edit.googlecode.com", "foo"); - equals(true, attrVal === "bar", "Preserved namespaced attribute on import"); + equals(attrVal === "bar", true, "Preserved namespaced attribute on import"); var output = svgCanvas.getSvgString(); var has_xlink = output.indexOf('xmlns:xlink="http://www.w3.org/1999/xlink"') !== -1; var has_se = output.indexOf('xmlns:se=') !== -1; - var has_foo = output.indexOf('xmlns:foo=') === -1; + var has_foo = output.indexOf('xmlns:foo=') !== -1; var has_attr = output.indexOf('se:foo="bar"') !== -1; - equals(true, has_attr, "Preserved namespaced attribute on export"); - equals(true, has_xlink, "Included xlink: xmlns"); - equals(true, has_se, "Included se: xmlns"); - equals(true, has_foo, "Did not include foo: xmlns"); - + equals(has_attr, true, "Preserved namespaced attribute on export"); + equals(has_xlink, true, "Included xlink: xmlns"); + equals(has_se, true, "Included se: xmlns"); + equals(has_foo, false, "Did not include foo: xmlns"); }); + test("Test import math elements inside a foreignObject", function() { + expect(4); + var set = svgCanvas.setSvgString(''+ + ''+ + ''+ + 'A'+ + '0'+ + ''+ + ''+ + ''+ + ''); + var fo = document.getElementById('fo'); + // we cannot use getElementById('math') because not all browsers understand MathML and do not know to use the @id attribute + // see Bug https://bugs.webkit.org/show_bug.cgi?id=35042 + var math = fo.firstChild; + + equals(!!math, true, "Math element exists"); + equals(math.nodeName, 'math', "Math element has the proper nodeName"); + equals(math.getAttribute('id'), 'm', "Math element has an id"); + equals(math.namespaceURI, "http://www.w3.org/1998/Math/MathML", "Preserved MathML namespace"); + }); + test("Test XML entities in attribute", function() { + expect(3); + + equals(svgCanvas.getPrivateMethods().toXml("<"), "<", "Escaped < properly"); + equals(svgCanvas.getPrivateMethods().toXml(">"), ">", "Escaped > properly"); + equals(svgCanvas.getPrivateMethods().toXml("&"), "&", "Escaped & properly"); + // TODO: what about " and ' ? + }); });