Liferay.Loader.define('frontend-js-web@4.0.60/liferay/delegate/delegate.es', ['module', 'exports', 'require'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = void 0;

    /**
     * SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
     * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
     */

    /**
     * Checks if element is disabled or whether it exists in a disabled element tree
     * @param {!Element} element The DOM element to check.
     * @return {boolean}
     */
    function isDisabled(node) {
      return !!(node.disabled || node.closest('[disabled]'));
    }
    /**
     * Listens to the specified event on the given DOM element, but only calls the
     * given callback listener when it's triggered by elements that match the
     * given selector or target element.
     * @param {!Element} element The DOM element the event should be listened on.
     * @param {string} eventName The name of the event to listen to.
     * @param {string} selector Css selector that should match the event for the
     *     listener to be triggered.
     * @param {!function(!Object)} callback Function to be called when the event
     *     is triggered. It will receive the normalized event object.
     * @return {function} Can be used to remove the listener.
     */

    function delegate(element, eventName, selector, callback) {
      var eventHandler = function eventHandler(event) {
        var defaultPrevented = event.defaultPrevented,
            target = event.target;

        if (defaultPrevented || eventName === 'click' && isDisabled(target)) {
          return;
        }

        var delegateTarget = target.closest(selector);

        if (delegateTarget) {
          event.delegateTarget = delegateTarget;
          callback(event);
        }
      };

      element.addEventListener(eventName, eventHandler);
      return {
        dispose: function dispose() {
          element.removeEventListener(eventName, eventHandler);
        }
      };
    }

    var _default = delegate;
    exports.default = _default;
    //# sourceMappingURL=delegate.es.js.map
  }
});
//# sourceMappingURL=delegate.es.js.map