Permalink
Browse files

Merge pull request #342 from nvh/feature/fix-color-conversion-in-states

Only converting properties whose name end in 'color'
  • Loading branch information...
nvh committed Apr 14, 2016
2 parents bd79c54 + 1c4516b commit dc4d62267a1bf1fbdfdaecae97c8b908147bf433
Showing with 18 additions and 3 deletions.
  1. +3 −3 framer/LayerStates.coffee
  2. +15 −0 test/tests/LayerStatesTest.coffee
@@ -85,7 +85,6 @@ class exports.LayerStates extends BaseClass
# Allow dynamic properties as functions
value = value.call(@layer, @layer, propertyName, stateName) if _.isFunction(value)
# Set the new value
properties[propertyName] = value
@@ -178,8 +177,9 @@ class exports.LayerStates extends BaseClass
# TODO: Maybe we want to support advanced data structures like objects in the future too.
for k, v of properties
if _.isString(v) && Color.isColorString(v)
# We check if the property name ends with color, because we don't want
# to convert every string that looks like a Color, like the html property containing "add"
if _.isString(v) and _.endsWith(k.toLowerCase(),"color") and Color.isColorString(v)
stateProperties[k] = new Color(v)
else if _.isNumber(v) or _.isFunction(v) or _.isBoolean(v) or _.isString(v) or Color.isColorObject(v) or v == null
stateProperties[k] = v
@@ -51,6 +51,15 @@ describe "LayerStates", ->
Framer.resetDefaults()
it "should convert string to colors in states", ->
layer = new Layer
layer.states.add
test:
backgroundColor:"fff"
color: "000"
layer.states._states.test.backgroundColor.isEqual(new Color("fff")).should.be.true
layer.states._states.test.color.isEqual(new Color("000")).should.be.true
describe "Switch", ->
@@ -70,6 +79,12 @@ describe "LayerStates", ->
layer.states.current.should.equal "stateB"
layer.y.should.equal 123
it "should not change html when using switch instant", ->
layer = new Layer
html: "fff"
layer.states.switchInstant('default')
layer.html.should.equal "fff"
describe "Properties", ->

0 comments on commit dc4d622

Please sign in to comment.