forked from ellisonleao/sharer.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsharer.min.js
1 lines (1 loc) · 2.8 KB
/
sharer.min.js
1
!function(t,e){"use strict";var a=function(t){this.elem=t};a.prototype={getValue:function(t){var e=this.elem.getAttribute(t);return void 0===e||null===e?"":e},share:function(){var t,e,a=this.elem.getAttribute("data-sharer"),r=this,u={facebook:function(){t="https://www.facebook.com/sharer/sharer.php",e={u:r.getValue("data-url")},r.urlSharer(t,e)},googleplus:function(){t="https://plus.google.com/share",e={url:r.getValue("data-url")},r.urlSharer(t,e)},linkedin:function(){t="https://www.linkedin.com/shareArticle",e={url:r.getValue("data-url"),mini:!0},r.urlSharer(t,e)},twitter:function(){t="https://twitter.com/intent/tweet/",e={text:r.getValue("data-title"),url:r.getValue("data-url")},r.urlSharer(t,e)},email:function(){var a=r.getValue("data-subject");t="mailto:"+r.getValue("data-to"),e={subject:a,body:a+"\n"+r.getValue("data-title")+"\n"+r.getValue("data-url")},r.urlSharer(t,e,!0)},whatsapp:function(){t="whatsapp://send",e={text:r.getValue("data-title")+" "+r.getValue("data-url")},r.urlSharer(t,e,!0)},telegram:function(){t="tg://msg_url",e={text:r.getValue("data-title")+" "+r.getValue("data-url")},r.urlSharer(t,e,!0)},viber:function(){t="viber://forward",e={text:r.getValue("data-title")+" "+r.getValue("data-url")},r.urlSharer(t,e,!0)},pinterest:function(){t="https://www.pinterest.com/pin/create/button/",e={url:r.getValue("data-url")},r.urlSharer(t,e)},tumblr:function(){t="http://tumblr.com/widgets/share/tool",e={canonicalUrl:r.getValue("data-url"),content:r.getValue("data-url"),posttype:"link",title:r.getValue("data-title"),caption:r.getValue("data-caption"),tags:r.getValue("data-tags")},r.urlSharer(t,e)},hackernews:function(){t="https://news.ycombinator.com/submitlink",e={u:r.getValue("data-url"),t:r.getValue("data-title")},r.urlSharer(t,e)},reddit:function(){t="https://www.reddit.com/submit",e={url:r.getValue("data-url")},r.urlSharer(t,e)},vk:function(){t="http://vk.com/share.php",e={url:r.getValue("data-url"),title:r.getValue("data-title"),description:r.getValue("data-caption")},r.urlSharer(t,e)},xing:function(){t="https://www.xing.com/app/user",e={op:"share",url:r.getValue("data-url"),title:r.getValue("data-title")},r.urlSharer(t,e)},buffer:function(){t="https://buffer.com/add",e={url:r.getValue("data-url"),title:r.getValue("data-url"),via:r.getValue("data-twitter-username"),picture:r.getValue("data-picture")},r.urlSharer(t,e)},"default":function(){}};return(u[a]||u["default"])()},urlSharer:function(e,a,r){var u,l="object"==typeof a?a:{},n=Object.keys(l),i="?";for(u=0;u<n.length;u++)"?"!==i&&(i+="&"),i+=n[u]+"="+encodeURIComponent(l[n[u]]);e+=i,r?t.location.href=e:t.open(e,"","height=400,width=400,scrollbars=no")}},t.addEventListener("load",function(){function t(t){var e=new a(t.srcElement);e.share()}var r,u=e.querySelectorAll(".sharer"),l=u.length;for(r=0;l>r;r++)u[r].addEventListener("click",t)})}(window,document);