123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- 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; };
-
- 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; }
-
- import Bootable from './bootable';
- import { consoleWarn } from '../util/console';
- function validateAttachTarget(val) {
- var type = typeof val === 'undefined' ? 'undefined' : _typeof(val);
- if (type === 'boolean' || type === 'string') return true;
- return val.nodeType === Node.ELEMENT_NODE;
- }
- /* @vue/component */
- export default {
- name: 'detachable',
- mixins: [Bootable],
- props: {
- attach: {
- type: null,
- default: false,
- validator: validateAttachTarget
- },
- contentClass: {
- default: ''
- }
- },
- data: function data() {
- return {
- hasDetached: false
- };
- },
- watch: {
- attach: function attach() {
- this.hasDetached = false;
- this.initDetach();
- },
-
- hasContent: 'initDetach'
- },
- beforeMount: function beforeMount() {
- var _this = this;
-
- this.$nextTick(function () {
- if (_this.activatorNode) {
- var activator = Array.isArray(_this.activatorNode) ? _this.activatorNode : [_this.activatorNode];
- activator.forEach(function (node) {
- node.elm && _this.$el.parentNode.insertBefore(node.elm, _this.$el);
- });
- }
- });
- },
- mounted: function mounted() {
- !this.lazy && this.initDetach();
- },
- deactivated: function deactivated() {
- this.isActive = false;
- },
- beforeDestroy: function beforeDestroy() {
- // IE11 Fix
- try {
- if (this.$refs.content) {
- this.$refs.content.parentNode.removeChild(this.$refs.content);
- }
- if (this.activatorNode) {
- var activator = Array.isArray(this.activatorNode) ? this.activatorNode : [this.activatorNode];
- activator.forEach(function (node) {
- node.elm && node.elm.parentNode.removeChild(node.elm);
- });
- }
- } catch (e) {
- console.log(e);
- }
- },
-
- methods: {
- getScopeIdAttrs: function getScopeIdAttrs() {
- var scopeId = this.$vnode && this.$vnode.context.$options._scopeId;
- return scopeId && _defineProperty({}, scopeId, '');
- },
- initDetach: function initDetach() {
- if (this._isDestroyed || !this.$refs.content || this.hasDetached ||
- // Leave menu in place if attached
- // and dev has not changed target
- this.attach === '' || // If used as a boolean prop (<v-menu attach>)
- this.attach === true || // If bound to a boolean (<v-menu :attach="true">)
- this.attach === 'attach' // If bound as boolean prop in pug (v-menu(attach))
- ) return;
- var target = void 0;
- if (this.attach === false) {
- // Default, detach to app
- target = document.querySelector('[data-app]');
- } else if (typeof this.attach === 'string') {
- // CSS selector
- target = document.querySelector(this.attach);
- } else {
- // DOM Element
- target = this.attach;
- }
- if (!target) {
- consoleWarn('Unable to locate target ' + (this.attach || '[data-app]'), this);
- return;
- }
- target.insertBefore(this.$refs.content, target.firstChild);
- this.hasDetached = true;
- }
- }
- };
- //# sourceMappingURL=detachable.js.map
|