Merge branch 'bzr/golem' of /Users/distler/Sites/code/instiki

This commit is contained in:
Jacques Distler 2010-02-12 12:40:25 -06:00
commit 852848749c
5 changed files with 110 additions and 77 deletions

View file

@ -82,11 +82,11 @@ function setupSVGedit(path){
f.insert({top: SVGeditButton}); f.insert({top: SVGeditButton});
SVGeditButton.disabled = true; SVGeditButton.disabled = true;
Event.observe(SVGeditButton, 'click', function(){ Event.observe(SVGeditButton, 'click', function(){
var editor = window.open(path, 'Edit SVG graphic', 'status=1,resizable=1,scrollbars=1');
if (selected) { if (selected) {
var editor = window.open(path +'?source=data:image/svg+xml;base64,' + window.btoa(selected), editor.addEventListener("load", function() {
'Editing Existing SVG Graphic', 'status=1,resizable=1,scrollbars=1'); editor.svgCanvas.setSvgString(selected);
} else { }, true);
var editor = window.open(path, 'Creating New SVG graphic', 'status=1,resizable=1,scrollbars=1');
} }
SVGeditButton.disabled = true; SVGeditButton.disabled = true;
SVGeditButton.value = 'Create SVG graphic'; SVGeditButton.value = 'Create SVG graphic';

View file

@ -625,6 +625,7 @@ function svg_edit_setup() {
// updates the toolbar (colors, opacity, etc) based on the selected element // updates the toolbar (colors, opacity, etc) based on the selected element
var updateToolbar = function() { var updateToolbar = function() {
if (selectedElement != null && if (selectedElement != null &&
selectedElement.tagName != "foreignObject" &&
selectedElement.tagName != "image" && selectedElement.tagName != "image" &&
selectedElement.tagName != "g") selectedElement.tagName != "g")
{ {

View file

@ -976,7 +976,7 @@ function BatchCommand(text) {
if($.inArray(attr, w_attrs) !== -1) { if($.inArray(attr, w_attrs) !== -1) {
return num * res.w; return num * res.w;
} else if($.inArray(attr, w_attrs) !== -1) { } else if($.inArray(attr, h_attrs) !== -1) {
return num * res.h; return num * res.h;
} else { } else {
return num * Math.sqrt((res.w*res.w) + (res.h*res.h))/Math.sqrt(2); return num * Math.sqrt((res.w*res.w) + (res.h*res.h))/Math.sqrt(2);
@ -1003,7 +1003,7 @@ function BatchCommand(text) {
val *= 100; val *= 100;
if($.inArray(attr, w_attrs) !== -1) { if($.inArray(attr, w_attrs) !== -1) {
val = val / res.w; val = val / res.w;
} else if($.inArray(attr, w_attrs) !== -1) { } else if($.inArray(attr, h_attrs) !== -1) {
val = val / res.h; val = val / res.h;
} else { } else {
return val / Math.sqrt((res.w*res.w) + (res.h*res.h))/Math.sqrt(2); return val / Math.sqrt((res.w*res.w) + (res.h*res.h))/Math.sqrt(2);
@ -4720,11 +4720,18 @@ function BatchCommand(text) {
} }
// else, create a new point, append to pts array, update path element // else, create a new point, append to pts array, update path element
else { else {
// Checks if current target or parents are #svgcontent
if(!$.contains(container, evt.target)) {
// Clicked outside canvas, so don't make point
return false;
}
var lastx = current_path_pts[len-2], lasty = current_path_pts[len-1]; var lastx = current_path_pts[len-2], lasty = current_path_pts[len-1];
// we store absolute values in our path points array for easy checking above // we store absolute values in our path points array for easy checking above
current_path_pts.push(x); current_path_pts.push(x);
current_path_pts.push(y); current_path_pts.push(y);
d_attr += "L" + round(x) + "," + round(y) + " "; d_attr += "L" + round(x) + "," + round(y) + " ";
path.setAttribute("d", d_attr); path.setAttribute("d", d_attr);
// set stretchy line to latest point // set stretchy line to latest point
@ -7743,7 +7750,7 @@ function BatchCommand(text) {
// Function: getVersion // Function: getVersion
// Returns a string which describes the revision number of SvgCanvas. // Returns a string which describes the revision number of SvgCanvas.
this.getVersion = function() { this.getVersion = function() {
return "svgcanvas.js ($Rev: 1380 $)"; return "svgcanvas.js ($Rev: 1382 $)";
}; };
this.setUiStrings = function(strs) { this.setUiStrings = function(strs) {

View file

@ -163,6 +163,31 @@
equals(null, t.getAttribute("d"), "Imported a <text> with a d attribute"); equals(null, t.getAttribute("d"), "Imported a <text> with a d attribute");
}); });
// This test makes sure import/export properly handles namespaced attributes
test("Test importing/exporting namespaced attributes", function() {
expect(5);
var set = svgCanvas.setSvgString('<svg width="640" height="480" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:se="http://svg-edit.googlecode.com" xmlns:foo="http://example.com">'+
'<image xlink:href="../editor/images/logo.png"/>' +
'<polyline id="se_test_elem" se:foo="bar"/>' +
'</svg>');
var attrVal = document.getElementById('se_test_elem').getAttributeNS("http://svg-edit.googlecode.com", "foo");
equals(true, attrVal === "bar", "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_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");
});
}); });
</script> </script>
</head> </head>