UNPKG

vuepress-plugin-social-share

Version:

Social sharing plugin for VuePress

71 lines (70 loc) 2.25 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const constants_1 = require("../constants"); const SocialShare_1 = __importDefault(require("./SocialShare")); const GlobalSocialShare = { name: 'GlobalSocialShare', inheritAttrs: false, computed: { visible() { return !(this.$frontmatter.noGlobalSocialShare || this.$frontmatter.noSocialShare); }, }, data() { return { isActive: false, }; }, methods: { handleClick(evt) { const { target } = evt; if (!this.$el.contains) return; if (this.$el.contains(target)) return; this.isActive = false; }, toggle(evt) { this.isActive = !this.isActive; evt.stopPropagation(); }, }, render(h) { if (!this.visible) return null; const renderButtonIcon = () => h('span', { class: 'social-share-icon-svg', domProps: { innerHTML: this.isActive ? constants_1.SVG_ICON_CLOSE : constants_1.SVG_ICON_SHARE, }, }); const renderGlobalButton = () => h('button', { attrs: { class: 'social-share-btn social-share-trigger', type: 'button', role: 'button', }, on: { click: this.toggle, }, }, [renderButtonIcon()]); const renderSocialShare = () => h(SocialShare_1.default, { style: { display: this.isActive ? 'block' : 'none' }, props: Object.assign({}, this.$attrs), }); return h('div', { attrs: { class: 'social-share-global' } }, [ renderSocialShare(), renderGlobalButton(), ]); }, mounted() { document.addEventListener('click', this.handleClick); this.$once('hook:beforeDestroy', () => { document.removeEventListener('click', this.handleClick); }); }, }; exports.default = GlobalSocialShare;