@uni/toast
Version:
[](https://www.npmjs.com/package/@uni/toast)
80 lines (63 loc) • 1.62 kB
JavaScript
export var DOMUtil = /*#__PURE__*/function () {
function DOMUtil(ele, index) {
if (index === void 0) {
index = 0;
}
this.element = void 0;
if (typeof ele === 'string') {
var _nodeList$index;
var nodeList = document.querySelectorAll(ele);
this.element = (_nodeList$index = nodeList[index]) != null ? _nodeList$index : null;
} else {
this.element = ele;
}
}
var _proto = DOMUtil.prototype;
_proto.isAppeared = function isAppeared() {
var _this$getComputedStyl;
if (!this.element) return false;
return ((_this$getComputedStyl = this.getComputedStyle()) == null ? void 0 : _this$getComputedStyl.display) !== 'none';
}
/**
* get element computed style
*/
;
_proto.getComputedStyle = function getComputedStyle() {
if (this.element) {
return window.getComputedStyle(this.element);
}
return null;
};
_proto.toString = function toString() {
if (this.element) {
return this.element.innerHTML;
}
return '';
};
/**
* trigger dom event
* @param type
* @param arg
*/
_proto.trigger = function trigger(type, arg) {
var event;
switch (type) {
case 'click':
event = new window.MouseEvent(type);
break;
case 'focus':
case 'blur':
event = new window.FocusEvent(type);
break;
case 'change':
event = new window.Event(type);
this.element.value = String(arg);
break;
default:
}
if (this.element && event) {
this.element.dispatchEvent(event);
}
};
return DOMUtil;
}();