Fix bug where IDs could not be changed. Moved cleanupElement into svgutils.js. Corrected MIME type of two new test files.

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1990 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Jeff Schiller 2011-02-10 04:10:03 +00:00
parent ca671f90d2
commit 45a26c1602
4 changed files with 51 additions and 48 deletions

View File

@ -1902,15 +1902,17 @@
return false; return false;
} }
if(isNaN(val)) { if (attr !== "id") {
val = svgCanvas.convertToNum(attr, val); if (isNaN(val)) {
} else if(curConfig.baseUnit !== 'px') { val = svgCanvas.convertToNum(attr, val);
// Convert unitless value to one with given unit } else if(curConfig.baseUnit !== 'px') {
// Convert unitless value to one with given unit
var unitData = svgedit.units.getTypeMap(); var unitData = svgedit.units.getTypeMap();
if(selectedElement[attr] || svgCanvas.getMode() === "pathedit" || attr === "x" || attr === "y") { if(selectedElement[attr] || svgCanvas.getMode() === "pathedit" || attr === "x" || attr === "y") {
val *= unitData[curConfig.baseUnit]; val *= unitData[curConfig.baseUnit];
}
} }
} }

View File

@ -236,37 +236,6 @@ var cur_shape = all_properties.shape;
// default size of 1 until it needs to grow bigger // default size of 1 until it needs to grow bigger
var selectedElements = new Array(1); var selectedElements = new Array(1);
// Function: cleanupElement
// Remove unneeded (default) attributes, makes resulting SVG smaller
//
// Parameters:
// element - DOM element to clean up
var cleanupElement = this.cleanupElement = function(element) {
var handle = svgroot.suspendRedraw(60);
var defaults = {
'fill-opacity':1,
'stop-opacity':1,
'opacity':1,
'stroke':'none',
'stroke-dasharray':'none',
'stroke-linejoin':'miter',
'stroke-linecap':'butt',
'stroke-opacity':1,
'stroke-width':1,
'rx':0,
'ry':0
}
for(var attr in defaults) {
var val = defaults[attr];
if(element.getAttribute(attr) == val) {
element.removeAttribute(attr);
}
}
svgroot.unsuspendRedraw(handle);
};
// Function: addSvgElementFromJson // Function: addSvgElementFromJson
// Create a new SVG element based on the given object keys/values and add it to the current layer // Create a new SVG element based on the given object keys/values and add it to the current layer
// The element will be ran through cleanupElement before being returned // The element will be ran through cleanupElement before being returned
@ -279,7 +248,7 @@ var cleanupElement = this.cleanupElement = function(element) {
// //
// Returns: The new element // Returns: The new element
var addSvgElementFromJson = this.addSvgElementFromJson = function(data) { var addSvgElementFromJson = this.addSvgElementFromJson = function(data) {
var shape = getElem(data.attr.id); var shape = svgedit.utilities.getElem(data.attr.id);
// if shape is a path but we need to create a rect/ellipse, then remove the path // if shape is a path but we need to create a rect/ellipse, then remove the path
var current_layer = getCurrentDrawing().getCurrentLayer(); var current_layer = getCurrentDrawing().getCurrentLayer();
if (shape && data.element != shape.tagName) { if (shape && data.element != shape.tagName) {
@ -293,7 +262,7 @@ var addSvgElementFromJson = this.addSvgElementFromJson = function(data) {
} }
} }
if(data.curStyles) { if(data.curStyles) {
assignAttributes(shape, { svgedit.utilities.assignAttributes(shape, {
"fill": cur_shape.fill, "fill": cur_shape.fill,
"stroke": cur_shape.stroke, "stroke": cur_shape.stroke,
"stroke-width": cur_shape.stroke_width, "stroke-width": cur_shape.stroke_width,
@ -306,8 +275,8 @@ var addSvgElementFromJson = this.addSvgElementFromJson = function(data) {
"style": "pointer-events:inherit" "style": "pointer-events:inherit"
}, 100); }, 100);
} }
assignAttributes(shape, data.attr, 100); svgedit.utilities.assignAttributes(shape, data.attr, 100);
cleanupElement(shape); svgedit.utilities.cleanupElement(shape);
return shape; return shape;
}; };
@ -327,7 +296,7 @@ var getMatrix = svgedit.math.getMatrix;
// send in an object implementing the ElementContainer interface (see units.js) // send in an object implementing the ElementContainer interface (see units.js)
svgedit.units.init({ svgedit.units.init({
getBaseUnit: function() { return curConfig.baseUnit; }, getBaseUnit: function() { return curConfig.baseUnit; },
getElement: getElem, getElement: svgedit.utilities.getElem,
getHeight: function() { return svgcontent.getAttribute("height")/current_zoom; }, getHeight: function() { return svgcontent.getAttribute("height")/current_zoom; },
getWidth: function() { return svgcontent.getAttribute("width")/current_zoom; }, getWidth: function() { return svgcontent.getAttribute("width")/current_zoom; },
getRoundDigits: function() { return save_options.round_digits; } getRoundDigits: function() { return save_options.round_digits; }
@ -352,6 +321,7 @@ var getBBox = canvas.getBBox = svgedit.utilities.getBBox;
var getRotationAngle = canvas.getRotationAngle = svgedit.utilities.getRotationAngle; var getRotationAngle = canvas.getRotationAngle = svgedit.utilities.getRotationAngle;
var getElem = canvas.getElem = svgedit.utilities.getElem; var getElem = canvas.getElem = svgedit.utilities.getElem;
var assignAttributes = canvas.assignAttributes = svgedit.utilities.assignAttributes; var assignAttributes = canvas.assignAttributes = svgedit.utilities.assignAttributes;
var cleanupElement = this.cleanupElement = svgedit.utilities.cleanupElement;
// import from sanitize.js // import from sanitize.js
var nsMap = svgedit.sanitize.getNSMap(); var nsMap = svgedit.sanitize.getNSMap();
@ -6109,7 +6079,7 @@ this.importSvgString = function(xmlString) {
return true; return true;
}; };
// TODO(codedread): Move all layer/context functions in draw.js
// Layer API Functions // Layer API Functions
// Group: Layers // Group: Layers
@ -8777,7 +8747,6 @@ this.getPrivateMethods = function() {
BatchCommand: BatchCommand, BatchCommand: BatchCommand,
call: call, call: call,
ChangeElementCommand: ChangeElementCommand, ChangeElementCommand: ChangeElementCommand,
cleanupElement: cleanupElement,
copyElem: copyElem, copyElem: copyElem,
ffClone: ffClone, ffClone: ffClone,
findDefs: findDefs, findDefs: findDefs,

View File

@ -9,8 +9,8 @@
// Dependencies: // Dependencies:
// 1) jQuery // 1) jQuery
// 2) browser.js: for getBBox(), getElem(), assignAttributes() // 2) browser.js
// 3) svgtransformlist.js: only for getRotationAngle() // 3) svgtransformlist.js
var svgedit = svgedit || {}; var svgedit = svgedit || {};
@ -610,4 +610,36 @@ svgedit.utilities.assignAttributes = function(node, attrs, suspendLength, unitCh
if (!svgedit.browser.isOpera()) svgroot_.unsuspendRedraw(handle); if (!svgedit.browser.isOpera()) svgroot_.unsuspendRedraw(handle);
}; };
// Function: cleanupElement
// Remove unneeded (default) attributes, makes resulting SVG smaller
//
// Parameters:
// element - DOM element to clean up
svgedit.utilities.cleanupElement = function(element) {
var handle = svgroot_.suspendRedraw(60);
var defaults = {
'fill-opacity':1,
'stop-opacity':1,
'opacity':1,
'stroke':'none',
'stroke-dasharray':'none',
'stroke-linejoin':'miter',
'stroke-linecap':'butt',
'stroke-opacity':1,
'stroke-width':1,
'rx':0,
'ry':0
}
for(var attr in defaults) {
var val = defaults[attr];
if(element.getAttribute(attr) == val) {
element.removeAttribute(attr);
}
}
svgroot_.unsuspendRedraw(handle);
};
})(); })();

View File

@ -241,7 +241,7 @@ svgedit.units.convertToNum = function(attr, val) {
// Parameters: // Parameters:
// attr - String with the name of the attribute associated with the value // attr - String with the name of the attribute associated with the value
// val - String with the attribute value to check // val - String with the attribute value to check
svgedit.units.isValidUnit = function(attr, val) { svgedit.units.isValidUnit = function(attr, val) {debugger;
var valid = false; var valid = false;
if(unit_attrs.indexOf(attr) >= 0) { if(unit_attrs.indexOf(attr) >= 0) {
// True if it's just a number // True if it's just a number