index.js 60 KB

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