vuetify
Version:
Vue.js 2 Semantic Component Framework
76 lines (62 loc) • 2.16 kB
JavaScript
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; };
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;
}
export default {
name: 'detachable',
mixins: [Bootable],
props: {
attach: {
type: [Boolean, String, Object],
default: false,
validator: validateAttachTarget
},
contentClass: {
default: ''
}
},
mounted: function mounted() {
this.initDetach();
},
deactivated: function deactivated() {
this.isActive = false;
},
beforeDestroy: function beforeDestroy() {
if (!this.$refs.content) return;
// IE11 Fix
try {
this.$refs.content.parentNode.removeChild(this.$refs.content);
} catch (e) {}
},
methods: {
initDetach: function initDetach() {
if (this._isDestroyed || !this.$refs.content ||
// 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);
}
}
};