Created
June 30, 2019 03:30
-
-
Save rrfaria/dad5128e3a8e5a9e3a776d8248ae4361 to your computer and use it in GitHub Desktop.
This file contains 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
var __ = function () { | |
this.context = []; | |
var self = this; | |
this.selector = function (_elem, _sel) { | |
return _elem.querySelectorAll(_sel); | |
} | |
this.on = function (_event, _element, _function) { | |
this.context = self.selector(document, _element); | |
document.addEventListener(_event, function (e) { | |
var elem = e.target; | |
while (elem != null) { | |
if ("#" + elem.id == _element || self.isClass(elem, _element) || self.elemEqal(elem)) { | |
_function(e, elem); | |
} | |
elem = elem.parentElement; | |
} | |
}, false); | |
}; | |
this.isClass = function (_elem, _class) { | |
var names = _elem.className.trim().split(" "); | |
for (this.it = 0; this.it < names.length; this.it++) { | |
names[this.it] = "." + names[this.it]; | |
} | |
return names.indexOf(_class) != -1 ? true : false; | |
}; | |
this.elemEqal = function (_elem) { | |
var flg = false; | |
for (this.it = 0; this.it < this.context.length; this.it++) { | |
if (this.context[this.it] === _elem && !flg) { | |
flg = true; | |
} | |
} | |
return flg; | |
}; | |
} | |
function _(_sel_string) { | |
var new_selc = new __(_sel_string); | |
return new_selc; | |
} | |
_(document).on("click", "#brnPrepend", function (_event, _element) { | |
console.log(_event); | |
console.log(_element); | |
// Todo | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment