Project

General

Profile

1
import {Component, ElementRef, Input} from '@angular/core';
2
 import {SafeHtmlPipe} from '../utils/pipes/safeHTML.pipe';
3
 import {ActivatedRoute} from '@angular/router';
4
declare var loadAltmetrics:any;
5
//<altmetrics [id]="10.7717/peerj.1150" type="doi"></altmetrics>
6
@Component({
7
  selector: 'altmetrics',
8
  template: `
9
   <div [innerHTML]="altmetrics | safeHtml"></div>
10
  `
11
})
12
export class AltMetricsComponent {
13
  @Input() id ;
14
  @Input() type = 'doi'; // doi or arxiv
15

    
16
  // public doi="10.7717/peerj.1150";
17
  public altmetrics:string;
18
  private sub:any;
19

    
20
  constructor(private route: ActivatedRoute) {
21

    
22
    // if (typeof document !== 'undefined') {
23
    //    let yourModule = require('../utils/altmetrics.js');
24
    //  }
25
  }
26
  ngOnInit() {
27
    this.sub =  this.route.queryParams.subscribe(data => {
28
      if(this.type == "doi"){
29
        this.altmetrics='<div data-badge-popover="right" data-hide-no-mentions="true" data-badge-type="donut" data-doi="'+this.id+'" class="altmetric-embed uk-text-center"> </div>';
30
      }else{
31
        this.altmetrics='<div data-badge-popover="right" data-hide-no-mentions="true" data-badge-type="donut" data-arxiv-id="'+this.id+'" class="altmetric-embed uk-text-center"> </div>';
32
      }
33
      if (typeof document !== 'undefined') {
34
      //   let yourModule = require('../utils/altmetrics.js');
35
        loadAltmetrics("altmetric-embed-js","https://d1bxh8uas1mnw7.cloudfront.net/assets/altmetric_badges-8f271adb184c21cc5169a7f67f7fe5ab.js");
36
      }
37
  });
38
  }
39
  ngOnDestroy() {
40
    this.sub.unsubscribe();
41
  }
42

    
43
}
(1-1/15)