index.js 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602
  1. function initLanguage(langKey) {
  2. let defaultLang = 'en';
  3. let lang = langKey || defaultLang;
  4. if (defaultLang !== lang) {
  5. injectLanguageJsSources(lang);
  6. //updateLanguageText();
  7. }
  8. }
  9. // logout
  10. $("#modal_logout_btn").on("click", function () {
  11. // logout();
  12. });
  13. function logout() {
  14. $.ajax(`${CCB.base_url}api/logout`, {
  15. type: "GET",
  16. xhrFields: {
  17. withCredentials: true
  18. },
  19. success: () => {
  20. // $('#login_iframe').attr('src', '//staging.cocorobo.cn/login/');
  21. appendIframe("TM_login");
  22. $('#TM_login').children().css("height", "820px");
  23. appendIframe("before_login");
  24. appendIframe("cloud_askLogin");
  25. Materialize.toast(CCB.str_group.success_userLogout, 4000);
  26. CCB.userState = false;
  27. $("#cloud_fileListArea").html("");
  28. loginModalStatus();
  29. $("#modal_logout_btn").addClass('blue')
  30. $(".svgImg").css('display', 'none');
  31. $(".translate-signout").css('opacity', '1')
  32. }
  33. });
  34. }
  35. // 点击语言下拉隐藏
  36. // document.onclick = function () {
  37. // $('#languages').removeClass('active');
  38. // $('#languages').css({ display: 'none' })
  39. // }
  40. // 点击切换语言
  41. // $('#nav_language').click(function (e) {
  42. // $('#languages').addClass('active');
  43. // $('#languages').css({ display: 'block', opacity: 1, position: 'absolute',top:'64px' })
  44. // var ev = e || window.event;
  45. // if (ev.stopPropagation) { //阻止冒泡,否则会触发点击空白区域的事件
  46. // ev.stopPropagation();
  47. // } else if (window.event) {
  48. // window.event.cancelBubble = true; //兼容IE
  49. // }
  50. // })
  51. function getUrlLanguage() {
  52. const val = location.search.match(new RegExp('[?&]lang=([^&]+)'));
  53. let language = val ? decodeURIComponent(val[1].replace(/\+/g, '%20')) : '';
  54. if (['en', 'zh-hant', 'zh-hans'].indexOf(language) < 0) return 'zh-hant';
  55. return language;
  56. };
  57. function injectLanguageJsSources(langKey) {
  58. const head = document.getElementsByTagName('head')[0];
  59. // Retrieve and inject Ardublockly translations synchronously
  60. const appLangJsLoad = document.createElement('script');
  61. const request = createAjaxRequest();
  62. const appLangJdPath = `msg/${langKey}.js`;
  63. try {
  64. request.open('GET', appLangJdPath, false);
  65. request.send('');
  66. appLangJsLoad.text = request.responseText;
  67. } catch (e) {
  68. // But still asynchronous lazy load so at least some text gets translated
  69. appLangJsLoad.src = appLangJdPath;
  70. }
  71. head.appendChild(appLangJsLoad);
  72. // Retrieve and inject Blockly translations asynchronously
  73. const blocklyLangJsLoad = document.createElement('script');
  74. blocklyLangJsLoad.src = `blockly/msg/js/${langKey}.js`;
  75. head.appendChild(blocklyLangJsLoad);
  76. };
  77. function createAjaxRequest() {
  78. let request = false;
  79. try {
  80. // Firefox, Chrome, IE7+, Opera, Safari
  81. request = new XMLHttpRequest();
  82. } catch (e) {
  83. // IE6 and earlier
  84. try {
  85. request = new ActiveXObject('Msxml2.XMLHTTP');
  86. } catch (e) {
  87. try {
  88. request = new ActiveXObject('Microsoft.XMLHTTP');
  89. } catch (e) {
  90. throw 'Your browser does not support AJAX. You will not be able to' +
  91. 'use all of Ardublockly features.';
  92. request = null;
  93. }
  94. }
  95. }
  96. return request;
  97. };
  98. function updateLanguageText() {
  99. for (let textId in LOCALISED_TEXT) {
  100. const textStrings = document.getElementsByClassName(`translate-${textId}`);
  101. for (let i = 0; i < textStrings.length; i++) {
  102. textStrings[i].innerHTML = LOCALISED_TEXT[textId];
  103. }
  104. }
  105. };
  106. function clearBlocks(cb = () => { }) {
  107. const length = Blockly.mainWorkspace.getAllBlocks(true).length;
  108. if (length < 2) {
  109. Blockly.mainWorkspace.clear();
  110. cb();
  111. } else {
  112. Blockly.confirm(
  113. Blockly.Msg.DELETE_ALL_BLOCKS.replace("%1", length),
  114. ok => {
  115. if (!ok) return;
  116. Blockly.mainWorkspace.clear();
  117. cb();
  118. }
  119. );
  120. }
  121. }
  122. function addLibButton(lang) {
  123. // const addLib = document.createElement("button");
  124. // addLib.className = "waves-effect waves-light btn blue";
  125. // let content = lang === 'zh-hans' ? "添加库" : lang === 'zh-hant' ? "添加庫" : "Add Library";
  126. // addLib.textContent = content;
  127. // addLib.style = `
  128. // position: absolute;
  129. // width: 88%;
  130. // bottom: 10px;
  131. // left: 50%;
  132. // transform: translateX(-50%);
  133. // `;
  134. // $(addLib).click(e =>
  135. // blockpy.components.dialog.show("Add Library", document.createElement("div")));
  136. // $(".blocklyToolboxDiv").append(addLib);
  137. }
  138. // /**
  139. // * Save blocks into local storage. Note that MSIE 11 does not support
  140. // * LocalStorage on file:// URLs.
  141. // */
  142. // function saveLocalStorageBlocks() {
  143. // if (window.sessionStorage) {
  144. // var xml = blockpy.components.editor.getBlocksFromXml();
  145. // var text = Blockly.Xml.domToText(xml);
  146. // localStorage.setItem("blocks", text);
  147. // }
  148. // // blockpy.components.editor.getBlocksFromXml()
  149. // };
  150. // /** Load blocks saved on loacl storage and deletes them from storage. */
  151. // function loadLocalStorageBlocks() {
  152. // // try {
  153. // // var loadOnce = window.localStorage.loadOnceBlocks;
  154. // // } catch (e) {
  155. // // // Firefox sometimes throws a SecurityError when accessing sessionStorage.
  156. // // // Restarting Firefox fixes this, so it looks like a bug.
  157. // // var loadOnce = null;
  158. // // }
  159. // var loadBlocks = localStorage.getItem("blocks");
  160. // if (loadBlocks) {
  161. // var xml = Blockly.Xml.textToDom(loadBlocks);
  162. // blockpy.components.editor.setBlocksFromXml(xml);
  163. // localStorage.removeItem('blocks')
  164. // }
  165. // };
  166. var copyCodeClipboard;
  167. $(window).one("load", () => {
  168. // 判断从python blcokly 跳转过来是ai或者iot
  169. if (window.location.search.indexOf('name') > -1 || getLocalStorage("type") == 1) {
  170. $("#mode")[0].selectedIndex = 0;
  171. $("#mode")[0].onchange();
  172. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
  173. selectmode($("#mode")[0], true);
  174. appearExample(1);
  175. } else {
  176. $("#mode")[0].selectedIndex = 1;
  177. $("#mode")[0].onchange();
  178. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
  179. selectmode($("#mode")[0], true);
  180. appearExample(0);
  181. }
  182. $('#white-box').css('display', 'none');
  183. const _lang = getUrlLanguage();
  184. const copyCodeClipboard = new ClipboardJS(".copy_code", {
  185. text: function () {
  186. return blockpy.components.editor.codeMirror.getValue();
  187. // const codes = $(".CodeMirror-code pre");
  188. // let target = "";
  189. // for (let i = 0; i < codes.length; i++) {
  190. // let line = codes[i].textContent;
  191. // !(line.length === 1 && line.charCodeAt(0) === 8203) ? target += line : "";
  192. // i !== codes.length - 1 ? target += "\n" : "";
  193. // }
  194. // return target;
  195. }
  196. });
  197. copyCodeClipboard.on("success", () => copyCodeToast(2000));
  198. const copyCodeToast = (function (lang) {
  199. let toast = null,
  200. timeout = null;
  201. const content = lang === 'zh-hans' ? "复制成功" :
  202. lang === 'zh-hant' ? "複製成功" : "Copy Successfully";
  203. return function (ms) {
  204. if (toast) {
  205. toast.dismiss();
  206. clearTimeout(timeout);
  207. }
  208. toast = Materialize.toast(content, ms, 'shareUrl');
  209. timeout = setTimeout(() => toast = timeout = null, ms);
  210. };
  211. })(_lang);
  212. $("#delete-all").click(() => clearBlocks());
  213. $("#screenshot").click(() => Blockly.captureDialog_());
  214. $("#clearOutput").click(() => $(".blockpy-printer").html(""));
  215. $("#resetAll").click(() => clearBlocks(() => $(".blockpy-printer").html("")));
  216. $("#lang-tool").click(() => $("#side-lang-trigger > a").dropdown('open'));
  217. $("#file-tool").click(() => $("#side-file-trigger > a").dropdown('open'));
  218. $("#blockpy-content > .blockpy-editor img.fullscreenIcon").click(e => {
  219. $(e.currentTarget.parentNode).toggleClass("fullscreen");
  220. $("#blockpy-content > .blockpy-editor img.fullscreenIcon").toggleClass("hidden");
  221. $("html").toggleClass("fullscreenMode");
  222. setTimeout(function () {
  223. Blockly.svgResize(blockpy.components.editor.blockly);
  224. Blockly.svgResize(Blockly.mainWorkspace);
  225. }, 100)
  226. });
  227. $("#blockpy-content .card-header > img.fullscreenIcon").click(e => {
  228. $(e.currentTarget.parentNode.parentNode).toggleClass("fullscreen");
  229. $("#blockpy-content .card-header > img.fullscreenIcon").toggleClass("hidden");
  230. $("html").toggleClass("fullscreenMode");
  231. setTimeout(() => $(".blockpy-toolbar > .blockpy-text")
  232. .css("height", "90%")
  233. .css("height", "100%"), 0);
  234. });
  235. // 提示全屏
  236. setTimeout(() => {
  237. if (document.body.clientWidth < 1265) {
  238. alert(CCB.str_group.alert)
  239. }
  240. myChart = echarts.init(document.getElementById('echartsMain'));
  241. window.onresize = function () {
  242. myChart.resize();
  243. }
  244. }, 1000)
  245. // 加载echarts
  246. myChart = myChart = echarts.init(document.getElementById('echartsMain'));
  247. window.onresize = function () {
  248. myChart.resize();
  249. }
  250. // 点击复制分享链接
  251. copyShare()
  252. $("#local_connect_select li").bind({
  253. mouseover: function () {
  254. $(this).children("ul").toggle();
  255. $("#plugin_mac_or_windows").css("opacity", "1");
  256. $("#connect_method").css("opacity", "1");
  257. },
  258. mouseout: function () {
  259. $(this).children("ul").toggle();
  260. $("#plugin_mac_or_windows").css("opacity", "0");
  261. $("#connect_method").css("opacity", "0");
  262. }
  263. });
  264. $("#local_help li").bind({
  265. mouseover: function () {
  266. $(this).children("ul").toggle();
  267. $("#local_help_ai_kit").css("opacity", "1");
  268. $("#help_extends").css("opacity", "1");
  269. },
  270. mouseout: function () {
  271. $(this).children("ul").toggle();
  272. $("#local_help_ai_kit").css("opacity", "0");
  273. $("#help_extends").css("opacity", "0");
  274. }
  275. });
  276. });
  277. window.onbeforeunload = window.onunload = function () {
  278. if ($("#mode")[0].selectedIndex == 1) {
  279. saveLocalStorage("type", 0);
  280. saveLocalStorageBlocks("pythonai-mode-blocks-xml");
  281. } else {
  282. saveLocalStorage("type", 1);
  283. saveLocalStorageBlocks("pythonmc-mode-blocks-xml");
  284. }
  285. }
  286. window.onload = function () {
  287. var url = window.location.hash.substring(1);
  288. // if (url) {
  289. // document.getElementById('ipAddress').value = 'ws://' + url;
  290. // }
  291. if (window.location.search.indexOf("en") > -1) {
  292. $("#cloud_input").attr("placeholder", "name");
  293. $("#donload_file_cloud_input").attr("placeholder", "name");
  294. }
  295. else if (window.location.search.indexOf("zh-hans") > -1) {
  296. $("#cloud_input").attr("placeholder", "名称");
  297. $("#donload_file_cloud_input").attr("placeholder", "名称");
  298. }
  299. else {
  300. $("#cloud_input").attr("placeholder", "名稱");
  301. $("#donload_file_cloud_input").attr("placeholder", "名稱");
  302. }
  303. $('.dropdown-trigger').dropdown();
  304. setTimeout(() => $('.modal').modal(), 0);
  305. blockpy = new BlockPy({
  306. blocklyPath: "blockly/",
  307. attachmentPoint: document.getElementById("blockpy-div"),
  308. instructor:
  309. !getQueryParams()["instructor"] ||
  310. getQueryParams()["instructor"] == "true",
  311. developer: true,
  312. editor: getQueryParams()["mode"] || "Split",
  313. urls: {
  314. }
  315. });
  316. // ready();
  317. var size = calculate_size($("#term")[0]);
  318. term = new Terminal({
  319. cols: size[0],
  320. rows: size[1],
  321. useStyle: true,
  322. screenKeys: true,
  323. cursorBlink: false
  324. });
  325. term.open(document.getElementById("term"));
  326. //show_https_warning();
  327. $(".filled-in")[0].onclick = function () {
  328. var _chi = $(".filled-in")[0];
  329. var _par = $(".filled-in")[0].parentNode;
  330. if (!_chi.checked) {
  331. _par.children[1].className = 'filled-in_nocheked translatable_Adapter_fill_connected';
  332. _par.children[1].innerHTML = CCB.str_group.Adapter_fill_connected;
  333. } else {
  334. _par.children[1].className = 'translatable_Adapter_connected';
  335. _par.children[1].innerHTML = CCB.str_group.Adapter_connected;
  336. };
  337. }
  338. setTimeout(() => {
  339. cocoblockly();
  340. }, 0);
  341. $('.blockpy-toolbar-download').on(
  342. "click", () =>
  343. $("#button_save").click()
  344. // export_data(pythonnewcode || Blockly.Python.workspaceToCode(blockpy.components.editor.blockly) || blockpy.components.editor.codeMirror.getValue(), '.py', 0)
  345. );
  346. $('.blockpy-toolbar-edit').click(e => $('#toggle-button').click());
  347. const uploadXmlButton = $('#pyFileImport > input');
  348. uploadXmlButton.change(function () {
  349. var fr = new FileReader();
  350. var files = uploadXmlButton[0].files;
  351. const file = files[0];
  352. Ardublockly.alertExampleMessage(
  353. '', Ardublockly.getLocalStr('loadBlockBody'),
  354. true, {});
  355. fr.onload = function (e) {
  356. var pyInnerHTML = e.target.result;
  357. blockpy.components.editor.codeMirror.setValue(pyInnerHTML);
  358. };
  359. fr.readAsText(file);
  360. setTimeout(() => {
  361. $('#loading').css({ 'display': 'none' });
  362. $('#example_alert').modal('close');
  363. }, 300)
  364. uploadXmlButton.val("");
  365. });
  366. // $('.blockpy-toolbar-upload').click(e => $('#pyFileImport > input').click());
  367. fanyi();
  368. selectOnload();
  369. styled()
  370. let iframe = document.createElement("iframe")
  371. iframe.src = window.location.host.indexOf("beta") > -1 ? "//beta.project-x.cocorobo.cn/" : '//project-x.cocorobo.cn/';
  372. iframe.style.width = "100%";
  373. iframe.style.height = "50vh";
  374. document.getElementById('iframe').appendChild(iframe)
  375. // $('#select_mode')[0].onchange = function(e){
  376. // var e = e.target;
  377. // selectmode(e.selectedIndex);
  378. // var _index = e.selectedIndex;
  379. //   localStorage.setItem("ModeIndex",_index);
  380. //   
  381. // }
  382. // var _index = localStorage.getItem("ModeIndex") != "undefined" ? localStorage.getItem("ModeIndex") : 0;
  383. // selectmode(parseInt(_index));
  384. // $('#select_mode')[0].selectedIndex = parseInt(_index);
  385. $('#toggle-button').click(() => {
  386. if ($('#toggle-button')[0].checked) {
  387. $('#edit')[0].style.display = 'none';
  388. // $('.translatable_editing')[0].style.display = "none";
  389. // $('.translatable_close_editing')[0].style.display = "inline-block"
  390. $("#edit-on").css({
  391. "display": "block"
  392. });
  393. $("#edit-off").css({
  394. "display": "none"
  395. });
  396. } else {
  397. $('#edit')[0].style.display = 'block';
  398. // $('.translatable_editing')[0].style.display = "inline-block";
  399. // $('.translatable_close_editing')[0].style.display = "none"
  400. $("#edit-on").css({
  401. "display": "none"
  402. });
  403. $("#edit-off").css({
  404. "display": "block"
  405. });
  406. }
  407. })
  408. $('#sketch_name').focus(function () {
  409. if (window.location.search.indexOf("en") > -1) {
  410. this.setAttribute("placeholder", "Please enter the name of the work");
  411. $('#sketch_name').css("width", "330px");
  412. }
  413. else if (window.location.search.indexOf("zh-hans") > -1) {
  414. this.setAttribute("placeholder", "请输入作品名称");
  415. $('#sketch_name').css("width", "200px");
  416. }
  417. else {
  418. this.setAttribute("placeholder", "請輸入作品名稱");
  419. $('#sketch_name').css("width", "200px");
  420. }
  421. }).blur(function () {
  422. if (window.location.search.indexOf("en") > -1) {
  423. this.setAttribute("placeholder", "Please enter the name of the work");
  424. $('#sketch_name').css("width", "330px");
  425. }
  426. else if (window.location.search.indexOf("zh-hans") > -1) {
  427. this.setAttribute("placeholder", "请输入作品名称");
  428. $('#sketch_name').css("width", "200px");
  429. }
  430. else {
  431. this.setAttribute("placeholder", "請輸入作品名稱");
  432. $('#sketch_name').css("width", "200px");
  433. }
  434. });
  435. $("#python_full_screen").click(() => {
  436. window.location.href = "./python/?" + window.location.href.split("?")[1];
  437. });
  438. $("#confirm_btn").click(() => {
  439. var _xml = blockpy.components.editor.getBlocksFromXml();
  440. _xml.setAttribute("type", $("#mode")[0].selectedIndex == 1 ? "AI" : "IoT")
  441. var code = Blockly.Xml.domToPrettyText(_xml);
  442. //var code = Ardublockly.generateXml();
  443. var title = $("#cloud_input").val() != '' ? $("#cloud_input").val() : '未命名';
  444. savelxfile(title, code, showSaveToast);
  445. });
  446. $("#cancel_btn").click(() => {
  447. $("#cloud_storage_name_modal").modal("close");
  448. });
  449. $("#donload_file_confirm_btn").click(() => {
  450. var title = $("#donload_file_cloud_input").val() != '' ? $("#donload_file_cloud_input").val() : '未命名';
  451. downloadXml(title);
  452. $("#donload_file_cocorobo").modal("close");
  453. });
  454. $("#donload_file_cancel_btn").click(() => {
  455. $("#donload_file_cocorobo").modal("close");
  456. });
  457. }
  458. function styled() {
  459. if (window.location.search.indexOf("en") > -1) {
  460. $(".downbox-style").css({ width: '280px', marginLeft: '-100px' })
  461. $("#downboxModule").addClass("english");
  462. $("#local_saveOrOpen").addClass("fileEnglish");
  463. $("#local_connect_select").addClass("fileEnglish");
  464. // $("#Serial_Interaction").css("marginLeft", "15px");
  465. // $("#Serial_Display").css("marginLeft", "35px");
  466. $("#iot_modules").css("width", "170px");
  467. $("#plugin_mac_or_windows").css("left", "208px");
  468. $("#connect_method").css("left", "208px");
  469. $("#connect_method").css("minWidth", "155px");
  470. $("#local_help").addClass("helpEnglish");
  471. $("#local_help_ai_kit").css("left", "242px");
  472. $("#help_extends").css("left", "242px");
  473. // $("#Serial_Interaction").css("left","120px");
  474. // $("#Serial_Display").css("left","260px");
  475. $("body").css("font-family", "Arial");
  476. $("input").css("font-family", "Arial");
  477. $("#workspace_screenshot").css("right", "470px");
  478. $("#downloadbutton-li").css("right", "62px");
  479. $("#uploadpy").css("width", "120px");
  480. }
  481. }
  482. function selectConnectMethods(type) {
  483. if ($('#runCode')[0].innerHTML == CCB.str_group.uploading) {
  484. if (type == 0) {
  485. $('.select-connected')[0].selectedIndex = 1;
  486. return null;
  487. }
  488. else {
  489. $('.select-connected')[0].selectedIndex = 0;
  490. return null;
  491. }
  492. }
  493. if (type == 0) {
  494. $('.select-connected')[0].selectedIndex = 0;
  495. $('.btn-network')[0].className = 'col cs6 btn-network';
  496. $('.btn-network')[1].className = 'col cs6 btn-network hidden';
  497. } else {
  498. $('#runCode')[0].innerHTML = Ardublockly.LOCALISED_TEXT.runCode;
  499. $('#uploadFiles')[0].innerHTML = Ardublockly.LOCALISED_TEXT.uploadFiles;
  500. $('.select-connected')[0].selectedIndex = 1;
  501. $('.btn-network')[1].className = 'col cs6 btn-network';
  502. $('.btn-network')[0].className = 'col cs6 btn-network hidden';
  503. }
  504. }
  505. function fanyi() {
  506. $('.ModeSelect')[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_Example;
  507. $('.ModeBox')[0].children[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.artificial_intelligence_textbook_program;
  508. $('.Hardware9 div')[0].innerHTML = Ardublockly.LOCALISED_TEXT.third_grade;
  509. $('.ModeBox ul')[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.recorded_voice_command;
  510. $('.ModeBox ul')[0].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.voice_recognition_lamp_stand;
  511. $('.Hardware5 div')[0].innerHTML = Ardublockly.LOCALISED_TEXT.fifth_grade;
  512. $('.ModeBox ul')[1].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.recorded_voice_command;
  513. $('.ModeBox ul')[1].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.intelligent_curtain;
  514. $('.ModeBox ul')[1].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.fruit_picking_robot;
  515. $('.Hardware6 div')[0].innerHTML = Ardublockly.LOCALISED_TEXT.sixth_grade;
  516. $('.ModeBox ul')[2].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.intelligent_traffic_lights;
  517. $('.ModeBox ul')[2].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.seeing_eye_necklace;
  518. $('.Hardware7 div')[0].innerHTML = Ardublockly.LOCALISED_TEXT.seventh_grade;
  519. $('.ModeBox ul')[3].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.face_recognition_electronic_police;
  520. $('.Hardware8 div')[0].innerHTML = Ardublockly.LOCALISED_TEXT.eighth_grade;
  521. $('.ModeBox ul')[4].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.payment_platform;
  522. $('.ModeBox')[0].children[1].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_Basics;
  523. $('.ModeBox ul')[5].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_sbcb;
  524. $('.ModeBox ul')[5].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_sbcsl;
  525. $('.ModeBox ul')[5].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_tacl
  526. $('.ModeBox ul')[5].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_ba
  527. $('.ModeBox ul')[5].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_desl
  528. $('.ModeBox ul')[5].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_tdsl;
  529. $('.ModeBox ul')[5].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_ha;
  530. $('.ModeBox ul')[5].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_ssl;
  531. $('.ModeBox ul')[5].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_ldliv;
  532. $('.ModeBox')[0].children[2].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_imefc;
  533. $('.ModeBox ul')[6].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_uls;
  534. $('.ModeBox ul')[6].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_umdm;
  535. $('.ModeBox ul')[6].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_uoglls;
  536. $('.ModeBox ul')[6].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_auogsm;
  537. $('.ModeBox ul')[6].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_ctsotem;
  538. $('.ModeBox ul')[6].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_thwos;
  539. $('.ModeBox ul')[6].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_sdla;
  540. $('.ModeBox ul')[6].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_line;
  541. $('.ModeBox ul')[6].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_bccs;
  542. $('.ModeBox ul')[6].children[9].innerHTML = Ardublockly.LOCALISED_TEXT.select_stepCounter;
  543. $('.ModeBox')[0].children[3].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_ionc;
  544. $('.ModeBox ul')[7].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_btsldtc;
  545. $('.ModeBox ul')[7].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_ktsedti;
  546. $('.ModeBox ul')[7].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_btoldalua;
  547. $('.ModeBox ul')[7].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_tsedtc;
  548. $('.ModeBox ul')[7].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_toedaluatc;
  549. $('.ModeBox ul')[7].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_ewhadtnocd;
  550. $('.ModeBox ul')[7].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_ledss;
  551. $('.ModeBox ul')[7].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_ledac;
  552. $('.ModeBox ul')[7].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_ctwn;
  553. $('.ModeBox ul')[7].children[9].innerHTML = Ardublockly.LOCALISED_TEXT.select_bssbms;
  554. $('.ModeBox ul')[7].children[10].innerHTML = Ardublockly.LOCALISED_TEXT.select_bsrbmc;
  555. $('.ModeBox ul')[7].children[11].innerHTML = Ardublockly.LOCALISED_TEXT.select_wrcbms;
  556. $('.ModeBox ul')[7].children[12].innerHTML = Ardublockly.LOCALISED_TEXT.select_wrcbmr;
  557. $('.ModeBox ul')[7].children[13].innerHTML = Ardublockly.LOCALISED_TEXT.select_snt;
  558. $('.ModeBox ul')[7].children[14].innerHTML = Ardublockly.LOCALISED_TEXT.select_dwsdat;
  559. $('.ModeBox')[0].children[4].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_work_u;
  560. $('.ModeBox ul')[8].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_middle_led;
  561. $('.ModeBox ul')[8].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_all_led;
  562. $('.ModeBox ul')[8].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_liu_led;
  563. $('.ModeBox ul')[8].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_warning;
  564. $('.ModeBox ul')[8].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_music;
  565. $('.ModeBox ul')[8].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_button_open;
  566. $('.ModeBox ul')[8].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_touch_open;
  567. $('.ModeBox ul')[8].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_button_close;
  568. $('.ModeBox ul')[8].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_control_LED;
  569. $('.ModeBox ul')[8].children[9].innerHTML = Ardublockly.LOCALISED_TEXT.select_sensor_LED;
  570. $('.ModeBox ul')[8].children[10].innerHTML = Ardublockly.LOCALISED_TEXT.select_humidity_alarm;
  571. $('.ModeBox')[0].children[5].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_work_d;
  572. $('.ModeBox ul')[9].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_shaking_LED;
  573. // $('.ModeBox ul')[4].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_connect_wifi;
  574. $('.ModeBox ul')[9].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_show_statement;
  575. $('.ModeBox ul')[9].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_establish_WiFi;
  576. $('.ModeBox ul')[9].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_download_lighting;
  577. $('.ModeBox ul')[9].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_controlling_servo;
  578. $('.ModeBox ul')[9].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_move_servo;
  579. $('.ModeBox ul')[9].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_button_controlling_servo;
  580. $('.ModeBox ul')[9].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_face_recognition_door;
  581. $('.ModeBox ul')[9].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_speech_recognition_car;
  582. $('.ModeBox ul')[9].children[9].innerHTML = Ardublockly.LOCALISED_TEXT.select_gyro_control_robot;
  583. $('.ModeBox ul')[9].children[10].innerHTML = Ardublockly.LOCALISED_TEXT.select_gesture_recognition_robot;
  584. $('.ModeBox ul')[9].children[11].innerHTML = Ardublockly.LOCALISED_TEXT.select_speech_recogniton_lamp;
  585. $('.ModeBox')[0].children[6].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_smmlc;
  586. $('.ModeBox ul')[10].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_gcaerhk;
  587. $('.ModeBox ul')[10].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_frs;
  588. $('.ModeBox ul')[10].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_ors;
  589. $('.ModeBox ul')[10].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_fr;
  590. $('.ModeBox ul')[10].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_or;
  591. $('.ModeBox ul')[10].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_srd;
  592. $('.ModeBox ul')[10].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_srt;
  593. $('.ModeBox ul')[10].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_mhdr;
  594. $('.ModeBox')[0].children[7].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_ambc;
  595. $('.ModeBox ul')[11].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_bcsc;
  596. $('.ModeBox ul')[11].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_kcpccs;
  597. $('.ModeBox ul')[11].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_kcpficc;
  598. $('.ModeBox ul')[11].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_bccs;
  599. $('.ModeBox ul')[11].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_mc;
  600. $('.ModeBox ul')[11].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_sor;
  601. $('.ModeBox ul')[11].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_sdla;
  602. $('.ModeBox')[0].children[8].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_amefc;
  603. $('.ModeBox ul')[12].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_auls;
  604. $('.ModeBox ul')[12].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_aumdm;
  605. $('.ModeBox ul')[12].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_auogsm;
  606. $('.ModeBox ul')[12].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_actsotem;
  607. $('.ModeBox ul')[12].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_greedy_snake;
  608. $('.ModeBox')[0].children[9].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_amvc;
  609. $('.ModeBox ul')[13].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_bctbotci;
  610. $('.ModeBox ul')[13].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_aca;
  611. $('.ModeBox ul')[13].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_rqc;
  612. $('.ModeBox ul')[13].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_lhbl;
  613. $('.ModeBox ul')[13].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_fgr;
  614. $('.ModeBox ul')[13].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_fgaat;
  615. $('.ModeBox')[0].children[10].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_av;
  616. $('.ModeBox ul')[14].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.paly_video;
  617. $('.ModeBox ul')[14].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.paly_music;
  618. $('.ModeBox ul')[14].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.recording_camera;
  619. $('.ModeBox ul')[14].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.microphone_sound_analysis;
  620. $('.ModeBox')[0].children[11].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_teacher;
  621. $('.ModeBox ul')[15].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_thw;
  622. $('.ModeBox ul')[15].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_thwos;
  623. $('.ModeBox ul')[15].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_uoc;
  624. $('.ModeBox ul')[15].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_mc;
  625. $('.ModeBox ul')[15].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_sor;
  626. $('.ModeBox')[0].children[12].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_teacher2;
  627. $('.ModeBox ul')[16].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_aiaor;
  628. $('.ModeBox ul')[16].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_aifr;
  629. $('.ModeBox ul')[16].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_aica;
  630. $('.ModeBox ul')[16].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_aisrc;
  631. $('.ModeBox ul')[16].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_aisrr;
  632. $('.ModeBox ul')[16].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_aiaa;
  633. $('.ModeBox')[0].children[13].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_teachingcases;
  634. $('.ModeBox ul')[17].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ex1_servo;
  635. $('.ModeBox ul')[17].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.ex2_Ultrasound;
  636. // $('.ModeBox ul')[12].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.ex3_RangeFinder;
  637. // $('.ModeBox ul')[12].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.ex4_LightStrip;
  638. // $('.ModeBox ul')[12].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.ex5_Microbit;
  639. // $('.ModeBox ul')[12].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.ex6_MicrobitFace;
  640. // $('.ModeBox ul')[12].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.ex7_Door;
  641. $('.ModeBox ul')[17].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.ex4_LightStrip
  642. $('.ModeBox ul')[17].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.ex5_Microbit;
  643. $('.ModeBox ul')[17].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.ex6_MicrobitFace;
  644. $('.ModeBox ul')[17].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.ex7_Door;
  645. $('.ModeBox')[0].children[14].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_wc;
  646. $('.ModeBox ul')[18].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_smaa;
  647. $('.ModeBox ul')[18].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.ai_gc;
  648. $('.ModeBox ul')[18].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.ai_wsb;
  649. $('.ModeBox')[0].children[15].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_ad;
  650. $('.ModeBox ul')[19].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_trsr;
  651. $('.ModeBox ul')[19].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.ai_tpl2;
  652. $('.ModeBox ul')[19].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.ai_tpll;
  653. $('.ModeBox ul')[19].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.ai_tph;
  654. // $('.ModeBox ul')[3].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_Mandarin;
  655. // $('.ModeBox ul')[3].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_English;
  656. // $('.ModeBox ul')[3].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_Cantonese;
  657. // $('#uploadFiles')[0].innerHTML = Ardublockly.LOCALISED_TEXT.uploadFiles;
  658. // $("#sketch_name").val(Ardublockly.LOCALISED_TEXT.sketch_name);
  659. $('#runCode')[0].innerHTML = Ardublockly.LOCALISED_TEXT.runCode;
  660. $('#uploadFiles')[0].innerHTML = Ardublockly.LOCALISED_TEXT.uploadFiles;
  661. // $('#resetDevice')[0].innerHTML = Ardublockly.LOCALISED_TEXT.resetDevice;
  662. $('#select_dropdown')[0].value = Ardublockly.LOCALISED_TEXT.select_dropdown;
  663. $('#iot_modules')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
  664. $(".qiehuanbtn")[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.a_csm;
  665. $("#localsssssaveOrOpen")[0].children[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.a_butvmi;
  666. $("#localsssssaveOrOpen")[0].children[1].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.a_buartlp;
  667. // $("#Serial_Interaction")[0].innerHTML = Ardublockly.LOCALISED_TEXT.Serial_Interaction;
  668. $('#ai_tt div')[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_thw;
  669. $('#ai_tt div')[1].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_thwos;
  670. $('#ai_tt div')[2].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_uoc;
  671. $('#ai_tt div')[3].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_mc;
  672. $('#ai_tt div')[4].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_sor;
  673. }
  674. function selectOnload() {
  675. $('.select-connected')[0].onchange = function () {
  676. var a = $('.select-connected')[0].selectedIndex;
  677. if ($('#runCode')[0].innerHTML == CCB.str_group.uploading) {
  678. if (a == 0) {
  679. $('.select-connected')[0].selectedIndex = 1;
  680. return null;
  681. } else {
  682. $('.select-connected')[0].selectedIndex = 0;
  683. return null;
  684. }
  685. }
  686. if (a == 0) {
  687. $('.btn-network')[0].className = 'col s6 btn-network';
  688. $('.btn-network')[1].className = 'col s6 btn-network hidden';
  689. } else {
  690. $('.btn-network')[1].className = 'col s6 btn-network';
  691. $('.btn-network')[0].className = 'col s6 btn-network hidden';
  692. }
  693. }
  694. $('.selectMode_input')[0].onclick = function (e) {
  695. $('.MouduleBox')[0].style.cssText = 'display:block';
  696. }
  697. $('.ModeSelectBox')[0].onclick = function (e) {
  698. U.UF.EV.stopBubble();
  699. $('.ModeSelect')[0].className = 'ModeSelect active';
  700. $('#downboxModule').css("display", "none");
  701. }
  702. likeclose($('.selectMode_input')[0], $('.MouduleBox')[0], '', '');
  703. likeclose($('.ModeSelect')[0].children[0], $('.ModeSelect')[0], 1, 'ModeSelect');
  704. likeclose($('#bar_ai img')[0], $('.MouduleBox')[1], '', '');
  705. likeclose($('#bar_t img')[0], $('#ai_tt')[0], '', '');
  706. var MChild = $('.MouduleBox')[0].children;
  707. var tchild = $('.MouduleBox')[1].children;
  708. for (var i = 0; i < MChild.length; i++) {
  709. tchild[i].onclick = MChild[i].onclick = function (e) {
  710. window.event ? window.event.cancelBubble = true : e.stopPropagation()
  711. var e = e.target;
  712. if (e.parentElement.children[2] && e.parentElement.children[2].children.length > 0) { } else {
  713. if (e.innerHTML == Ardublockly.LOCALISED_TEXT.iot_module) {
  714. $("#mode")[0].selectedIndex = 0;
  715. $("#mode")[0].onchange();
  716. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
  717. appearExample(1);
  718. }
  719. else if (e.innerHTML == Ardublockly.LOCALISED_TEXT.ai_module) {
  720. $("#mode")[0].selectedIndex = 1;
  721. $("#mode")[0].onchange();
  722. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
  723. appearExample(0);
  724. }
  725. $('.MouduleBox')[0].style.display = 'none';
  726. $('.MouduleBox')[1].style.display = 'none';
  727. $('#ai_tt')[0].style.display = 'none';
  728. }
  729. }
  730. }
  731. for (var i = 0; i < $('.ModeBox')[0].children.length; i++) {
  732. $('.ModeBox')[0].children[i].onclick = function (e) {
  733. window.event ? window.event.cancelBubble = true : e.stopPropagation()
  734. }
  735. }
  736. // "AI/云端语音识别 (普通话).txt", "AI/云端语音识别 (英文).txt", "AI/云端语音识别 (粤语).txt"
  737. var _arr = [
  738. ["AI/AI 广州/录制语音指令.xml",
  739. "AI/AI 广州/语音识别台灯.xml",
  740. ],
  741. [
  742. "AI/AI 广州/录制语音指令.xml",
  743. "AI/AI 广州/智能窗帘.xml",
  744. "AI/AI 广州/水果采摘机器人.xml",
  745. ],
  746. [
  747. "AI/AI 广州/智能交通信号灯.xml",
  748. "AI/AI 广州/导盲项链.xml",
  749. ],
  750. [
  751. // "AI/AI 广州/二维码包裹分拣机器人.xml",
  752. "AI/AI 广州/人脸辨识电子警察.xml",
  753. ],
  754. [
  755. "AI/AI 广州/支付台.xml"
  756. ],
  757. [
  758. "Main/IoT 模块基础案例/侧边按键控制蜂鸣器.xml",
  759. "Main/IoT 模块基础案例/侧边按键控制开关 LED.xml",
  760. "Main/IoT 模块基础案例/触摸区域控制 LED.xml",
  761. "Main/IoT 模块基础案例/蜂鸣器警报.xml",
  762. "Main/IoT 模块基础案例/黑暗环境感应光照灯.xml",
  763. "Main/IoT 模块基础案例/倾斜方向感应 LED.xml",
  764. "Main/IoT 模块基础案例/湿度报警器.xml",
  765. "Main/IoT 模块基础案例/摇晃感应 LED.xml",
  766. "Main/IoT 模块基础案例/LED 显示光线强度值.xml"
  767. ],
  768. [
  769. "Main/IoT 模块扩展功能案例/使用 LED 灯屏.xml",
  770. "Main/IoT 模块扩展功能案例/使用电机驱动模块.xml",
  771. "Main/IoT 模块扩展功能案例/使用游戏手柄LED 灯屏.xml",
  772. "Main/IoT 模块扩展功能案例/使用游戏手柄屏幕.xml",
  773. "Main/IoT 模块扩展功能案例/在扩展模块上控制舵机.xml",
  774. "Main/IoT 模块扩展功能案例/屏幕显示Hello_World.xml",
  775. "Main/IoT 模块扩展功能案例/屏幕绘制线条动画.xml",
  776. "Main/IoT 模块基础案例/按键控制屏幕直线转动.xml",
  777. "Main/IoT 模块基础案例/按键控制颜色切换.xml",
  778. "Main/IoT 模块扩展功能案例/计步器.xml"
  779. ],
  780. [
  781. "Main/IoT 模块联网案例/按键发送光照数据至 CocoCloud.xml",
  782. "Main/IoT 模块联网案例/按键发送环境数据至 IFTTT.xml",
  783. "Main/IoT 模块联网案例/按键获取光照数据并根据条件亮灯.xml",
  784. "Main/IoT 模块联网案例/定时发送环境数据至 CocoCloud.xml",
  785. "Main/IoT 模块联网案例/定时接收环境数据并根据条件亮灯.xml",
  786. "Main/IoT 模块联网案例/建立 WiFi 热点并显示连接设备数量.xml",
  787. "Main/IoT 模块联网案例/局域网环境数据存储 - 服务器端.xml",
  788. "Main/IoT 模块联网案例/局域网环境数据获取 - 客户端.xml",
  789. "Main/IoT 模块联网案例/连接 WiFi 网络.xml",
  790. "Main/IoT 模块联网案例/模块间按钮状态存储 - 服务端.xml",
  791. "Main/IoT 模块联网案例/模块间按钮状态接收 - 客户端.xml",
  792. "Main/IoT 模块联网案例/模块间进行 WebSocket 实时通信 - 发送端.xml",
  793. "Main/IoT 模块联网案例/模块间进行 WebSocket 实时通信 - 接收端.xml",
  794. "Main/IoT 模块联网案例/同步网络时间.xml",
  795. "Main/IoT 模块联网案例/数字手表显示实时时间.xml"
  796. ],
  797. [
  798. "Main/IoT工作坊/00 程序/01 點亮正中間的LED燈.xml",
  799. "Main/IoT工作坊/00 程序/02 點亮所有LED燈.xml",
  800. "Main/IoT工作坊/00 程序/03 流水燈.xml",
  801. "Main/IoT工作坊/00 程序/04 蜂鳴器警報.xml",
  802. "Main/IoT工作坊/00 程序/05 8-bit音樂.xml",
  803. "Main/IoT工作坊/00 程序/06 序列埠通訊:按鈕開關.xml",
  804. "Main/IoT工作坊/00 程序/07 序列埠通訊:觸摸開關.xml",
  805. "Main/IoT工作坊/00 程序/08 按鈕開關蜂鳴器.xml",
  806. "Main/IoT工作坊/00 程序/09 觸摸開關燈.xml",
  807. "Main/IoT工作坊/00 程序/10 補光裝置.xml",
  808. "Main/IoT工作坊/00 程序/11 濕度報警器.xml"
  809. ],
  810. [
  811. "Main/IoT工作坊/00 程序/12 晃晃燈.xml",
  812. // "Main/IoT工作坊/00 程序/13 連接Wi-Fi.xml",
  813. "Main/IoT工作坊/00 程序/14 連接Wi-Fi並顯示連接狀態.xml",
  814. "Main/IoT工作坊/00 程序/15 建立熱點並顯示已連接的設備數.xml",
  815. "Main/IoT工作坊/00 程序/16 亮度數據上傳與下載.xml",
  816. "Main/IoT工作坊/00 程序/17 伺服馬達來回擺動.xml",
  817. "Main/IoT工作坊/00 程序/19 伺服馬達定時擺動.xml",
  818. "Main/IoT工作坊/00 程序/20 按鍵控制伺服馬達.xml",
  819. "Main/IoT工作坊/00 程序/18 閘門(人臉識別).xml",
  820. "Main/IoT工作坊/00 程序/體驗 iot-機械車(語音控制).xml",
  821. "Main/IoT工作坊/00 程序/體驗 iot-機械人(陀螺儀).xml",
  822. "Main/IoT工作坊/00 程序/體驗 iot-機械人(姿態識別).xml",
  823. "Main/IoT工作坊/00 程序/體驗 iot-檯燈(語音控制).xml"
  824. ],
  825. [
  826. "AI/AI 模块机器学习案例/垃圾分类识别(香港版).xml",
  827. "AI/AI 模块机器学习案例/人脸识别.xml",
  828. "AI/AI 模块机器学习案例/物体识别.xml",
  829. "AI/AI 模块机器学习案例/face.xml",
  830. "AI/AI 模块机器学习案例/object.xml",
  831. "AI/AI 模块机器学习案例/語音錄製.xml",
  832. "AI/AI 模块机器学习案例/語音識別.xml",
  833. "AI/AI 模块机器学习案例/MNIST 手写数字识别.xml"
  834. ],
  835. ["AI/AI 模块基础案例/按键控制屏幕时针转动.xml",
  836. "AI/AI 模块基础案例/按键控制图片改变颜色制式.xml",
  837. "AI/AI 模块基础案例/按键控制图片进行反色变化.xml",
  838. "AI/AI 模块基础案例/按键控制颜色切换.xml",
  839. "AI/AI 模块基础案例/迷你相机.xml",
  840. "AI/AI 模块基础案例/屏幕方向旋转.xml",
  841. "AI/AI 模块基础案例/屏幕绘制线条动画.xml"],
  842. ["AI/AI 模块扩展功能案例/使用 LED 灯屏.xml",
  843. "AI/AI 模块扩展功能案例/使用电机驱动模块.xml",
  844. "AI/AI 模块扩展功能案例/使用游戏手柄 + 屏幕模块.xml",
  845. "AI/AI 模块扩展功能案例/在扩展模块上控制舵机.xml",
  846. "AI/AI 模块扩展功能案例/贪吃蛇.xml"],
  847. ["AI/AI 模块视觉案例/按键改变相机图像的亮度.xml",
  848. "AI/AI 模块视觉案例/区域颜色分析.xml",
  849. "AI/AI 模块视觉案例/识别 QR 二维码.xml",
  850. "AI/AI 模块视觉案例/寻线(黑线).xml",
  851. "AI/AI 模块视觉案例/寻找绿色的圆形.xml",
  852. "AI/AI 模块视觉案例/寻找绿色区域并进行追踪.xml"],
  853. ["AI/AI 模块影音案例/播放录制的视频档案.xml",
  854. "AI/AI 模块影音案例/播放音乐.xml",
  855. "AI/AI 模块影音案例/录制摄像头画面并保存.xml",
  856. "AI/AI 模块影音案例/麦克风声音频谱分析.xml"],
  857. ["AI/AI 教学/AI_Workshop_ex1.xml",
  858. "AI/AI 教学/AI_Workshop_ex2.xml",
  859. "AI/AI 教学/AI_Workshop_ex3.xml",
  860. "AI/AI 教学/AI_Workshop_ex4.xml",
  861. "AI/AI 教学/AI_Workshop_ex5.xml"
  862. ],
  863. ["AI/AI 教学/AI_Workshop_II_ex1.xml",
  864. "AI/AI 教学/AI_Workshop_II_ex2.xml",
  865. "AI/AI 教学/AI_Workshop_II_ex3.xml",
  866. "AI/AI 教学/AI_Workshop_II_ex4a.xml",
  867. "AI/AI 教学/AI_Workshop_II_ex4b.xml",
  868. "AI/AI 教学/AI_Workshop_II_ex5.xml"],
  869. ["AI/AI 扩展使用案例/AI_Workshop_III_ex1_Servo.xml",
  870. "AI/AI 扩展使用案例/AI_Workshop_III_ex2_Ultrasound.xml",
  871. "AI/AI 扩展使用案例/AI_Workshop_III_ex4_LightStrip.xml",
  872. "AI/AI 扩展使用案例/AI_Workshop_III_ex5_Microbit.xml",
  873. "AI/AI 扩展使用案例/AI_Workshop_III_ex6_MicrobitFace.xml",
  874. "AI/AI 扩展使用案例/AI_Workshop_III_ex7_Door.xml"],
  875. ["AI/AI 垃圾分类/AI_Workshop_IV_1.xml",
  876. "AI/AI 垃圾分类/AI_Workshop_IV_2.xml",
  877. "AI/AI 垃圾分类/AI_Workshop_IV_3.xml",
  878. ],
  879. ["AI/AI 教学/第一場-路標識別(香港標識).xml",
  880. "AI/AI 教学/第二場-巡線(單線-靠左行駛).xml",
  881. "AI/AI 教学/第二場-巡線(雙線).xml",
  882. "AI/AI 教学/第三場-自動駕駛-香港標識.xml"
  883. ]
  884. ];
  885. // var _arr = [
  886. // ["Main/LED 灯闪烁.xml", "Main/按钮控制LED灯.xml", "Main/拨盘控制LED灯开关.xml", "Main/触摸控制LED灯开关.xml", "Main/LCD图形绘制动画.xml", "Main/LCD显示环境数据.xml", "Main/触摸控制小方块.xml", "Main/运动传感器数值显示.xml", "Main/简易计步器.xml", "Main/平衡球程序.xml", "Main/LCD 显示倾斜方向.xml", "Main/按钮计时器.xml"],
  887. // ["Main/连接周边WiFi网络.xml", "Main/建立WiFi热点.xml", "Main/IFTTT发送环境数据.xml", "Main/IFTTT触发事件.xml", "Main/ThingSpeak发送数据及获取最新数据.xml", "Main/CocoCloud发送数据及获取数据.xml", "Main/onenet_nbiot_send.xml", "Main/onenet_nbiot_read.xml", "Main/cococloud_nbiot_send.xml"],
  888. // ["AI/迷你照相機.xml", "AI/LCD 按鈕控制時針轉動.xml", "AI/LCD 按鈕控制顏色切換.xml", "AI/LCD 繪製圖形動畫.xml", "AI/屏幕圖片裁剪.xml", "AI/屏幕圖案旋轉.xml", "AI/按鍵改變圖片至反色.xml", "AI/按鍵改變圖片顏色模式.xml", "AI/按鍵改變圖片尺寸.xml"],
  889. // ["AI/二维码识别.xml", "AI/视觉循迹(黑线).xml", "AI/寻找绿色区域并追踪.xml", "AI/区域颜色分析.xml", "AI/寻找绿色的圆形.xml", "AI/按鍵改變相機顏色模式.xml", "AI/按鍵改變相機圖像的亮度.xml"],
  890. // ["AI/手写数字识别.xml", "AI/人脸检测.xml", "AI/物体识别.xml", "AI/hktrashclassification_9classes.xml"],
  891. // ["AI/麦克风分析声音频谱.xml", "AI/播放音频文件.xml", "AI/播放影片档案.xml", "AI/录制摄像头画面.xml"]
  892. // ];
  893. for (var i = 0; i < $('ul.HarxA').length; i++) {
  894. for (var j = 0; j < $('ul.HarxA')[i].children.length; j++) {
  895. if (i == 15) {
  896. $('#ai_tt div')[j].onclick = (function (i, j) {
  897. return function () {
  898. if (_arr[i][j].split("/")[0] == "Main") {
  899. $("#mode")[0].selectedIndex = 0;
  900. $("#mode")[0].onchange();
  901. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
  902. appearExample(1);
  903. } else {
  904. $("#mode")[0].selectedIndex = 1;
  905. $("#mode")[0].onchange();
  906. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
  907. appearExample(0);
  908. }
  909. $('.ModeSelect')[0].className = 'ModeSelect';
  910. Ardublockly.alertExampleMessage(
  911. '',
  912. Ardublockly.getLocalStr('loadBlockBody'),
  913. true, {});
  914. readTxt("src/python/" + _arr[i][j], function (txt) {
  915. if (_arr[i][j].split(".")[1] == "xml") {
  916. var xmlfile = Blockly.Xml.textToDom(txt);
  917. blockpy.components.editor.setBlocksFromXml(xmlfile);
  918. } else {
  919. blockpy.components.editor.codeMirror.setValue(txt);
  920. }
  921. setTimeout(() => {
  922. $('#loading').css({ 'display': 'none' });
  923. $('#example_alert').modal('close');
  924. }, 300)
  925. });
  926. }
  927. })(15, j)
  928. }
  929. if ($('ul.HarxA').length == i) {
  930. // ai_tt.children[j].innerHTML = (_arr[i][j].split(".")[1] == "xml" ? ("<span style='color:#00FF7F'>[" + "xml" + "] &nbsp</span>") : ("<span style='color:#FF7F00'>[" + "py" + "] &nbsp</span>")) + $('ul.HarxA')[i].children[j].innerHTML;
  931. ai_tt.children[j].onclick = (function (i, j) {
  932. return function () {
  933. if (_arr[i][j].split("/")[0] == "Main") {
  934. $("#mode")[0].selectedIndex = 0;
  935. $("#mode")[0].onchange();
  936. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
  937. appearExample(1);
  938. } else {
  939. $("#mode")[0].selectedIndex = 1;
  940. $("#mode")[0].onchange();
  941. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
  942. appearExample(0);
  943. }
  944. $('.ModeSelect')[0].className = 'ModeSelect';
  945. readTxt("src/python/" + _arr[i][j], function (txt) {
  946. if (_arr[i][j].split(".")[1] == "xml") {
  947. var xmlfile = Blockly.Xml.textToDom(txt);
  948. blockpy.components.editor.setBlocksFromXml(xmlfile);
  949. } else {
  950. blockpy.components.editor.codeMirror.setValue(txt);
  951. }
  952. });
  953. }
  954. })(i, j)
  955. }
  956. if (i === 10 && (j !== 0 && j !== 1 && j !== 2)) {
  957. $('ul.HarxA')[i].children[j].innerHTML = (_arr[i][j].split(".")[1] == "xml" ? ("<span style='color:orange'>[" + "beta" + "] &nbsp</span>") : ("<span style='color:#FF7F00'>[" + "py" + "] &nbsp</span>")) + $('ul.HarxA')[i].children[j].innerHTML
  958. }
  959. $('ul.HarxA')[i].children[j].onclick = (function (i, j) {
  960. return function () {
  961. if (_arr[i][j].split("/")[0] == "Main") {
  962. $("#mode")[0].selectedIndex = 0;
  963. $("#mode")[0].onchange();
  964. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
  965. appearExample(1);
  966. } else {
  967. $("#mode")[0].selectedIndex = 1;
  968. $("#mode")[0].onchange();
  969. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
  970. appearExample(0);
  971. }
  972. $('.ModeSelect')[0].className = 'ModeSelect';
  973. Ardublockly.alertExampleMessage(
  974. '',
  975. Ardublockly.getLocalStr('loadBlockBody'),
  976. true, {});
  977. readTxt("src/python/" + _arr[i][j], function (txt) {
  978. if (_arr[i][j].split(".")[1] == "xml") {
  979. var xmlfile = Blockly.Xml.textToDom(txt);
  980. blockpy.components.editor.setBlocksFromXml(xmlfile);
  981. } else {
  982. blockpy.components.editor.codeMirror.setValue(txt);
  983. }
  984. if ($('ul.HarxA')[i].children[j].id) {
  985. fileDownload(`src/python/AI/AI 扩展使用案例/${$('ul.HarxA')[i].children[j].id}.hex`, $('ul.HarxA')[i].children[j].id + '.hex')
  986. }
  987. setTimeout(() => {
  988. $('#loading').css({ 'display': 'none' });
  989. $('#example_alert').modal('close');
  990. }, 300)
  991. });
  992. }
  993. })(i, j)
  994. }
  995. }
  996. $('.qiehuanbtn')[0].onclick = function (e) {
  997. if (!(CCB.socket && CCB.socket.id)) {
  998. return;
  999. }
  1000. U.UF.EV.stopBubble();
  1001. if (Ardublockly.LANG == "en") {
  1002. $('#localsssssaveOrOpen')[0].className = 'dropdown-content qiehuan qiehuanposi';
  1003. } else {
  1004. $('#localsssssaveOrOpen')[0].className = 'dropdown-content qiehuan';
  1005. }
  1006. }
  1007. var _aqieM = $("#localsssssaveOrOpen")[0].children;
  1008. for (var i = 0; i < _aqieM.length; i++) {
  1009. $("#localsssssaveOrOpen")[0].children[i].addEventListener('click', function () {
  1010. window.event ? window.event.cancelBubble = false : e.stopPropagation()
  1011. var e = this;
  1012. $('#runCuploadFilesode')[0].innerHTML = e.children[0].innerHTML;
  1013. })
  1014. // $("#localsssssaveOrOpen")[0].children[i].children[0].onclick = function (e) {
  1015. // window.event ? window.event.cancelBubble = true : e.stopPropagation()
  1016. // }
  1017. }
  1018. qiehuanjjj($('.qiehuanbtn')[0], $('#localsssssaveOrOpen')[0]);
  1019. $(".switch_box1")[0].onclick = switchCC;
  1020. $(".switch_box")[0].onclick = switchCC;
  1021. $(".switch_box2")[0].onclick = switchCC;
  1022. $("#repl_delete")[0].onclick = function () {
  1023. $("#repl_box_content")[0].innerHTML = "";
  1024. }
  1025. }
  1026. function switchCC(e) {
  1027. var e = e.target || e;
  1028. var flag = true;
  1029. var pythonbox = $("#python_box")[0];
  1030. var replbox = $("#repl_box")[0];
  1031. var repl_delete = $("#repl_delete")[0]
  1032. if (e.className.indexOf("switch_select") != -1) {
  1033. return;
  1034. } else {
  1035. var switch_select = $(".switch_select")[0]
  1036. switch_select.className = switch_select.className.replace(" switch_select", "");
  1037. e.className += " switch_select";
  1038. if (e.className.indexOf("switch_box1") != -1) {
  1039. pythonbox.className = "card-content hidden"
  1040. replbox.className = "card-content"
  1041. repl_delete.style.display = "none";
  1042. $('#switchSerial1').click();
  1043. $("#Serial_Display").addClass("display_switch_box2");
  1044. $(".blockpy-toolbar-edit").css({
  1045. "display": "none"
  1046. });
  1047. $(".copy_code").css({
  1048. "display": "none"
  1049. });
  1050. $(".blockpy-toolbar-download").css({
  1051. "display": "none"
  1052. });
  1053. $(".blockpy-toolbar-upload").css({
  1054. "display": "none"
  1055. });
  1056. $("#repl_delete").css("display", "block");
  1057. }
  1058. else if (e.className.indexOf("switch_box2") != -1) {
  1059. pythonbox.className = "card-content hidden"
  1060. replbox.className = "card-content"
  1061. repl_delete.style.display = "none";
  1062. $('#switchSerial2').click();
  1063. $(".blockpy-toolbar-edit").css({
  1064. "display": "none"
  1065. });
  1066. $(".copy_code").css({
  1067. "display": "none"
  1068. });
  1069. $(".blockpy-toolbar-download").css({
  1070. "display": "none"
  1071. });
  1072. $(".blockpy-toolbar-upload").css({
  1073. "display": "none"
  1074. });
  1075. $("#repl_delete").css("display", "none");
  1076. }
  1077. else {
  1078. pythonbox.className = "card-content"
  1079. replbox.className = "card-content hidden"
  1080. repl_delete.style.display = "none";
  1081. $("#Serial_Display").removeClass("display_switch_box2");
  1082. $(".blockpy-toolbar-edit").css({
  1083. "display": "block"
  1084. });
  1085. $(".copy_code").css({
  1086. "display": "block"
  1087. });
  1088. $(".blockpy-toolbar-download").css({
  1089. "display": "block"
  1090. });
  1091. $(".blockpy-toolbar-upload").css({
  1092. "display": "block"
  1093. });
  1094. $("#repl_delete").css("display", "none");
  1095. }
  1096. }
  1097. }
  1098. function readTxt(url, fun) {
  1099. var xhr = new XMLHttpRequest();
  1100. xhr.open('get', url, true);
  1101. xhr.send();
  1102. xhr.onreadystatechange = function () {
  1103. if (xhr.readyState == 4 && xhr.status == 200) {
  1104. fun(xhr.responseText)
  1105. }
  1106. };
  1107. }
  1108. function qiehuanjjj(ele, _container) {
  1109. $("body")[0].addEventListener('click', function (e) {
  1110. if (ele != e.target) {
  1111. _container.className = 'dropdown-content';
  1112. }
  1113. })
  1114. }
  1115. function likeclose(ele, _container, type, _className) {
  1116. $("body")[0].addEventListener('click', function (e) {
  1117. if (ele != e.target) {
  1118. if (type == 1) {
  1119. _container.className = _className;
  1120. } else {
  1121. _container.style.display = 'none'
  1122. }
  1123. }
  1124. })
  1125. }
  1126. function export_data(data, postfix, is_firefox) {
  1127. let url = new Blob([data], { type: 'text/plain' });
  1128. let download_link = URL.createObjectURL(url);
  1129. let a = document.createElement('a');
  1130. a.style = "display:none";
  1131. a.href = download_link;
  1132. a.download = ($("#sketch_name").val() != '' ? $("#sketch_name").val() : "cocorobo") + postfix;
  1133. if (is_firefox) {
  1134. document.body.appendChild(a);
  1135. a.click();
  1136. setTimeout(() => document.body.removeChild(a), 100);
  1137. } else
  1138. a.click();
  1139. // URL.revokeObjectURL(download_link);
  1140. // IE edge need a short delay before revoke virtual download link
  1141. setTimeout(() => URL.revokeObjectURL(download_link), 100);
  1142. }
  1143. // 积木生成
  1144. function selectmode(sel, isload) {
  1145. var _type = getLocalStorage("type");
  1146. if (sel.selectedIndex == 0 && (_type != 1 || isload === true)) {
  1147. saveLocalStorageBlocks("pythonai-mode-blocks-xml");
  1148. saveLocalStorage("type", 1);
  1149. blockpy.setAssignment(
  1150. // settings
  1151. {},
  1152. // assignment
  1153. {
  1154. modules: {
  1155. added: ["Decisions", "Iteration", "Calculation", "Variables", "Values", "Lists", "Functions", "Logic", "Loops", "Math", "Text", "Dictionary", "Tuples", "Set", "Functionsa", "Output", "Files", "Time", "Serial Comm.", "MainBoard", "ExtendedFunction", "Third_party_Sensor"],
  1156. removed: ['A.I.Board']
  1157. }
  1158. },
  1159. // programs
  1160. {
  1161. __main__: ""
  1162. }
  1163. );
  1164. loadLocalStorageBlocks("pythonmc-mode-blocks-xml")
  1165. }
  1166. else if (sel.selectedIndex == 1 && (_type != 0 || isload === true)) {
  1167. saveLocalStorageBlocks("pythonmc-mode-blocks-xml");
  1168. saveLocalStorage("type", 0);
  1169. blockpy.setAssignment(
  1170. // settings
  1171. {},
  1172. // assignment
  1173. {
  1174. modules: {
  1175. added: ["Decisions", "Iteration", "Calculation", "Variables", "Values", "Lists", "Functions", "Logic", "Loops", "Math", "Text", "Dictionary", "Tuples", "Set", "Functionsa", "Output", "Files", "Time", "Serial Comm.", "A.I.Board", "ExtendedFunctions", "Third_party_Sensor"],
  1176. removed: ['MainBoard']
  1177. }
  1178. },
  1179. // programs
  1180. {
  1181. __main__: ""
  1182. }
  1183. );
  1184. loadLocalStorageBlocks("pythonai-mode-blocks-xml")
  1185. }
  1186. }
  1187. function getQueryParams() {
  1188. try {
  1189. url = window.location.href;
  1190. query_str = url.substr(url.indexOf("?") + 1, url.length - 1);
  1191. r_params = query_str.split("&");
  1192. params = {};
  1193. for (var i = 0; i < r_params.length; i++) {
  1194. param = r_params[i].split("=");
  1195. params[param[0]] = param[1];
  1196. }
  1197. return params;
  1198. } catch (e) {
  1199. return {};
  1200. }
  1201. }
  1202. // onresize 多次执行解决办法
  1203. var debounce = function (func, threshold, execAsap) {
  1204. var timeout;
  1205. return function debounced() {
  1206. var obj = this, args = arguments;
  1207. function delayed() {
  1208. if (!execAsap)
  1209. func.apply(obj, args);
  1210. timeout = null;
  1211. };
  1212. if (timeout)
  1213. clearTimeout(timeout);
  1214. else if (execAsap)
  1215. func.apply(obj, args);
  1216. timeout = setTimeout(delayed, threshold || 100);
  1217. };
  1218. }
  1219. window.onresize = debounce(function () {
  1220. if (document.body.clientWidth < 1265) {
  1221. alert(CCB.str_group.alert)
  1222. }
  1223. }, 100, true);
  1224. // 切换数据显示方式
  1225. var myChart = "";
  1226. function switchSerial(type) {
  1227. if (type == 2) {
  1228. document.getElementById('repl_box_content').style.display = 'none';
  1229. document.getElementById('echartsShow').style.display = 'block';
  1230. document.getElementById('repl_box_content').innerHTML = ""
  1231. // document.getElementsByClassName('translatable_serial_plotter')[0].classList.remove("serial-active")
  1232. // document.getElementsByClassName('translatable_serial_visualization')[0].classList.add("serial-active")
  1233. // document.getElementById('echartsShow').innerHTML = `<div id="echartsMain" class="echartsMain"></div>`
  1234. myChart.resize();
  1235. var options = {
  1236. title: {
  1237. // text: 'ECharts 入门示例'
  1238. },
  1239. tooltip: {},
  1240. legend: {
  1241. // data: ['销量']
  1242. },
  1243. xAxis: {
  1244. data: []
  1245. },
  1246. yAxis: {},
  1247. series: []
  1248. };
  1249. myChart.clear();
  1250. myChart.setOption(options);
  1251. document.getElementById('echartsMain').lastChild.innerHTML = CCB.str_group.echart_text;
  1252. document.getElementById('echartsMain').lastChild.classList.add("echart-text");
  1253. } else {
  1254. document.getElementById('repl_box_content').style.display = 'block';
  1255. document.getElementById('echartsShow').style.display = 'none';
  1256. // document.getElementsByClassName('translatable_serial_plotter')[0].classList.add("serial-active")
  1257. // document.getElementsByClassName('translatable_serial_visualization')[0].classList.remove("serial-active")
  1258. document.getElementById('repl_box_content').innerHTML = ""
  1259. }
  1260. }
  1261. // 点击下载文件
  1262. function fileDownload(url, name) {
  1263. var nowA = document.createElement('a');
  1264. nowA.setAttribute('href', url);
  1265. nowA.setAttribute('download', name);
  1266. nowA.style.display = 'none';
  1267. document.body.appendChild(nowA);
  1268. nowA.click();
  1269. document.body.removeChild(nowA);
  1270. }
  1271. // 点击复制分享链接
  1272. function copyShare() {
  1273. $('#cloudBtn-shares').click(() => {
  1274. if (CCB.userState) {
  1275. let time = 10000
  1276. var $toastContent = $(`<span id="abc">${CCB.str_group.share_loading}</span>`)
  1277. Materialize.toast($toastContent, time, "shareUrl")
  1278. let fileNmae = new Date().getTime()
  1279. $.ajax(`${CCB.base_url}blockx/`, {
  1280. type: "POST",
  1281. xhrFields: {
  1282. withCredentials: true
  1283. },
  1284. data: {
  1285. filename: fileNmae,
  1286. xml: Ardublockly.generateXml()
  1287. },
  1288. success: (res) => {
  1289. let fileobject = {
  1290. filenameId: res.filename,
  1291. filename: fileNmae,
  1292. time: getCurrentDate(),
  1293. timestamp: (new Date()).valueOf()
  1294. };
  1295. CCB.cloudFileList.push(fileobject);
  1296. CCB.selectCloudFile = filename;
  1297. let url = window.location.href + '&Qd=' + res.filename;
  1298. let flag = copyText(url);
  1299. // time = 3000;
  1300. // document.getElementById('abc').innerHTML = flag ? CCB.str_group.share_success : CCB.str_group.share_fail
  1301. setTimeout(function () {
  1302. Materialize.toast(flag ? CCB.str_group.share_success : CCB.str_group.share_fail, 3000, "shareUrl")
  1303. }, time)
  1304. },
  1305. error: () => {
  1306. $("#cloud_modal_preload").css("display", "none");
  1307. // time = 4000;
  1308. // Materialize.toast(CCB.str_group.error_uploadFile, 4000);
  1309. // document.getElementById('abc').style.display = CCB.str_group.error_uploadFile
  1310. setTimeout(function () {
  1311. Materialize.toast(CCB.str_group.error_uploadFile, 4000, 'shareUrl')
  1312. }, time)
  1313. }
  1314. });
  1315. } else {
  1316. Materialize.toast(CCB.str_group.requestLogin, 3000, 'shareUrl');
  1317. $("#login_modal").modal("open")
  1318. }
  1319. })
  1320. }
  1321. function openUrl(url) {
  1322. window.open(url, "_blank")
  1323. }
  1324. function appearExample(type) {
  1325. if (type == 0) {
  1326. $('.ModeBox')[0].children[0].style.display = "block";
  1327. $('.ModeBox')[0].children[1].style.display = "none";
  1328. $('.ModeBox')[0].children[2].style.display = "none";
  1329. $('.ModeBox')[0].children[3].style.display = "none";
  1330. $('.ModeBox')[0].children[4].style.display = "none";
  1331. $('.ModeBox')[0].children[5].style.display = "none";
  1332. $('.ModeBox')[0].children[6].style.display = "block";
  1333. $('.ModeBox')[0].children[7].style.display = "block";
  1334. $('.ModeBox')[0].children[8].style.display = "block";
  1335. $('.ModeBox')[0].children[9].style.display = "block";
  1336. $('.ModeBox')[0].children[10].style.display = "block";
  1337. $('.ModeBox')[0].children[11].style.display = "block";
  1338. $('.ModeBox')[0].children[12].style.display = "block";
  1339. $('.ModeBox')[0].children[13].style.display = "block";
  1340. $('.ModeBox')[0].children[14].style.display = "block";
  1341. $('.ModeBox')[0].children[15].style.display = "block";
  1342. } else {
  1343. $('.ModeBox')[0].children[0].style.display = "none";
  1344. $('.ModeBox')[0].children[0].style.display = "none";
  1345. $('.ModeBox')[0].children[1].style.display = "block";
  1346. $('.ModeBox')[0].children[2].style.display = "block";
  1347. $('.ModeBox')[0].children[3].style.display = "block";
  1348. $('.ModeBox')[0].children[4].style.display = "block";
  1349. $('.ModeBox')[0].children[5].style.display = "block";
  1350. $('.ModeBox')[0].children[6].style.display = "none";
  1351. $('.ModeBox')[0].children[7].style.display = "none";
  1352. $('.ModeBox')[0].children[8].style.display = "none";
  1353. $('.ModeBox')[0].children[9].style.display = "none";
  1354. $('.ModeBox')[0].children[10].style.display = "none";
  1355. $('.ModeBox')[0].children[11].style.display = "none";
  1356. $('.ModeBox')[0].children[12].style.display = "none";
  1357. $('.ModeBox')[0].children[13].style.display = "none";
  1358. $('.ModeBox')[0].children[14].style.display = "none";
  1359. $('.ModeBox')[0].children[15].style.display = "none";
  1360. }
  1361. }
  1362. function savelxfile(title, code, cb) {
  1363. var _token = window.localStorage.Token;
  1364. if (_token) {
  1365. $.ajax(`/api/web/v1/blockpy/project/add`, {
  1366. type: "POST",
  1367. headers: { 'Authorization': "Bearer " + _token },
  1368. data: { code: code, title: title },
  1369. success: (data) => {
  1370. cb(data)
  1371. }
  1372. });
  1373. }
  1374. }
  1375. function getlxfiles(page, cb) {
  1376. var _token = window.localStorage.Token;
  1377. if (_token) {
  1378. $.ajax(`/api/web/v1/blockpy/project/list`, {
  1379. type: "GET",
  1380. headers: { 'Authorization': "Bearer " + _token },
  1381. data: "pageNumber=" + "&" + page + "pageSize=500",
  1382. success: (data) => {
  1383. cb(data)
  1384. }
  1385. });
  1386. }
  1387. }
  1388. function getlxfilebyid(id) {
  1389. var _token = window.localStorage.Token;
  1390. if (_token) {
  1391. $.ajax(`/api/web/v1/blockpy/project/` + id, {
  1392. type: "GET",
  1393. headers: { 'Authorization': "Bearer " + _token },
  1394. success: (data) => {
  1395. cb(data)
  1396. }
  1397. });
  1398. }
  1399. }
  1400. function getFileList(data) {
  1401. var fileList = [];
  1402. data.data.records.filter(val => {
  1403. var filename = val.title;
  1404. var date = val.updateTime;
  1405. var Timestamp = new Date(date).getTime();
  1406. fileList.push({
  1407. filename: filename,
  1408. date: date,
  1409. timestamp: Timestamp,
  1410. filenameId: val.id
  1411. });
  1412. });
  1413. console.log(fileList, 'getCloudFileList')
  1414. updateCloudFileList(fileList);
  1415. updateCloudFilePanel();
  1416. // openCloudFile(CCB.cloudFileList[i].filename); 打开文件
  1417. let arr = window.location.search.split('&')[1]
  1418. if (arr) {
  1419. fileList.map(x => {
  1420. if (x.filenameid == arr.split('=')[1]) {
  1421. openCloudFile(x.filename)
  1422. }
  1423. return x;
  1424. })
  1425. }
  1426. }
  1427. function dellxfilebyid(id, cb) {
  1428. var _token = window.localStorage.Token;
  1429. if (_token) {
  1430. $.ajax(`/api/web/v1/blockpy/project/del/` + id, {
  1431. type: "GET",
  1432. headers: { 'Authorization': "Bearer " + _token },
  1433. success: (data) => {
  1434. cb(data)
  1435. }
  1436. });
  1437. }
  1438. }
  1439. function upadtelxfilenamebyid(id, title, cb) {
  1440. var _token = window.localStorage.Token;
  1441. if (_token) {
  1442. $.ajax(`/api/web/v1/blockpy/project/title/update`, {
  1443. type: "POST",
  1444. headers: { 'Authorization': "Bearer " + _token },
  1445. data: { id: id, title: title },
  1446. success: (data) => {
  1447. cb(data)
  1448. }
  1449. });
  1450. }
  1451. }
  1452. function uploadlxfilecontentbyid(id, code, cb) {
  1453. var _token = window.localStorage.Token;
  1454. if (_token) {
  1455. $.ajax(`/api/web/v1/blockpy/project/code/update`, {
  1456. type: "POST",
  1457. headers: { 'Authorization': "Bearer " + _token },
  1458. data: { id: id, code: code },
  1459. success: (data) => {
  1460. cb(data)
  1461. }
  1462. });
  1463. }
  1464. }
  1465. function showSaveToast(data) {
  1466. $("#cloud_storage_name_modal").modal("close");
  1467. setTimeout(function () {
  1468. Materialize.toast(data.success ? '保存成功' : '保存失败', 3000, "shareUrl")
  1469. }, getCurrentDate())
  1470. $("#cloud_input").val('');
  1471. }