UNPKG

zarm

Version:

基于 React 的移动端UI库

66 lines (57 loc) 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; /* eslint-disable @typescript-eslint/no-empty-interface */ var supportsPassive = false; try { var opts = Object.defineProperty({}, 'passive', { get: function get() { supportsPassive = true; return true; } }); window.addEventListener('test', function () {}, opts); // eslint-disable-next-line no-empty } catch (e) {} var _default = { supportsPassiveEvents: supportsPassive, on: function on(el, type, callback) { var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : { passive: false }; if (el.addEventListener) { el.addEventListener(type, callback, supportsPassive ? options : false); } else { el.attachEvent("on".concat(type), function () { callback.call(el); }); } }, off: function off(el, type, callback) { var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : { passive: false }; if (el.removeEventListener) { el.removeEventListener(type, callback, supportsPassive ? options : false); } else { el.detachEvent("on".concat(type), callback); } }, once: function once(el, type, callback) { var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : { passive: false }; var typeArray = type.split(' '); var recursiveFunction = function recursiveFunction(e) { if (e.target) { e.target.removeEventListener(e.type, recursiveFunction, supportsPassive ? options : false); } return callback(e); }; for (var i = typeArray.length - 1; i >= 0; i -= 1) { this.on(el, typeArray[i], recursiveFunction); } } }; exports.default = _default;