123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817 |
- "use strict";
- function initLanguage(langKey) {
- var defaultLang = 'en';
- var lang = langKey || defaultLang;
- if (defaultLang !== lang) {
- injectLanguageJsSources(lang); //updateLanguageText();
- }
- } // logout
- $("#modal_logout_btn").on("click", function () {// logout();
- });
- function logout() {
- $.ajax("".concat(CCB.base_url, "api/logout"), {
- type: "GET",
- xhrFields: {
- withCredentials: true
- },
- success: function success() {
- // $('#login_iframe').attr('src', '//staging.cocorobo.cn/login/');
- appendIframe("TM_login");
- $('#TM_login').children().css("height", "820px");
- appendIframe("before_login");
- appendIframe("cloud_askLogin");
- Materialize.toast(CCB.str_group.success_userLogout, 4000);
- CCB.userState = false;
- $("#cloud_fileListArea").html("");
- loginModalStatus();
- $("#modal_logout_btn").addClass('blue');
- $(".svgImg").css('display', 'none');
- $(".translate-signout").css('opacity', '1');
- }
- });
- } // 点击语言下拉隐藏
- // document.onclick = function () {
- // $('#languages').removeClass('active');
- // $('#languages').css({ display: 'none' })
- // }
- // 点击切换语言
- // $('#nav_language').click(function (e) {
- // $('#languages').addClass('active');
- // $('#languages').css({ display: 'block', opacity: 1, position: 'absolute',top:'64px' })
- // var ev = e || window.event;
- // if (ev.stopPropagation) { //阻止冒泡,否则会触发点击空白区域的事件
- // ev.stopPropagation();
- // } else if (window.event) {
- // window.event.cancelBubble = true; //兼容IE
- // }
- // })
- function getUrlLanguage() {
- var val = location.search.match(new RegExp('[?&]lang=([^&]+)'));
- var language = val ? decodeURIComponent(val[1].replace(/\+/g, '%20')) : '';
- if (['en', 'zh-hant', 'zh-hans'].indexOf(language) < 0) return 'zh-hant';
- return language;
- }
- ;
- function injectLanguageJsSources(langKey) {
- var head = document.getElementsByTagName('head')[0]; // Retrieve and inject Ardublockly translations synchronously
- var appLangJsLoad = document.createElement('script');
- var request = createAjaxRequest();
- var appLangJdPath = "msg/".concat(langKey, ".js");
- try {
- request.open('GET', appLangJdPath, false);
- request.send('');
- appLangJsLoad.text = request.responseText;
- } catch (e) {
- // But still asynchronous lazy load so at least some text gets translated
- appLangJsLoad.src = appLangJdPath;
- }
- head.appendChild(appLangJsLoad); // Retrieve and inject Blockly translations asynchronously
- var blocklyLangJsLoad = document.createElement('script');
- blocklyLangJsLoad.src = "blockly/msg/js/".concat(langKey, ".js");
- head.appendChild(blocklyLangJsLoad);
- }
- ;
- function createAjaxRequest() {
- var request = false;
- try {
- // Firefox, Chrome, IE7+, Opera, Safari
- request = new XMLHttpRequest();
- } catch (e) {
- // IE6 and earlier
- try {
- request = new ActiveXObject('Msxml2.XMLHTTP');
- } catch (e) {
- try {
- request = new ActiveXObject('Microsoft.XMLHTTP');
- } catch (e) {
- throw 'Your browser does not support AJAX. You will not be able to' + 'use all of Ardublockly features.';
- request = null;
- }
- }
- }
- return request;
- }
- ;
- function updateLanguageText() {
- for (var textId in LOCALISED_TEXT) {
- var textStrings = document.getElementsByClassName("translate-".concat(textId));
- for (var _i = 0; _i < textStrings.length; _i++) {
- textStrings[_i].innerHTML = LOCALISED_TEXT[textId];
- }
- }
- }
- ;
- function clearBlocks() {
- var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () { };
- var length = Blockly.mainWorkspace.getAllBlocks(true).length;
- if (length < 2) {
- Blockly.mainWorkspace.clear();
- cb();
- } else {
- Blockly.confirm(Blockly.Msg.DELETE_ALL_BLOCKS.replace("%1", length), function (ok) {
- if (!ok) return;
- Blockly.mainWorkspace.clear();
- cb();
- });
- }
- }
- function addLibButton(lang) { } // const addLib = document.createElement("button");
- // addLib.className = "waves-effect waves-light btn blue";
- // let content = lang === 'zh-hans' ? "添加库" : lang === 'zh-hant' ? "添加庫" : "Add Library";
- // addLib.textContent = content;
- // addLib.style = `
- // position: absolute;
- // width: 88%;
- // bottom: 10px;
- // left: 50%;
- // transform: translateX(-50%);
- // `;
- // $(addLib).click(e =>
- // blockpy.components.dialog.show("Add Library", document.createElement("div")));
- // $(".blocklyToolboxDiv").append(addLib);
- // /**
- // * Save blocks into local storage. Note that MSIE 11 does not support
- // * LocalStorage on file:// URLs.
- // */
- // function saveLocalStorageBlocks() {
- // if (window.sessionStorage) {
- // var xml = blockpy.components.editor.getBlocksFromXml();
- // var text = Blockly.Xml.domToText(xml);
- // localStorage.setItem("blocks", text);
- // }
- // // blockpy.components.editor.getBlocksFromXml()
- // };
- // /** Load blocks saved on loacl storage and deletes them from storage. */
- // function loadLocalStorageBlocks() {
- // // try {
- // // var loadOnce = window.localStorage.loadOnceBlocks;
- // // } catch (e) {
- // // // Firefox sometimes throws a SecurityError when accessing sessionStorage.
- // // // Restarting Firefox fixes this, so it looks like a bug.
- // // var loadOnce = null;
- // // }
- // var loadBlocks = localStorage.getItem("blocks");
- // if (loadBlocks) {
- // var xml = Blockly.Xml.textToDom(loadBlocks);
- // blockpy.components.editor.setBlocksFromXml(xml);
- // localStorage.removeItem('blocks')
- // }
- // };
- var copyCodeClipboard;
- $(window).one("load", function () {
- // 判断从python blcokly 跳转过来是ai或者iot
- if (window.location.search.indexOf('name') > -1 || getLocalStorage("type") == 1) {
- $("#mode")[0].selectedIndex = 1;
- $("#mode")[0].onchange();
- $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
- selectmode($("#mode")[0], true);
- } else {
- $("#mode")[0].selectedIndex = 0;
- $("#mode")[0].onchange();
- $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
- selectmode($("#mode")[0], true);
- }
- $('#white-box').css('display', 'none');
- var _lang = getUrlLanguage();
- var copyCodeClipboard = new ClipboardJS(".copy_code", {
- text: function text() {
- return blockpy.components.editor.codeMirror.getValue(); // const codes = $(".CodeMirror-code pre");
- // let target = "";
- // for (let i = 0; i < codes.length; i++) {
- // let line = codes[i].textContent;
- // !(line.length === 1 && line.charCodeAt(0) === 8203) ? target += line : "";
- // i !== codes.length - 1 ? target += "\n" : "";
- // }
- // return target;
- }
- });
- copyCodeClipboard.on("success", function () {
- return copyCodeToast(2000);
- });
- var copyCodeToast = function (lang) {
- var toast = null,
- timeout = null;
- var content = lang === 'zh-hans' ? "复制成功" : lang === 'zh-hant' ? "複製成功" : "Copy Successfully";
- return function (ms) {
- if (toast) {
- toast.dismiss();
- clearTimeout(timeout);
- }
- toast = Materialize.toast(content, ms);
- timeout = setTimeout(function () {
- return toast = timeout = null;
- }, ms);
- };
- }(_lang);
- $("#delete-all").click(function () {
- return clearBlocks();
- });
- $("#screenshot").click(function () {
- return Blockly.captureDialog_();
- });
- $("#clearOutput").click(function () {
- return $(".blockpy-printer").html("");
- });
- $("#resetAll").click(function () {
- return clearBlocks(function () {
- return $(".blockpy-printer").html("");
- });
- });
- $("#lang-tool").click(function () {
- return $("#side-lang-trigger > a").dropdown('open');
- });
- $("#file-tool").click(function () {
- return $("#side-file-trigger > a").dropdown('open');
- });
- $("#blockpy-content > .blockpy-editor img.fullscreenIcon").click(function (e) {
- $(e.currentTarget.parentNode).toggleClass("fullscreen");
- $("#blockpy-content > .blockpy-editor img.fullscreenIcon").toggleClass("hidden");
- $("html").toggleClass("fullscreenMode");
- setTimeout(function () {
- Blockly.svgResize(blockpy.components.editor.blockly);
- Blockly.svgResize(Blockly.mainWorkspace);
- }, 100);
- });
- $("#blockpy-content .card-header > img.fullscreenIcon").click(function (e) {
- $(e.currentTarget.parentNode.parentNode).toggleClass("fullscreen");
- $("#blockpy-content .card-header > img.fullscreenIcon").toggleClass("hidden");
- $("html").toggleClass("fullscreenMode");
- setTimeout(function () {
- return $(".blockpy-toolbar > .blockpy-text").css("height", "90%").css("height", "100%");
- }, 0);
- }); // 提示全屏
- setTimeout(function () {
- if (document.body.clientWidth < 1265) {
- alert(CCB.str_group.alert);
- }
- }, 1000);
- });
- window.onbeforeunload = window.onunload = function () {
- if ($("#mode")[0].selectedIndex == 0) {
- saveLocalStorage("type", 0);
- saveLocalStorageBlocks("pythonmc-mode-blocks-xml");
- } else {
- saveLocalStorage("type", 1);
- saveLocalStorageBlocks("pythonai-mode-blocks-xml");
- }
- };
- window.onload = function () {
- var url = window.location.hash.substring(1); // if (url) {
- // document.getElementById('ipAddress').value = 'ws://' + url;
- // }
- $('.dropdown-trigger').dropdown();
- setTimeout(function () {
- return $('.modal').modal();
- }, 0);
- blockpy = new BlockPy({
- blocklyPath: "blockly/",
- attachmentPoint: document.getElementById("blockpy-div"),
- instructor: !getQueryParams()["instructor"] || getQueryParams()["instructor"] == "true",
- developer: true,
- editor: getQueryParams()["mode"] || "Split",
- urls: {}
- }); // ready();
- var size = calculate_size($("#term")[0]);
- term = new Terminal({
- cols: size[0],
- rows: size[1],
- useStyle: true,
- screenKeys: true,
- cursorBlink: false
- });
- term.open(document.getElementById("term")); //show_https_warning();
- $(".filled-in")[0].onclick = function () {
- var _chi = $(".filled-in")[0];
- var _par = $(".filled-in")[0].parentNode;
- if (!_chi.checked) {
- _par.children[1].className = 'filled-in_nocheked translatable_Adapter_fill_connected';
- _par.children[1].innerHTML = CCB.str_group.Adapter_fill_connected;
- } else {
- _par.children[1].className = 'translatable_Adapter_connected';
- _par.children[1].innerHTML = CCB.str_group.Adapter_connected;
- }
- ;
- };
- setTimeout(function () {
- cocoblockly();
- }, 0);
- $('.blockpy-toolbar-download').on("click", function () {
- return export_data(pythonnewcode || Blockly.Python.workspaceToCode(blockpy.components.editor.blockly) || blockpy.components.editor.codeMirror.getValue(), '.py', 0);
- });
- var uploadXmlButton = $('#pyFileImport > input');
- uploadXmlButton.change(function () {
- var fr = new FileReader();
- var files = uploadXmlButton[0].files;
- var file = files[0];
- fr.onload = function (e) {
- var pyInnerHTML = e.target.result;
- blockpy.components.editor.codeMirror.setValue(pyInnerHTML);
- };
- fr.readAsText(file);
- uploadXmlButton.val("");
- });
- $('.blockpy-toolbar-upload').click(function (e) {
- return $('#pyFileImport > input').click();
- });
- fanyi();
- selectOnload();
- styled();
- var iframe = document.createElement("iframe");
- iframe.src = '//project-x.cocorobo.cn/';
- iframe.style.width = "100%";
- iframe.style.height = "50vh";
- document.getElementById('iframe').appendChild(iframe); // $('#select_mode')[0].onchange = function(e){
- // var e = e.target;
- // selectmode(e.selectedIndex);
- // var _index = e.selectedIndex;
- // localStorage.setItem("ModeIndex",_index);
- //
- // }
- // var _index = localStorage.getItem("ModeIndex") != "undefined" ? localStorage.getItem("ModeIndex") : 0;
- // selectmode(parseInt(_index));
- // $('#select_mode')[0].selectedIndex = parseInt(_index);
- $('#toggle-button').click(function () {
- if ($('#toggle-button')[0].checked) {
- $('#edit')[0].style.display = 'none'; // $('.translatable_editing')[0].style.display = "none";
- // $('.translatable_close_editing')[0].style.display = "inline-block"
- } else {
- $('#edit')[0].style.display = 'block'; // $('.translatable_editing')[0].style.display = "inline-block";
- // $('.translatable_close_editing')[0].style.display = "none"
- }
- });
- };
- function styled() {
- if (window.location.search.indexOf("en") > -1) {
- $(".downbox-style").css({
- width: '280px',
- marginLeft: '-100px'
- });
- }
- }
- function fanyi() {
- $('.ModeSelect')[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_Example;
- $('.ModeBox')[0].children[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_Basics;
- $('.ModeBox ul')[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_sbcb;
- $('.ModeBox ul')[0].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_sbcsl;
- $('.ModeBox ul')[0].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_tacl;
- $('.ModeBox ul')[0].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_ba;
- $('.ModeBox ul')[0].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_desl;
- $('.ModeBox ul')[0].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_tdsl;
- $('.ModeBox ul')[0].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_ha;
- $('.ModeBox ul')[0].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_ssl;
- $('.ModeBox ul')[0].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_ldliv;
- $('.ModeBox ul')[0].children[9].innerHTML = Ardublockly.LOCALISED_TEXT.select_line;
- $('.ModeBox ul')[0].children[10].innerHTML = Ardublockly.LOCALISED_TEXT.select_bccs;
- $('.ModeBox')[0].children[1].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_imefc;
- $('.ModeBox ul')[1].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_uls;
- $('.ModeBox ul')[1].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_umdm;
- $('.ModeBox ul')[1].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_uoglls;
- $('.ModeBox ul')[1].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_auogsm;
- $('.ModeBox ul')[1].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_ctsotem;
- $('.ModeBox ul')[1].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_thwos;
- $('.ModeBox ul')[1].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_sdla;
- $('.ModeBox')[0].children[2].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_ionc;
- $('.ModeBox ul')[2].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_btsldtc;
- $('.ModeBox ul')[2].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_ktsedti;
- $('.ModeBox ul')[2].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_btoldalua;
- $('.ModeBox ul')[2].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_tsedtc;
- $('.ModeBox ul')[2].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_ewhadtnocd;
- $('.ModeBox ul')[2].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_ledss;
- $('.ModeBox ul')[2].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_ledac;
- $('.ModeBox ul')[2].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_ctwn;
- $('.ModeBox ul')[2].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_bssbms;
- $('.ModeBox ul')[2].children[9].innerHTML = Ardublockly.LOCALISED_TEXT.select_bsrbmc;
- $('.ModeBox ul')[2].children[10].innerHTML = Ardublockly.LOCALISED_TEXT.select_wrcbms;
- $('.ModeBox ul')[2].children[11].innerHTML = Ardublockly.LOCALISED_TEXT.select_wrcbmr;
- $('.ModeBox ul')[2].children[12].innerHTML = Ardublockly.LOCALISED_TEXT.select_snt;
- $('.ModeBox')[0].children[3].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_smmlc;
- $('.ModeBox ul')[3].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_gcaerhk;
- $('.ModeBox ul')[3].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_fr;
- $('.ModeBox ul')[3].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_or;
- $('.ModeBox ul')[3].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_mhdr;
- $('.ModeBox')[0].children[4].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_ambc;
- $('.ModeBox ul')[4].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_bcsc;
- $('.ModeBox ul')[4].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_kcpccs;
- $('.ModeBox ul')[4].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_kcpficc;
- $('.ModeBox ul')[4].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_bccs;
- $('.ModeBox ul')[4].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_mc;
- $('.ModeBox ul')[4].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_sor;
- $('.ModeBox ul')[4].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_sdla;
- $('.ModeBox')[0].children[5].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_amefc;
- $('.ModeBox ul')[5].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_auls;
- $('.ModeBox ul')[5].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_aumdm;
- $('.ModeBox ul')[5].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_auogsm;
- $('.ModeBox ul')[5].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_actsotem;
- $('.ModeBox')[0].children[6].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_amvc;
- $('.ModeBox ul')[6].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_bctbotci;
- $('.ModeBox ul')[6].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_aca;
- $('.ModeBox ul')[6].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_rqc;
- $('.ModeBox ul')[6].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_lhbl;
- $('.ModeBox ul')[6].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_fgr;
- $('.ModeBox ul')[6].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_fgaat;
- $('.ModeBox')[0].children[7].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_av;
- $('.ModeBox ul')[7].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.paly_video;
- $('.ModeBox ul')[7].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.paly_music;
- $('.ModeBox ul')[7].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.recording_camera;
- $('.ModeBox ul')[7].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.microphone_sound_analysis;
- $('.ModeBox')[0].children[8].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_teacher;
- $('.ModeBox ul')[8].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_thw;
- $('.ModeBox ul')[8].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_thwos;
- $('.ModeBox ul')[8].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_uoc;
- $('.ModeBox ul')[8].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_mc;
- $('.ModeBox ul')[8].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_sor; // $('.ModeBox ul')[3].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_Mandarin;
- // $('.ModeBox ul')[3].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_English;
- // $('.ModeBox ul')[3].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_Cantonese;
- // $('#uploadFiles')[0].innerHTML = Ardublockly.LOCALISED_TEXT.uploadFiles;
- $("#sketch_name")[0].value = Ardublockly.LOCALISED_TEXT.sketch_name; // $('#runCode')[0].innerHTML = Ardublockly.LOCALISED_TEXT.runCode;
- // $('#uploadFiles')[0].innerHTML = Ardublockly.LOCALISED_TEXT.uploadFiles;
- $('#resetDevice')[0].innerHTML = Ardublockly.LOCALISED_TEXT.resetDevice;
- $('#select_dropdown')[0].value = Ardublockly.LOCALISED_TEXT.select_dropdown;
- $('#iot_modules')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
- $(".qiehuanbtn")[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.a_csm;
- $("#localsssssaveOrOpen")[0].children[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.a_butvmi;
- $("#localsssssaveOrOpen")[0].children[1].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.a_buartlp;
- $("#Serial_Interaction")[0].innerHTML = Ardublockly.LOCALISED_TEXT.Serial_Interaction;
- }
- function selectOnload() {
- $('.select-connected')[0].onchange = function () {
- var a = $('.select-connected')[0].selectedIndex;
- if ($('#runCode')[0].innerHTML == CCB.str_group.uploading) {
- if (a == 0) {
- $('.select-connected')[0].selectedIndex = 1;
- return null;
- } else {
- $('.select-connected')[0].selectedIndex = 0;
- return null;
- }
- }
- if (a == 0) {
- $('.btn-network')[0].className = 'row btn-network';
- $('.btn-network')[1].className = 'row btn-network hidden';
- } else {
- $('.btn-network')[1].className = 'row btn-network';
- $('.btn-network')[0].className = 'row btn-network hidden';
- }
- };
- $('.selectMode_input')[0].onclick = function (e) {
- $('.MouduleBox')[0].style.cssText = 'display:block';
- };
- $('.ModeSelectBox')[0].onclick = function (e) {
- U.UF.EV.stopBubble();
- $('.ModeSelect')[0].className = 'ModeSelect active';
- };
- likeclose($('.selectMode_input')[0], $('.MouduleBox')[0], '', '');
- likeclose($('.ModeSelect')[0].children[0], $('.ModeSelect')[0], 1, 'ModeSelect');
- likeclose($('#bar_ai img')[0], $('.MouduleBox')[1], '', '');
- likeclose($('#bar_t img')[0], $('#ai_tt')[0], '', '');
- var MChild = $('.MouduleBox')[0].children;
- var tchild = $('.MouduleBox')[1].children;
- for (var i = 0; i < MChild.length; i++) {
- tchild[i].onclick = MChild[i].onclick = function (e) {
- window.event ? window.event.cancelBubble = true : e.stopPropagation();
- var e = e.target;
- if (e.parentElement.children[2] && e.parentElement.children[2].children.length > 0) { } else {
- if (e.innerHTML == Ardublockly.LOCALISED_TEXT.iot_module) {
- $("#mode")[0].selectedIndex = 0;
- $("#mode")[0].onchange();
- $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
- } else if (e.innerHTML == Ardublockly.LOCALISED_TEXT.ai_module) {
- $("#mode")[0].selectedIndex = 1;
- $("#mode")[0].onchange();
- $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
- }
- $('.MouduleBox')[0].style.display = 'none';
- $('.MouduleBox')[1].style.display = 'none';
- $('#ai_tt')[0].style.display = 'none';
- }
- };
- }
- for (var i = 0; i < $('.ModeBox')[0].children.length; i++) {
- $('.ModeBox')[0].children[i].onclick = function (e) {
- window.event ? window.event.cancelBubble = true : e.stopPropagation();
- };
- } // "AI/云端语音识别 (普通话).txt", "AI/云端语音识别 (英文).txt", "AI/云端语音识别 (粤语).txt"
- 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 = [
- // ["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"],
- // ["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"],
- // ["AI/迷你照相機.xml", "AI/LCD 按鈕控制時針轉動.xml", "AI/LCD 按鈕控制顏色切換.xml", "AI/LCD 繪製圖形動畫.xml", "AI/屏幕圖片裁剪.xml", "AI/屏幕圖案旋轉.xml", "AI/按鍵改變圖片至反色.xml", "AI/按鍵改變圖片顏色模式.xml", "AI/按鍵改變圖片尺寸.xml"],
- // ["AI/二维码识别.xml", "AI/视觉循迹(黑线).xml", "AI/寻找绿色区域并追踪.xml", "AI/区域颜色分析.xml", "AI/寻找绿色的圆形.xml", "AI/按鍵改變相機顏色模式.xml", "AI/按鍵改變相機圖像的亮度.xml"],
- // ["AI/手写数字识别.xml", "AI/人脸检测.xml", "AI/物体识别.xml", "AI/hktrashclassification_9classes.xml"],
- // ["AI/麦克风分析声音频谱.xml", "AI/播放音频文件.xml", "AI/播放影片档案.xml", "AI/录制摄像头画面.xml"]
- // ];
- for (var i = 0; i < $('.HarxA').length; i++) {
- for (var j = 0; j < $('.HarxA')[i].children.length; j++) {
- if ($('.HarxA').length - 1 == i) {
- ai_tt.children[j].innerHTML = (_arr[i][j].split(".")[1] == "xml" ? "<span style='color:#00FF7F'>[" + "xml" + "]  </span>" : "<span style='color:#FF7F00'>[" + "py" + "]  </span>") + $('.HarxA')[i].children[j].innerHTML;
- ai_tt.children[j].onclick = function (i, j) {
- return function () {
- if (_arr[i][j].split("/")[0] == "Main") {
- $("#mode")[0].selectedIndex = 0;
- $("#mode")[0].onchange();
- $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
- } else {
- $("#mode")[0].selectedIndex = 1;
- $("#mode")[0].onchange();
- $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
- }
- $('.ModeSelect')[0].className = 'ModeSelect';
- readTxt("/src/python/" + _arr[i][j], function (txt) {
- if (_arr[i][j].split(".")[1] == "xml") {
- var xmlfile = Blockly.Xml.textToDom(txt);
- blockpy.components.editor.setBlocksFromXml(xmlfile);
- } else {
- blockpy.components.editor.codeMirror.setValue(txt);
- }
- });
- };
- }(i, j);
- }
- $('.HarxA')[i].children[j].innerHTML = (_arr[i][j].split(".")[1] == "xml" ? "<span style='color:#00FF7F'>[" + "xml" + "]  </span>" : "<span style='color:#FF7F00'>[" + "py" + "]  </span>") + $('.HarxA')[i].children[j].innerHTML;
- $('.HarxA')[i].children[j].onclick = function (i, j) {
- return function () {
- if (_arr[i][j].split("/")[0] == "Main") {
- $("#mode")[0].selectedIndex = 0;
- $("#mode")[0].onchange();
- $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
- } else {
- $("#mode")[0].selectedIndex = 1;
- $("#mode")[0].onchange();
- $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
- }
- $('.ModeSelect')[0].className = 'ModeSelect';
- readTxt("/src/python/" + _arr[i][j], function (txt) {
- if (_arr[i][j].split(".")[1] == "xml") {
- var xmlfile = Blockly.Xml.textToDom(txt);
- blockpy.components.editor.setBlocksFromXml(xmlfile);
- } else {
- blockpy.components.editor.codeMirror.setValue(txt);
- }
- });
- };
- }(i, j);
- }
- }
- $('.qiehuanbtn')[0].onclick = function (e) {
- if (!(CCB.socket && CCB.socket.id)) {
- return;
- }
- U.UF.EV.stopBubble();
- if (Ardublockly.LANG == "en") {
- $('#localsssssaveOrOpen')[0].className = 'dropdown-content qiehuan qiehuanposi';
- } else {
- $('#localsssssaveOrOpen')[0].className = 'dropdown-content qiehuan';
- }
- };
- var _aqieM = $("#localsssssaveOrOpen")[0].children;
- for (var i = 0; i < _aqieM.length; i++) {
- $("#localsssssaveOrOpen")[0].children[i].addEventListener('click', function () {
- window.event ? window.event.cancelBubble = false : e.stopPropagation();
- var e = this;
- $('#runCuploadFilesode')[0].innerHTML = e.children[0].innerHTML;
- }); // $("#localsssssaveOrOpen")[0].children[i].children[0].onclick = function (e) {
- // window.event ? window.event.cancelBubble = true : e.stopPropagation()
- // }
- }
- qiehuanjjj($('.qiehuanbtn')[0], $('#localsssssaveOrOpen')[0]);
- $(".switch_box1")[0].onclick = switchCC;
- $(".switch_box")[0].onclick = switchCC;
- $("#repl_delete")[0].onclick = function () {
- $("#repl_box_content")[0].innerHTML = "";
- };
- }
- function switchCC(e) {
- var e = e.target || e;
- var flag = true;
- var pythonbox = $("#python_box")[0];
- var replbox = $("#repl_box")[0];
- var repl_delete = $("#repl_delete")[0];
- if (e.className.indexOf("switch_select") != -1) {
- return;
- } else {
- var switch_select = $(".switch_select")[0];
- switch_select.className = switch_select.className.replace(" switch_select", "");
- e.className += " switch_select";
- if (e.className.indexOf("switch_box1") != -1) {
- pythonbox.className = "card-content hidden";
- replbox.className = "card-content";
- repl_delete.style.display = "block";
- } else {
- pythonbox.className = "card-content";
- replbox.className = "card-content hidden";
- repl_delete.style.display = "none";
- }
- }
- }
- function readTxt(url, fun) {
- var xhr = new XMLHttpRequest();
- xhr.open('get', url, true);
- xhr.send();
- xhr.onreadystatechange = function () {
- if (xhr.readyState == 4 && xhr.status == 200) {
- fun(xhr.responseText);
- }
- };
- }
- function qiehuanjjj(ele, _container) {
- $("body")[0].addEventListener('click', function (e) {
- if (ele != e.target) {
- _container.className = 'dropdown-content';
- }
- });
- }
- function likeclose(ele, _container, type, _className) {
- $("body")[0].addEventListener('click', function (e) {
- if (ele != e.target) {
- if (type == 1) {
- _container.className = _className;
- } else {
- _container.style.display = 'none';
- }
- }
- });
- }
- function export_data(data, postfix, is_firefox) {
- var url = new Blob([data], {
- type: 'text/plain'
- });
- var download_link = URL.createObjectURL(url);
- var a = document.createElement('a');
- a.style = "display:none";
- a.href = download_link;
- a.download = ($(".sketch_name").val() || "cocorobo") + postfix;
- if (is_firefox) {
- document.body.appendChild(a);
- a.click();
- setTimeout(function () {
- return document.body.removeChild(a);
- }, 100);
- } else a.click(); // URL.revokeObjectURL(download_link);
- // IE edge need a short delay before revoke virtual download link
- setTimeout(function () {
- return URL.revokeObjectURL(download_link);
- }, 100);
- } // 积木生成
- function selectmode(sel, isload) {
- var _type = getLocalStorage("type");
- if (sel.selectedIndex == 0 && (_type != 0 || isload === true)) {
- saveLocalStorageBlocks("pythonai-mode-blocks-xml");
- saveLocalStorage("type", 0);
- blockpy.setAssignment( // settings
- {}, // assignment
- {
- modules: {
- 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"],
- removed: ['A.I.Board']
- }
- }, // programs
- {
- __main__: ""
- });
- loadLocalStorageBlocks("pythonmc-mode-blocks-xml");
- } else if (sel.selectedIndex == 1 && (_type != 1 || isload === true)) {
- saveLocalStorageBlocks("pythonmc-mode-blocks-xml");
- saveLocalStorage("type", 1);
- blockpy.setAssignment( // settings
- {}, // assignment
- {
- modules: {
- 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"],
- removed: ['MainBoard']
- }
- }, // programs
- {
- __main__: ""
- });
- loadLocalStorageBlocks("pythonai-mode-blocks-xml");
- }
- }
- function getQueryParams() {
- try {
- url = window.location.href;
- query_str = url.substr(url.indexOf("?") + 1, url.length - 1);
- r_params = query_str.split("&");
- params = {};
- for (i in r_params) {
- param = r_params[i].split("=");
- params[param[0]] = param[1];
- }
- return params;
- } catch (e) {
- return {};
- }
- } // onresize 多次执行解决办法
- var debounce = function debounce(func, threshold, execAsap) {
- var timeout;
- return function debounced() {
- var obj = this,
- args = arguments;
- function delayed() {
- if (!execAsap) func.apply(obj, args);
- timeout = null;
- }
- ;
- if (timeout) clearTimeout(timeout); else if (execAsap) func.apply(obj, args);
- timeout = setTimeout(delayed, threshold || 100);
- };
- };
- window.onresize = debounce(function () {
- if (document.body.clientWidth < 1265) {
- alert(CCB.str_group.alert);
- }
- }, 100, true);
|