Remove Base.toFloat() and replace with direct parseFloat() calls.

This commit is contained in:
Jürg Lehni 2013-02-28 14:32:34 -08:00
parent d3435ec803
commit e392496f9d
3 changed files with 13 additions and 13 deletions

View file

@ -469,11 +469,7 @@ this.Base = Base.inject(/** @lends Base# */{
*/
formatFloat: function(num, precision) {
precision = precision ? Math.pow(10, precision) : 100000;
return (Math.round(num * precision) / precision);
},
toFloat: function(str) {
return parseFloat(str, 10);
return Math.round(num * precision) / precision;
}
}
});

View file

@ -30,6 +30,7 @@ new function() {
// Base.pick(base.value, base)
return base
? index !== undefined
// Item list? Look up by index:
? index < base.numberOfItems
? Base.pick((base = base.getItem(index)).value, base)
: null
@ -56,7 +57,7 @@ new function() {
return value === 'none'
? null
: type === 'number'
? Base.toFloat(value)
? parseFloat(value)
: type === 'array'
? value ? value.split(/[\s,]+/g).map(parseFloat) : []
: type === 'color' && getDefinition(value)
@ -358,6 +359,9 @@ new function() {
function applyAttributes(item, node) {
// SVG attributes can be set both as styles and direct node attributes,
// so we need to parse both
// TODO: Instead of looping through the styles, we need to loop through
// a list of styles relevant to SVG, and calculate the computed style,
// to support style classes too.
for (var i = 0, l = node.style.length; i < l; i++) {
var name = node.style[i];
item = applyAttribute(item, node, name, node.style[Base.camelize(name)]);
@ -411,7 +415,7 @@ new function() {
case 'stop-opacity':
// http://www.w3.org/TR/SVG/masking.html#OpacityProperty
case 'opacity':
var opacity = Base.toFloat(value);
var opacity = parseFloat(value);
if (name === 'stop-opacity') {
item.color.setAlpha(opacity);
} else {
@ -425,7 +429,7 @@ new function() {
var color = item[name == 'fill-opacity' ? 'getFillColor'
: 'getStrokeColor']();
if (color)
color.setAlpha(Base.toFloat(value));
color.setAlpha(parseFloat(value));
break;
case 'visibility':
item.setVisible(value === 'visible');
@ -485,7 +489,7 @@ new function() {
item.setFont(value.split(',')[0].replace(/^\s+|\s+$/g, ''));
break;
case 'font-size':
item.setFontSize(Base.toFloat(value));
item.setFontSize(parseFloat(value));
break;
case 'text-anchor':
item.setJustification({

View file

@ -129,12 +129,12 @@ var Component = this.Component = Base.extend(Callback, /** @lends Component# */{
DomElement.set(this._inputItem, key, value);
// Read back and convert from input again, to make sure we're in sync
value = DomElement.get(this._inputItem, key);
this._value = this._info.number ? Base.toFloat(value) : value;
this._value = this._info.number ? parseFloat(value, 10) : value;
},
getRange: function() {
return [Base.toFloat(DomElement.get(this._inputItem, 'min')),
Base.toFloat(DomElement.get(this._inputItem, 'max'))];
return [parseFloat(DomElement.get(this._inputItem, 'min')),
parseFloat(DomElement.get(this._inputItem, 'max'))];
},
setRange: function(min, max) {
@ -159,7 +159,7 @@ var Component = this.Component = Base.extend(Callback, /** @lends Component# */{
},
getStep: function() {
return Base.toFloat(DomElement.get(this._inputItem, 'step'));
return parseFloat(DomElement.get(this._inputItem, 'step'));
},
setStep: function(step) {