Skip to content

Commit

Permalink
Rewrite print for clarity and fix context bug
Browse files Browse the repository at this point in the history
  • Loading branch information
koenbok committed May 11, 2016
1 parent 51ebe97 commit 358bf74
Showing 1 changed file with 47 additions and 41 deletions.
88 changes: 47 additions & 41 deletions framer/Print.coffee
Original file line number Original file line Diff line number Diff line change
@@ -1,60 +1,66 @@
Utils = require "./Utils" Utils = require "./Utils"
{Context} = require "./Context" {Context} = require "./Context"


""" class Printer

Todo: constructor: ->
- Better looks @_context = new Context(name:"Print")
- Resizable @_context.run => Events.wrap(window).addEventListener("resize", @resize)
- Live in own space on top of all Framer stuff
createLayer: =>
"""

return @_printLayer if @_printLayer
printContext = null
printLayer = null @_context.run =>


exports.print = (args...) -> @_printLayer = new Layer

@_printLayer.scrollVertical = true
if not printContext @_printLayer.ignoreEvents = false
printContext = new Context(name:"Print") @_printLayer.html = ""

@_printLayer.style =
printContext.run ->

if not printLayer

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


printLayer.opacity = 0.9 @_printLayer.opacity = 0.9
printLayer.style.zIndex = 999 # Always stay on top @_printLayer.style.zIndex = 999 # Always stay on top
printLayer.visible = true @_printLayer.visible = true
printLayer.backgroundColor = "white" @_printLayer.backgroundColor = "white"
# printLayer.bringToFront()
@resize()


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


update() resize: =>
return unless @_printLayer
@_printLayer.width = window.innerWidth
@_printLayer.height = 160
@_printLayer.maxY = window.innerHeight


printContext.domEventManager.wrap(window).addEventListener("resize", update) print: (args...) =>

@createLayer()


printPrefix = "» " printPrefix = "» "

printNode = document.createElement("div") printNode = document.createElement("div")
printNode.innerHTML = _.escape(printPrefix + args.map((obj) -> Utils.inspect(obj)).join(", ")) + "<br>"
printNode.style["-webkit-user-select"] = "text" printNode.style["-webkit-user-select"] = "text"
printNode.style["cursor"] = "auto" printNode.style["cursor"] = "auto"
printNode.innerHTML = _.escape(printPrefix + args.map((obj) -> Utils.inspect(obj)).join(", ")) + "<br>"

@_printLayer._element.appendChild(printNode)


printLayer._element.appendChild(printNode) @scrollToBottom()
Utils.delay(0, @scrollToBottom)


Utils.delay 0, -> scrollToBottom: =>
printLayer._element.scrollTop = printLayer._element.scrollHeight return unless @_printLayer
@_printLayer._element.scrollTop = @_printLayer._element.scrollHeight

_printer = null

exports.print = (args...) ->
_printer ?= new Printer
_printer.print(args...)

0 comments on commit 358bf74

Please sign in to comment.