2022-05-17 11:15:15 +02:00
|
|
|
import {
|
|
|
|
Component,
|
2023-02-17 18:40:05 +01:00
|
|
|
Inject, Input,
|
2022-05-17 11:15:15 +02:00
|
|
|
OnInit,
|
|
|
|
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";
|
2022-05-06 16:00:52 +02:00
|
|
|
import {Subscriber} from "rxjs";
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2023-07-04 18:12:34 +02:00
|
|
|
declare var a2a;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'addThis',
|
|
|
|
template: `
|
2023-07-04 18:12:34 +02:00
|
|
|
<div [id]="'addToAny'+(url ? ('_'+url) : '')" #addToAny class="a2a_kit a2a_kit_size_42 a2a_default_style fully_rounded" [attr.data-a2a-url]="url">
|
|
|
|
<a class="a2a_button_twitter"></a>
|
|
|
|
<a class="a2a_button_facebook"></a>
|
|
|
|
<a class="a2a_button_linkedin"></a>
|
|
|
|
<a class="a2a_button_mendeley"></a>
|
|
|
|
<a class="a2a_button_reddit"></a>
|
|
|
|
<a class="a2a_button_email"></a>
|
|
|
|
<a class="a2a_dd" href="https://www.addtoany.com/share"></a>
|
|
|
|
</div>
|
2023-02-17 18:40:05 +01:00
|
|
|
<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 {
|
2023-02-17 18:40:05 +01:00
|
|
|
subs = [];
|
2022-05-06 16:00:52 +02:00
|
|
|
showWarning = false;
|
2023-02-17 18:40:05 +01:00
|
|
|
@Input() url: string = null;
|
2023-07-04 18:12:34 +02:00
|
|
|
|
2023-02-17 18:40:05 +01:00
|
|
|
constructor(private route: ActivatedRoute, @Inject(DOCUMENT) private document, private rendererFactory: RendererFactory2) {
|
|
|
|
}
|
|
|
|
|
2022-05-06 16:00:52 +02:00
|
|
|
public ngOnDestroy() {
|
2023-02-17 18:40:05 +01:00
|
|
|
for (let value of this.subs) {
|
2022-05-06 16:00:52 +02:00
|
|
|
if (value instanceof Subscriber) {
|
|
|
|
value.unsubscribe();
|
|
|
|
} else if (value instanceof Function) {
|
|
|
|
value();
|
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
}
|
2023-07-04 18:12:34 +02:00
|
|
|
//
|
|
|
|
// if(typeof document !== 'undefined') {
|
|
|
|
// 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.');
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// let script = null;
|
|
|
|
// head.childNodes.forEach(node => {
|
|
|
|
// if(node.id === "addToAnyScript") {
|
|
|
|
// // script = node;
|
|
|
|
// node.remove();
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
// // let script = head.nativeElement.getElementById("script");
|
|
|
|
// // if(script) {
|
|
|
|
// // renderer.removeChild(head, script);
|
|
|
|
// // script.remove();
|
|
|
|
// // }
|
|
|
|
// }
|
2020-11-11 15:43:13 +01:00
|
|
|
}
|
2023-07-04 18:12:34 +02:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
ngOnInit() {
|
2023-07-04 18:12:34 +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 {
|
2023-07-04 18:12:34 +02:00
|
|
|
if (!this.document.getElementById('addToAnyScript') && typeof document !== 'undefined') {
|
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');
|
2023-07-04 18:12:34 +02:00
|
|
|
renderer.setAttribute(script, "id", "addToAnyScript");
|
|
|
|
renderer.setAttribute(script, "src", "https://static.addtoany.com/menu/page.js");
|
2020-05-26 12:16:03 +02:00
|
|
|
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') {
|
2023-07-04 18:12:34 +02:00
|
|
|
if(typeof a2a !== 'undefined' && this.document.getElementById('addToAny'+(this.url ? ('_'+this.url) : '')) && !this.document.getElementById('addToAny'+(this.url ? ('_'+this.url) : '')).innerText) {
|
|
|
|
a2a.init_all();
|
2020-05-26 12:16:03 +02:00
|
|
|
}
|
|
|
|
}
|
2022-05-06 16:00:52 +02:00
|
|
|
this.subs.push(setTimeout(() => {
|
2023-07-04 18:12:34 +02:00
|
|
|
if (this.document.getElementById('addToAny'+(this.url ? ('_'+this.url) : '')) && !this.document.getElementById('addToAny'+(this.url ? ('_'+this.url) : '')).innerText) {
|
2022-05-06 16:00:52 +02:00
|
|
|
this.showWarning = true;
|
|
|
|
}
|
2022-05-17 11:15:15 +02:00
|
|
|
}, 4000));
|
2023-02-17 18:40:05 +01:00
|
|
|
} catch (e) {
|
|
|
|
// console.error(e)
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2023-07-04 18:12:34 +02:00
|
|
|
|
2022-05-06 16:00:52 +02:00
|
|
|
}));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|