vanillajs-browser-helpers
Version:
Collection of convenience code snippets (helpers) that aims to make it a little easier to work with vanilla JS in the browser
25 lines (24 loc) • 895 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var isEventTarget_1 = __importDefault(require("./isEventTarget"));
var eventOptionsSupported_1 = __importDefault(require("./eventOptionsSupported"));
function off(elm, eventNames, handler, options) {
if (!isEventTarget_1.default(elm)) {
options = handler;
handler = eventNames;
eventNames = elm;
elm = document;
}
var opts = eventOptionsSupported_1.default()
? options
: !!(options && options.capture);
if (!Array.isArray(eventNames)) {
eventNames = [eventNames];
}
eventNames.forEach(function (evt) { return elm.removeEventListener(evt, handler, opts); });
return elm;
}
exports.default = off;