Move convertAttrs into units.js

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1849 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
Jeff Schiller
2010-11-06 14:37:00 +00:00
parent e64bee32a8
commit abab2645af
2 changed files with 40 additions and 48 deletions

View File

@@ -138,4 +138,39 @@ svgedit.units.setUnitAttr = function(elem, attr, val) {
elem.setAttribute(attr, val);
};
var attrsToConvert = {
"line": ['x1', 'x2', 'y1', 'y2'],
"circle": ['cx', 'cy', 'r'],
"ellipse": ['cx', 'cy', 'rx', 'ry'],
"foreignObject": ['x', 'y', 'width', 'height'],
"rect": ['x', 'y', 'width', 'height'],
"image": ['x', 'y', 'width', 'height'],
"use": ['x', 'y', 'width', 'height'],
"text": ['x', 'y']
};
// Function: svgedit.units.convertAttrs
// Converts all applicable attributes to the configured baseUnit
//
// Parameters:
// element - a DOM element whose attributes should be converted
svgedit.units.convertAttrs = function(element) {
var elName = element.tagName;
var unit = svgedit.units.config_.baseUnit;
var attrs = attrsToConvert[elName];
if(!attrs) return;
var len = attrs.length
for(var i = 0; i < len; i++) {
var attr = attrs[i];
var cur = element.getAttribute(attr);
if(cur) {
if(!isNaN(cur)) {
element.setAttribute(attr, (cur / svgedit.units.typeMap_[unit]) + unit);
} else {
// Convert existing?
}
}
}
};
})();