Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. /*
  2. * AbstractorJs
  3. **/
  4.  
  5.  
  6. var
  7. // Author
  8. AbstractorJs = "Create by Freddy J. Fernandez C. on Thu Nov 19 2015 04:19:20 GMT-04",
  9.  
  10. // document as doc
  11. doc = document,
  12.  
  13. // document.body as body
  14. body = doc.body,
  15.  
  16. // document.head as head
  17. head = doc.head,
  18.  
  19. // undefined as udef, ndef
  20. ndef,udef = undefined,
  21.  
  22.  
  23. gEId = function(id){return doc.getElementById(id)},
  24. gEName = function(name){return doc.getElementsByName(name)},
  25.  
  26. O = function(){
  27. var a = arguments;
  28. if ( a.lenght >3 || a.lenght < 1 ){
  29. console.log('Para crear un objeto se necesita un parametro como minimo y 3 como maximo');
  30. console.log('(1) Nombre del elemento o etiqueta a crear');
  31. console.log('(2) Objeto con los atributos y valores correspondiente a cada atributo');
  32. console.log('(3) Contenido del elemento o etiqueta, este puede ser un objeto o una cadena');
  33. }
  34. if (typeof a[0] === "string" || typeof a[1] === "object" ){}
  35. },
  36.  
  37.  
  38. E = function(){
  39. var o = arguments;
  40.  
  41. for (e in o){
  42. if (typeof e === "object"){
  43.  
  44. }
  45. }
  46.  
  47. },
  48.  
  49. newElement = function(){
  50. // Para crear un elemento necesita como minimo 1 parametro o 3 como maximo.
  51. // (1) String: Nombre o etiqueta del elemento a crear.
  52. // (2) Object: Objeto con clave valor que representa los atributos del elemento.
  53. // (3) String||Object: Representa el contenido del elemento.
  54. // Example
  55. // newElement('a',{'href':'www.google.com','target':'black','class':'btn-default'},"New Url")
  56.  
  57. var
  58. o = arguments,
  59. e;
  60.  
  61. //console.log(o.length);
  62.  
  63. if ( typeof o[0] === "string" ){
  64. e = doc.createElement(o[0]);
  65. }
  66.  
  67. if ( typeof o[1] === "object" ){
  68. for(a in o[1]){
  69. e.setAttribute(a,o[1][a]);
  70. }
  71. }else if ( typeof o[1] === "function" && o.length == 2 ){
  72. o[1]();
  73. }
  74.  
  75.  
  76. if ( typeof o[2] === "string" ){
  77. e.textContent = o[2];
  78. }else if ( typeof o[2] === "object" ){
  79. e.appendChild(o[2]);
  80. }
  81.  
  82. if ( o.length == 4 && typeof o[3] === "function" ){
  83. o[3]();
  84. }
  85.  
  86.  
  87. return e;
  88. },
  89.  
  90. e=newElement,
  91.  
  92. addContent = function(elem,content){
  93. if (typeof content === "object")
  94. elem.appendChild(content);
  95. else if (typeof content === "string")
  96. elem.textContent = content;
  97. },
  98.  
  99. nDiv = function(){return newElement('div')},
  100. nUrl = function(url,text){
  101. var e = newElement('a');
  102. if (url!=undefined){e.href=url};
  103. if (text!=undefined){e.text=text};
  104. return e;
  105. };
  106.  
  107. body.addEle = function(ele){ return body.appendChild(ele) };
  108. body.addElement = function(ele){return this.appendChild(ele)};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement