1
|
import {Component, EventEmitter, Inject, OnInit, Output, RendererFactory2, ViewEncapsulation} from '@angular/core';
|
2
|
import {ActivatedRoute} from '@angular/router';
|
3
|
import {DOCUMENT} from "@angular/common";
|
4
|
|
5
|
interface addthis {
|
6
|
layers: Refresh;
|
7
|
init: Function;
|
8
|
toolbox: Function;
|
9
|
}
|
10
|
|
11
|
interface Refresh {
|
12
|
refresh: Function;
|
13
|
}
|
14
|
|
15
|
declare var addthis: addthis;
|
16
|
|
17
|
@Component({
|
18
|
selector: 'addThis',
|
19
|
template: `
|
20
|
<div class="addthis_inline_share_toolbox_lcx9"></div>
|
21
|
`
|
22
|
})
|
23
|
export class AddThisComponent implements OnInit {
|
24
|
sub;
|
25
|
constructor(private route: ActivatedRoute, @Inject(DOCUMENT) private document, private rendererFactory: RendererFactory2) {}
|
26
|
ngOnDestroy() {
|
27
|
if(this.sub) {
|
28
|
this.sub.unsubscribe();
|
29
|
}
|
30
|
}
|
31
|
ngOnInit() {
|
32
|
|
33
|
this.sub = this.route.queryParams.subscribe(data => {
|
34
|
try {
|
35
|
if (!this.document.getElementById('addThisScript') && typeof document !== 'undefined') {
|
36
|
// console.log(" create script AddThis");
|
37
|
const renderer = this.rendererFactory.createRenderer(this.document, {
|
38
|
id: '-1',
|
39
|
encapsulation: ViewEncapsulation.None,
|
40
|
styles: [],
|
41
|
data: {}
|
42
|
});
|
43
|
const head = this.document.body;
|
44
|
if (head === null) {
|
45
|
throw new Error('<head> not found within DOCUMENT.');
|
46
|
}
|
47
|
const script = renderer.createElement('script');
|
48
|
renderer.setAttribute(script, "id", "addThisScript");
|
49
|
renderer.setAttribute(script, "src", "https://s7.addthis.com/js/300/addthis_widget.js#pubid=ra-559d24521cd8c080");
|
50
|
renderer.setAttribute(script, "type", "text/javascript");
|
51
|
renderer.appendChild(head, script);
|
52
|
}
|
53
|
if (typeof document !== 'undefined') {
|
54
|
if(typeof addthis !== 'undefined' && addthis.layers && addthis.layers.refresh) {
|
55
|
// console.log("Add This: Call Refresh")
|
56
|
addthis.layers.refresh();
|
57
|
}
|
58
|
}
|
59
|
}catch (e) {
|
60
|
// console.error(e)
|
61
|
}
|
62
|
|
63
|
});
|
64
|
}
|
65
|
}
|