2022-05-17 11:15:15 +02:00
|
|
|
import {
|
|
|
|
ChangeDetectorRef,
|
|
|
|
Component,
|
|
|
|
EventEmitter,
|
|
|
|
Inject,
|
|
|
|
OnInit,
|
|
|
|
Output,
|
|
|
|
RendererFactory2,
|
|
|
|
ViewChild,
|
|
|
|
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";
|
2022-05-06 16:00:52 +02:00
|
|
|
import {Subscriber} from "rxjs";
|
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: `
|
2022-05-06 16:00:52 +02:00
|
|
|
<div id="addThis" class="addthis_inline_share_toolbox_lcx9_8cfy"></div>
|
|
|
|
<div *ngIf="showWarning" class="uk-alert uk-alert-warning uk-animation-fade" >
|
|
|
|
Do the share buttons not appear? Please make sure, any blocking addon is disabled, and then reload the page.
|
|
|
|
</div>
|
2017-12-19 13:53:46 +01:00
|
|
|
`
|
|
|
|
})
|
2020-03-16 14:09:46 +01:00
|
|
|
export class AddThisComponent implements OnInit {
|
2022-05-06 16:00:52 +02:00
|
|
|
subs=[];
|
|
|
|
showWarning = false;
|
2020-05-26 12:16:03 +02:00
|
|
|
constructor(private route: ActivatedRoute, @Inject(DOCUMENT) private document, private rendererFactory: RendererFactory2) {}
|
2022-05-06 16:00:52 +02:00
|
|
|
public ngOnDestroy() {
|
|
|
|
for(let value of this.subs){
|
|
|
|
if (value instanceof Subscriber) {
|
|
|
|
value.unsubscribe();
|
|
|
|
} else if (value instanceof Function) {
|
|
|
|
value();
|
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
}
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
ngOnInit() {
|
2020-05-26 12:16:03 +02:00
|
|
|
|
2022-05-06 16:00:52 +02:00
|
|
|
this.subs.push(this.route.queryParams.subscribe(data => {
|
|
|
|
this.showWarning = false;
|
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();
|
|
|
|
}
|
|
|
|
}
|
2022-05-06 16:00:52 +02:00
|
|
|
this.subs.push(setTimeout(() => {
|
2022-05-18 11:31:46 +02:00
|
|
|
if(this.document.getElementById('addThis') && !this.document.getElementById('addThis').innerText){
|
2022-05-06 16:00:52 +02:00
|
|
|
this.showWarning = true;
|
|
|
|
}
|
2022-05-17 11:15:15 +02:00
|
|
|
}, 4000));
|
2020-05-26 12:16:03 +02:00
|
|
|
}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
|
|
|
|
2022-05-06 16:00:52 +02:00
|
|
|
}));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|