Permalink
Browse files

Fix issue where setting perspective to 0 wouldn’t have the desired ef…

…fect
  • Loading branch information...
nvh committed Jul 12, 2017
1 parent b0ae258 commit 9e9ce722c2e1d049f8a45342f3f548e5c2026abb
Showing with 43 additions and 7 deletions.
  1. +15 −3 framer/Context.coffee
  2. +28 −4 test/tests/ContextTest.coffee
View
@@ -31,6 +31,15 @@ these at any time.
###
webkitPerspectiveForValue = (value) ->
if value in ["none", null, 0]
return "none"
else if _.isNumber(value)
return value
else
return null
Contexts = []
class exports.Context extends BaseClass
@@ -293,7 +302,9 @@ class exports.Context extends BaseClass
@_element = document.createElement("div")
@_element.id = "FramerContextRoot-#{@_name}"
@_element.classList.add("framerContext")
@_element.style["webkitPerspective"] = @perspective
webkitPerspective = webkitPerspectiveForValue(@perspective)
if webkitPerspective?
@_element.style["webkitPerspective"] = webkitPerspective
@_element.style["backgroundColor"] = @backgroundColor
@__pendingElementAppend = =>
@@ -366,9 +377,10 @@ class exports.Context extends BaseClass
get: ->
return @_perspective
set: (value) ->
if _.isNumber(value)
webkitPerspective = webkitPerspectiveForValue(value)
if webkitPerspective?
@_perspective = value
@_element?.style["webkitPerspective"] = @_perspective
@_element?.style["webkitPerspective"] = webkitPerspective
_updatePerspective: ->
@_element?.style["webkitPerspectiveOrigin"] = "#{@perspectiveOriginX * 100}% #{@perspectiveOriginY * 100}%"
@@ -1,4 +1,4 @@
assert = require "assert"
{expect} = require "chai"
describe "Context", ->
@@ -282,12 +282,36 @@ describe "Context", ->
context._element.style["backgroundColor"].should.equal colorString
it "should have a default perspective of 0", ->
context = new Framer.Context(name: "Test")
context._element.style["webkitPerspective"].should.equal "0"
context._element.style["webkitPerspective"].should.equal "none"
context.perspective.should.equal 0
it "should allow the perspective to be changed", ->
context = new Framer.Context(name: "Test")
context.perspective = 800
context.perspective.should.equal 800
context._element.style["webkitPerspective"].should.equal "800"
it "should set the perspective to 'none' if set to 0", ->
context = new Framer.Context(name: "Test")
context.perspective = 0
context.perspective.should.equal 0
context._element.style["webkitPerspective"].should.equal "none"
it "should set the perspective to 'none' if set to none", ->
context = new Framer.Context(name: "Test")
context.perspective = "none"
context.perspective.should.equal "none"
context._element.style["webkitPerspective"].should.equal "none"
it "should set the perspective to 'none' if set to null", ->
context = new Framer.Context(name: "Test")
context.perspective = null
expect(context.perspective).to.be.null
context._element.style["webkitPerspective"].should.equal "none"
it "should not allow setting the perspective to random string", ->
context = new Framer.Context(name: "Test")
context.perspective = "bla"
context.perspective.should.equal 0
context._element.style["webkitPerspective"].should.equal "none"

0 comments on commit 9e9ce72

Please sign in to comment.