index.js 63 KB

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