2020-05-26 12:16:03 +02:00
|
|
|
import {Component, EventEmitter, Inject, OnInit, Output, RendererFactory2, ViewEncapsulation} from '@angular/core';
|
2017-12-19 13:53:46 +01:00
|
|
|
import {ActivatedRoute} from '@angular/router';
|
2020-05-26 12:16:03 +02:00
|
|
|
import {DOCUMENT} from "@angular/common";
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2020-03-16 14:09:46 +01:00
|
|
|
interface addthis {
|
|
|
|
layers: Refresh;
|
|
|
|
init: Function;
|
|
|
|
toolbox: Function;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Refresh {
|
|
|
|
refresh: Function;
|
|
|
|
}
|
|
|
|
|
|
|
|
declare var addthis: addthis;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'addThis',
|
|
|
|
template: `
|
2020-05-26 12:16:03 +02:00
|
|
|
<div class="addthis_inline_share_toolbox_lcx9"></div>
|
2017-12-19 13:53:46 +01:00
|
|
|
`
|
|
|
|
})
|
2020-03-16 14:09:46 +01:00
|
|
|
export class AddThisComponent implements OnInit {
|
2020-11-11 15:43:13 +01:00
|
|
|
sub;
|
2020-05-26 12:16:03 +02:00
|
|
|
constructor(private route: ActivatedRoute, @Inject(DOCUMENT) private document, private rendererFactory: RendererFactory2) {}
|
2020-11-11 15:43:13 +01:00
|
|
|
ngOnDestroy() {
|
|
|
|
if(this.sub) {
|
|
|
|
this.sub.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
ngOnInit() {
|
2020-05-26 12:16:03 +02:00
|
|
|
|
2020-11-11 15:43:13 +01:00
|
|
|
this.sub = this.route.queryParams.subscribe(data => {
|
2020-05-26 12:16:03 +02:00
|
|
|
try {
|
|
|
|
if (!this.document.getElementById('addThisScript') && typeof document !== 'undefined') {
|
2020-06-01 11:02:16 +02:00
|
|
|
// console.log(" create script AddThis");
|
2020-05-26 12:16:03 +02:00
|
|
|
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('<head> 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);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-05-26 12:16:03 +02:00
|
|
|
if (typeof document !== 'undefined') {
|
|
|
|
if(typeof addthis !== 'undefined' && addthis.layers && addthis.layers.refresh) {
|
|
|
|
// console.log("Add This: Call Refresh")
|
|
|
|
addthis.layers.refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}catch (e) {
|
2020-08-17 10:51:46 +02:00
|
|
|
// console.error(e)
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-05-26 12:16:03 +02:00
|
|
|
|
2020-03-16 14:09:46 +01:00
|
|
|
});
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|