Skip to content

Commit

Permalink
Add close button to Printer
Browse files Browse the repository at this point in the history
  • Loading branch information
nvh committed Oct 6, 2016
1 parent e5584ac commit 16a1777
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions framer/Print.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ class Printer
@_context.run => Events.wrap(window).addEventListener("resize", @resize) @_context.run => Events.wrap(window).addEventListener("resize", @resize)


createLayer: => createLayer: =>

return @_printLayer if @_printLayer return @_printLayer if @_printLayer

@_context.run => @_context.run =>
@_container = new Layer
backgroundColor: null
@_container.style.zIndex = 999 # Always stay on top


@_printLayer = new Layer @_printLayer = new Layer
parent: @_container

@_printLayer.scrollVertical = true @_printLayer.scrollVertical = true
@_printLayer.ignoreEvents = false @_printLayer.ignoreEvents = false
@_printLayer.html = "" @_printLayer.html = ""
Expand All @@ -25,31 +30,45 @@ class Printer
"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.visible = true @_printLayer.visible = true
@_printLayer.backgroundColor = "white" @_printLayer.backgroundColor = "white"


@_closeButton = new Layer
parent: @_container
html: '<svg><g><path d="M6.73184358,5 L10,1.73184358 L8.26815642,0 L5,3.26815642 L1.73184358,0 L0,1.73184358 L3.26815642,5 L0,8.26815642 L1.73184358,10 L5,6.73184358 L8.26815642,10 L10,8.26815642 L6.73184358,5 Z" fill="#BDBDBD"></path></g></svg>'
y: 6
width: 10
height: 10
backgroundColor: null
@_closeButton.onClick =>
@hide()
@resize() @resize()


return @_printLayer return @_printLayer


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

@_printLayer.size = @_container.size
@_closeButton.maxX = @_container.maxX - @_closeButton.y

hide: ->
@_container.visible = false


print: (args...) => print: (args...) =>

@createLayer()


@createLayer()
@_container.visible = true
printPrefix = "» " printPrefix = "» "

printNode = document.createElement("div") printNode = document.createElement("div")
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>" printNode.innerHTML = _.escape(printPrefix + args.map((obj) -> Utils.inspect(obj)).join(", ")) + "<br>"

@_printLayer._element.appendChild(printNode) @_printLayer._element.appendChild(printNode)


@scrollToBottom() @scrollToBottom()
Expand Down

0 comments on commit 16a1777

Please sign in to comment.