Archived
1
0
This repository has been archived on 2024-09-09. You can view files and clone it, but cannot push or open issues or pull requests.
code-server/packages/vscode/src/fill/dom.ts

32 lines
1005 B
TypeScript
Raw Normal View History

2019-02-01 19:38:42 +01:00
import * as dom from "vs/base/browser/dom";
import { IDisposable } from "vs/base/common/lifecycle";
2019-01-19 01:04:24 +01:00
// Firefox has no implementation of toElement.
2019-01-08 01:46:19 +01:00
if (!("toElement" in MouseEvent.prototype)) {
Object.defineProperty(MouseEvent.prototype, "toElement", {
get: function (): EventTarget | null {
// @ts-ignore
const event = this as MouseEvent;
switch (event.type) {
case "mouseup":
case "focusin":
case "mousenter":
case "mouseover":
case "dragenter":
return event.target;
default:
return event.relatedTarget;
}
},
});
}
2019-02-01 19:38:42 +01:00
const _addDisposableListener = dom.addDisposableListener;
2019-02-02 02:55:32 +01:00
// tslint:disable-next-line no-any
2019-02-01 19:38:42 +01:00
const addDisposableListener = (node: Element | Window | Document, type: string, handler: (event: any) => void, useCapture?: boolean): IDisposable => {
return _addDisposableListener(node, type === "mousewheel" ? "wheel" : type, handler, useCapture);
};
const target = dom as typeof dom;
target.addDisposableListener = addDisposableListener;