mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-06-03 00:33:48 -04:00
Remove Base.toFloat() and replace with direct parseFloat() calls.
This commit is contained in:
parent
d3435ec803
commit
e392496f9d
3 changed files with 13 additions and 13 deletions
src
|
@ -469,11 +469,7 @@ this.Base = Base.inject(/** @lends Base# */{
|
||||||
*/
|
*/
|
||||||
formatFloat: function(num, precision) {
|
formatFloat: function(num, precision) {
|
||||||
precision = precision ? Math.pow(10, precision) : 100000;
|
precision = precision ? Math.pow(10, precision) : 100000;
|
||||||
return (Math.round(num * precision) / precision);
|
return Math.round(num * precision) / precision;
|
||||||
},
|
|
||||||
|
|
||||||
toFloat: function(str) {
|
|
||||||
return parseFloat(str, 10);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -30,6 +30,7 @@ new function() {
|
||||||
// Base.pick(base.value, base)
|
// Base.pick(base.value, base)
|
||||||
return base
|
return base
|
||||||
? index !== undefined
|
? index !== undefined
|
||||||
|
// Item list? Look up by index:
|
||||||
? index < base.numberOfItems
|
? index < base.numberOfItems
|
||||||
? Base.pick((base = base.getItem(index)).value, base)
|
? Base.pick((base = base.getItem(index)).value, base)
|
||||||
: null
|
: null
|
||||||
|
@ -56,7 +57,7 @@ new function() {
|
||||||
return value === 'none'
|
return value === 'none'
|
||||||
? null
|
? null
|
||||||
: type === 'number'
|
: type === 'number'
|
||||||
? Base.toFloat(value)
|
? parseFloat(value)
|
||||||
: type === 'array'
|
: type === 'array'
|
||||||
? value ? value.split(/[\s,]+/g).map(parseFloat) : []
|
? value ? value.split(/[\s,]+/g).map(parseFloat) : []
|
||||||
: type === 'color' && getDefinition(value)
|
: type === 'color' && getDefinition(value)
|
||||||
|
@ -358,6 +359,9 @@ new function() {
|
||||||
function applyAttributes(item, node) {
|
function applyAttributes(item, node) {
|
||||||
// SVG attributes can be set both as styles and direct node attributes,
|
// SVG attributes can be set both as styles and direct node attributes,
|
||||||
// so we need to parse both
|
// 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++) {
|
for (var i = 0, l = node.style.length; i < l; i++) {
|
||||||
var name = node.style[i];
|
var name = node.style[i];
|
||||||
item = applyAttribute(item, node, name, node.style[Base.camelize(name)]);
|
item = applyAttribute(item, node, name, node.style[Base.camelize(name)]);
|
||||||
|
@ -411,7 +415,7 @@ new function() {
|
||||||
case 'stop-opacity':
|
case 'stop-opacity':
|
||||||
// http://www.w3.org/TR/SVG/masking.html#OpacityProperty
|
// http://www.w3.org/TR/SVG/masking.html#OpacityProperty
|
||||||
case 'opacity':
|
case 'opacity':
|
||||||
var opacity = Base.toFloat(value);
|
var opacity = parseFloat(value);
|
||||||
if (name === 'stop-opacity') {
|
if (name === 'stop-opacity') {
|
||||||
item.color.setAlpha(opacity);
|
item.color.setAlpha(opacity);
|
||||||
} else {
|
} else {
|
||||||
|
@ -425,7 +429,7 @@ new function() {
|
||||||
var color = item[name == 'fill-opacity' ? 'getFillColor'
|
var color = item[name == 'fill-opacity' ? 'getFillColor'
|
||||||
: 'getStrokeColor']();
|
: 'getStrokeColor']();
|
||||||
if (color)
|
if (color)
|
||||||
color.setAlpha(Base.toFloat(value));
|
color.setAlpha(parseFloat(value));
|
||||||
break;
|
break;
|
||||||
case 'visibility':
|
case 'visibility':
|
||||||
item.setVisible(value === 'visible');
|
item.setVisible(value === 'visible');
|
||||||
|
@ -485,7 +489,7 @@ new function() {
|
||||||
item.setFont(value.split(',')[0].replace(/^\s+|\s+$/g, ''));
|
item.setFont(value.split(',')[0].replace(/^\s+|\s+$/g, ''));
|
||||||
break;
|
break;
|
||||||
case 'font-size':
|
case 'font-size':
|
||||||
item.setFontSize(Base.toFloat(value));
|
item.setFontSize(parseFloat(value));
|
||||||
break;
|
break;
|
||||||
case 'text-anchor':
|
case 'text-anchor':
|
||||||
item.setJustification({
|
item.setJustification({
|
||||||
|
|
|
@ -129,12 +129,12 @@ var Component = this.Component = Base.extend(Callback, /** @lends Component# */{
|
||||||
DomElement.set(this._inputItem, key, value);
|
DomElement.set(this._inputItem, key, value);
|
||||||
// Read back and convert from input again, to make sure we're in sync
|
// Read back and convert from input again, to make sure we're in sync
|
||||||
value = DomElement.get(this._inputItem, key);
|
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() {
|
getRange: function() {
|
||||||
return [Base.toFloat(DomElement.get(this._inputItem, 'min')),
|
return [parseFloat(DomElement.get(this._inputItem, 'min')),
|
||||||
Base.toFloat(DomElement.get(this._inputItem, 'max'))];
|
parseFloat(DomElement.get(this._inputItem, 'max'))];
|
||||||
},
|
},
|
||||||
|
|
||||||
setRange: function(min, max) {
|
setRange: function(min, max) {
|
||||||
|
@ -159,7 +159,7 @@ var Component = this.Component = Base.extend(Callback, /** @lends Component# */{
|
||||||
},
|
},
|
||||||
|
|
||||||
getStep: function() {
|
getStep: function() {
|
||||||
return Base.toFloat(DomElement.get(this._inputItem, 'step'));
|
return parseFloat(DomElement.get(this._inputItem, 'step'));
|
||||||
},
|
},
|
||||||
|
|
||||||
setStep: function(step) {
|
setStep: function(step) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue