Skip to content

Commit c7f1469

Browse files
committed
Update simulator
1 parent e6966cb commit c7f1469

4 files changed

Lines changed: 34 additions & 12 deletions

File tree

components/simulator/.bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
"jquery-i18next": "^1.2.0",
2525
"bootstrap-select": "^1.12.1"
2626
},
27-
"_release": "8bafcbac99",
27+
"_release": "86510d22b9",
2828
"_resolution": {
2929
"type": "branch",
3030
"branch": "blockly",
31-
"commit": "8bafcbac9967dbeafbb374277d67babca6bb6d7f"
31+
"commit": "86510d22b9d5a335d4c44dbba0de110e2f1e71d4"
3232
},
3333
"_source": "https://git.kingkit.codes/webduino/simulator.git",
3434
"_target": "blockly",

components/simulator/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
</button>
4545
</div>
4646
<div class="navbar-right margin-fixed hidden">
47-
<select id="lang" class="selectpicker" data-container="body" data-width="auto">
47+
<select id="lang" class="selectpicker hidden" data-container="body" data-width="auto">
4848
<option value="en" data-i18n="language.en"></option>
4949
<option value="zh-tw" data-i18n="language.zh-tw"></option>
5050
<option value="zh-cn" data-i18n="language.zh-cn"></option>

components/simulator/js/blockly.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,33 @@
1515
}
1616

1717
function language(val) {
18+
if (!app.isReady()) {
19+
readyHandler(language, this, [val]);
20+
return;
21+
}
22+
1823
var mapping = {
1924
'en': 'en',
2025
'zh-hant': 'zh-tw',
2126
'zh-hans': 'zh-cn'
2227
};
23-
24-
setTimeout(function timer() {
25-
if (app.language) {
26-
app.language = mapping[val];
27-
} else {
28-
setTimeout(timer, 10);
29-
}
30-
}, 10);
31-
28+
29+
app.language = mapping[val];
30+
$('#lang').selectpicker('val', mapping[val]);
31+
}
32+
33+
function readyHandler(func, thisArg, args) {
34+
if (app.isReady()) {
35+
func.apply(this, args);
36+
} else {
37+
setTimeout(function runner() {
38+
if (app.isReady) {
39+
func.apply(this, args);
40+
} else {
41+
setTimeout(runner, 10);
42+
}
43+
}, 10);
44+
}
3245
}
3346

3447
window.blockly = {

components/simulator/js/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
var app = new Vue({
1313
el: '#app',
1414
data: {
15+
ready: false,
16+
i18nextReady: false,
1517
language: '', // 語系
1618
drawingPath: false, // 畫線狀態
1719
movingCircle: false, // 編輯時,移動圓點
@@ -20,9 +22,15 @@
2022
instance: [], // 保存使用的功能實例
2123
engineStarting: false // Engine 是否啟動中
2224
},
25+
mounted: function () {
26+
this.ready = true;
27+
},
2328
methods: {
2429
save: function (inst) {
2530
this.instance.push(inst);
31+
},
32+
isReady: function () {
33+
return this.ready && this.i18nextReady;
2634
}
2735
}
2836
});
@@ -207,6 +215,7 @@
207215
jqueryI18next.init(i18next, $);
208216
$('body').localize();
209217
app.language = i18next.language;
218+
app.i18nextReady = true;
210219
});
211220
}
212221

0 commit comments

Comments
 (0)