Created
June 13, 2011 20:13
-
-
Save dfurber/1023580 to your computer and use it in GitHub Desktop.
CoffeeScript version of jQuery DOM Shortcut
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
do -> | |
setOptions = (el, attributes) -> | |
for own key, value of attributes | |
el.setAttribute key, value | |
el | |
_(['ol','ul','li','span','strong','p','h1','h2','h3','h4']).each (tag) -> | |
window["_#{tag}"] = (html, attributes, children...) -> | |
el = document.createElement tag | |
if attributes? | |
if attributes.jquery? | |
children.unshift attributes | |
else | |
el = setOptions el, attributes | |
if html? | |
if html.jquery? | |
children.unshift attributes | |
else | |
if typeof html is 'object' | |
el = setOptions el, html | |
else if typeof html is 'string' | |
el.innerHTML = html | |
el = $(el) | |
for child in children | |
el.append child | |
el | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment