Permalink
Browse files

Compat fix for layer.borderRadius

  • Loading branch information...
koenbok committed Sep 30, 2014
1 parent ae4fc9b commit e81fc3300fb2aa207af27b60209787483b8b5522
Showing with 48 additions and 1 deletion.
  1. +21 −1 framer/Layer.coffee
  2. +5 −0 framer/LayerStyle.coffee
  3. +22 −0 test/tests/LayerTest.coffee
View
@@ -173,7 +173,8 @@ class exports.Layer extends BaseClass
@define "color", layerProperty @, "color", "color", null, _.isString
# Border properties
@define "borderRadius", layerProperty @, "borderRadius", "borderRadius", 0, _.isNumber
# Todo: make this default, for compat we still allow strings but throw a warning
# @define "borderRadius", layerProperty @, "borderRadius", "borderRadius", 0, _.isNumber
@define "borderColor", layerProperty @, "borderColor", "border", null, _.isString
@define "borderWidth", layerProperty @, "borderWidth", "border", 0, _.isNumber
@@ -193,6 +194,25 @@ class exports.Layer extends BaseClass
# See: https://github.com/koenbok/Framer/issues/63
@_element.setAttribute "name", value
##############################################################
# Border radius compatibility
@define "borderRadius",
exportable: true
default: 0
get: ->
@_properties["borderRadius"]
set: (value) ->
if value and not _.isNumber(value)
console.warn "Layer.borderRadius should be a numeric property, not type #{typeof(value)}"
@_properties["borderRadius"] = value
@_element.style["borderRadius"] = LayerStyle["borderRadius"](@)
@emit("change:borderRadius", value)
##############################################################
# Geometry
View
@@ -147,6 +147,11 @@ exports.LayerStyle =
return layer._properties.color
borderRadius: (layer) ->
# Compatibility fix, remove later
if not _.isNumber(layer._properties.borderRadius)
return layer._properties.borderRadius
return layer._properties.borderRadius + "px"
border: (layer) ->
@@ -240,6 +240,28 @@ describe "Layer", ->
layer.x = "hello"
f.should.throw()
it "should set borderRadius", ->
testBorderRadius = (layer, value) ->
layer.style["border-top-left-radius"].should.equal "#{value} #{value}"
layer.style["border-top-right-radius"].should.equal "#{value} #{value}"
layer.style["border-bottom-left-radius"].should.equal "#{value} #{value}"
layer.style["border-bottom-right-radius"].should.equal "#{value} #{value}"
layer = new Layer
layer.borderRadius = 10
layer.borderRadius.should.equal 10
testBorderRadius(layer, "10px")
layer.borderRadius = "50%"
layer.borderRadius.should.equal "50%"
testBorderRadius(layer, "50%")
describe "Filter Properties", ->

0 comments on commit e81fc33

Please sign in to comment.