UNPKG

ng-intercom

Version:

[![npm](https://img.shields.io/npm/v/ng-intercom.svg)](https://www.npmjs.com/package/ng-intercom) [![npm](https://img.shields.io/npm/dm/ng-intercom.svg)](https://www.npmjs.com/ng-intercom) [![Build status][ci-image]][ci-url] [![Maintenance](https://img.sh

2 lines 7.75 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("rxjs/operators"),require("@angular/common"),require("@angular/router"),require("@angular/core")):"function"==typeof define&&define.amd?define("ng-intercom",["exports","rxjs/operators","@angular/common","@angular/router","@angular/core"],e):e(t["ng-intercom"]={},t.rxjs.operators,t.ng.common,t.ng.router,t.ng.core)}(this,function(t,c,s,a,u){"use strict";var i=function(){return(i=Object.assign||function(t){for(var e,r=1,o=arguments.length;r<o;r++)for(var n in e=arguments[r])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,arguments)};function n(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var o,n,i=r.call(t),c=[];try{for(;(void 0===e||0<e--)&&!(o=i.next()).done;)c.push(o.value)}catch(s){n={error:s}}finally{try{o&&!o.done&&(r=i["return"])&&r.call(i)}finally{if(n)throw n.error}}return c}var r=function(){function t(){}return t.decorators=[{type:u.Injectable}],t}(),o=function(){function t(t,e,r,o,n){var i=this;this.config=t,this.platformId=e,this.router=r,this.rendererFactory=o,this.document=n,s.isPlatformBrowser(this.platformId)&&(this.renderer2=this.rendererFactory.createRenderer(this.document,{id:"-1",encapsulation:u.ViewEncapsulation.None,styles:[],data:{}}),t&&t.updateOnRouterChange?this.router.events.pipe(c.filter(function(t){return t instanceof a.NavigationEnd})).subscribe(function(t){i.update()}):u.isDevMode()&&console.warn("\n Common practice in single page applications is to update whenever the route changes.\n ng-intercom supports this functionality out of the box just set 'updateOnRouterChange' to true in your Intercom Module config.\n This warning will not appear in production, if you choose not to use router updating.\n "))}return t.prototype.boot=function(r){var o=this;if(s.isPlatformBrowser(this.platformId)){var n=r.app_id?r.app_id:this.config.appId;this.loadIntercom(this.config,function(t){var e=i({},r,{app_id:n});return o._callIntercom("boot",e)})}},t.prototype.shutdown=function(){return this._callIntercom("shutdown")},t.prototype.update=function(t){return this._callIntercom("update",t)},t.prototype.hide=function(){return this._callIntercom("hide")},t.prototype.show=function(t){return t?this.showNewMessage(t):this._callIntercom("show")},t.prototype.showMessages=function(){return this._callIntercom("showMessages")},t.prototype.showNewMessage=function(t){return this._callIntercom("showNewMessage",t)},t.prototype.trackEvent=function(t,e){return this._callIntercom("trackEvent",t,e)},t.prototype.getVisitorId=function(){return this._callIntercom("getVisitorId")},Object.defineProperty(t.prototype,"visitorId",{get:function(){return this._callIntercom("getVisitorId")},enumerable:!0,configurable:!0}),t.prototype.onShow=function(t){return this._callIntercom("onShow",t)},t.prototype.onHide=function(t){return this._callIntercom("onHide",t)},t.prototype.onUnreadCountChange=function(t){return this._callIntercom("onUnreadCountChange",t)},t.prototype.startTour=function(t){return this._callIntercom("startTour",t)},t.prototype._callIntercom=function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];if(s.isPlatformBrowser(this.platformId))return window.Intercom?window.Intercom.apply(window,function o(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(n(arguments[e]));return t}([t],e)):void 0},t.prototype.injectIntercomScript=function(t,e){if(s.isPlatformBrowser(this.platformId)){window.intercomSettings=t;var r=this.document.createElement("script");r.type="text/javascript",r.async=!0,r.src="https://widget.intercom.io/widget/"+this.id,r.attachEvent?r.attachEvent("onload",e):r.addEventListener("load",e,!1),this.renderer2&&this.renderer2.appendChild&&this.renderer2.appendChild(this.document.head,r),window.Intercom("update",t)}},t.prototype.loadIntercom=function(t,e){if(s.isPlatformBrowser(this.platformId)){this.id=t.appId;var r=window,o=r.Intercom;if(r.intercomSettings=t,"function"==typeof o)o("reattach_activator"),o("update",t),e();else{var n=function(){n.c(arguments)};n.q=[],n.c=function(t){n.q.push(t)},r.Intercom=n,this.injectIntercomScript(t,e)}}},t.decorators=[{type:u.Injectable}],t.ctorParameters=function(){return[{type:r,decorators:[{type:u.Inject,args:[r]}]},{type:Object,decorators:[{type:u.Inject,args:[u.PLATFORM_ID]}]},{type:a.Router,decorators:[{type:u.Optional},{type:u.Inject,args:[a.Router]}]},{type:u.RendererFactory2},{type:undefined,decorators:[{type:u.Optional},{type:u.Inject,args:[s.DOCUMENT]}]}]},t}(),p=function(){function t(t){this.intercom=t}return t.prototype.onClick=function(){!1!==this.intercomHide&&this.intercom.hide()},t.decorators=[{type:u.Directive,args:[{selector:"[intercomHide]"}]}],t.ctorParameters=function(){return[{type:o}]},t.propDecorators={intercomHide:[{type:u.Input}],onClick:[{type:u.HostListener,args:["click"]}]},t}(),h=function(){function t(t){this.intercom=t}return t.prototype.onClick=function(){!1!==this.intercomShowMessages&&this.intercom.showMessages()},t.decorators=[{type:u.Directive,args:[{selector:"[intercomShowMessages]"}]}],t.ctorParameters=function(){return[{type:o}]},t.propDecorators={intercomShowMessages:[{type:u.Input}],onClick:[{type:u.HostListener,args:["click"]}]},t}(),l=function(){function t(t){this.intercom=t}return t.prototype.onClick=function(){(this.message?this.message:this.intercomShowNewMessage)?this.intercom.showNewMessage(this.message):this.intercom.showNewMessage()},t.decorators=[{type:u.Directive,args:[{selector:"[intercomShowNewMessage]"}]}],t.ctorParameters=function(){return[{type:o}]},t.propDecorators={message:[{type:u.Input}],intercomShowNewMessage:[{type:u.Input}],onClick:[{type:u.HostListener,args:["click"]}]},t}(),m=function(){function t(t){this.intercom=t}return t.prototype.onClick=function(){(this.message?this.message:this.intercomShow)?this.intercom.showNewMessage(this.message):this.intercom.show()},t.decorators=[{type:u.Directive,args:[{selector:"[intercomShow]"}]}],t.ctorParameters=function(){return[{type:o}]},t.propDecorators={message:[{type:u.Input}],intercomShow:[{type:u.Input}],onClick:[{type:u.HostListener,args:["click"]}]},t}(),d=function(){function t(t){this.intercom=t}return t.prototype.onClick=function(){!1!==this.intercomShutdown&&this.intercom.shutdown()},t.decorators=[{type:u.Directive,args:[{selector:"[intercomShutdown]"}]}],t.ctorParameters=function(){return[{type:o}]},t.propDecorators={intercomShutdown:[{type:u.Input}],onClick:[{type:u.HostListener,args:["click"]}]},t}(),f=function(){function t(t){this.intercom=t}return t.prototype.onClick=function(){var t=this.event?this.event:this.intercomTrackEvent;if(t&&this.metadata)this.intercom.trackEvent(t,this.metadata);else{if(!t||this.metadata)throw new Error("Error in intercomTrackEvent directive: You must specify an event to track.");this.intercom.trackEvent(t)}},t.decorators=[{type:u.Directive,args:[{selector:"[intercomTrackEvent]"}]}],t.ctorParameters=function(){return[{type:o}]},t.propDecorators={event:[{type:u.Input}],intercomTrackEvent:[{type:u.Input}],metadata:[{type:u.Input}],onClick:[{type:u.HostListener,args:["click"]}]},t}(),e=function(){function e(){}return e.forRoot=function(t){return{ngModule:e,providers:[o,{provide:r,useValue:t}]}},e.decorators=[{type:u.NgModule,args:[{imports:[a.RouterModule],declarations:[p,h,l,m,d,f],exports:[p,h,l,m,d,f],providers:[o,r]}]}],e}();t.Intercom=o,t.IntercomConfig=r,t.IntercomHideDirective=p,t.IntercomModule=e,t.IntercomShowDirective=m,t.IntercomShowMessagesDirective=h,t.IntercomShowNewMessageDirective=l,t.IntercomShutdownDirective=d,t.IntercomTrackEventDirective=f,Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=ng-intercom.umd.min.js.map