62 lines
1.9 KiB
TypeScript
62 lines
1.9 KiB
TypeScript
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;
|
|
init: Function;
|
|
toolbox: Function;
|
|
}
|
|
|
|
interface Refresh {
|
|
refresh: Function;
|
|
}
|
|
|
|
declare var addthis: addthis;
|
|
|
|
@Component({
|
|
selector: 'addThis',
|
|
template: `
|
|
<div class="addthis_inline_share_toolbox_lcx9"></div>
|
|
`
|
|
})
|
|
export class AddThisComponent implements OnInit {
|
|
|
|
constructor(private route: ActivatedRoute, @Inject(DOCUMENT) private document, private rendererFactory: RendererFactory2) {}
|
|
|
|
ngOnInit() {
|
|
|
|
this.route.queryParams.subscribe(data => {
|
|
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('<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);
|
|
}
|
|
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)
|
|
}
|
|
|
|
});
|
|
}
|
|
}
|