Newer
Older
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
import { Injectable, Renderer2 } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
import { APIService } from 'common/shared.module';
@Injectable({
providedIn: 'root'
})
export class ExternalResourceService {
geoGebraInitStarted = false;
isGeoGebraScriptInitialized = new BehaviorSubject<boolean>(this.geoGebraInitStarted);
resourceUrl: string;
constructor(private apiService: APIService) {
this.resourceUrl = apiService.getResourceURL();
}
initializeGeoGebra(renderer: Renderer2): void {
if (!this.geoGebraInitStarted) {
this.geoGebraInitStarted = true;
console.log('Initializing geogebra scripts');
const script = renderer.createElement('script');
script.type = 'text/javascript';
script.src = `${this.resourceUrl}/GeoGebra/GeoGebra/deployggb.js`;
script.onload = () => {
this.isGeoGebraScriptInitialized.next(true);
};
renderer.appendChild(document.head, script);
}
}
isGeoGebraLoaded(): Observable<boolean> {
return this.isGeoGebraScriptInitialized as Observable<boolean>;
}
getGeoGebraHTML5URL(): string {
return `${this.resourceUrl}/GeoGebra/GeoGebra/HTML5/5.0/web3d/`;
}
}