Instantly share code, notes, and snippets.
Created
May 9, 2017 23:14
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save nawawishkid-old/99eab374123808cd56c533fec150997a to your computer and use it in GitHub Desktop.
Social media sharing bar plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function RK_ShareBar(a=null){this.cssDefault={sharer:"facebook, line, twitter, google",tabSize:"2em",tabRadius:"25%",hover:"widen",position:"top-left",shadow:!0},this.cssRaw=function(a,b){return null===a?b:"object"==typeof a?a:void 0}(a,this.cssDefault),this.cssValid=function(a,b){var c=void 0!==a.sharer?a.sharer.match(/(facebook|google|twitter|tumblr|pinterest|line|linkedin)/g)||b.sharer:b.sharer,d=void 0!==a.tabSize?a.tabSize.match(/^\d*(em|px)$/g)||b.tabSize:b.tabSize,e=void 0!==a.tabRadius?a.tabRadius.match(/^\d*(em|px|%)$/g)||b.tabRadius:b.tabRadius,f=void 0!==a.hover?a.hover.match(/^(widen|enlarge)$/g)||b.hover:b.hover,g=void 0!==a.position?a.position.match(/^(top-left|top-right|bottom-left|bottom-right)$/g)||b.position:b.position,h=void 0!==a.shadow?a.shadow:b.shadow;return{sharer:"object"==typeof c?c.join(","):c,tabSize:"object"==typeof d?d[0]:d,tabRadius:"object"==typeof e?e[0]:e,hover:"object"==typeof f?f[0]:f,position:"object"==typeof g?g[0]:g,shadow:h?"shadow":""}}(this.cssRaw,this.cssDefault),this.cssInit=function(a){function z(a){for(let b=0;b<a.length;b++)c.insertRule(a[b],c.cssRules.length)}var c,b=document.createElement("style");document.head.appendChild(b),c=b.sheet;var d,e,f,g,h,i,j,k;d=".rkShareBar-tab{cursor:pointer;display:flex;justify-content:center;align-items:center;color:#fff;transition:all .4s}|#rkShareBar.top-left{top:10%;left:0}|#rkShareBar.top-right{top:10%;right:0}|#rkShareBar.bottom-left{bottom:10%;left:0}|#rkShareBar.bottom-right{bottom:10%;right:0}|#rkShareBar[class*=-right] .rkShareBar-tab{float:right;clear:right}|#rkShareBar.shadow{box-shadow:0 0 3px 0 rgba(0,0,0,.5)}|#rkShareBar.shadow:hover{box-shadow:none}|#rkShareBar.shadow .rkShareBar-tab:hover{box-shadow:0 0 3px 0 rgba(0,0,0,.5)}|.rkShareBar-tab[data-sharer=facebook]{background-color:#3b5998}|.rkShareBar-tab[data-sharer=twitter]{background-color:#55acee}|.rkShareBar-tab[data-sharer=google],.rkShareBar-tab[data-sharer=pinterest]{background-color:#fff}|.rkShareBar-tab[data-sharer=linkedin]{background-color:#007bb6}|.rkShareBar-tab[data-sharer=tumblr]{background-size:contain;background-color:#32506d}|.rkShareBar-tab[data-sharer=line]{background-color:#00b900}|.rkShareBar-tab svg{width:75%;height:75%}|.rkShareBar-tab[data-sharer=twitter] svg{width:66.67%;height:66.67%}",d=d.split("|"),z(d);var n=".rkShareBar-tab",o=a.tabSize,p=a.tabRadius,q=a.position,r=1.5*o.replace(/\D*/g,""),s=o.replace(/\d*/g,""),t=.6*p.replace(/\D*/g,""),u=p.replace(/\d*/g,""),v="em"===s?16*r:r,w="%"===u?t/100*v+"px":p,x=q.includes("-right")?"left":"right";e="#rkShareBar {width: "+o+";position: fixed;z-index: 99;border-top-"+x+"-radius: "+w+";border-bottom-"+x+"-radius: "+w+";}",f=n+" {width: "+o+";height: "+o+";}",g=n+":first-child {border-top-"+x+"-radius: "+p+";}",h=n+":last-child {border-bottom-"+x+"-radius: "+p+";}",i=n+":hover {border-top-"+x+"-radius: "+t+u+";border-bottom-"+x+"-radius: "+t+u+";}",j=n+".widen:hover {width: "+r+s+";}",k=n+".enlarge:hover {width: "+r+s+";height: "+r+s+";}",z([e,f,g,h,i,j,k])}(this.cssValid),this.tabInit=function(a,b){var c=document.getElementById("rkShareBar");for(c.className=b.position+" "+b.shadow;c.firstElementChild;)c.removeChild(c.lastElementChild);var d=a.split(",");for(let a=0;a<d.length;a++){d[a]=d[a].trim();if(void 0===SharerInfo[d[a]].url)return!1;var f=document.createElement("div");f.className="rkShareBar-tab "+b.hover,f.dataset.sharer=d[a],f.innerHTML=SharerInfo[f.dataset.sharer].svg,f.title="Please, share this page to "+d[a],c.appendChild(f),f.addEventListener("click",function(){var a=window.innerWidth/2,b=a-a/2,c="location=yes,height=500,width=500,left="+b+",top=0,resizable=yes,scrollbars=yes,status=yes",d=this.dataset.sharer;window.open(SharerInfo[d].url,"_blank",c)})}}(this.cssValid.sharer,this.cssValid)}var bar=document.createElement("div");bar.id="rkShareBar",document.body.appendChild(bar);var thisUrl=window.location.href,SharerInfo={facebook:{url:"https://www.facebook.com/sharer/sharer.php?u="+thisUrl,svg:'<svg width="355.9" height="355.9" viewBox="0 0 355.85734 355.85999" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#clipPath56)" transform="matrix(1.3333 0 0 -1.3333 -164.74 516.6)"><path d="M375.7 120.5c8.2 0 14.8 6.6 14.8 14.8v237.4c0 8-6.6 14.7-14.8 14.7H138.3c-8 0-14.7-6.6-14.7-14.7V135.3c0-8.2 6.6-14.7 14.7-14.7z" fill="#3c5a99"/><path d="M307.7 120.5V224h34.7l5.2 40.2h-40V290c0 11.6 3.3 19.5 20 19.5H349v36c-3.7.5-16.4 1.6-31 1.6-30.8 0-52-18.6-52-53V264h-34.7V224H266V120.4z" fill="#fff"/></g></svg>'},twitter:{url:"https://twitter.com/intent/tweet?url="+thisUrl+"&text="+document.title+"&hashtags=abc,edf&via=rakkid&related=kidziikidz",svg:'<svg width="364.5" height="296.2" viewBox="0 0 364.51999 296.23733" xmlns="http://www.w3.org/2000/svg"><path d="M364.5 35c-13.4 6-27.8 10-43 11.8 15.5-9.2 27.4-24 33-41.3C340 14 324 20.3 307 23.5 293.3 9.2 274 0 252.4 0c-41.3 0-74.8 33.5-74.8 74.8 0 5.8.6 11.6 2 17-62.2-3-117.3-33-154.2-78-6.5 11-10.2 23.8-10.2 37.5 0 26 13.3 48.8 33.3 62.2-12.2-.4-23.8-3.7-34-9.3v1c0 36.2 26 66.4 60 73.3-6 1.7-12.8 2.6-19.6 2.6-5 0-9.6-.4-14-1.3 9.4 29.7 37 51.4 69.7 52-25.6 20-57.8 32-93 32-6 0-12-.4-17.7-1C33 283.8 72.4 296 114.6 296c137.6 0 212.8-114 212.8-212.7 0-3.3 0-6.5-.2-9.7C341.8 63.2 354.5 50 364.5 35" fill="#fff"/></svg>'},google:{url:"https://plus.google.com/share?url="+thisUrl,svg:'<svg viewBox="0 0 18 18" xmlns="http://www.w3.org/2000/svg"><g fill="none" fill-rule="evenodd"><path d="M17.6 9.2V7.4H9v3.4h4.8c-.2 1.2-.8 2-1.8 2.8v2.2h3c1.7-1.5 2.6-4 2.6-6.6z" fill="#4285f4"/><path d="M9 18c2.4 0 4.5-.8 6-2.2l-3-2.2c-.8.5-1.8.8-3 .8-2.3 0-4.3-1.6-5-3.7H1V13c1.4 3 4.5 5 8 5z" fill="#34a853"/><path d="M4 10.7c-.2-.5-.3-1-.3-1.7s0-1.2.3-1.7V5H1C.3 6.2 0 7.5 0 9s.3 2.8 1 4z" fill="#fbbc05"/><path d="M9 3.6c1.3 0 2.5.4 3.4 1.3L15 2.2C13.5 1 11.4 0 9 0 5.5 0 2.4 2 1 5l3 2.3c.7-2 2.7-3.7 5-3.7z" fill="#ea4335"/><path d="M0 0h18v18H0z"/></g></svg>'},line:{url:"",svg:'<svg viewBox="0 0 191.03206 191.03739" xmlns="http://www.w3.org/2000/svg"><path d="M156.5 0H34.8C15.8 0 0 15.5 0 34.6v121.6c0 19 15.4 34.8 34.5 34.8h121.7c19 0 34.8-15.4 34.8-34.5V34.8c0-19-15.4-34.8-34.5-34.8" fill="#00b900"/><path d="M164.7 87c0-31-31.2-56.3-69.5-56.3C56.8 30.7 25.6 56 25.6 87c0 28 24.8 51.4 58.2 55.8 2.3.5 5.4 1.5 6 3.4.8 1.8.6 4.6.4 6.3 0 0-1 5-1 6-.3 1.7-1.4 7 6 3.7 7.4-3 40-23.5 54.6-40.3 10-11.2 15-22.4 15-35" fill="#fff"/><path d="M81 72h-4.8c-.8 0-1.4.7-1.4 1.4v30.3c0 .8.6 1.4 1.4 1.4h5c.6 0 1.2-.5 1.2-1.3V73.4c0-.7-.6-1.3-1.3-1.3M114.6 72h-4.8c-.8 0-1.4.7-1.4 1.4v18l-14-18.7v-.2H94v-.2H94h-.2V72h-.2-5.2c-.6 0-1.2.7-1.2 1.4v30.3c0 .8.6 1.4 1.3 1.4h5c.6 0 1.2-.5 1.2-1.3v-18l14 18.8c0 .2.2.3.3.4h5.6c.8 0 1.4-.5 1.4-1.3V73.4c0-.7-.6-1.3-1.4-1.3M69.3 97.5H56v-24c0-.8-.6-1.4-1.3-1.4h-5c-.6 0-1.2.7-1.2 1.4v30.3c0 .4 0 .7.3 1 .3.2.6.4 1 .4h19.5c.7 0 1.3-.5 1.3-1.3V99c0-1-.6-1.5-1.3-1.5M141.6 79.7c.7 0 1.3-.6 1.3-1.4v-5c0-.6-.7-1.2-1.4-1.2H122c-.3 0-.6.2-1 .5 0 .3-.3.6-.3 1v30.2c0 .4.2.7.4 1 .4.3.7.4 1 .4h19.6c.7 0 1.3-.5 1.3-1.3V99c0-1-.7-1.5-1.4-1.5h-13.3v-5h13.3c.7 0 1.3-.7 1.3-1.5v-4.8c0-.8-.7-1.4-1.4-1.4h-13.3v-5z" fill="#00b900"/></svg>'},pinterest:{url:"https://pinterest.com/pin/create/button/?url="+thisUrl+"&media=http://rakkid.esy.es/projects/wat-samakkeebanpot/media/temple-1-min.jpg&description=นี่คือคำอธิบาย",svg:'<svg viewBox="0 0 177.52716 177.52673" xmlns="http://www.w3.org/2000/svg"><path d="M185 88.8c0 53-43 96-96 96s-96-43-96-96 43-96 96-96 96 43 96 96" fill="#fff"/><path d="M88.8 0C39.8 0 0 39.7 0 88.8c0 37.6 23.4 69.7 56.4 82.6-.8-7-1.5-17.8.3-25.4L67 101.8s-2.5-5.3-2.5-13c0-12.5 7-21.7 16-21.7C88 67 91.8 73 91.8 79.7c0 7.6-5 19-7.4 29.6-2 8.8 4.4 16 13.2 16 15.7 0 28-16.6 28-40.6 0-21.3-15.4-36.2-37.2-36.2-25.3 0-40 19-40 38.6 0 7.6 2.8 15.8 6.5 20.2.6 1 .7 1.7.5 2.6-.6 2.8-2 8.8-2.4 10-.3 1.7-1.2 2-3 1.2-11-5-18-21.4-18-34.4C32 58.6 52.5 33 90.8 33c30.8 0 54.7 22 54.7 51.2 0 30.6-19.2 55.2-46 55.2-9 0-17.5-4.7-20.4-10.2l-5.5 21c-2 7.8-7.4 17.5-11 23.4 8.3 2.5 17 4 26.3 4 49 0 88.7-39.8 88.7-88.8S137.8 0 88.8 0" fill="#bd1e24"/></svg>'},linkedin:{url:"https://www.linkedin.com/shareArticle?mini=true&url="+thisUrl+"&title="+document.title,svg:'<svg viewBox="0 0 206.88 192" xmlns="http://www.w3.org/2000/svg"><path d="M177.8 0H14.2C6.4 0 0 6.2 0 13.8V178c0 7.8 6.4 14 14.2 14h163.6c7.8 0 14.2-6.2 14.2-14V14C192 6.2 185.6 0 177.8 0" fill="#0977b6"/><path d="M42.7 26.4c9 0 16.5 7.4 16.5 16.5 0 9-7.4 16.5-16.5 16.5-9 0-16.5-7.4-16.5-16.6 0-9.2 7.4-16.6 16.5-16.6M28.5 72H57v91.6H28.4V72M74.8 72H102v12.5h.5c3.8-7.2 13-14.8 27-14.8 28.8 0 34 19 34 43.7v50.2h-28.4V119c0-10.6 0-24.2-14.7-24.2-14.8 0-17 11.5-17 23.5v45.3H74.8V72" fill="#fff"/><path d="M201.7 159.4h-1v-1.8h1.2c.5 0 1.2 0 1.2 1 0 .8-.7.8-1.5.8zm1 .6c.8 0 1.3-.6 1.3-1.5 0-1-.7-1.5-2-1.5h-2v5.4h.8V160h1l1.4 2.4h1l-1.7-2.4" fill="#231f20"/><path d="M201.8 164c-2.5 0-4.4-1.8-4.4-4.3s2-4.4 4.4-4.4c2.4 0 4.3 2 4.3 4.4 0 2.5-1.8 4.4-4.2 4.4zm0-9.4c-3 0-5 2.3-5 5 0 3 2 5.2 5 5.2 2.8 0 5-2.2 5-5 0-3-2.2-5.2-5-5.2" fill="#231f20"/></svg>'},tumblr:{url:"https://tumblr.com/share/link?url="+thisUrl,svg:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024"><path fill="#fff" d="M702.8 799.6c-22.2 23.7-73.7 39.8-119.8 40.6h-5c-155 0-188.5-114-188.5-180.3V475.2h-61a12.8 12.8 0 0 1-12.8-12.8v-87.2a21.7 21.7 0 0 1 14.5-20.5c79.4-28 104.4-97.3 108-150 1-14.2 8.4-21 20.7-21h90.8a12.8 12.8 0 0 1 12.8 12.8v147.7H669a12.8 12.8 0 0 1 12.8 12.7v104.8a12.8 12.8 0 0 1-12.8 12.8H562v170.7c0 43 28.3 54.7 45.8 54.7 16.7-.4 33.2-5.5 41.5-8.8 6-2.5 11.5-4 16.3-3 4.5 1.2 7.4 4.4 9.4 10.2l28.2 82.4c2.3 6.6 4.3 13.7-.4 18.8z"/></svg>'}}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment