edo-htqw
Version:
A easier HTML element's dom operation libary.
45 lines (44 loc) • 1.4 kB
JavaScript
import edoTypeError from "./error/edoTypeError";
export default function (edo) {
function prevent(event) {
event.preventDefault();
}
function ob(val) {
const temp = { prevent };
for (let s in val) {
temp[s] = val[s];
}
return temp;
}
edo.proto('click', function (call) {
try {
if (call === null) {
this.el.onclick = null;
}
else {
this.el.onclick = (event) => {
const temp = ob({ 0: event });
call.call(this, temp);
};
}
return true;
}
catch (_a) {
return false;
}
});
edo.proto('onEventL', function (n, l) {
if (!(l instanceof Function)) {
throw new edoTypeError(`This type should is Function, fault ${Object.prototype.toString.call(l).split(' ')[1].replace(']', '')}`);
}
this.el.addEventListener(n, l);
return true;
});
edo.proto('offEventL', function (n, l) {
if (!(l instanceof Function)) {
throw new edoTypeError(`This type should is Function, fault ${Object.prototype.toString.call(l).split(' ')[1].replace(']', '')}`);
}
this.el.removeEventListener(n, l);
return true;
});
}