-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite print for clarity and fix context bug
- Loading branch information
Showing
1 changed file
with
47 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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...) |