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,
|
statusBar: StatusBar,
|
||||||
splashScreen: SplashScreen,
|
splashScreen: SplashScreen,
|
||||||
) {
|
) {
|
||||||
platform.ready()
|
|
||||||
.then(() => {
|
|
||||||
this.translate.setDefaultLang(DEFAULT_LANG)
|
this.translate.setDefaultLang(DEFAULT_LANG)
|
||||||
this.translate.use(this.translate.getBrowserLang()) // @TODO: check if this works on all platforms!
|
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) {
|
if ((<any>window).cordova) {
|
||||||
statusBar.overlaysWebView(false)
|
statusBar.overlaysWebView(false)
|
||||||
statusBar.backgroundColorByHexString(COLORS.PRIMARY)
|
statusBar.backgroundColorByHexString(COLORS.PRIMARY)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 171d2d909fde5b95c3b1b6af490d872d1b03fe52
|
Subproject commit c43a8244e72996457ce832317bb463787645caae
|
|
@ -18,7 +18,7 @@
|
||||||
<button
|
<button
|
||||||
ion-fab
|
ion-fab
|
||||||
large
|
large
|
||||||
color ="light"
|
color="light"
|
||||||
[title]="'BLOCKLY.BTN_OTA' | translate"
|
[title]="'BLOCKLY.BTN_OTA' | translate"
|
||||||
(click)="launchOtaWizard();"
|
(click)="launchOtaWizard();"
|
||||||
>
|
>
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
<button
|
<button
|
||||||
ion-fab
|
ion-fab
|
||||||
mini
|
mini
|
||||||
color ="light"
|
color="light"
|
||||||
[title]="'BLOCKLY.BTN_CODE' | translate"
|
[title]="'BLOCKLY.BTN_CODE' | translate"
|
||||||
(click)="toggleView();"
|
(click)="toggleView();"
|
||||||
>
|
>
|
||||||
|
@ -38,5 +38,5 @@
|
||||||
</button>
|
</button>
|
||||||
</ion-fab>
|
</ion-fab>
|
||||||
|
|
||||||
<iframe #blocklyFrame scrolling="no" src='assets/blockly.html'></iframe>
|
<iframe #blocklyFrame scrolling="no" [src]="blocklyUrl"></iframe>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
import { Component, ViewChild, ElementRef } from '@angular/core';
|
import { Component, ViewChild, ElementRef } from '@angular/core';
|
||||||
|
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
|
||||||
import { IonicPage, NavController, NavParams } from 'ionic-angular';
|
import { IonicPage, NavController, NavParams } from 'ionic-angular';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
|
||||||
import { OtaWizardPage } from '../ota-wizard/ota-wizard';
|
import { OtaWizardPage } from '../ota-wizard/ota-wizard';
|
||||||
|
|
||||||
@IonicPage()
|
@IonicPage()
|
||||||
|
@ -9,13 +12,18 @@ import { OtaWizardPage } from '../ota-wizard/ota-wizard';
|
||||||
})
|
})
|
||||||
export class BlocklyPage {
|
export class BlocklyPage {
|
||||||
@ViewChild('blocklyFrame') blocklyFrame: ElementRef
|
@ViewChild('blocklyFrame') blocklyFrame: ElementRef
|
||||||
|
blocklyUrl: SafeResourceUrl
|
||||||
|
|
||||||
messageHandler: (ev: IframePostMessageEvent) => void
|
private messageHandler: (ev: IframePostMessageEvent) => void
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public navCtrl: NavController,
|
public navCtrl: NavController,
|
||||||
public navParams: NavParams,
|
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
|
// need to assign it here to keep the function reference for unsubscribing again
|
||||||
// and to maintain the this scope properly
|
// and to maintain the this scope properly
|
||||||
this.messageHandler = (ev: IframePostMessageEvent) => {
|
this.messageHandler = (ev: IframePostMessageEvent) => {
|
||||||
|
@ -42,6 +50,12 @@ export class BlocklyPage {
|
||||||
toggleView () {
|
toggleView () {
|
||||||
this.blocklyFrame.nativeElement.contentWindow.postMessage('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 {
|
interface IframePostMessageEvent extends MessageEvent {
|
||||||
|
|
Loading…
Add table
Reference in a new issue