UNPKG

ng2-awesome-disqus

Version:
110 lines 4.37 kB
import { Component, Input, Output, ChangeDetectionStrategy, Renderer2, ElementRef, EventEmitter } from '@angular/core'; import { DisqusService } from './disqus.service'; var DisqusComponent = (function () { function DisqusComponent(renderer, el, dService) { this.renderer = renderer; this.el = el; this.dService = dService; /** Track Comments */ this.comment = new EventEmitter(); } DisqusComponent.prototype.ngOnChanges = function (changes) { if (!this.dService.disqus) { this.addDisqusScript(); } else { var idChange = changes['identifier']; var urlChange = changes['url']; var catChange = changes['categoryId']; var titleChange = changes['title']; var langChange = changes['language']; var isResetNeeded = false; if (idChange && idChange.currentValue !== idChange.previousValue) { isResetNeeded = true; } if (urlChange && urlChange.currentValue !== urlChange.previousValue) { isResetNeeded = true; } if (catChange && catChange.currentValue !== catChange.previousValue) { isResetNeeded = true; } if (titleChange && titleChange.currentValue !== titleChange.previousValue) { isResetNeeded = true; } if (langChange && langChange.currentValue !== langChange.previousValue) { isResetNeeded = true; } if (isResetNeeded) { this.reset(); } } }; DisqusComponent.prototype.addDisqusScript = function () { /** Set disqus config */ this.dService.disqusConfig = this.getConfig(); /** Add DISQUS script */ var disqusScript = this.renderer.createElement('script'); disqusScript.src = "//" + this.shortname + ".disqus.com/embed.js"; disqusScript.async = true; disqusScript.type = 'text/javascript'; this.renderer.setAttribute(disqusScript, 'data-timestamp', new Date().getTime().toString()); this.renderer.appendChild(this.el.nativeElement, disqusScript); }; /** Reset disqus with new inputs. */ DisqusComponent.prototype.reset = function () { this.dService.disqus.reset({ reload: true, config: this.getConfig() }); }; /** Get disqus settings from inputs */ DisqusComponent.prototype.getConfig = function () { var self = this; return function () { this.page.identifier = self.identifier; this.page.url = self.dService.validateUrl(self.url); this.page.title = self.title; this.category_id = self.categoryId; this.language = self.language; /* Available callbacks are afterRender, onInit, onNewComment, onPaginate, onReady, preData, preInit, preReset */ this.callbacks.onNewComment = [function (comment) { self.comment.emit(comment); }]; }; }; DisqusComponent.prototype.ngOnDestroy = function () { if (this.dService.window) { this.dService.window.DISQUS = undefined; this.dService.window.disqusConfig = undefined; } else { global.DISQUS = undefined; global.disqusConfig = undefined; } }; return DisqusComponent; }()); export { DisqusComponent }; DisqusComponent.decorators = [ { type: Component, args: [{ selector: 'disqus', template: '<div id="disqus_thread"></div>', changeDetection: ChangeDetectionStrategy.OnPush },] }, ]; /** @nocollapse */ DisqusComponent.ctorParameters = function () { return [ { type: Renderer2, }, { type: ElementRef, }, { type: DisqusService, }, ]; }; DisqusComponent.propDecorators = { 'shortname': [{ type: Input },], 'identifier': [{ type: Input },], 'url': [{ type: Input },], 'categoryId': [{ type: Input },], 'language': [{ type: Input },], 'title': [{ type: Input },], 'comment': [{ type: Output },], }; //# sourceMappingURL=disqus.component.js.map