viniceosm
3/21/2018 - 5:25 PM

vkek - manipular o DOM

vkek - manipular o DOM

function Vkek(){
	// this.el será o elemento buscado apartir do Vkek.$()
}

Vkek.prototype = {
	$: function(selector) {
		if (typeof selector == 'string') {
			this.el = (document.querySelectorAll(selector).length > 1) ? document.querySelectorAll(selector) : document.querySelector(selector);
		} else {
			this.el = selector;
		}

		return this;
	},
	addEvent: function(eventName, fn) {
		this.el.addEventListener(eventName, fn);

		return this;
	},
	click: function(fn){
		this.el.addEventListener('click', fn);

		return this;
	},
	load: function(fn){
		window.addEventListener('load', fn);

		return this;
	},
	html: function(html){
		if (html == undefined) {
			return this.el.innerHTML;
		}
		this.el.innerHTML = html;

		return this;
	},
	each: function(fn){
		for (i in this.el) {
			fn(this.el[i], i);
		}
	}
}

function vkek(selector) {
	_vkek = new Vkek();

	if (selector != undefined){
		_vkek.$(selector).el;
	}

	return _vkek;
}