index.js 65 KB

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