event.js 975 B

12345678910111213141516171819202122232425
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. import { Emitter } from '../common/event.js';
  6. export class DomEmitter {
  7. constructor(element, type, useCapture) {
  8. const fn = (e) => this.emitter.fire(e);
  9. this.emitter = new Emitter({
  10. onFirstListenerAdd: () => element.addEventListener(type, fn, useCapture),
  11. onLastListenerRemove: () => element.removeEventListener(type, fn, useCapture)
  12. });
  13. }
  14. get event() {
  15. return this.emitter.event;
  16. }
  17. dispose() {
  18. this.emitter.dispose();
  19. }
  20. }
  21. export function stopEvent(event) {
  22. event.preventDefault();
  23. event.stopPropagation();
  24. return event;
  25. }