big-moving.ru/api/soft/monako/esm/vs/base/browser/event.js

25 lines
995 B
JavaScript
Raw Normal View History

2022-06-24 15:29:23 +05:00
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Event as BaseEvent, Emitter } from '../common/event.js';
export var domEvent = function (element, type, useCapture) {
var fn = function (e) { return emitter.fire(e); };
var emitter = new Emitter({
onFirstListenerAdd: function () {
element.addEventListener(type, fn, useCapture);
},
onLastListenerRemove: function () {
element.removeEventListener(type, fn, useCapture);
}
});
return emitter.event;
};
export function stop(event) {
return BaseEvent.map(event, function (e) {
e.preventDefault();
e.stopPropagation();
return e;
});
}