You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.3 KiB

  1. import getWindow from "../dom-utils/getWindow.js"; // eslint-disable-next-line import/no-unused-modules
  2. var passive = {
  3. passive: true
  4. };
  5. function effect(_ref) {
  6. var state = _ref.state,
  7. instance = _ref.instance,
  8. options = _ref.options;
  9. var _options$scroll = options.scroll,
  10. scroll = _options$scroll === void 0 ? true : _options$scroll,
  11. _options$resize = options.resize,
  12. resize = _options$resize === void 0 ? true : _options$resize;
  13. var window = getWindow(state.elements.popper);
  14. var scrollParents = [].concat(state.scrollParents.reference, state.scrollParents.popper);
  15. if (scroll) {
  16. scrollParents.forEach(function (scrollParent) {
  17. scrollParent.addEventListener('scroll', instance.update, passive);
  18. });
  19. }
  20. if (resize) {
  21. window.addEventListener('resize', instance.update, passive);
  22. }
  23. return function () {
  24. if (scroll) {
  25. scrollParents.forEach(function (scrollParent) {
  26. scrollParent.removeEventListener('scroll', instance.update, passive);
  27. });
  28. }
  29. if (resize) {
  30. window.removeEventListener('resize', instance.update, passive);
  31. }
  32. };
  33. } // eslint-disable-next-line import/no-unused-modules
  34. export default {
  35. name: 'eventListeners',
  36. enabled: true,
  37. phase: 'write',
  38. fn: function fn() {},
  39. effect: effect,
  40. data: {}
  41. };