vue-social-sharing
Version:
A Vue.js component for sharing links to social networks
6 lines • 5.81 kB
JavaScript
/*!
* vue-social-sharing v2.3.4
* (c) 2019 nicolasbeauvais
* Released under the MIT License.
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("vue")):"function"==typeof define&&define.amd?define(["vue"],e):t.VueSocialSharing=e(t.Vue)}(this,function(t){"use strict";t="default"in t?t.default:t;var e={functional:!0,props:{network:{type:String,default:""}},render:function(t,e){var r=e.parent._data.baseNetworks[e.props.network];return r?t(e.parent.networkTag,{staticClass:e.data.staticClass||null,staticStyle:e.data.staticStyle||null,class:e.data.class||null,style:e.data.style||null,attrs:{id:e.data.attrs.id||null,"data-link":"popup"===r.type?"#share-"+e.props.network:e.parent.createSharingUrl(e.props.network),"data-action":"popup"===r.type?null:r.action},on:{click:"popup"===r.type?function(){e.parent.share(e.props.network)}:function(){e.parent.touch(e.props.network)}}},e.children):console.warn("Network "+e.props.network+" does not exist")}},r={sharer:"mailto:?subject=@title&body=@url%0D%0A%0D%0A@description",type:"direct"},i={sharer:"https://www.facebook.com/sharer/sharer.php?u=@url&title=@title&description=@description"e=@quote&hashtag=@hashtags",type:"popup"},o={sharer:"https://plus.google.com/share?url=@url",type:"popup"},p={sharer:"http://line.me/R/msg/text/?@description%0D%0A@url",type:"popup"},s={sharer:"https://www.linkedin.com/shareArticle?mini=true&url=@url&title=@title&summary=@description",type:"popup"},n={sharer:"https://connect.ok.ru/dk?st.cmd=WidgetSharePreview&st.shareUrl=@url&st.comments=@description",type:"popup"},a={sharer:"https://pinterest.com/pin/create/button/?url=@url&media=@media&description=@title",type:"popup"},l={sharer:"https://www.reddit.com/submit?url=@url&title=@title",type:"popup"},u={sharer:"https://web.skype.com/share?url=@description%0D%0A@url",type:"popup"},h={sharer:"https://t.me/share/url?url=@url&text=@description",type:"popup"},c={sharer:"https://twitter.com/intent/tweet?text=@title&url=@url&hashtags=@hashtags@twitteruser",type:"popup"},d={sharer:"viber://forward?text=@url @description",type:"direct"},w={sharer:"https://vk.com/share.php?url=@url&title=@title&description=@description&image=@media&noparse=true",type:"popup"},m={sharer:"http://service.weibo.com/share/share.php?url=@url&title=@title",type:"popup"},f={sharer:"whatsapp://send?text=@description%0D%0A@url",type:"direct",action:"share/whatsapp/share"},g={sharer:"sms:?body=@url%20@description",type:"direct"},y={email:r,facebook:i,googleplus:o,line:p,linkedin:s,odnoklassniki:n,pinterest:a,reddit:l,skype:u,telegram:h,twitter:c,viber:d,vk:w,weibo:m,whatsapp:f,sms:g},b="undefined"!=typeof window,k=b?window:null,v={props:{url:{type:String,default:b?window.location.href:""},title:{type:String,default:""},description:{type:String,default:""},quote:{type:String,default:""},hashtags:{type:String,default:""},twitterUser:{type:String,default:""},withCounts:{type:[String,Boolean],default:!1},googleKey:{type:String,default:void 0},media:{type:String,default:""},networkTag:{type:String,default:"span"},networks:{type:Object,default:function(){return{}}}},data:function(){return{baseNetworks:y,popup:{status:!1,resizable:!0,toolbar:!1,menubar:!1,scrollbars:!1,location:!1,directories:!1,width:626,height:436,top:0,left:0,window:void 0,interval:null}}},methods:{createSharingUrl:function(t){return this.baseNetworks[t].sharer.replace(/ /g,encodeURIComponent(this.url)).replace(/ /g,encodeURIComponent(this.title)).replace(/ /g,encodeURIComponent(this.description)).replace(/ /g,encodeURIComponent(this.quote)).replace(/ /g,this.encodeFacebookHashtags(t,this.hashtags)).replace(/ /g,this.media).replace(/ /g,this.twitterUser?"&via="+this.twitterUser:"")},encodeFacebookHashtags:function(t,e){return"facebook"===t?"%23"+e:e},share:function(t){this.openSharer(t,this.createSharingUrl(t)),this.$root.$emit("social_shares_open",t,this.url),this.$emit("open",t,this.url)},touch:function(t){window.open(this.createSharingUrl(t),"_self"),this.$root.$emit("social_shares_open",t,this.url),this.$emit("open",t,this.url)},openSharer:function(t,e){var r=this;this.popup.window&&this.popup.interval&&(clearInterval(this.popup.interval),this.popup.window.close(),this.$root.$emit("social_shares_change",t,this.url),this.$emit("change",t,this.url)),this.popup.window=window.open(e,"sharer","status="+(this.popup.status?"yes":"no")+",height="+this.popup.height+",width="+this.popup.width+",resizable="+(this.popup.resizable?"yes":"no")+",left="+this.popup.left+",top="+this.popup.top+",screenX="+this.popup.left+",screenY="+this.popup.top+",toolbar="+(this.popup.toolbar?"yes":"no")+",menubar="+(this.popup.menubar?"yes":"no")+",scrollbars="+(this.popup.scrollbars?"yes":"no")+",location="+(this.popup.location?"yes":"no")+",directories="+(this.popup.directories?"yes":"no")),this.popup.window.focus(),this.popup.interval=setInterval(function(){r.popup.window.closed&&(clearInterval(r.popup.interval),r.popup.window=void 0,r.$root.$emit("social_shares_close",t,r.url),r.$emit("close",t,r.url))},500)}},beforeMount:function(){this.baseNetworks=t.util.extend(this.baseNetworks,this.networks)},mounted:function(){if(b){var t=void 0!==k.screenLeft?k.screenLeft:screen.left,e=void 0!==k.screenTop?k.screenTop:screen.top,r=k.innerWidth?k.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:screen.width,i=k.innerHeight?k.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:screen.height;this.popup.left=r/2-this.popup.width/2+t,this.popup.top=i/2-this.popup.height/2+e}},components:{network:e}};return v.version="2.3.4",v.install=function(t){t.component("social-sharing",v)},"undefined"!=typeof window&&(window.SocialSharing=v),v});