diff --git a/landingPages/landing-utils/addThis.component.ts b/landingPages/landing-utils/addThis.component.ts index 4bfeaad0..59679c36 100644 --- a/landingPages/landing-utils/addThis.component.ts +++ b/landingPages/landing-utils/addThis.component.ts @@ -1,15 +1,6 @@ -import { - AfterContentInit, - AfterViewInit, - Component, - ElementRef, - EventEmitter, - Input, - OnInit, - Output, - ViewChild -} from '@angular/core'; +import {Component, EventEmitter, Inject, OnInit, Output, RendererFactory2, ViewEncapsulation} from '@angular/core'; import {ActivatedRoute} from '@angular/router'; +import {DOCUMENT} from "@angular/common"; interface addthis { layers: Refresh; @@ -26,25 +17,45 @@ declare var addthis: addthis; @Component({ selector: 'addThis', template: ` -

+
` }) export class AddThisComponent implements OnInit { - @Output() event: EventEmitter = new EventEmitter(); - - constructor(private route: ActivatedRoute) {} + + constructor(private route: ActivatedRoute, @Inject(DOCUMENT) private document, private rendererFactory: RendererFactory2) {} ngOnInit() { + this.route.queryParams.subscribe(data => { - if (typeof document !== 'undefined' && typeof addthis !== 'undefined') { - if(addthis.layers && addthis.layers.refresh) { - addthis.layers.refresh(); - } else { - this.event.emit(false); + try { + if (!this.document.getElementById('addThisScript') && typeof document !== 'undefined') { + console.log(" create script AddThis") + const renderer = this.rendererFactory.createRenderer(this.document, { + id: '-1', + encapsulation: ViewEncapsulation.None, + styles: [], + data: {} + }); + const head = this.document.body; + if (head === null) { + throw new Error(' not found within DOCUMENT.'); + } + const script = renderer.createElement('script'); + renderer.setAttribute(script, "id", "addThisScript"); + renderer.setAttribute(script, "src", "https://s7.addthis.com/js/300/addthis_widget.js#pubid=ra-559d24521cd8c080"); + renderer.setAttribute(script, "type", "text/javascript"); + renderer.appendChild(head, script); } - } else { - this.event.emit(false); + if (typeof document !== 'undefined') { + if(typeof addthis !== 'undefined' && addthis.layers && addthis.layers.refresh) { + // console.log("Add This: Call Refresh") + addthis.layers.refresh(); + } + } + }catch (e) { + console.error(e) } + }); } } diff --git a/landingPages/landing-utils/citeThis/citeThis.component.ts b/landingPages/landing-utils/citeThis/citeThis.component.ts index a8933c68..071da55f 100644 --- a/landingPages/landing-utils/citeThis/citeThis.component.ts +++ b/landingPages/landing-utils/citeThis/citeThis.component.ts @@ -1,13 +1,23 @@ -import {Component, ElementRef, Input, OnDestroy, OnInit} from '@angular/core'; +import { + Component, + ElementRef, + Inject, + Input, + OnDestroy, + OnInit, + RendererFactory2, + ViewEncapsulation +} from '@angular/core'; import {ActivatedRoute} from '@angular/router'; import {Citation, CitationData} from './citation.class'; import {ResultLandingInfo} from "../../../utils/entities/resultLandingInfo"; +import {DOCUMENT} from "@angular/common"; declare var CSL: any; declare var Sys: any; declare var UIkit: any; -// +// @Component({ selector: 'citeThis', template: ` @@ -23,7 +33,7 @@ declare var UIkit: any;
-
+