exercise.service.ts 1.36 KB
Newer Older
1
/* tslint:disable:no-string-literal */
2
3
import {Injectable} from '@angular/core';

4
5
6
7
8
9
10
11
12
13
declare var H5P: any;
// dirty hack to prevent H5P access errors after resize events
window.onresize = () => {
    /* tslint:disable:prefer-const */
    /* tslint:disable:no-shadowed-variable */
    let H5P: any;
    /* tslint:enable:prefer-const */
    /* tslint:enable:no-shadowed-variable */
};

14
15
16
17
18
@Injectable({
    providedIn: 'root'
})
export class ExerciseService {
    public excludeOOV = false;
19
    public fillBlanksString = 'fill_blanks';
20
    public h5pIframeString = '#h5p-iframe-1';
21
    public kwicGraphs: string;
22
    public vocListString = 'voc_list';
23

24
    constructor() {
25
26
27
28
29
30
31
32
33
34
35
36
    }

    createGuid() {
        function s4() {
            return Math.floor((1 + Math.random()) * 0x10000)
                .toString(16)
                .substring(1);
        }

        return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
            s4() + '-' + s4() + s4() + s4();
    }
37
38
39
40
41
42
43
44
45
46
47

    initH5P(exerciseTypePath: string) {
        // dirty hack to get H5P going without explicit button click on the new page
        setTimeout(() => {
            H5P.jQuery('.h5p-container').empty().h5p({
                frameJs: 'assets/dist/js/h5p-standalone-frame.min.js',
                frameCss: 'assets/dist/styles/h5p.css',
                h5pContent: 'assets/h5p/' + exerciseTypePath
            });
        }, 50);
    }
48
}