More bogus namespace fixes

This commit is contained in:
Jacques Distler 2010-04-28 16:44:07 -05:00
parent 86a53d1dfa
commit 10cf102544

View file

@ -1,4 +1,4 @@
/* /*
* svgcanvas.js * svgcanvas.js
* *
* Licensed under the Apache License, Version 2 * Licensed under the Apache License, Version 2
@ -1617,7 +1617,7 @@ function BatchCommand(text) {
var el = this; var el = this;
$.each(this.attributes, function(i, attr) { $.each(this.attributes, function(i, attr) {
var uri = attr.namespaceURI; var uri = attr.namespaceURI;
if(uri && !nsuris[uri] && nsMap[uri] !== 'xmlns') { if(uri && !nsuris[uri] && nsMap[uri] !== 'xmlns' && nsMap[uri] !== 'xml' ) {
nsuris[uri] = true; nsuris[uri] = true;
out.push(" xmlns:" + nsMap[uri] + '="' + uri +'"'); out.push(" xmlns:" + nsMap[uri] + '="' + uri +'"');
} }
@ -1632,9 +1632,6 @@ function BatchCommand(text) {
// Namespaces have already been dealt with, so skip // Namespaces have already been dealt with, so skip
if(attr.nodeName.indexOf('xmlns:') === 0) continue; if(attr.nodeName.indexOf('xmlns:') === 0) continue;
//remove bogus attributes added by Gecko
if (attr.localName == '-moz-math-font-style') continue;
// only serialize attributes we don't use internally // only serialize attributes we don't use internally
if (attrVal != "" && if (attrVal != "" &&
$.inArray(attr.localName, ['width','height','xmlns','x','y','viewBox','id','overflow']) == -1) $.inArray(attr.localName, ['width','height','xmlns','x','y','viewBox','id','overflow']) == -1)
@ -1651,7 +1648,8 @@ function BatchCommand(text) {
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);
var attrVal = toXml(attr.nodeValue); var attrVal = toXml(attr.nodeValue);
if (attr.localName == '-moz-math-font-style') continue; //remove bogus attributes added by Gecko
if ($.inArray(attr.localName, ['-moz-math-font-style', '_moz-math-font-style']) !== -1) continue;
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; if(attr.localName == "class" && attrVal.indexOf('se_') == 0) continue;
@ -7595,9 +7593,9 @@ function BatchCommand(text) {
this.changeSelectedAttribute("opacity", val); this.changeSelectedAttribute("opacity", val);
}; };
this.getBlur = function() { this.getBlur = function(elem) {
var val = 0; var val = 0;
var elem = selectedElements[0]; // var elem = selectedElements[0];
if(elem) { if(elem) {
var filter_url = elem.getAttribute('filter'); var filter_url = elem.getAttribute('filter');
@ -7609,26 +7607,58 @@ function BatchCommand(text) {
} }
} }
return val; return val;
};
(function() {
var cur_command = null;
var filter = null;
var filterHidden = false;
canvas.setBlurNoUndo = function(val) {
if(!filter) {
canvas.setBlur(val);
return;
}
if(val === 0) {
// Don't change the StdDev, as that will hide the element.
// Instead, just remove the value for "filter"
canvas.changeSelectedAttributeNoUndo("filter", "");
filterHidden = true;
} else {
if(filterHidden) {
canvas.changeSelectedAttributeNoUndo("filter", 'url(#' + selectedElements[0].id + '_blur)');
}
canvas.changeSelectedAttributeNoUndo("stdDeviation", val, [filter.firstChild]);
}
}
function finishChange() {
var bCmd = canvas.finishUndoableChange();
cur_command.addSubCommand(bCmd);
addCommandToHistory(cur_command);
cur_command = null;
filter = null;
}
canvas.setBlur = function(val, complete) {
if(cur_command) {
finishChange();
return;
} }
this.setBlur = function(val, noUndo) {
// Looks for associated blur, creates one if not found // Looks for associated blur, creates one if not found
var elem_id = selectedElements[0].id; var elem = selectedElements[0];
var filter = getElem(elem_id + '_blur'); var elem_id = elem.id;
filter = getElem(elem_id + '_blur');
val -= 0; val -= 0;
var batchCmd = new BatchCommand();
// Blur found! // Blur found!
if(filter) { if(filter) {
if(val === 0) { if(val === 0) {
$(filter).remove(); filter = null;
} else {
var elem = filter.firstChild;
if(noUndo) {
this.changeSelectedAttributeNoUndo('stdDeviation', val, [elem]);
} else {
this.changeSelectedAttribute('stdDeviation', val, [elem]);
}
} }
} else { } else {
// Not found, so create // Not found, so create
@ -7647,13 +7677,21 @@ function BatchCommand(text) {
filter.appendChild(newblur); filter.appendChild(newblur);
findDefs().appendChild(filter); findDefs().appendChild(filter);
batchCmd.addSubCommand(new InsertElementCommand(filter));
} }
var changes = {filter: elem.getAttribute('filter')};
if(val === 0) { if(val === 0) {
selectedElements[0].removeAttribute("filter"); elem.removeAttribute("filter");
batchCmd.addSubCommand(new ChangeElementCommand(elem, changes));
return;
} else { } else {
this.changeSelectedAttribute("filter", 'url(#' + elem_id + '_blur)'); this.changeSelectedAttribute("filter", 'url(#' + elem_id + '_blur)');
batchCmd.addSubCommand(new ChangeElementCommand(elem, changes));
if(val > 3) { if(val > 3) {
// TODO: Create algorithm here where size is based on expected blur // TODO: Create algorithm here where size is based on expected blur
assignAttributes(filter, { assignAttributes(filter, {
@ -7669,7 +7707,15 @@ function BatchCommand(text) {
filter.removeAttribute('height'); filter.removeAttribute('height');
} }
} }
cur_command = batchCmd;
canvas.beginUndoableChange("stdDeviation", [filter?filter.firstChild:null]);
if(complete) {
canvas.setBlurNoUndo(val);
finishChange();
}
}; };
}());
this.getFillOpacity = function() { this.getFillOpacity = function() {
return cur_shape.fill_opacity; return cur_shape.fill_opacity;
@ -8946,7 +8992,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: 1548 $)"; return "svgcanvas.js ($Rev: 1552 $)";
}; };
this.setUiStrings = function(strs) { this.setUiStrings = function(strs) {