| |
| |
| |
| |
| |
| |
|
|
| const oldTrigger = window.$.fn.trigger; |
|
|
| function triggerWithNativeEventDispatch(jqEventOrType, data) { |
| let isFirstElementOnPath = true; |
|
|
| const type = jqEventOrType.type || jqEventOrType; |
| const onEventAttributeName = `on${type}`; |
|
|
| function nativeDispatchSingleElement(element: HTMLElement) { |
| if (isFirstElementOnPath) { |
| isFirstElementOnPath = false; |
|
|
| if (element[onEventAttributeName] |
| || (element[type] instanceof Function |
| |
| && !(type === 'click' && element.tagName.toUpperCase() === 'A')) |
| ) { |
| |
| |
| |
| |
| |
| return; |
| } |
| } |
|
|
| |
| if (((window.$._data(element, 'events') || {}) as any)[type] && window.$._data(element, 'handle')) { |
| |
| return; |
| } |
|
|
| if (element.dispatchEvent) { |
| const event = new Event(type, { |
| |
| bubbles: false, |
| cancelable: true, |
| }); |
| element.dispatchEvent(event); |
| } |
| } |
|
|
| function nativeDispatch(element: HTMLElement) { |
| nativeDispatchSingleElement(element); |
|
|
| const parent = element.parentElement; |
| if (parent) { |
| nativeDispatch(parent); |
| } |
| } |
|
|
| const result = oldTrigger.call(this, jqEventOrType, data); |
| if (type === 'focus' || type === 'blur') { |
| return result; |
| } |
|
|
| this.each(function onEach() { |
| nativeDispatch(this); |
| }); |
|
|
| return result; |
| } |
|
|
| window.$.fn.trigger = triggerWithNativeEventDispatch; |
|
|