FrameWork
by ConnorM
HTML
<div>
<div class="some">text</div>
</div>
<div id="t">
<div class="some">TEXT</div>
</div>
<div class="some">WOW</div>
JavaScript
/////////////////////// FOREACH ///////////////////
Object.prototype.foreach = function (callback){
var length = this.length || Object.keys(this).length;
for(var i = 0; i < length; i++) {
callback ? callback.call(this[Object.keys(this)[i]], Object.keys(this)[i], this[Object.keys(this)[i]]) : '';
}
}
/////////////////////////// CREATE ELEMENT /////////////////////////////
documentCreateElement = function ( type, attributes ) {
var element = document.createElement( type );
if(attributes){
attributes.foreach(function( key, value ) {
if(key === 'style') {
attributes.style.foreach(function( _key, _value ){
element.style[_key] = _value;
});
} else if(key === 'text') {
var text = document.createTextNode(attributes['text']);
element.appendChild(text);
} else {
var attr = document.createAttribute(key);
attr.nodeValue = value;
element.setAttributeNode(attr);
}
});
}
return element;
}
var documentFindElement = function( element ) {
var id = element.charAt(0);
console.log(this.nodeType)
switch ( id ) {
case '#':
return this.getElementById(element.substring(1));
break;
case '.':
return this.getElementsByClassName(element.substring(1));
break;
default:
return this.getElementsByTagName(element);
break;
}
};
if(typeof HTMLDocument !== 'undefined') {
HTMLDocument.prototype.create = documentCreateElement;
HTMLDocument.prototype.find = documentFindElement;
} else {
Document.prototype.create = documentCreateElement;
Document.prototype.find = documentFindElement;
}
//////////////////////// EVENTS ///////////////////
HTMLElement.prototype.on = function ( event,...