exercise.page.ts 1.82 KB
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 39 40 41 42 43 44 45 46 47 48 49 50
/* tslint:disable:no-string-literal */
import {Component, OnInit} from '@angular/core';
import {HelperService} from '../helper.service';
import {NavController} from '@ionic/angular';
import {ActivatedRoute} from '@angular/router';
import {TranslateService} from '@ngx-translate/core';

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 */
};

@Component({
    selector: 'app-exercise',
    templateUrl: './exercise.page.html',
    styleUrls: ['./exercise.page.scss'],
})
export class ExercisePage implements OnInit {

    HelperService = HelperService;

    constructor(public navCtrl: NavController,
                public activatedRoute: ActivatedRoute,
                public translateService: TranslateService) {
        this.activatedRoute.queryParams.subscribe((params: object) => {
            const exerciseType: string = params['type'];
            const file: string = params['file'];
            const lang: string = this.translateService.currentLang;
            window.localStorage.setItem(HelperService.config['localStorageKeyH5P'],
                HelperService.baseUrl + '/assets/h5p/' + exerciseType + '/content/' + file + '_' + lang + '.json');
            // 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/' + exerciseType
                });
            }, 50);
        });
    }

    ngOnInit() {
    }

}