jojequery
Version:
jojequery
47 lines (31 loc) • 666 B
JavaScript
function Selector(selector) {
var els = document.querySelectorAll(selector);
var self = this;
[].forEach.call(els, function(el) {
self.push(el);
});
}
function Plugins() {}
Plugins.prototype = new Array();
var fn = new Plugins();
Selector.prototype = fn;
fn.each = function(fn) {
this.forEach(function(el) {
fn.call(el);
});
return this;
};
function $(selector) {
if( selector instanceof Document ) {
return {
ready: function(fn) {
document.addEventListener('DOMContentLoaded', function() {
fn($);
});
}
};
}
return new Selector(selector);
}
$.fn = fn;
module.exports = $;