fix: iframe input hook (#991)
* fix: iframe input hook (#990) * Update observer.ts * format code with prettier * format all code with prettier Co-authored-by: luocq3 <luocq3@asiainfo.com> Co-authored-by: Yun Feng <yun.feng@anu.edu.au>
This commit is contained in:
@@ -428,28 +428,40 @@ function initInputObserver({
|
||||
const handlers: Array<
|
||||
listenerHandler | hookResetter
|
||||
> = events.map((eventName) => on(eventName, eventHandler, doc));
|
||||
const propertyDescriptor = Object.getOwnPropertyDescriptor(
|
||||
HTMLInputElement.prototype,
|
||||
const currentWindow = doc.defaultView;
|
||||
if (!currentWindow) {
|
||||
return () => {
|
||||
handlers.forEach((h) => h());
|
||||
};
|
||||
}
|
||||
const propertyDescriptor = currentWindow.Object.getOwnPropertyDescriptor(
|
||||
currentWindow.HTMLInputElement.prototype,
|
||||
'value',
|
||||
);
|
||||
const hookProperties: Array<[HTMLElement, string]> = [
|
||||
[HTMLInputElement.prototype, 'value'],
|
||||
[HTMLInputElement.prototype, 'checked'],
|
||||
[HTMLSelectElement.prototype, 'value'],
|
||||
[HTMLTextAreaElement.prototype, 'value'],
|
||||
[currentWindow.HTMLInputElement.prototype, 'value'],
|
||||
[currentWindow.HTMLInputElement.prototype, 'checked'],
|
||||
[currentWindow.HTMLSelectElement.prototype, 'value'],
|
||||
[currentWindow.HTMLTextAreaElement.prototype, 'value'],
|
||||
// Some UI library use selectedIndex to set select value
|
||||
[HTMLSelectElement.prototype, 'selectedIndex'],
|
||||
[HTMLOptionElement.prototype, 'selected'],
|
||||
[currentWindow.HTMLSelectElement.prototype, 'selectedIndex'],
|
||||
[currentWindow.HTMLOptionElement.prototype, 'selected'],
|
||||
];
|
||||
if (propertyDescriptor && propertyDescriptor.set) {
|
||||
handlers.push(
|
||||
...hookProperties.map((p) =>
|
||||
hookSetter<HTMLElement>(p[0], p[1], {
|
||||
set() {
|
||||
// mock to a normal event
|
||||
eventHandler({ target: this as EventTarget } as Event);
|
||||
hookSetter<HTMLElement>(
|
||||
p[0],
|
||||
p[1],
|
||||
{
|
||||
set() {
|
||||
// mock to a normal event
|
||||
eventHandler({ target: this as EventTarget } as Event);
|
||||
},
|
||||
},
|
||||
}),
|
||||
false,
|
||||
currentWindow,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user