update: 增加事件 options 参数
This commit is contained in:
parent
592bfdd610
commit
6c410ada92
|
@ -442,11 +442,11 @@ class NodeEntry implements NodeInterface {
|
|||
on<R = any, F extends EventListener<R> = EventListener<R>>(
|
||||
eventType: string,
|
||||
listener: F,
|
||||
rewrite?: boolean | undefined,
|
||||
options?: boolean | AddEventListenerOptions,
|
||||
): NodeInterface {
|
||||
this.each((node, i) => {
|
||||
node.addEventListener(eventType, listener, false);
|
||||
if (this.events[i]) this.events[i].on(eventType, listener, rewrite);
|
||||
node.addEventListener(eventType, listener, options);
|
||||
if (this.events[i]) this.events[i].on(eventType, listener, options);
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
@ -457,10 +457,15 @@ class NodeEntry implements NodeInterface {
|
|||
* @param {Function} listener 事件函数
|
||||
* @return 返回当前实例
|
||||
*/
|
||||
off(eventType: string, listener: EventListener): NodeInterface {
|
||||
off(
|
||||
eventType: string,
|
||||
listener: EventListener,
|
||||
options?: boolean | EventListenerOptions,
|
||||
): NodeInterface {
|
||||
this.each((node, i) => {
|
||||
node.removeEventListener(eventType, listener, false);
|
||||
if (this.events[i]) this.events[i].off(eventType, listener);
|
||||
node.removeEventListener(eventType, listener, options);
|
||||
if (this.events[i])
|
||||
this.events[i].off(eventType, listener, options);
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -15,13 +15,13 @@ class Event implements EventInterface {
|
|||
on<R = any, F extends EventListener<R> = EventListener<R>>(
|
||||
eventType: string,
|
||||
listener: F,
|
||||
rewrite?: boolean,
|
||||
options?: boolean | AddEventListenerOptions,
|
||||
): void {
|
||||
if (!this.listeners[eventType] || rewrite) {
|
||||
if (!this.listeners[eventType]) {
|
||||
this.listeners[eventType] = [];
|
||||
}
|
||||
|
||||
this.listeners[eventType].push(listener);
|
||||
if (typeof options !== 'object' || !options.once)
|
||||
this.listeners[eventType].push(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,14 +24,18 @@ export interface EventInterface {
|
|||
on<R = any, F extends EventListener<R> = EventListener<R>>(
|
||||
eventType: string,
|
||||
listener: F,
|
||||
rewrite?: boolean,
|
||||
options?: boolean | AddEventListenerOptions,
|
||||
): void;
|
||||
/**
|
||||
* 解除绑定
|
||||
* @param eventType
|
||||
* @param listener
|
||||
*/
|
||||
off(eventType: string, listener: EventListener): void;
|
||||
off(
|
||||
eventType: string,
|
||||
listener: EventListener,
|
||||
options?: boolean | EventListenerOptions,
|
||||
): void;
|
||||
/**
|
||||
* 触发事件
|
||||
* @param eventType 事件类型
|
||||
|
@ -285,7 +289,7 @@ export interface NodeInterface {
|
|||
on<R = any, F extends EventListener<R> = EventListener<R>>(
|
||||
eventType: string,
|
||||
listener: F,
|
||||
rewrite?: boolean | undefined,
|
||||
options?: boolean | AddEventListenerOptions,
|
||||
): NodeInterface;
|
||||
|
||||
/**
|
||||
|
@ -294,7 +298,11 @@ export interface NodeInterface {
|
|||
* @param {Function} listener 事件函数
|
||||
* @return {NodeInterface} 返回当前实例
|
||||
*/
|
||||
off(eventType: string, listener: EventListener): NodeInterface;
|
||||
off(
|
||||
eventType: string,
|
||||
listener: EventListener,
|
||||
options?: boolean | EventListenerOptions,
|
||||
): NodeInterface;
|
||||
|
||||
/**
|
||||
* 获取当前元素节点相对于视口的位置
|
||||
|
|
|
@ -190,6 +190,7 @@ class CollapseComponent implements CollapseComponentInterface {
|
|||
node.attributes({
|
||||
'data-name': escape(name),
|
||||
});
|
||||
node.removeAllEvents();
|
||||
node.on(
|
||||
'click',
|
||||
(event: MouseEvent) => {
|
||||
|
@ -198,7 +199,9 @@ class CollapseComponent implements CollapseComponentInterface {
|
|||
event.preventDefault();
|
||||
if (onSelect) onSelect(event, data);
|
||||
},
|
||||
true,
|
||||
{
|
||||
once: true,
|
||||
},
|
||||
);
|
||||
node.on(
|
||||
'mouseenter',
|
||||
|
@ -209,7 +212,9 @@ class CollapseComponent implements CollapseComponentInterface {
|
|||
.removeClass('data-mention-item-active');
|
||||
node.addClass('data-mention-item-active');
|
||||
},
|
||||
true,
|
||||
{
|
||||
once: true,
|
||||
},
|
||||
);
|
||||
return node;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue