Permalink
Browse files

Cleaned up debug code, press escape for debug view

  • Loading branch information...
koenbok committed Jan 14, 2013
1 parent 54e88cc commit 53fd22efdb7ad4d35e7f3a7a59cc31bec7e33467
Showing with 58 additions and 25 deletions.
  1. +57 −0 src/debug.coffee
  2. +1 −25 src/init.coffee
View
@@ -0,0 +1,57 @@
utils = require "../utils"
window.document.onkeydown = (event) ->
if event.keyCode == 27 # Escape
for view in View.Views
if view._debug
view._element.removeChild view._debug.node
view.style = view._debug.style
view.clip = view._debug.clip
delete view._debug
else
color = "rgba(50,150,200,.35)"
# color = utils.randomColor(.2)
node = document.createElement "div"
node.innerHTML = "#{view.name or view.id}"
node.innerHTML += " <span style='opacity:.5'>in #{view.superView.name or view.superView.id}</span>" if view.superView
node.style.position = "absolute"
node.style.padding = "3px"
view._debug =
style: utils.extend {}, view.style
node: node
clip: view.clip
view._element.appendChild node
view.style =
color: "white"
margin: "-1px"
font: "10px/1em Monaco"
backgroundColor: "#{color}"
# boxShadow: "inset 0 0 1px rgba(50,150,200,.8)";
border: "1px solid #{color}"
backgroundImage: null
view.clip = false
window.onerror = (e) ->
errorView = new View x:20, y:20, width:350, height:60
errorView.html = "<b>Javascript Error</b><br>Inspect the error console for more info."
errorView.style =
font: "13px/1.3em Menlo, Monaco"
backgroundColor: "rgba(255,0,0,0.5)"
padding: "12px"
border: "1px solid rgba(255,0,0,0.5)"
borderRadius: "5px"
errorView.scale = 0.5
errorView.animate
properties: {scale:1.0}
curve: "spring(150,8,1500)"
View
@@ -1,6 +1,7 @@
require "./css"
utils = require "./utils"
debug = require "./debug"
{View} = require "./views/view"
{ViewList} = require "./views/view"
@@ -31,28 +32,3 @@ if window
for k, v of Global
window[k] = v
Global.debug = (value) ->
for view in ViewList
if value is true
colorValue = -> parseInt(Math.random() * 255)
debugStyle =
backgroundImage: ""
backgroundColor: "rgba(0,100,255,0.2)"
# border: "2px solid rgba(0,100,255,0.1)"
view._debugStyle = {}
for key of debugStyle
view._debugStyle[key] = view.style[key]
view.style = debugStyle
else if value is false
view.style = view._debugStyle
else return
Global._debug = value
toggler = utils.toggle true, false
window.addEventListener "keydown", (e) ->
if e.keyCode is 68 and e.shiftKey
Global.debug toggler()

0 comments on commit 53fd22e

Please sign in to comment.