click-outside.js 967 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.ClickOutsideMixin = void 0;
  4. var _event = require("../utils/dom/event");
  5. /**
  6. * Listen to click outside event
  7. */
  8. var ClickOutsideMixin = function ClickOutsideMixin(config) {
  9. return {
  10. props: {
  11. closeOnClickOutside: {
  12. type: Boolean,
  13. default: true
  14. }
  15. },
  16. data: function data() {
  17. var _this = this;
  18. var clickOutsideHandler = function clickOutsideHandler(event) {
  19. if (_this.closeOnClickOutside && !_this.$el.contains(event.target)) {
  20. _this[config.method]();
  21. }
  22. };
  23. return {
  24. clickOutsideHandler: clickOutsideHandler
  25. };
  26. },
  27. mounted: function mounted() {
  28. (0, _event.on)(document, config.event, this.clickOutsideHandler);
  29. },
  30. beforeDestroy: function beforeDestroy() {
  31. (0, _event.off)(document, config.event, this.clickOutsideHandler);
  32. }
  33. };
  34. };
  35. exports.ClickOutsideMixin = ClickOutsideMixin;