Ohm-Management - Projektarbeit B-ME
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.

detachable.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  6. var _bootable = require('./bootable');
  7. var _bootable2 = _interopRequireDefault(_bootable);
  8. var _console = require('../util/console');
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  11. function validateAttachTarget(val) {
  12. var type = typeof val === 'undefined' ? 'undefined' : _typeof(val);
  13. if (type === 'boolean' || type === 'string') return true;
  14. return val.nodeType === Node.ELEMENT_NODE;
  15. }
  16. /* @vue/component */
  17. exports.default = {
  18. name: 'detachable',
  19. mixins: [_bootable2.default],
  20. props: {
  21. attach: {
  22. type: null,
  23. default: false,
  24. validator: validateAttachTarget
  25. },
  26. contentClass: {
  27. default: ''
  28. }
  29. },
  30. data: function data() {
  31. return {
  32. hasDetached: false
  33. };
  34. },
  35. watch: {
  36. attach: function attach() {
  37. this.hasDetached = false;
  38. this.initDetach();
  39. },
  40. hasContent: 'initDetach'
  41. },
  42. beforeMount: function beforeMount() {
  43. var _this = this;
  44. this.$nextTick(function () {
  45. if (_this.activatorNode) {
  46. var activator = Array.isArray(_this.activatorNode) ? _this.activatorNode : [_this.activatorNode];
  47. activator.forEach(function (node) {
  48. node.elm && _this.$el.parentNode.insertBefore(node.elm, _this.$el);
  49. });
  50. }
  51. });
  52. },
  53. mounted: function mounted() {
  54. !this.lazy && this.initDetach();
  55. },
  56. deactivated: function deactivated() {
  57. this.isActive = false;
  58. },
  59. beforeDestroy: function beforeDestroy() {
  60. // IE11 Fix
  61. try {
  62. if (this.$refs.content) {
  63. this.$refs.content.parentNode.removeChild(this.$refs.content);
  64. }
  65. if (this.activatorNode) {
  66. var activator = Array.isArray(this.activatorNode) ? this.activatorNode : [this.activatorNode];
  67. activator.forEach(function (node) {
  68. node.elm && node.elm.parentNode.removeChild(node.elm);
  69. });
  70. }
  71. } catch (e) {
  72. console.log(e);
  73. }
  74. },
  75. methods: {
  76. getScopeIdAttrs: function getScopeIdAttrs() {
  77. var scopeId = this.$vnode && this.$vnode.context.$options._scopeId;
  78. return scopeId && _defineProperty({}, scopeId, '');
  79. },
  80. initDetach: function initDetach() {
  81. if (this._isDestroyed || !this.$refs.content || this.hasDetached ||
  82. // Leave menu in place if attached
  83. // and dev has not changed target
  84. this.attach === '' || // If used as a boolean prop (<v-menu attach>)
  85. this.attach === true || // If bound to a boolean (<v-menu :attach="true">)
  86. this.attach === 'attach' // If bound as boolean prop in pug (v-menu(attach))
  87. ) return;
  88. var target = void 0;
  89. if (this.attach === false) {
  90. // Default, detach to app
  91. target = document.querySelector('[data-app]');
  92. } else if (typeof this.attach === 'string') {
  93. // CSS selector
  94. target = document.querySelector(this.attach);
  95. } else {
  96. // DOM Element
  97. target = this.attach;
  98. }
  99. if (!target) {
  100. (0, _console.consoleWarn)('Unable to locate target ' + (this.attach || '[data-app]'), this);
  101. return;
  102. }
  103. target.insertBefore(this.$refs.content, target.firstChild);
  104. this.hasDetached = true;
  105. }
  106. }
  107. };
  108. //# sourceMappingURL=detachable.js.map