Skip to content
Permalink
Browse files

Adding a print function and a Screen object

  • Loading branch information...
koenbok committed Jun 16, 2014
1 parent f34db1c commit fafb01643a5f8adaa921770caa87f5e2e8ee577a
Showing with 86 additions and 2 deletions.
  1. +2 −0 framer/Framer.coffee
  2. +45 −0 framer/Print.coffee
  3. +21 −0 framer/Screen.coffee
  4. +18 −2 framer/Utils.coffee
@@ -9,6 +9,8 @@ Framer.Frame = (require "./Frame").Frame
Framer.Layer = (require "./Layer").Layer
Framer.Events = (require "./Events").Events
Framer.Animation = (require "./Animation").Animation
Framer.Screen = (require "./Screen").Screen
Framer.print = (require "./Print").print

_.extend window, Framer if window

@@ -0,0 +1,45 @@
Utils = require "./Utils"
{Session} = require "./Session"

"""
Todo:
- Better looks
- Resizable
- Live in own space on top of all Framer stuff
"""

exports.print = (args...) ->

printLayer = Session.printLayer

if not printLayer

printLayer = new Layer
printLayer.scrollVertical = true
printLayer.html = ""
printLayer.style =
"font": "12px/1.35em Menlo"
"color": "rgba(0,0,0,.7)"
"padding": "8px"
"padding-bottom": "30px"
"zIndex": 9999
"border-top": "1px solid #ccc"
"backgroundColor": "#fff"

update = ->
printLayer.width = window.innerWidth
printLayer.height = 160
printLayer.maxY = window.innerHeight

update()

Screen.on "resize", update

printLayer.visible = true

printLayer.html += "&raquo; #{args.map(Utils.stringify).join ', '}<br>"
printLayer._element.scrollTop = printLayer._element.scrollHeight

Session.printLayer = printLayer
@@ -0,0 +1,21 @@
{BaseClass} = require "./BaseClass"

class ScreenClass extends BaseClass

constructor: (options) ->
super options
@_setupResizeListener()

@define "width", get: -> window.innerWidth
@define "height", get: -> window.innerHeight

_setupResizeListener: ->

oldResizeFunction = window.onresize

window.onresize = =>
@emit "resize", @
oldResizeFunction?()

# We use this as a singleton
exports.Screen = new ScreenClass
@@ -1,5 +1,6 @@
{_} = require "./Underscore"
{Session} = require "./Session"
{Screen} = require "./Screen"

Utils = {}

@@ -12,9 +13,13 @@ Utils.reset = ->
# Reset all pending operations to the dom
__domComplete = []

# Reset the print console layer
Session.printLayer = null

# Remove all the listeners so we don't leak memory
for layer in Session._LayerList
layer.removeAllListeners()
if Session._LayerList
for layer in Session._LayerList
layer.removeAllListeners()

Session._LayerList = []
Session._RootElement?.innerHTML = ""
@@ -29,6 +34,8 @@ Utils.reset = ->
clearInterval delayInterval
Session._delayIntervals = []



Utils.getValue = (value) ->
return value() if _.isFunction value
return value
@@ -155,6 +162,15 @@ Utils.labelLayer = (layer, text, style={}) ->
layer.style = style
layer.html = text

Utils.stringify = (obj) ->
try
return JSON.stringify obj if _.isObject obj
catch
""
return "undefined" if obj is undefined
return obj.toString() if obj.toString
return obj

Utils.uuid = ->

chars = "0123456789abcdefghijklmnopqrstuvwxyz".split("")

0 comments on commit fafb016

Please sign in to comment.
You can’t perform that action at this time.