mirror of
https://github.com/sensebox/blockly-app
synced 2025-06-09 03:05:51 +02:00
apply language to blockly iframe
This commit is contained in:
parent
fc8d75aa3a
commit
9231b6920e
4 changed files with 21 additions and 9 deletions
|
@ -27,12 +27,10 @@ export class openSenseApp {
|
|||
statusBar: StatusBar,
|
||||
splashScreen: SplashScreen,
|
||||
) {
|
||||
platform.ready()
|
||||
.then(() => {
|
||||
this.translate.setDefaultLang(DEFAULT_LANG)
|
||||
this.translate.use(this.translate.getBrowserLang()) // @TODO: check if this works on all platforms!
|
||||
// @TODO: also pass language to blockly (if possible?)
|
||||
|
||||
platform.ready()
|
||||
.then(() => {
|
||||
if ((<any>window).cordova) {
|
||||
statusBar.overlaysWebView(false)
|
||||
statusBar.backgroundColorByHexString(COLORS.PRIMARY)
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 171d2d909fde5b95c3b1b6af490d872d1b03fe52
|
||||
Subproject commit c43a8244e72996457ce832317bb463787645caae
|
|
@ -38,5 +38,5 @@
|
|||
</button>
|
||||
</ion-fab>
|
||||
|
||||
<iframe #blocklyFrame scrolling="no" src='assets/blockly.html'></iframe>
|
||||
<iframe #blocklyFrame scrolling="no" [src]="blocklyUrl"></iframe>
|
||||
</ion-content>
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
import { Component, ViewChild, ElementRef } from '@angular/core';
|
||||
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
|
||||
import { IonicPage, NavController, NavParams } from 'ionic-angular';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
|
||||
import { OtaWizardPage } from '../ota-wizard/ota-wizard';
|
||||
|
||||
@IonicPage()
|
||||
|
@ -9,13 +12,18 @@ import { OtaWizardPage } from '../ota-wizard/ota-wizard';
|
|||
})
|
||||
export class BlocklyPage {
|
||||
@ViewChild('blocklyFrame') blocklyFrame: ElementRef
|
||||
blocklyUrl: SafeResourceUrl
|
||||
|
||||
messageHandler: (ev: IframePostMessageEvent) => void
|
||||
private messageHandler: (ev: IframePostMessageEvent) => void
|
||||
|
||||
constructor(
|
||||
public navCtrl: NavController,
|
||||
public navParams: NavParams,
|
||||
private sanitizer: DomSanitizer,
|
||||
translate: TranslateService,
|
||||
) {
|
||||
this.blocklyUrl = this.buildBlocklyUrl(translate.currentLang)
|
||||
|
||||
// need to assign it here to keep the function reference for unsubscribing again
|
||||
// and to maintain the this scope properly
|
||||
this.messageHandler = (ev: IframePostMessageEvent) => {
|
||||
|
@ -42,6 +50,12 @@ export class BlocklyPage {
|
|||
toggleView () {
|
||||
this.blocklyFrame.nativeElement.contentWindow.postMessage('toggleView', '*')
|
||||
}
|
||||
|
||||
buildBlocklyUrl (lang: string): SafeResourceUrl {
|
||||
if (!lang) this.log.error('building url with empty language!')
|
||||
const url = `./assets/blockly.html?lang=${lang}`
|
||||
return this.sanitizer.bypassSecurityTrustResourceUrl(url)
|
||||
}
|
||||
}
|
||||
|
||||
interface IframePostMessageEvent extends MessageEvent {
|
||||
|
|
Loading…
Add table
Reference in a new issue