Permalink
Browse files

Add Utils.reset() to reset all the layers

  • Loading branch information...
koenbok committed May 21, 2014
1 parent 20decd2 commit 0a8a76864923c566c06dbe47f0a36ef112aa1375
Showing with 48 additions and 20 deletions.
  1. +2 −0 framer/Config.coffee
  2. +14 −13 framer/Layer.coffee
  3. +1 −0 framer/Session.coffee
  4. +28 −7 framer/Utils.coffee
  5. +3 −0 test/tests/LayerTest.coffee
@@ -21,6 +21,8 @@ exports.Config =
#"overflow": "visible"
#"z-index": 0
"-webkit-box-sizing": "border-box"
"-webkit-user-select": "none"
"cursor": "default"
# "-webkit-transform-style": "preserve-3d"
# "-webkit-backface-visibility": "visible"
#"-webkit-backface-visibility": ""
@@ -4,6 +4,7 @@ Utils = require "./Utils"
{Config} = require "./Config"
{Defaults} = require "./Defaults"
{Session} = require "./Session"
{BaseClass} = require "./BaseClass"
{EventEmitter} = require "./EventEmitter"
{Animation} = require "./Animation"
@@ -12,8 +13,8 @@ Utils = require "./Utils"
{LayerStates} = require "./LayerStates"
{LayerDraggable} = require "./LayerDraggable"
_RootElement = null
_LayerList = []
Session._RootElement = null
Session._LayerList = []
layerProperty = (name, cssProperty, fallback, validator, set) ->
exportable: true
@@ -53,7 +54,7 @@ class exports.Layer extends BaseClass
constructor: (options={}) ->
_LayerList.push @
Session._LayerList.push @
# We have to create the element before we set the defaults
@_createElement()
@@ -279,23 +280,23 @@ class exports.Layer extends BaseClass
Utils.domComplete @__insertElement
__insertElement: =>
if not _RootElement
_RootElement = document.createElement "div"
_RootElement.id = "FramerRoot"
_.extend _RootElement.style, Config.rootBaseCSS
document.body.appendChild _RootElement
if not Session._RootElement
Session._RootElement = document.createElement "div"
Session._RootElement.id = "FramerRoot"
_.extend Session._RootElement.style, Config.rootBaseCSS
document.body.appendChild Session._RootElement
_RootElement.appendChild @_element
Session._RootElement.appendChild @_element
destroy: ->
if @superLayer
@superLayer._subLayers = _.without @superLayer._subLayers, @
@_element.parentNode.removeChild @_element
@_element.parentNode?.removeChild @_element
@removeAllListeners()
_LayerList = _.without _LayerList, @
Session._LayerList = _.without Session._LayerList, @
##############################################################
@@ -451,7 +452,7 @@ class exports.Layer extends BaseClass
# If there is no superLayer we need to walk through the root
if @superLayer is null
return _.filter _LayerList, (layer) =>
return _.filter Session._LayerList, (layer) =>
layer isnt @ and layer.superLayer is null
return _.without @superLayer.subLayers, @
@@ -604,4 +605,4 @@ class exports.Layer extends BaseClass
on: @::addListener
off: @::removeListener
exports.Layer.Layers = -> _.clone _LayerList
exports.Layer.Layers = -> _.clone Session._LayerList
@@ -0,0 +1 @@
exports.Session = {}
@@ -1,10 +1,31 @@
# Utils.log = ->
# console.log arguments.join " "
{_} = require "./Underscore"
{Session} = require "./Session"
Utils = {}
Utils.reset = ->
Utils.domComplete ->
for layer in Session._LayerList
layer.removeAllListeners()
Session._LayerList = []
Session._RootElement?.innerHTML = ""
if Session._delayTimers
for delayTimer in Session._delayTimers
clearTimeout delayTimer
Session._delayTimers = []
if Session._delayIntervals
for delayInterval in Session._delayIntervals
clearInterval delayInterval
Session._delayIntervals = []
Utils.getValue = (value) ->
return value() if _.isFunction value
return value
Utils.setDefaultProperties = (obj, defaults, warn=true) ->
result = {}
@@ -66,14 +87,14 @@ Utils.getTime = -> Date.now() / 1000
Utils.delay = (time, f) ->
timer = setTimeout f, time * 1000
# window._delayTimers ?= []
# window._delayTimers.push timer
Session._delayTimers ?= []
Session._delayTimers.push timer
return timer
Utils.interval = (time, f) ->
timer = setInterval f, time * 1000
# window._delayIntervals ?= []
# window._delayIntervals.push timer
Session._delayIntervals ?= []
Session._delayIntervals.push timer
return timer
Utils.debounce = (threshold=0.1, fn, immediate) ->
@@ -7,6 +7,9 @@ describe "Layer", ->
# afterEach ->
# Utils.clearAll()
# beforeEach ->
# Framer.Utils.reset()
describe "Defaults", ->
it "should set defaults", ->

0 comments on commit 0a8a768

Please sign in to comment.