2020-03-12 14:49:10 +01:00
|
|
|
import {Component, Input} from '@angular/core';
|
|
|
|
import {ActivatedRoute} from '@angular/router';
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
declare var loadAltmetrics:any;
|
|
|
|
//<altmetrics [id]="10.7717/peerj.1150" type="doi"></altmetrics>
|
|
|
|
@Component({
|
|
|
|
selector: 'altmetrics',
|
|
|
|
template: `
|
2023-01-23 15:19:00 +01:00
|
|
|
<div [innerHTML]="altmetrics | safeHtml"></div>
|
2017-12-19 13:53:46 +01:00
|
|
|
`
|
|
|
|
})
|
|
|
|
export class AltMetricsComponent {
|
2023-01-23 15:19:00 +01:00
|
|
|
@Input() id;
|
2017-12-19 13:53:46 +01:00
|
|
|
@Input() type = 'doi'; // doi or arxiv
|
2023-01-23 15:19:00 +01:00
|
|
|
@Input() size: string = 'donut';
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
// public doi="10.7717/peerj.1150";
|
|
|
|
public altmetrics:string;
|
|
|
|
private sub:any;
|
|
|
|
|
|
|
|
constructor(private route: ActivatedRoute) {
|
|
|
|
|
|
|
|
// if (typeof document !== 'undefined') {
|
|
|
|
// let yourModule = require('../utils/altmetrics.js');
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
ngOnInit() {
|
|
|
|
this.sub = this.route.queryParams.subscribe(data => {
|
|
|
|
if(this.type == "doi"){
|
2023-01-23 15:19:00 +01:00
|
|
|
this.altmetrics='<div data-badge-details="right" data-hide-no-mentions="true" data-link-target="_blank" data-badge-type="'+this.size+'" data-doi="'+this.id+'" class="altmetric-embed"> </div>';
|
2017-12-19 13:53:46 +01:00
|
|
|
}else{
|
2023-01-23 15:19:00 +01:00
|
|
|
this.altmetrics='<div data-badge-details="right" data-hide-no-mentions="true" data-link-target="_blank" data-badge-type="'+this.size+'" data-arxiv-id="'+this.id+'" class="altmetric-embed"> </div>';
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
if (typeof document !== 'undefined') {
|
|
|
|
// let yourModule = require('../utils/altmetrics.js');
|
|
|
|
loadAltmetrics("altmetric-embed-js","https://d1bxh8uas1mnw7.cloudfront.net/assets/altmetric_badges-8f271adb184c21cc5169a7f67f7fe5ab.js");
|
|
|
|
}
|
2020-03-12 14:49:10 +01:00
|
|
|
});
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-03-12 14:49:10 +01:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.sub.unsubscribe();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|