Skip to content

Commit

Permalink
Added trigger when context element is part of the dom
Browse files Browse the repository at this point in the history
  • Loading branch information
nvh committed Jan 19, 2018
1 parent 37e97cb commit c404ded
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions framer/Context.coffee
Expand Up @@ -78,6 +78,7 @@ class exports.Context extends BaseClass
@perspectiveOriginX = options.perspectiveOriginX
@perspectiveOriginY = options.perspectiveOriginY

@elementInDOM = false
@reset()

if options.hasOwnProperty("index")
Expand Down Expand Up @@ -302,6 +303,8 @@ class exports.Context extends BaseClass
parentElement = @_parent?._element
parentElement ?= document.body
parentElement.appendChild(@_element)
@elementInDOM = true
@_layers?.map (l) -> l.elementInsertedIntoDocument()

Utils.domComplete(@__pendingElementAppend)

Expand All @@ -312,6 +315,7 @@ class exports.Context extends BaseClass

if @_element?.parentNode
@_element.parentNode.removeChild(@_element)
@elementInDOM = false

if @__pendingElementAppend
Utils.domCompleteCancel(@__pendingElementAppend)
Expand Down
5 changes: 5 additions & 0 deletions framer/Layer.coffee
Expand Up @@ -892,6 +892,11 @@ class exports.Layer extends BaseClass
@bringToFront()
@_context.element.appendChild(@_element)

# This method is called as soon as the @_element is part of the DOM
# If layers are initialized before the DOM is complete,
# the contexts calls this methods on all Layers as soon as it appends itself to the document
elementInsertedIntoDocument: ->

_createHTMLElementIfNeeded: ->
if not @_elementHTML
@_elementHTML = document.createElement "div"
Expand Down

0 comments on commit c404ded

Please sign in to comment.