@zomoz/ngx-share
Version:
Share buttons components for Angular and Ionic.
3 lines (2 loc) • 13.4 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/common"),require("rxjs/operators"),require("@angular/common/http"),require("rxjs/observable/empty"),require("rxjs/observable/of")):"function"==typeof define&&define.amd?define(["exports","@angular/core","@angular/common","rxjs/operators","@angular/common/http","rxjs/observable/empty","rxjs/observable/of"],e):e((t["ngx-share"]=t["ngx-share"]||{},t["ngx-share"].core={}),t.ng.core,t.ng.common,t.Rx.Observable.prototype,t.ng.common.http,t.Rx.Observable,t.Rx.Observable)}(this,function(t,e,r,o,n,i,s){"use strict";var a=new e.InjectionToken("CONFIG"),p=o.map(function(t){return t.prop.share[t.os]+t.url}),c=o.map(function(t){var e=t.prop.share.metaTags,r=t.metaTags,o=t.prop.share[t.os],n=t.url;return e&&Object.keys(e).map(function(t){r[t]&&(n+="&"+e[t]+"="+r[t])}),o+n}),u=o.map(function(t){return t.window.print()}),l=o.map(function(t){if(!t.includes("&description")){var e=document.querySelector('meta[property="og:description"]');e?t+="&description="+e.getAttribute("content"):console.warn("[ShareButtons]: You didn't set the description text for Pinterest button")}if(!t.includes("&media")){var r=document.querySelector('meta[property="og:image"]');r?t+="&media="+r.getAttribute("content"):console.warn("[ShareButtons]: You didn't set the image URL for Pinterest button")}return t}),h=[o.map(function(t){t.renderer.setStyle(t.el,"pointer-events","none"),t.temp={text:t.prop.text,icon:t.prop.icon};var e=decodeURIComponent(t.url),r=t.renderer.createElement("textarea");return r.style.position="fixed",r.style.top=0,r.style.left=0,r.style.width="2em",r.style.height="2em",r.style.padding=0,r.style.border="none",r.style.outline="none",r.style.boxShadow="none",r.style.background="transparent",r.value=e,t.renderer.appendChild(t.el,r),r.select(),document.execCommand("copy"),t.renderer.removeChild(t.el,r),t.prop.text=t.prop.successText,t.prop.icon=t.prop.successIcon,t.cd.markForCheck(),t},function(t){t.prop.text=t.prop.failText,t.prop.icon=t.prop.failIcon,t.cd.markForCheck(),console.warn("[ShareButtons]: Print button could not copy URL to clipboard")}),o.delay(2e3),o.map(function(t){t.renderer.setStyle(t.el,"pointer-events","auto"),t.prop.text=t.temp.text,t.prop.icon=t.temp.icon,t.cd.markForCheck()})],d={facebook:{type:"facebook",text:"Facebook",icon:"fa fa-facebook",color:"#3b5998",share:{desktop:"https://www.facebook.com/sharer/sharer.php?u=",android:"https://www.facebook.com/sharer/sharer.php?u=",ios:"https://www.facebook.com/sharer/sharer.php?u=",operators:[p]},count:{request:"http",url:"https://graph.facebook.com?id=",operators:[o.map(function(t){return+t.share.share_count})]}},twitter:{type:"twitter",text:"Twitter",icon:"fa fa-twitter",color:"#00acee",share:{desktop:"https://twitter.com/intent/tweet?url=",android:"https://twitter.com/intent/tweet?url=",ios:"https://twitter.com/intent/tweet?url=",operators:[c],metaTags:{description:"text",tags:"hashtags",via:"via"}}},google:{type:"google",text:"Google+",icon:"fa fa-google-plus",color:"#DB4437",share:{desktop:"https://plus.google.com/share?url=",android:"https://plus.google.com/share?url=",ios:"https://plus.google.com/share?url=",operators:[p]}},linkedin:{type:"linkedin",text:"LinkedIn",icon:"fa fa-linkedin",color:"#006fa6",share:{desktop:"http://www.linkedin.com/shareArticle?url=",android:"http://www.linkedin.com/shareArticle?url=",ios:"http://www.linkedin.com/shareArticle?url=",operators:[c],metaTags:{title:"title",description:"summary"}},count:{request:"jsonp",url:"https://www.linkedin.com/countserv/count/share?url=",operators:[o.map(function(t){return+t.count})]}},pinterest:{type:"pinterest",text:"Pinterest",icon:"fa fa-pinterest-p",color:"#BD091D",share:{desktop:"https://in.pinterest.com/pin/create/button/?url=",android:"https://in.pinterest.com/pin/create/button/?url=",ios:"https://in.pinterest.com/pin/create/button/?url=",operators:[c,l],metaTags:{description:"description",image:"media"}},count:{request:"http",url:"https://api.pinterest.com/v1/urls/count.json?url=",args:{responseType:"text"},operators:[o.map(function(t){return JSON.parse(t.replace(/^receiveCount\((.*)\)/,"$1"))}),o.map(function(t){return+t.count})]}},reddit:{type:"reddit",text:"Reddit",icon:"fa fa-reddit-alien",color:"#FF4006",share:{desktop:"http://www.reddit.com/submit?url=",android:"http://www.reddit.com/submit?url=",ios:"http://www.reddit.com/submit?url=",operators:[c],metaTags:{title:"title"}},count:{request:"http",url:"https://buttons.reddit.com/button_info.json?url=",operators:[o.map(function(t){return+t.data.children[0].data.score})]}},tumblr:{type:"tumblr",text:"Tumblr",icon:"fa fa-tumblr",color:"#36465D",share:{desktop:"http://tumblr.com/widgets/share/tool?canonicalUrl=",android:"http://tumblr.com/widgets/share/tool?canonicalUrl=",ios:"http://tumblr.com/widgets/share/tool?canonicalUrl=",operators:[c],metaTags:{description:"caption",tags:"tags"}},count:{request:"jsonp",url:"https://api.tumblr.com/v2/share/stats?url=",operators:[o.map(function(t){return+t.response.note_count})]}},whatsapp:{type:"whatsapp",text:"WhatsApp",icon:"fa fa-whatsapp",color:"#25D366",share:{desktop:"https://web.whatsapp.com/send?",android:"https://api.whatsapp.com/send?",ios:"https://api.whatsapp.com/send?",operators:[c],metaTags:{description:"text"}}},telegram:{type:"telegram",text:"Telegram",icon:"fa fa-send",color:"#0088cc",share:{desktop:"https://t.me/share/url?url=",android:"https://t.me/share/url?url=",ios:"https://t.me/share/url?url=",operators:[c],metaTags:{description:"text"}}},vk:{type:"vk",text:"VKontakte",icon:"fa fa-vk",color:"#4C75A3",share:{desktop:"http://vk.com/share.php?url=",android:"http://vk.com/share.php?url=",ios:"http://vk.com/share.php?url=",operators:[p]}},stumble:{type:"stumble",text:"Stumble",icon:"fa fa-stumbleupon",color:"#eb4924",share:{desktop:"http://www.stumbleupon.com/submit?url=",android:"http://www.stumbleupon.com/submit?url=",ios:"http://www.stumbleupon.com/submit?url=",operators:[p]}},email:{type:"email",text:"Email",icon:"fa fa-envelope",color:"#32A1A3",share:{desktop:"mailto:?",android:"mailto:?",ios:"mailto:?",operators:[c],metaTags:{title:"subject",description:"body"}}},copy:{type:"copy",text:"Copy link",successText:"Copied",successIcon:"fa fa-check",failText:"Error",failIcon:"fa fa-exclamation",icon:"fa fa-link",color:"#607D8B",share:{operators:h}},print:{type:"print",text:"Print",icon:"fa fa-print",color:"brown",share:{operators:[u]}}},m=function(){function t(t){this.prop=d,this.allButtons=Object.keys(this.prop),this.options={theme:"default",include:this.allButtons,exclude:[],size:0,title:null,image:null,description:null,tags:null,gaTracking:!1,twitterAccount:null,windowWidth:800,windowHeight:500},t&&(this.options=b(this.options,t.options),this.prop=b(this.prop,t.prop)),this.os=function(){var t=navigator.userAgent||navigator.vendor||(window||global).opera;if(/android/i.test(t))return"android";if(/iPad|iPhone|iPod/.test(t)&&!(window||global).MSStream)return"ios";return"desktop"}()}return Object.defineProperty(t.prototype,"twitterAccount",{get:function(){return this.options.twitterAccount},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buttons",{get:function(){var t=this;return this.options.exclude.length?this.options.include.filter(function(e){return t.options.exclude.indexOf(e)<0}):this.options.include},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"theme",{get:function(){return this.options.theme},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"windowSize",{get:function(){return"width="+this.options.windowWidth+", height="+this.options.windowHeight},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"title",{get:function(){return this.options.title},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"description",{get:function(){return this.options.description},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"image",{get:function(){return this.options.image},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"tags",{get:function(){return this.options.tags},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"gaTracking",{get:function(){return this.options.gaTracking},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"size",{get:function(){return this.options.size},enumerable:!0,configurable:!0}),t.prototype.registerButton=function(t,e){var r;this.prop=Object.assign({},d,((r={})[t]=e,r)),this.allButtons=Object.keys(this.prop)},t}();function f(t){return t&&"object"==typeof t&&!Array.isArray(t)}function b(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];if(!e.length)return t;var o,n,i=e.shift();if(f(t)&&f(i))for(var s in i)f(i[s])?(t[s]||Object.assign(t,((o={})[s]={},o)),b(t[s],i[s])):Object.assign(t,((n={})[s]=i[s],n));return b.apply(void 0,[t].concat(e))}m.decorators=[{type:e.Injectable}],m.ctorParameters=function(){return[{type:undefined,decorators:[{type:e.Inject,args:[a]}]}]};var g=function(){function t(t,r,o,n,i){this.shareService=t,this.http=r,this.renderer=o,this.cd=n,this.el=i,this.sbTitle=this.shareService.title,this.sbDescription=this.shareService.description,this.sbImage=this.shareService.image,this.sbTags=this.shareService.tags,this.sbCount=new e.EventEmitter,this.sbOpened=new e.EventEmitter,this.sbClosed=new e.EventEmitter,this.window=window||global}return Object.defineProperty(t.prototype,"setButton",{set:function(t){var e=Object.assign({},this.shareService.prop[t]);if(!e)throw new Error("[ShareButtons]: The share button '"+t+"' does not exist!");this.prop=e,this.renderer.removeClass(this.el.nativeElement,"sb-"+this.buttonClass),this.renderer.addClass(this.el.nativeElement,"sb-"+e.type),this.buttonClass=e.type,this.emitCount()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"sbUrl",{set:function(t){t!==this.url&&(this.url=this.getValidURL(t),this.emitCount())},enumerable:!0,configurable:!0}),t.prototype.onClick=function(){var t=this;this.url||(this.url=encodeURIComponent(this.window.location.href)),this.sbOpened.emit(this.prop.type);var e,r={url:this.url,cd:this.cd,renderer:this.renderer,window:this.window,prop:this.prop,el:this.el.nativeElement,os:this.shareService.os,metaTags:{title:this.sbTitle,description:this.sbDescription,image:this.sbImage,tags:this.sbTags,via:this.shareService.twitterAccount}};(e=s.of(r)).pipe.apply(e,this.prop.share.operators.concat([o.tap(function(e){return t.share(e)}),o.take(1)])).subscribe()},t.prototype.emitCount=function(){var t=this;this.url&&this.sbCount.observers.length&&this.prop.count&&this.count(this.url).subscribe(function(e){return t.sbCount.emit(e)})},t.prototype.share=function(t){var e,r=this;if(t&&(this.shareService.gaTracking&&"undefined"!=typeof ga&&ga("send","social",this.prop.type,"click",this.url),e=this.window.open(t,"newwindow",this.shareService.windowSize)),this.sbClosed.observers.length&&e)var o=this.window.setInterval(function(){e.closed&&(r.window.clearInterval(o),r.sbClosed.emit(r.prop.type))},200)},t.prototype.count=function(t){return"jsonp"===this.prop.count.request?(e=this.http.jsonp(this.prop.count.url+t,"callback")).pipe.apply(e,this.prop.count.operators.concat([o.catchError(function(){return i.empty()})])):(r=this.http.get(this.prop.count.url+t,this.prop.count.args)).pipe.apply(r,this.prop.count.operators.concat([o.catchError(function(){return i.empty()})]));var e,r},t.prototype.getValidURL=function(t){if(t){if(/(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/.test(t))return encodeURIComponent(t);console.warn("[ShareButtons]: Sharing link '"+t+"' is invalid!")}return encodeURIComponent(this.window.location.href)},t}();g.decorators=[{type:e.Directive,args:[{selector:"[shareButton]"}]}],g.ctorParameters=function(){return[{type:m},{type:n.HttpClient},{type:e.Renderer2},{type:e.ChangeDetectorRef},{type:e.ElementRef}]},g.propDecorators={sbTitle:[{type:e.Input}],sbDescription:[{type:e.Input}],sbImage:[{type:e.Input}],sbTags:[{type:e.Input}],setButton:[{type:e.Input,args:["shareButton"]}],sbUrl:[{type:e.Input}],sbCount:[{type:e.Output}],sbOpened:[{type:e.Output}],sbClosed:[{type:e.Output}],onClick:[{type:e.HostListener,args:["click"]}]};var y=function(){function t(){}return t.prototype.transform=function(t,e){return"number"!=typeof t&&(t=1),w(t,e)},t}();y.decorators=[{type:e.Pipe,args:[{name:"nFormatter"}]}],y.ctorParameters=function(){return[]};var w=function(t,e){for(var r=[{value:1e18,symbol:"E"},{value:1e15,symbol:"P"},{value:1e12,symbol:"T"},{value:1e9,symbol:"G"},{value:1e6,symbol:"M"},{value:1e3,symbol:"K"}],o=/\.0+$|(\.[0-9]*[1-9])0+$/,n=0;n<r.length;n++)if(t>=r[n].value)return(t/r[n].value).toFixed(e).replace(o,"$1")+r[n].symbol;return t.toFixed(e).replace(o,"$1")};function v(t){return new m(t)}var k=function(){function t(){}return t.forRoot=function(e){return{ngModule:t,providers:[{provide:a,useValue:e},{provide:m,useFactory:v,deps:[a]}]}},t}();k.decorators=[{type:e.NgModule,args:[{declarations:[g,y],imports:[r.CommonModule],exports:[r.CommonModule,g,y]}]}],k.ctorParameters=function(){return[]},t.ShareButtonsFactory=v,t.ShareModule=k,t.CONFIG=a,t.ShareButtons=m,t.ShareButtonDirective=g,t.NFormatterPipe=y,t.nFormatter=w,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=ngx-share-core.umd.min.js.map