Guest User

Untitled

a guest
Jan 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. void function(root) {
  2. var html, tags
  3. , slice = [].slice
  4. , class_of = {}.toString
  5. , keys = Object.keys
  6.  
  7. // (object:Object) → Boolean
  8. // Returns whether the object is a String or not
  9. function strp(object) {
  10. return class_of.call(object) == '[object String]' }
  11.  
  12.  
  13. // (tag:String attributes:Obj childs:HTMLElement...) → HTMLElement
  14. // Creates an HTMLElement
  15. function make_element(tag, attributes) { var elm
  16. elm = document.createElement(tag)
  17.  
  18. keys(attributes).forEach(function(key) {
  19. elm.setAttribute(key, attributes[key]) })
  20.  
  21. slice.call(arguments, 2).forEach(function(child) {
  22. if (strp(child)) child = document.createTextNode(child)
  23. elm.appendChild(child) })
  24.  
  25. return elm }
  26.  
  27.  
  28. // Builds tags and export stuff
  29. tags = ['a', 'div']
  30. root.html = html = {}
  31.  
  32. html.make_element = make_element
  33. html.body = document.body
  34.  
  35. tags.forEach(function(tag) {
  36. html[tag] = function() {
  37. return make_element.apply(html, [tag].concat(slice.call(arguments))) }})
  38. }(this)
Add Comment
Please, Sign In to add comment