index.dev.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. "use strict";
  2. function initLanguage(langKey) {
  3. var defaultLang = 'en';
  4. var lang = langKey || defaultLang;
  5. if (defaultLang !== lang) {
  6. injectLanguageJsSources(lang); //updateLanguageText();
  7. }
  8. } // logout
  9. $("#modal_logout_btn").on("click", function () {// logout();
  10. });
  11. function logout() {
  12. $.ajax("".concat(CCB.base_url, "api/logout"), {
  13. type: "GET",
  14. xhrFields: {
  15. withCredentials: true
  16. },
  17. success: function success() {
  18. // $('#login_iframe').attr('src', '//staging.cocorobo.cn/login/');
  19. appendIframe("TM_login");
  20. $('#TM_login').children().css("height", "820px");
  21. appendIframe("before_login");
  22. appendIframe("cloud_askLogin");
  23. Materialize.toast(CCB.str_group.success_userLogout, 4000);
  24. CCB.userState = false;
  25. $("#cloud_fileListArea").html("");
  26. loginModalStatus();
  27. $("#modal_logout_btn").addClass('blue');
  28. $(".svgImg").css('display', 'none');
  29. $(".translate-signout").css('opacity', '1');
  30. }
  31. });
  32. } // 点击语言下拉隐藏
  33. // document.onclick = function () {
  34. // $('#languages').removeClass('active');
  35. // $('#languages').css({ display: 'none' })
  36. // }
  37. // 点击切换语言
  38. // $('#nav_language').click(function (e) {
  39. // $('#languages').addClass('active');
  40. // $('#languages').css({ display: 'block', opacity: 1, position: 'absolute',top:'64px' })
  41. // var ev = e || window.event;
  42. // if (ev.stopPropagation) { //阻止冒泡,否则会触发点击空白区域的事件
  43. // ev.stopPropagation();
  44. // } else if (window.event) {
  45. // window.event.cancelBubble = true; //兼容IE
  46. // }
  47. // })
  48. function getUrlLanguage() {
  49. var val = location.search.match(new RegExp('[?&]lang=([^&]+)'));
  50. var language = val ? decodeURIComponent(val[1].replace(/\+/g, '%20')) : '';
  51. if (['en', 'zh-hant', 'zh-hans'].indexOf(language) < 0) return 'zh-hant';
  52. return language;
  53. }
  54. ;
  55. function injectLanguageJsSources(langKey) {
  56. var head = document.getElementsByTagName('head')[0]; // Retrieve and inject Ardublockly translations synchronously
  57. var appLangJsLoad = document.createElement('script');
  58. var request = createAjaxRequest();
  59. var appLangJdPath = "msg/".concat(langKey, ".js");
  60. try {
  61. request.open('GET', appLangJdPath, false);
  62. request.send('');
  63. appLangJsLoad.text = request.responseText;
  64. } catch (e) {
  65. // But still asynchronous lazy load so at least some text gets translated
  66. appLangJsLoad.src = appLangJdPath;
  67. }
  68. head.appendChild(appLangJsLoad); // Retrieve and inject Blockly translations asynchronously
  69. var blocklyLangJsLoad = document.createElement('script');
  70. blocklyLangJsLoad.src = "blockly/msg/js/".concat(langKey, ".js");
  71. head.appendChild(blocklyLangJsLoad);
  72. }
  73. ;
  74. function createAjaxRequest() {
  75. var request = false;
  76. try {
  77. // Firefox, Chrome, IE7+, Opera, Safari
  78. request = new XMLHttpRequest();
  79. } catch (e) {
  80. // IE6 and earlier
  81. try {
  82. request = new ActiveXObject('Msxml2.XMLHTTP');
  83. } catch (e) {
  84. try {
  85. request = new ActiveXObject('Microsoft.XMLHTTP');
  86. } catch (e) {
  87. throw 'Your browser does not support AJAX. You will not be able to' + 'use all of Ardublockly features.';
  88. request = null;
  89. }
  90. }
  91. }
  92. return request;
  93. }
  94. ;
  95. function updateLanguageText() {
  96. for (var textId in LOCALISED_TEXT) {
  97. var textStrings = document.getElementsByClassName("translate-".concat(textId));
  98. for (var _i = 0; _i < textStrings.length; _i++) {
  99. textStrings[_i].innerHTML = LOCALISED_TEXT[textId];
  100. }
  101. }
  102. }
  103. ;
  104. function clearBlocks() {
  105. var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () { };
  106. var length = Blockly.mainWorkspace.getAllBlocks(true).length;
  107. if (length < 2) {
  108. Blockly.mainWorkspace.clear();
  109. cb();
  110. } else {
  111. Blockly.confirm(Blockly.Msg.DELETE_ALL_BLOCKS.replace("%1", length), function (ok) {
  112. if (!ok) return;
  113. Blockly.mainWorkspace.clear();
  114. cb();
  115. });
  116. }
  117. }
  118. function addLibButton(lang) { } // const addLib = document.createElement("button");
  119. // addLib.className = "waves-effect waves-light btn blue";
  120. // let content = lang === 'zh-hans' ? "添加库" : lang === 'zh-hant' ? "添加庫" : "Add Library";
  121. // addLib.textContent = content;
  122. // addLib.style = `
  123. // position: absolute;
  124. // width: 88%;
  125. // bottom: 10px;
  126. // left: 50%;
  127. // transform: translateX(-50%);
  128. // `;
  129. // $(addLib).click(e =>
  130. // blockpy.components.dialog.show("Add Library", document.createElement("div")));
  131. // $(".blocklyToolboxDiv").append(addLib);
  132. // /**
  133. // * Save blocks into local storage. Note that MSIE 11 does not support
  134. // * LocalStorage on file:// URLs.
  135. // */
  136. // function saveLocalStorageBlocks() {
  137. // if (window.sessionStorage) {
  138. // var xml = blockpy.components.editor.getBlocksFromXml();
  139. // var text = Blockly.Xml.domToText(xml);
  140. // localStorage.setItem("blocks", text);
  141. // }
  142. // // blockpy.components.editor.getBlocksFromXml()
  143. // };
  144. // /** Load blocks saved on loacl storage and deletes them from storage. */
  145. // function loadLocalStorageBlocks() {
  146. // // try {
  147. // // var loadOnce = window.localStorage.loadOnceBlocks;
  148. // // } catch (e) {
  149. // // // Firefox sometimes throws a SecurityError when accessing sessionStorage.
  150. // // // Restarting Firefox fixes this, so it looks like a bug.
  151. // // var loadOnce = null;
  152. // // }
  153. // var loadBlocks = localStorage.getItem("blocks");
  154. // if (loadBlocks) {
  155. // var xml = Blockly.Xml.textToDom(loadBlocks);
  156. // blockpy.components.editor.setBlocksFromXml(xml);
  157. // localStorage.removeItem('blocks')
  158. // }
  159. // };
  160. var copyCodeClipboard;
  161. $(window).one("load", function () {
  162. // 判断从python blcokly 跳转过来是ai或者iot
  163. if (window.location.search.indexOf('name') > -1 || getLocalStorage("type") == 1) {
  164. $("#mode")[0].selectedIndex = 1;
  165. $("#mode")[0].onchange();
  166. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
  167. selectmode($("#mode")[0], true);
  168. } else {
  169. $("#mode")[0].selectedIndex = 0;
  170. $("#mode")[0].onchange();
  171. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
  172. selectmode($("#mode")[0], true);
  173. }
  174. $('#white-box').css('display', 'none');
  175. var _lang = getUrlLanguage();
  176. var copyCodeClipboard = new ClipboardJS(".copy_code", {
  177. text: function text() {
  178. return blockpy.components.editor.codeMirror.getValue(); // const codes = $(".CodeMirror-code pre");
  179. // let target = "";
  180. // for (let i = 0; i < codes.length; i++) {
  181. // let line = codes[i].textContent;
  182. // !(line.length === 1 && line.charCodeAt(0) === 8203) ? target += line : "";
  183. // i !== codes.length - 1 ? target += "\n" : "";
  184. // }
  185. // return target;
  186. }
  187. });
  188. copyCodeClipboard.on("success", function () {
  189. return copyCodeToast(2000);
  190. });
  191. var copyCodeToast = function (lang) {
  192. var toast = null,
  193. timeout = null;
  194. var content = lang === 'zh-hans' ? "复制成功" : lang === 'zh-hant' ? "複製成功" : "Copy Successfully";
  195. return function (ms) {
  196. if (toast) {
  197. toast.dismiss();
  198. clearTimeout(timeout);
  199. }
  200. toast = Materialize.toast(content, ms);
  201. timeout = setTimeout(function () {
  202. return toast = timeout = null;
  203. }, ms);
  204. };
  205. }(_lang);
  206. $("#delete-all").click(function () {
  207. return clearBlocks();
  208. });
  209. $("#screenshot").click(function () {
  210. return Blockly.captureDialog_();
  211. });
  212. $("#clearOutput").click(function () {
  213. return $(".blockpy-printer").html("");
  214. });
  215. $("#resetAll").click(function () {
  216. return clearBlocks(function () {
  217. return $(".blockpy-printer").html("");
  218. });
  219. });
  220. $("#lang-tool").click(function () {
  221. return $("#side-lang-trigger > a").dropdown('open');
  222. });
  223. $("#file-tool").click(function () {
  224. return $("#side-file-trigger > a").dropdown('open');
  225. });
  226. $("#blockpy-content > .blockpy-editor img.fullscreenIcon").click(function (e) {
  227. $(e.currentTarget.parentNode).toggleClass("fullscreen");
  228. $("#blockpy-content > .blockpy-editor img.fullscreenIcon").toggleClass("hidden");
  229. $("html").toggleClass("fullscreenMode");
  230. setTimeout(function () {
  231. Blockly.svgResize(blockpy.components.editor.blockly);
  232. Blockly.svgResize(Blockly.mainWorkspace);
  233. }, 100);
  234. });
  235. $("#blockpy-content .card-header > img.fullscreenIcon").click(function (e) {
  236. $(e.currentTarget.parentNode.parentNode).toggleClass("fullscreen");
  237. $("#blockpy-content .card-header > img.fullscreenIcon").toggleClass("hidden");
  238. $("html").toggleClass("fullscreenMode");
  239. setTimeout(function () {
  240. return $(".blockpy-toolbar > .blockpy-text").css("height", "90%").css("height", "100%");
  241. }, 0);
  242. }); // 提示全屏
  243. setTimeout(function () {
  244. if (document.body.clientWidth < 1265) {
  245. alert(CCB.str_group.alert);
  246. }
  247. }, 1000);
  248. });
  249. window.onbeforeunload = window.onunload = function () {
  250. if ($("#mode")[0].selectedIndex == 0) {
  251. saveLocalStorage("type", 0);
  252. saveLocalStorageBlocks("pythonmc-mode-blocks-xml");
  253. } else {
  254. saveLocalStorage("type", 1);
  255. saveLocalStorageBlocks("pythonai-mode-blocks-xml");
  256. }
  257. };
  258. window.onload = function () {
  259. var url = window.location.hash.substring(1); // if (url) {
  260. // document.getElementById('ipAddress').value = 'ws://' + url;
  261. // }
  262. $('.dropdown-trigger').dropdown();
  263. setTimeout(function () {
  264. return $('.modal').modal();
  265. }, 0);
  266. blockpy = new BlockPy({
  267. blocklyPath: "blockly/",
  268. attachmentPoint: document.getElementById("blockpy-div"),
  269. instructor: !getQueryParams()["instructor"] || getQueryParams()["instructor"] == "true",
  270. developer: true,
  271. editor: getQueryParams()["mode"] || "Split",
  272. urls: {}
  273. }); // ready();
  274. var size = calculate_size($("#term")[0]);
  275. term = new Terminal({
  276. cols: size[0],
  277. rows: size[1],
  278. useStyle: true,
  279. screenKeys: true,
  280. cursorBlink: false
  281. });
  282. term.open(document.getElementById("term")); //show_https_warning();
  283. $(".filled-in")[0].onclick = function () {
  284. var _chi = $(".filled-in")[0];
  285. var _par = $(".filled-in")[0].parentNode;
  286. if (!_chi.checked) {
  287. _par.children[1].className = 'filled-in_nocheked translatable_Adapter_fill_connected';
  288. _par.children[1].innerHTML = CCB.str_group.Adapter_fill_connected;
  289. } else {
  290. _par.children[1].className = 'translatable_Adapter_connected';
  291. _par.children[1].innerHTML = CCB.str_group.Adapter_connected;
  292. }
  293. ;
  294. };
  295. setTimeout(function () {
  296. cocoblockly();
  297. }, 0);
  298. $('.blockpy-toolbar-download').on("click", function () {
  299. return export_data(pythonnewcode || Blockly.Python.workspaceToCode(blockpy.components.editor.blockly) || blockpy.components.editor.codeMirror.getValue(), '.py', 0);
  300. });
  301. var uploadXmlButton = $('#pyFileImport > input');
  302. uploadXmlButton.change(function () {
  303. var fr = new FileReader();
  304. var files = uploadXmlButton[0].files;
  305. var file = files[0];
  306. fr.onload = function (e) {
  307. var pyInnerHTML = e.target.result;
  308. blockpy.components.editor.codeMirror.setValue(pyInnerHTML);
  309. };
  310. fr.readAsText(file);
  311. uploadXmlButton.val("");
  312. });
  313. $('.blockpy-toolbar-upload').click(function (e) {
  314. return $('#pyFileImport > input').click();
  315. });
  316. fanyi();
  317. selectOnload();
  318. styled();
  319. var iframe = document.createElement("iframe");
  320. iframe.src = '//project-x.cocorobo.cn/';
  321. iframe.style.width = "100%";
  322. iframe.style.height = "50vh";
  323. document.getElementById('iframe').appendChild(iframe); // $('#select_mode')[0].onchange = function(e){
  324. // var e = e.target;
  325. // selectmode(e.selectedIndex);
  326. // var _index = e.selectedIndex;
  327. //   localStorage.setItem("ModeIndex",_index);
  328. //   
  329. // }
  330. // var _index = localStorage.getItem("ModeIndex") != "undefined" ? localStorage.getItem("ModeIndex") : 0;
  331. // selectmode(parseInt(_index));
  332. // $('#select_mode')[0].selectedIndex = parseInt(_index);
  333. $('#toggle-button').click(function () {
  334. if ($('#toggle-button')[0].checked) {
  335. $('#edit')[0].style.display = 'none'; // $('.translatable_editing')[0].style.display = "none";
  336. // $('.translatable_close_editing')[0].style.display = "inline-block"
  337. } else {
  338. $('#edit')[0].style.display = 'block'; // $('.translatable_editing')[0].style.display = "inline-block";
  339. // $('.translatable_close_editing')[0].style.display = "none"
  340. }
  341. });
  342. };
  343. function styled() {
  344. if (window.location.search.indexOf("en") > -1) {
  345. $(".downbox-style").css({
  346. width: '280px',
  347. marginLeft: '-100px'
  348. });
  349. }
  350. }
  351. function fanyi() {
  352. $('.ModeSelect')[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_Example;
  353. $('.ModeBox')[0].children[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_Basics;
  354. $('.ModeBox ul')[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_sbcb;
  355. $('.ModeBox ul')[0].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_sbcsl;
  356. $('.ModeBox ul')[0].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_tacl;
  357. $('.ModeBox ul')[0].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_ba;
  358. $('.ModeBox ul')[0].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_desl;
  359. $('.ModeBox ul')[0].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_tdsl;
  360. $('.ModeBox ul')[0].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_ha;
  361. $('.ModeBox ul')[0].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_ssl;
  362. $('.ModeBox ul')[0].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_ldliv;
  363. $('.ModeBox ul')[0].children[9].innerHTML = Ardublockly.LOCALISED_TEXT.select_line;
  364. $('.ModeBox ul')[0].children[10].innerHTML = Ardublockly.LOCALISED_TEXT.select_bccs;
  365. $('.ModeBox')[0].children[1].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_imefc;
  366. $('.ModeBox ul')[1].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_uls;
  367. $('.ModeBox ul')[1].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_umdm;
  368. $('.ModeBox ul')[1].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_uoglls;
  369. $('.ModeBox ul')[1].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_auogsm;
  370. $('.ModeBox ul')[1].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_ctsotem;
  371. $('.ModeBox ul')[1].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_thwos;
  372. $('.ModeBox ul')[1].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_sdla;
  373. $('.ModeBox')[0].children[2].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_ionc;
  374. $('.ModeBox ul')[2].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_btsldtc;
  375. $('.ModeBox ul')[2].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_ktsedti;
  376. $('.ModeBox ul')[2].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_btoldalua;
  377. $('.ModeBox ul')[2].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_tsedtc;
  378. $('.ModeBox ul')[2].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_ewhadtnocd;
  379. $('.ModeBox ul')[2].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_ledss;
  380. $('.ModeBox ul')[2].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_ledac;
  381. $('.ModeBox ul')[2].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_ctwn;
  382. $('.ModeBox ul')[2].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_bssbms;
  383. $('.ModeBox ul')[2].children[9].innerHTML = Ardublockly.LOCALISED_TEXT.select_bsrbmc;
  384. $('.ModeBox ul')[2].children[10].innerHTML = Ardublockly.LOCALISED_TEXT.select_wrcbms;
  385. $('.ModeBox ul')[2].children[11].innerHTML = Ardublockly.LOCALISED_TEXT.select_wrcbmr;
  386. $('.ModeBox ul')[2].children[12].innerHTML = Ardublockly.LOCALISED_TEXT.select_snt;
  387. $('.ModeBox')[0].children[3].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_smmlc;
  388. $('.ModeBox ul')[3].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_gcaerhk;
  389. $('.ModeBox ul')[3].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_fr;
  390. $('.ModeBox ul')[3].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_or;
  391. $('.ModeBox ul')[3].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_mhdr;
  392. $('.ModeBox')[0].children[4].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_ambc;
  393. $('.ModeBox ul')[4].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_bcsc;
  394. $('.ModeBox ul')[4].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_kcpccs;
  395. $('.ModeBox ul')[4].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_kcpficc;
  396. $('.ModeBox ul')[4].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_bccs;
  397. $('.ModeBox ul')[4].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_mc;
  398. $('.ModeBox ul')[4].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_sor;
  399. $('.ModeBox ul')[4].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_sdla;
  400. $('.ModeBox')[0].children[5].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_amefc;
  401. $('.ModeBox ul')[5].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_auls;
  402. $('.ModeBox ul')[5].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_aumdm;
  403. $('.ModeBox ul')[5].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_auogsm;
  404. $('.ModeBox ul')[5].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_actsotem;
  405. $('.ModeBox')[0].children[6].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_amvc;
  406. $('.ModeBox ul')[6].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_bctbotci;
  407. $('.ModeBox ul')[6].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_aca;
  408. $('.ModeBox ul')[6].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_rqc;
  409. $('.ModeBox ul')[6].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_lhbl;
  410. $('.ModeBox ul')[6].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_fgr;
  411. $('.ModeBox ul')[6].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_fgaat;
  412. $('.ModeBox')[0].children[7].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_av;
  413. $('.ModeBox ul')[7].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.paly_video;
  414. $('.ModeBox ul')[7].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.paly_music;
  415. $('.ModeBox ul')[7].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.recording_camera;
  416. $('.ModeBox ul')[7].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.microphone_sound_analysis;
  417. $('.ModeBox')[0].children[8].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_teacher;
  418. $('.ModeBox ul')[8].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_thw;
  419. $('.ModeBox ul')[8].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_thwos;
  420. $('.ModeBox ul')[8].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_uoc;
  421. $('.ModeBox ul')[8].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_mc;
  422. $('.ModeBox ul')[8].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_sor; // $('.ModeBox ul')[3].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_Mandarin;
  423. // $('.ModeBox ul')[3].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_English;
  424. // $('.ModeBox ul')[3].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_Cantonese;
  425. // $('#uploadFiles')[0].innerHTML = Ardublockly.LOCALISED_TEXT.uploadFiles;
  426. $("#sketch_name")[0].value = Ardublockly.LOCALISED_TEXT.sketch_name; // $('#runCode')[0].innerHTML = Ardublockly.LOCALISED_TEXT.runCode;
  427. // $('#uploadFiles')[0].innerHTML = Ardublockly.LOCALISED_TEXT.uploadFiles;
  428. $('#resetDevice')[0].innerHTML = Ardublockly.LOCALISED_TEXT.resetDevice;
  429. $('#select_dropdown')[0].value = Ardublockly.LOCALISED_TEXT.select_dropdown;
  430. $('#iot_modules')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
  431. $(".qiehuanbtn")[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.a_csm;
  432. $("#localsssssaveOrOpen")[0].children[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.a_butvmi;
  433. $("#localsssssaveOrOpen")[0].children[1].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.a_buartlp;
  434. $("#Serial_Interaction")[0].innerHTML = Ardublockly.LOCALISED_TEXT.Serial_Interaction;
  435. }
  436. function selectOnload() {
  437. $('.select-connected')[0].onchange = function () {
  438. var a = $('.select-connected')[0].selectedIndex;
  439. if ($('#runCode')[0].innerHTML == CCB.str_group.uploading) {
  440. if (a == 0) {
  441. $('.select-connected')[0].selectedIndex = 1;
  442. return null;
  443. } else {
  444. $('.select-connected')[0].selectedIndex = 0;
  445. return null;
  446. }
  447. }
  448. if (a == 0) {
  449. $('.btn-network')[0].className = 'row btn-network';
  450. $('.btn-network')[1].className = 'row btn-network hidden';
  451. } else {
  452. $('.btn-network')[1].className = 'row btn-network';
  453. $('.btn-network')[0].className = 'row btn-network hidden';
  454. }
  455. };
  456. $('.selectMode_input')[0].onclick = function (e) {
  457. $('.MouduleBox')[0].style.cssText = 'display:block';
  458. };
  459. $('.ModeSelectBox')[0].onclick = function (e) {
  460. U.UF.EV.stopBubble();
  461. $('.ModeSelect')[0].className = 'ModeSelect active';
  462. };
  463. likeclose($('.selectMode_input')[0], $('.MouduleBox')[0], '', '');
  464. likeclose($('.ModeSelect')[0].children[0], $('.ModeSelect')[0], 1, 'ModeSelect');
  465. likeclose($('#bar_ai img')[0], $('.MouduleBox')[1], '', '');
  466. likeclose($('#bar_t img')[0], $('#ai_tt')[0], '', '');
  467. var MChild = $('.MouduleBox')[0].children;
  468. var tchild = $('.MouduleBox')[1].children;
  469. for (var i = 0; i < MChild.length; i++) {
  470. tchild[i].onclick = MChild[i].onclick = function (e) {
  471. window.event ? window.event.cancelBubble = true : e.stopPropagation();
  472. var e = e.target;
  473. if (e.parentElement.children[2] && e.parentElement.children[2].children.length > 0) { } else {
  474. if (e.innerHTML == Ardublockly.LOCALISED_TEXT.iot_module) {
  475. $("#mode")[0].selectedIndex = 0;
  476. $("#mode")[0].onchange();
  477. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
  478. } else if (e.innerHTML == Ardublockly.LOCALISED_TEXT.ai_module) {
  479. $("#mode")[0].selectedIndex = 1;
  480. $("#mode")[0].onchange();
  481. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
  482. }
  483. $('.MouduleBox')[0].style.display = 'none';
  484. $('.MouduleBox')[1].style.display = 'none';
  485. $('#ai_tt')[0].style.display = 'none';
  486. }
  487. };
  488. }
  489. for (var i = 0; i < $('.ModeBox')[0].children.length; i++) {
  490. $('.ModeBox')[0].children[i].onclick = function (e) {
  491. window.event ? window.event.cancelBubble = true : e.stopPropagation();
  492. };
  493. } // "AI/云端语音识别 (普通话).txt", "AI/云端语音识别 (英文).txt", "AI/云端语音识别 (粤语).txt"
  494. var _arr = [["Main/IoT 模块基础案例/侧边按键控制蜂鸣器.xml", "Main/IoT 模块基础案例/侧边按键控制开关 LED.xml", "Main/IoT 模块基础案例/触摸区域控制 LED.xml", "Main/IoT 模块基础案例/蜂鸣器警报.xml", "Main/IoT 模块基础案例/黑暗环境感应光照灯.xml", "Main/IoT 模块基础案例/倾斜方向感应 LED.xml", "Main/IoT 模块基础案例/湿度报警器.xml", "Main/IoT 模块基础案例/摇晃感应 LED.xml", "Main/IoT 模块基础案例/LED 显示光线强度值.xml", "Main/IoT 模块基础案例/按键控制屏幕直线转动.xml", "Main/IoT 模块基础案例/按键控制颜色切换.xml"], ["Main/IoT 模块扩展功能案例/使用 LED 灯屏.xml", "Main/IoT 模块扩展功能案例/使用电机驱动模块.xml", "Main/IoT 模块扩展功能案例/使用游戏手柄LED 灯屏.xml", "Main/IoT 模块扩展功能案例/使用游戏手柄屏幕.xml", "Main/IoT 模块扩展功能案例/在扩展模块上控制舵机.xml", "Main/IoT 模块扩展功能案例/屏幕显示Hello_World.xml", "Main/IoT 模块扩展功能案例/屏幕绘制线条动画.xml"], ["Main/IoT 模块联网案例/按键发送光照数据至 CocoCloud.xml", "Main/IoT 模块联网案例/按键发送环境数据至 IFTTT.xml", "Main/IoT 模块联网案例/按键获取光照数据并根据条件亮灯.xml", "Main/IoT 模块联网案例/定时发送环境数据至 CocoCloud.xml", "Main/IoT 模块联网案例/建立 WiFi 热点并显示连接设备数量.xml", "Main/IoT 模块联网案例/局域网环境数据存储 - 服务器端.xml", "Main/IoT 模块联网案例/局域网环境数据获取 - 客户端.xml", "Main/IoT 模块联网案例/连接 WiFi 网络.xml", "Main/IoT 模块联网案例/模块间按钮状态存储 - 服务端.xml", "Main/IoT 模块联网案例/模块间按钮状态接收 - 客户端.xml", "Main/IoT 模块联网案例/模块间进行 WebSocket 实时通信 - 发送端.xml", "Main/IoT 模块联网案例/模块间进行 WebSocket 实时通信 - 接收端.xml", "Main/IoT 模块联网案例/同步网络时间.xml"], ["AI/AI 模块机器学习案例/垃圾分类识别(香港版).xml", "AI/AI 模块机器学习案例/人脸检测.xml", "AI/AI 模块机器学习案例/物体识别.xml", "AI/AI 模块机器学习案例/MNIST 手写数字识别.xml"], ["AI/AI 模块基础案例/按键控制屏幕时针转动.xml", "AI/AI 模块基础案例/按键控制图片改变颜色制式.xml", "AI/AI 模块基础案例/按键控制图片进行反色变化.xml", "AI/AI 模块基础案例/按键控制颜色切换.xml", "AI/AI 模块基础案例/迷你相机.xml", "AI/AI 模块基础案例/屏幕方向旋转.xml", "AI/AI 模块基础案例/屏幕绘制线条动画.xml"], ["AI/AI 模块扩展功能案例/使用 LED 灯屏.xml", "AI/AI 模块扩展功能案例/使用电机驱动模块.xml", "AI/AI 模块扩展功能案例/使用游戏手柄 + 屏幕模块.xml", "AI/AI 模块扩展功能案例/在扩展模块上控制舵机.xml"], ["AI/AI 模块视觉案例/按键改变相机图像的亮度.xml", "AI/AI 模块视觉案例/区域颜色分析.xml", "AI/AI 模块视觉案例/识别 QR 二维码.xml", "AI/AI 模块视觉案例/寻线(黑线).xml", "AI/AI 模块视觉案例/寻找绿色的圆形.xml", "AI/AI 模块视觉案例/寻找绿色区域并进行追踪.xml"], ["AI/AI 模块影音案例/播放录制的视频档案.xml", "AI/AI 模块影音案例/播放音乐.xml", "AI/AI 模块影音案例/录制摄像头画面并保存.xml", "AI/AI 模块影音案例/麦克风声音频谱分析.xml"], ["AI/AI 教学/AI_Workshop_ex1.xml", "AI/AI 教学/AI_Workshop_ex2.xml", "AI/AI 教学/AI_Workshop_ex3.xml", "AI/AI 教学/AI_Workshop_ex4.xml", "AI/AI 教学/AI_Workshop_ex5.xml"],["Main/IoT工作坊/00 程序/01 點亮正中間的LED燈.xml","Main/IoT工作坊/00 程序/02 點亮所有LED燈.xml","Main/IoT工作坊/00 程序/03 流水燈.xml","Main/IoT工作坊/00 程序/04 蜂鳴器警報.xml","Main/IoT工作坊/00 程序/05 8-bit音樂.xml","Main/IoT工作坊/00 程序/06 序列埠通訊:按鈕開關.xml","Main/IoT工作坊/00 程序/07 序列埠通訊:觸摸開關.xml","Main/IoT工作坊/00 程序/08 按鈕關蜂鳴器.xml","Main/IoT工作坊/00 程序/09 觸摸開關燈.xml","Main/IoT工作坊/00 程序/10 補光裝置.xml","Main/IoT工作坊/00 程序/11 濕度報警器.xml","Main/IoT工作坊/00 程序/12 晃晃燈.xml","Main/IoT工作坊/00 程序/13 連接Wi-Fi.xml","Main/IoT工作坊/00 程序/14 連接Wi-Fi並顯示連接狀態.xml","Main/IoT工作坊/00 程序/15 建立熱點並顯示已連接的設備數.xml","Main/IoT工作坊/00 程序/16 亮度數據上傳與下載.xml","Main/IoT工作坊/00 程序/17 伺服馬達來回擺動.xml","Main/IoT工作坊/00 程序/18 閘門(人臉識別).xml","Main/IoT工作坊/00 程序/體驗 iot-機械車(語音控制).xml","Main/IoT工作坊/00 程序/體驗 iot-機械人(陀螺儀).xml","Main/IoT工作坊/00 程序/體驗 iot-機械人(姿態識別).xml","Main/IoT工作坊/00 程序/體驗 iot-檯燈(語音控制).xml"]]; // var _arr = [
  495. // ["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"],
  496. // ["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"],
  497. // ["AI/迷你照相機.xml", "AI/LCD 按鈕控制時針轉動.xml", "AI/LCD 按鈕控制顏色切換.xml", "AI/LCD 繪製圖形動畫.xml", "AI/屏幕圖片裁剪.xml", "AI/屏幕圖案旋轉.xml", "AI/按鍵改變圖片至反色.xml", "AI/按鍵改變圖片顏色模式.xml", "AI/按鍵改變圖片尺寸.xml"],
  498. // ["AI/二维码识别.xml", "AI/视觉循迹(黑线).xml", "AI/寻找绿色区域并追踪.xml", "AI/区域颜色分析.xml", "AI/寻找绿色的圆形.xml", "AI/按鍵改變相機顏色模式.xml", "AI/按鍵改變相機圖像的亮度.xml"],
  499. // ["AI/手写数字识别.xml", "AI/人脸检测.xml", "AI/物体识别.xml", "AI/hktrashclassification_9classes.xml"],
  500. // ["AI/麦克风分析声音频谱.xml", "AI/播放音频文件.xml", "AI/播放影片档案.xml", "AI/录制摄像头画面.xml"]
  501. // ];
  502. for (var i = 0; i < $('.HarxA').length; i++) {
  503. for (var j = 0; j < $('.HarxA')[i].children.length; j++) {
  504. if ($('.HarxA').length - 1 == i) {
  505. 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>") + $('.HarxA')[i].children[j].innerHTML;
  506. ai_tt.children[j].onclick = function (i, j) {
  507. return function () {
  508. if (_arr[i][j].split("/")[0] == "Main") {
  509. $("#mode")[0].selectedIndex = 0;
  510. $("#mode")[0].onchange();
  511. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
  512. } else {
  513. $("#mode")[0].selectedIndex = 1;
  514. $("#mode")[0].onchange();
  515. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
  516. }
  517. $('.ModeSelect')[0].className = 'ModeSelect';
  518. readTxt("/src/python/" + _arr[i][j], function (txt) {
  519. if (_arr[i][j].split(".")[1] == "xml") {
  520. var xmlfile = Blockly.Xml.textToDom(txt);
  521. blockpy.components.editor.setBlocksFromXml(xmlfile);
  522. } else {
  523. blockpy.components.editor.codeMirror.setValue(txt);
  524. }
  525. });
  526. };
  527. }(i, j);
  528. }
  529. $('.HarxA')[i].children[j].innerHTML = (_arr[i][j].split(".")[1] == "xml" ? "<span style='color:#00FF7F'>[" + "xml" + "] &nbsp</span>" : "<span style='color:#FF7F00'>[" + "py" + "] &nbsp</span>") + $('.HarxA')[i].children[j].innerHTML;
  530. $('.HarxA')[i].children[j].onclick = function (i, j) {
  531. return function () {
  532. if (_arr[i][j].split("/")[0] == "Main") {
  533. $("#mode")[0].selectedIndex = 0;
  534. $("#mode")[0].onchange();
  535. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
  536. } else {
  537. $("#mode")[0].selectedIndex = 1;
  538. $("#mode")[0].onchange();
  539. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
  540. }
  541. $('.ModeSelect')[0].className = 'ModeSelect';
  542. readTxt("/src/python/" + _arr[i][j], function (txt) {
  543. if (_arr[i][j].split(".")[1] == "xml") {
  544. var xmlfile = Blockly.Xml.textToDom(txt);
  545. blockpy.components.editor.setBlocksFromXml(xmlfile);
  546. } else {
  547. blockpy.components.editor.codeMirror.setValue(txt);
  548. }
  549. });
  550. };
  551. }(i, j);
  552. }
  553. }
  554. $('.qiehuanbtn')[0].onclick = function (e) {
  555. if (!(CCB.socket && CCB.socket.id)) {
  556. return;
  557. }
  558. U.UF.EV.stopBubble();
  559. if (Ardublockly.LANG == "en") {
  560. $('#localsssssaveOrOpen')[0].className = 'dropdown-content qiehuan qiehuanposi';
  561. } else {
  562. $('#localsssssaveOrOpen')[0].className = 'dropdown-content qiehuan';
  563. }
  564. };
  565. var _aqieM = $("#localsssssaveOrOpen")[0].children;
  566. for (var i = 0; i < _aqieM.length; i++) {
  567. $("#localsssssaveOrOpen")[0].children[i].addEventListener('click', function () {
  568. window.event ? window.event.cancelBubble = false : e.stopPropagation();
  569. var e = this;
  570. $('#runCuploadFilesode')[0].innerHTML = e.children[0].innerHTML;
  571. }); // $("#localsssssaveOrOpen")[0].children[i].children[0].onclick = function (e) {
  572. // window.event ? window.event.cancelBubble = true : e.stopPropagation()
  573. // }
  574. }
  575. qiehuanjjj($('.qiehuanbtn')[0], $('#localsssssaveOrOpen')[0]);
  576. $(".switch_box1")[0].onclick = switchCC;
  577. $(".switch_box")[0].onclick = switchCC;
  578. $("#repl_delete")[0].onclick = function () {
  579. $("#repl_box_content")[0].innerHTML = "";
  580. };
  581. }
  582. function switchCC(e) {
  583. var e = e.target || e;
  584. var flag = true;
  585. var pythonbox = $("#python_box")[0];
  586. var replbox = $("#repl_box")[0];
  587. var repl_delete = $("#repl_delete")[0];
  588. if (e.className.indexOf("switch_select") != -1) {
  589. return;
  590. } else {
  591. var switch_select = $(".switch_select")[0];
  592. switch_select.className = switch_select.className.replace(" switch_select", "");
  593. e.className += " switch_select";
  594. if (e.className.indexOf("switch_box1") != -1) {
  595. pythonbox.className = "card-content hidden";
  596. replbox.className = "card-content";
  597. repl_delete.style.display = "block";
  598. } else {
  599. pythonbox.className = "card-content";
  600. replbox.className = "card-content hidden";
  601. repl_delete.style.display = "none";
  602. }
  603. }
  604. }
  605. function readTxt(url, fun) {
  606. var xhr = new XMLHttpRequest();
  607. xhr.open('get', url, true);
  608. xhr.send();
  609. xhr.onreadystatechange = function () {
  610. if (xhr.readyState == 4 && xhr.status == 200) {
  611. fun(xhr.responseText);
  612. }
  613. };
  614. }
  615. function qiehuanjjj(ele, _container) {
  616. $("body")[0].addEventListener('click', function (e) {
  617. if (ele != e.target) {
  618. _container.className = 'dropdown-content';
  619. }
  620. });
  621. }
  622. function likeclose(ele, _container, type, _className) {
  623. $("body")[0].addEventListener('click', function (e) {
  624. if (ele != e.target) {
  625. if (type == 1) {
  626. _container.className = _className;
  627. } else {
  628. _container.style.display = 'none';
  629. }
  630. }
  631. });
  632. }
  633. function export_data(data, postfix, is_firefox) {
  634. var url = new Blob([data], {
  635. type: 'text/plain'
  636. });
  637. var download_link = URL.createObjectURL(url);
  638. var a = document.createElement('a');
  639. a.style = "display:none";
  640. a.href = download_link;
  641. a.download = ($(".sketch_name").val() || "cocorobo") + postfix;
  642. if (is_firefox) {
  643. document.body.appendChild(a);
  644. a.click();
  645. setTimeout(function () {
  646. return document.body.removeChild(a);
  647. }, 100);
  648. } else a.click(); // URL.revokeObjectURL(download_link);
  649. // IE edge need a short delay before revoke virtual download link
  650. setTimeout(function () {
  651. return URL.revokeObjectURL(download_link);
  652. }, 100);
  653. } // 积木生成
  654. function selectmode(sel, isload) {
  655. var _type = getLocalStorage("type");
  656. if (sel.selectedIndex == 0 && (_type != 0 || isload === true)) {
  657. saveLocalStorageBlocks("pythonai-mode-blocks-xml");
  658. saveLocalStorage("type", 0);
  659. blockpy.setAssignment( // settings
  660. {}, // assignment
  661. {
  662. modules: {
  663. 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"],
  664. removed: ['A.I.Board']
  665. }
  666. }, // programs
  667. {
  668. __main__: ""
  669. });
  670. loadLocalStorageBlocks("pythonmc-mode-blocks-xml");
  671. } else if (sel.selectedIndex == 1 && (_type != 1 || isload === true)) {
  672. saveLocalStorageBlocks("pythonmc-mode-blocks-xml");
  673. saveLocalStorage("type", 1);
  674. blockpy.setAssignment( // settings
  675. {}, // assignment
  676. {
  677. modules: {
  678. 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"],
  679. removed: ['MainBoard']
  680. }
  681. }, // programs
  682. {
  683. __main__: ""
  684. });
  685. loadLocalStorageBlocks("pythonai-mode-blocks-xml");
  686. }
  687. }
  688. function getQueryParams() {
  689. try {
  690. url = window.location.href;
  691. query_str = url.substr(url.indexOf("?") + 1, url.length - 1);
  692. r_params = query_str.split("&");
  693. params = {};
  694. for (i in r_params) {
  695. param = r_params[i].split("=");
  696. params[param[0]] = param[1];
  697. }
  698. return params;
  699. } catch (e) {
  700. return {};
  701. }
  702. } // onresize 多次执行解决办法
  703. var debounce = function debounce(func, threshold, execAsap) {
  704. var timeout;
  705. return function debounced() {
  706. var obj = this,
  707. args = arguments;
  708. function delayed() {
  709. if (!execAsap) func.apply(obj, args);
  710. timeout = null;
  711. }
  712. ;
  713. if (timeout) clearTimeout(timeout); else if (execAsap) func.apply(obj, args);
  714. timeout = setTimeout(delayed, threshold || 100);
  715. };
  716. };
  717. window.onresize = debounce(function () {
  718. if (document.body.clientWidth < 1265) {
  719. alert(CCB.str_group.alert);
  720. }
  721. }, 100, true);