misc cleaned up sanitize inconsistent indentation

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2469 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
Bruno Heridet
2013-02-25 12:39:27 +00:00
parent 71586aa5fe
commit 2c1c5da6de

View File

@@ -118,12 +118,13 @@ svgedit.sanitize.sanitizeSvg = function(node) {
// Trim whitespace
node.nodeValue = node.nodeValue.replace(/^\s+|\s+$/g, '');
// Remove if empty
if(node.nodeValue.length == 0) node.parentNode.removeChild(node);
if (node.nodeValue.length === 0) {
node.parentNode.removeChild(node);
}
}
// We only care about element nodes.
// Automatically return for all non-element nodes,
// such as comments, etc.
// Automatically return for all non-element nodes, such as comments, etc.
if (node.nodeType != 1) { // 1 == ELEMENT_NODE
return;
}
@@ -131,16 +132,17 @@ svgedit.sanitize.sanitizeSvg = function(node) {
var doc = node.ownerDocument;
var parent = node.parentNode;
// can parent ever be null here? I think the root node's parent is the document...
if (!doc || !parent) return;
if (!doc || !parent) {
return;
}
var allowedAttrs = svgWhiteList_[node.nodeName];
var allowedAttrsNS = svgWhiteListNS_[node.nodeName];
// if this element is supported, sanitize it
if (allowedAttrs != undefined) {
var se_attrs = [];
if (typeof allowedAttrs !== 'undefined') {
var seAttrs = [];
var i = node.attributes.length;
while (i--) {
// if the attribute is not in our whitelist, then remove it
@@ -157,15 +159,15 @@ svgedit.sanitize.sanitizeSvg = function(node) {
// TODO(codedread): Programmatically add the se: attributes to the NS-aware whitelist.
// Bypassing the whitelist to allow se: prefixes.
// Is there a more appropriate way to do this?
if(attrName.indexOf('se:') == 0) {
se_attrs.push([attrName, attr.nodeValue]);
if (attrName.indexOf('se:') === 0) {
seAttrs.push([attrName, attr.nodeValue]);
}
node.removeAttributeNS(attrNsURI, attrLocalName);
}
// Add spaces before negative signs where necessary
if(svgedit.browser.isGecko()) {
switch ( attrName ) {
if (svgedit.browser.isGecko()) {
switch (attrName) {
case 'transform':
case 'gradientTransform':
case 'patternTransform':
@@ -178,7 +180,7 @@ svgedit.sanitize.sanitizeSvg = function(node) {
if (attrName == 'style') {
var props = attr.nodeValue.split(';'),
p = props.length;
while(p--) {
while (p--) {
var nv = props[p].split(':');
var styleAttrName = $.trim(nv[0]);
var styleAttrVal = $.trim(nv[1]);
@@ -191,14 +193,14 @@ svgedit.sanitize.sanitizeSvg = function(node) {
}
}
$.each(se_attrs, function(i, attr) {
$.each(seAttrs, function(i, attr) {
node.setAttributeNS(NS.SE, attr[0], attr[1]);
});
// for some elements that have a xlink:href, ensure the URI refers to a local element
// (but not for links)
var href = svgedit.utilities.getHref(node);
if(href &&
if (href &&
['filter', 'linearGradient', 'pattern',
'radialGradient', 'textPath', 'use'].indexOf(node.nodeName) >= 0)
{
@@ -248,9 +250,7 @@ svgedit.sanitize.sanitizeSvg = function(node) {
// call sanitizeSvg on each of those children
var i = children.length;
while (i--) { svgedit.sanitize.sanitizeSvg(children[i]); }
}
};
})();