close-on-popstate.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.CloseOnPopstateMixin = void 0;
  4. var _event = require("../utils/dom/event");
  5. var _bindEvent = require("./bind-event");
  6. var CloseOnPopstateMixin = {
  7. mixins: [(0, _bindEvent.BindEventMixin)(function (bind, isBind) {
  8. this.handlePopstate(isBind && this.closeOnPopstate);
  9. })],
  10. props: {
  11. closeOnPopstate: Boolean
  12. },
  13. data: function data() {
  14. return {
  15. bindStatus: false
  16. };
  17. },
  18. watch: {
  19. closeOnPopstate: function closeOnPopstate(val) {
  20. this.handlePopstate(val);
  21. }
  22. },
  23. methods: {
  24. onPopstate: function onPopstate() {
  25. this.close();
  26. this.shouldReopen = false;
  27. },
  28. handlePopstate: function handlePopstate(bind) {
  29. /* istanbul ignore if */
  30. if (this.$isServer) {
  31. return;
  32. }
  33. if (this.bindStatus !== bind) {
  34. this.bindStatus = bind;
  35. var action = bind ? _event.on : _event.off;
  36. action(window, 'popstate', this.onPopstate);
  37. }
  38. }
  39. }
  40. };
  41. exports.CloseOnPopstateMixin = CloseOnPopstateMixin;