Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void function(root) {
- var html, tags
- , slice = [].slice
- , class_of = {}.toString
- , keys = Object.keys
- // (object:Object) → Boolean
- // Returns whether the object is a String or not
- function strp(object) {
- return class_of.call(object) == '[object String]' }
- // (tag:String attributes:Obj childs:HTMLElement...) → HTMLElement
- // Creates an HTMLElement
- function make_element(tag, attributes) { var elm
- elm = document.createElement(tag)
- keys(attributes).forEach(function(key) {
- elm.setAttribute(key, attributes[key]) })
- slice.call(arguments, 2).forEach(function(child) {
- if (strp(child)) child = document.createTextNode(child)
- elm.appendChild(child) })
- return elm }
- // Builds tags and export stuff
- tags = ['a', 'div']
- root.html = html = {}
- html.make_element = make_element
- html.body = document.body
- tags.forEach(function(tag) {
- html[tag] = function() {
- return make_element.apply(html, [tag].concat(slice.call(arguments))) }})
- }(this)
Add Comment
Please, Sign In to add comment