Created
June 2, 2013 19:12
-
-
Save napcs/5694538 to your computer and use it in GitHub Desktop.
Sometimes I need a way to view messages easily on devices where the console doesn't work. So I use this. It's a little crude but it works really well on tablets and phones when I need to watch events.
This file contains hidden or 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
/** | |
@method __message | |
@param text {string} The text you want to display | |
@param [append=null] {boolean} Whether the message should append to the box or not. | |
@example | |
$("a").on("click", function(event){ | |
window.__message("You clicked a thing!"); | |
}); | |
*/ | |
window.__message = function(text, append){ | |
id = "__messagearea" | |
var area = document.getElementById(id); | |
if(!area){ | |
area = document.createElement("div"); | |
area.id = id; | |
body = document.getElementsByTagName("body")[0]; | |
body.insertBefore(area, body.firstChild); | |
area.style.height = "50px"; | |
area.style.overflow = "scroll"; | |
area.style.position = "relative"; | |
area.style.border = "1px solid #ddd"; | |
} | |
if(append){ | |
area.innerHTML = text + "<br>" + area.innerHTML; | |
}else{ | |
area.innerHTML = text; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment