forked from akveo/nebular
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathakveo-services-banner.component.ts
55 lines (47 loc) · 1.69 KB
/
akveo-services-banner.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { Component, ElementRef, Inject, Input, OnInit, ViewChild } from '@angular/core';
import { NB_DOCUMENT, NB_WINDOW } from '@commudle/theme';
@Component({
selector: 'ngd-akveo-services-banner',
template: `
<span #wrapper class="hs-cta-wrapper" id="hs-cta-wrapper-{{ ctaId }}">
<span class="hs-cta-node hs-cta-{{ ctaId }}" id="hs-cta-{{ ctaId }}">
<a href="https://cta-redirect.hubspot.com/cta/redirect/2452262/{{ ctaId }}" target="_blank">
<img
class="hs-cta-img"
id="hs-cta-img-{{ ctaId }}"
[height]="height"
[width]="width"
src="https://no-cache.hubspot.com/cta/default/2452262/{{ ctaId }}.png"
alt="Services on Angular"
/>
</a>
</span>
</span>
`,
styleUrls: ['akveo-services-banner.component.scss'],
})
export class AkveoServicesBanner implements OnInit {
@Input() ctaId: string;
@Input() width: string;
@Input() height: string;
@ViewChild('wrapper', { static: true }) wrapper: ElementRef;
constructor(private host: ElementRef, @Inject(NB_DOCUMENT) private document, @Inject(NB_WINDOW) private window) {}
ngOnInit() {
if (this.window?.hbspt?.cta?.load) {
this.loadCta();
} else {
this.loadHubSpotCtaScript();
}
}
private loadCta() {
this.window.hbspt.cta.load(2452262, this.ctaId, {});
}
private loadHubSpotCtaScript() {
this.wrapper.nativeElement.appendChild(
this.document
.createRange()
.createContextualFragment(`<script type="text/javascript" src="https://js.hscta.net/cta/current.js"></script>`),
);
this.wrapper.nativeElement.querySelector('script').onload = this.loadCta.bind(this);
}
}