Last active
April 5, 2017 18:21
-
-
Save NrI3/9944a7275fe148a11d9c to your computer and use it in GitHub Desktop.
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
| /* | |
| * AbstractorJs | |
| **/ | |
| var | |
| // Author | |
| AbstractorJs = "Create by Freddy J. Fernandez C. on Thu Nov 19 2015 04:19:20 GMT-04", | |
| // document as doc | |
| doc = document, | |
| // document.body as body | |
| body = doc.body, | |
| // document.head as head | |
| head = doc.head, | |
| // undefined as udef, ndef | |
| ndef,udef = undefined, | |
| gEId = function(id){return doc.getElementById(id)}, | |
| gEName = function(name){return doc.getElementsByName(name)}, | |
| O = function(){ | |
| var a = arguments; | |
| if ( a.lenght >3 || a.lenght < 1 ){ | |
| console.log('Para crear un objeto se necesita un parametro como minimo y 3 como maximo'); | |
| console.log('(1) Nombre del elemento o etiqueta a crear'); | |
| console.log('(2) Objeto con los atributos y valores correspondiente a cada atributo'); | |
| console.log('(3) Contenido del elemento o etiqueta, este puede ser un objeto o una cadena'); | |
| } | |
| if (typeof a[0] === "string" || typeof a[1] === "object" ){} | |
| }, | |
| newElement = function(){ | |
| // Para crear un elemento necesita como minimo 1 parametro o 3 como maximo. | |
| // (1) String: Nombre o etiqueta del elemento a crear. | |
| // (2) Object: Objeto con clave valor que representa los atributos del elemento. | |
| // (3) String||Object: Representa el contenido del elemento. | |
| // Example | |
| // newElement('a',{'href':'www.google.com','target':'black','class':'btn-default'},"New Url") | |
| var | |
| o = arguments, | |
| e; | |
| //console.log(o.length); | |
| if ( typeof o[0] === "string" ){ | |
| e = doc.createElement(o[0]); | |
| } | |
| if ( typeof o[1] === "object" ){ | |
| for(a in o[1]){ | |
| e.setAttribute(a,o[1][a]); | |
| } | |
| }else if ( typeof o[1] === "function" && o.length == 2 ){ | |
| o[1](); | |
| } | |
| if ( typeof o[2] === "string" ){ | |
| e.textContent = o[2]; | |
| }else if ( typeof o[2] === "object" ){ | |
| e.appendChild(o[2]); | |
| } | |
| if ( o.length == 4 && typeof o[3] === "function" ){ | |
| o[3](); | |
| } | |
| return e; | |
| }, | |
| e=newElement, | |
| addContent = function(elem,content){ | |
| if (typeof content === "object") | |
| elem.appendChild(content); | |
| else if (typeof content === "string") | |
| elem.textContent = content; | |
| }, | |
| nDiv = function(){return newElement('div')}, | |
| nUrl = function(url,text){ | |
| var e = newElement('a'); | |
| if (url!=undefined){e.href=url}; | |
| if (text!=undefined){e.text=text}; | |
| return e; | |
| }; | |
| body.addEle = function(ele){ return body.appendChild(ele) }; | |
| body.addElement = function(ele){return this.appendChild(ele)}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment