Permalink
Browse files

Don’t set default values for “default” attributes

  • Loading branch information...
1 parent bb3d309 commit f3ca318b35f7ceb097aae86b2ec6680e9d73f2f0 @davidaurelio davidaurelio committed Dec 7, 2012
Showing with 22 additions and 17 deletions.
  1. +22 −17 src/renderer/svg/svg.js
View
@@ -57,19 +57,20 @@ define([
fontPrefix = AssetController.handlers.Font.prefix;
var basicAttributeMap = {
- cap: 'stroke-linecap',
- join: 'stroke-linejoin',
- miterLimit: 'stroke-miterlimit',
- opacity: 'opacity',
- fillOpacity: 'fill-opacity',
- strokeOpacity: 'stroke-opacity',
- fontSize: 'font-size',
- fontWeight: 'font-weight',
- fontStyle: 'font-style',
- textAnchor: 'text-anchor',
- text: 'text',
- cursor: 'cursor',
- fillRule: 'fill-rule'
+ // bonsai attribute: [svg attribute, default value]
+ cap: ['stroke-linecap', 'butt'],
+ join: ['stroke-linejoin', 'miter'],
+ miterLimit: ['stroke-miterlimit', '4'],
+ opacity: ['opacity', '1'],
+ fillOpacity: ['fill-opacity', '1'],
+ strokeOpacity: ['stroke-opacity', '1'],
+ fontSize: ['font-size'],
+ fontWeight: ['font-weight'],
+ fontStyle: ['font-style'],
+ textAnchor: ['text-anchor', 'start'],
+ text: ['text'],
davidaurelio
davidaurelio Dec 7, 2012 Owner

I have no idea what this attribute is good for. There is no text attribute in svg. Ideas @basecode @padolsey?

davidaurelio
davidaurelio Dec 7, 2012 Owner

As far as I can see it sets an attribute on <tspan>s, but there’s no point in that

basecode
basecode Dec 7, 2012 Owner

No idea.

+ cursor: ['cursor', 'inherit'],
+ fillRule: ['fill-rule', 'inherit']
};
var eventTypes = [
@@ -146,10 +147,14 @@ define([
value = attributes[i];
if (i in basicAttributeMap) {
- if (value != null) {
- el.setAttribute(basicAttributeMap[i], value);
- } else if (value === null) {
- el.removeAttribute(basicAttributeMap[i]);
+ var attributeInfo = basicAttributeMap[i];
+ var attributeName = attributeInfo[0], defaultValue = attributeInfo[1];
+
+ var isInitalValue = '' + value === defaultValue;
+ if (value !== null && !isInitalValue) {
+ el.setAttribute(attributeName, value);
+ } else if (value === null || isInitalValue) {
+ el.removeAttribute(attributeName);
}
continue;
}

0 comments on commit f3ca318

Please sign in to comment.