Advertisement
Talilo

Ace Editor Lib v.6.0.html

Feb 23rd, 2023 (edited)
675
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 11.25 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="pt-br">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>VS Code - IDE Online</title>
  8.     <link rel="icon" type="image/png" sizes="32x32" href="https://cdn.iconscout.com/icon/free/png-256/vscode-4069952-3365471.png">
  9.     <link rel="stylesheet" href="style.css">
  10.     <link rel="preconnect" href="https://fonts.googleapis.com">
  11.     <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  12.     <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap" rel="stylesheet">
  13.  
  14.     <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.6/ace.js"></script>
  15.     <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.6/ext-beautify.js"></script>
  16.     <style>
  17.         body {font-family: 'Roboto', sans-serif;
  18.             background-color:#323050;
  19.             color: white;
  20.         }
  21.        
  22.         #editor {
  23.           position: relative;
  24.           width: 93vw;
  25.           height: 85vh;
  26.         }
  27.  
  28.         #exportar {
  29.         border: solid gray 2px;
  30.         border-radius: 5px;
  31.         position:absolute;
  32.         width: 800px;
  33.         height: 255px;
  34.         top: 70px;
  35.         left: 450px;
  36.         background-color: #f1f0f2;
  37.         padding: 20px;
  38.        
  39.         }
  40.        
  41.         #fecha_exportar {
  42.         display:none}
  43.        
  44.         .nome_baixar_arq{
  45.         display: block;
  46.         color: #0d0d0d;
  47.         font-size: 20px;
  48.         cursor: pointer;
  49.         }
  50.         .nome_baixar_arquivo{
  51.          display: block;
  52.         color: #0d0d0d;
  53.         font-size: 20px;
  54.        
  55.        
  56.         }
  57.         .head{
  58.         display:flex;
  59.         justify-content: space-between;
  60.         align-items: center;
  61.         }
  62.        
  63.         .campo_nome_u{
  64.         display:flex;
  65.         justify-content: start;
  66.         align-items: center;
  67.         }
  68.         #nome_arquivo{
  69.         width: 40vw;
  70.         height: 25px;
  71.         padding: 5px;
  72.         margin: 10px;
  73.         }
  74.        
  75.         #salvar_final{
  76.         background-color:#007fff;
  77.         font-size: 18px;
  78.         color: white;
  79.         border: none;
  80.         cursor: pointer;
  81.         border-radius: 2px;
  82.         }
  83.        
  84.         #contener{
  85.         display:flex;
  86.         padding: 5px;
  87.         }
  88.        
  89.         #menu_vscode{
  90.         display:flex;
  91.         flex-direction: column;
  92.         max-height: 94vh;
  93.         justify-content: space-between;
  94.         align-items: center;
  95.        
  96.         }
  97.         .logo > i {
  98.         font-size: 30px;
  99.         padding:5px;
  100.         color: gray;
  101.         trasition: 0.5;
  102.         margin:10px 15px;
  103.         }
  104.        
  105.         .logo > img{
  106.         width: 25px;
  107.         margin: 20px 15px;
  108.         }
  109.        
  110.         .logo > i:hover{
  111.         color: #007fff;
  112.         cursor: pointer;
  113.         }
  114.         .barra_menus > ul{
  115.         display:flex;
  116.         list-style-type: none;
  117.         padding: 0 0px;
  118.         cursor: pointer;
  119.         }
  120.        
  121.         .barra_menus > ul > li{
  122.         padding: 0 20px;
  123.         font-size: 25px:
  124.         font-weight:300;
  125.         }
  126.        
  127.         li{font-size: 20px;
  128.         font-weight:300;
  129.         }
  130.        
  131.         .barra_menus > ul > li:hover{
  132.         color: #007fff;
  133.         font-size: 20px;
  134.         font-weight:300;
  135.         }
  136.        
  137.         .footer{
  138.         padding: 0 20px;
  139.         }
  140.        
  141.         .footer > button, #homebtn2{
  142.         background-color:#007fff;
  143.         font-size: 18px;
  144.         color: white;
  145.         border: none;
  146.         cursor: pointer;
  147.         border-radius: 0px;
  148.         margin: 5px;
  149.         }
  150.        
  151.         .footer > button > a, #homebtn2{
  152.         text-decoration: none;
  153.         color: #fff;
  154.         cursor: pointer;
  155.         }
  156.         .abrir{
  157.         display: inline;
  158.         }
  159.        
  160.     </style>
  161. </head>
  162. <body>
  163.         <div id="contener">
  164.             <!--MENU LATERAL VS CODE-->
  165.             <div id="menu_vscode">
  166.                 <div>
  167.                         <div class="logo">
  168.                         <img src="https://cdn.iconscout.com/icon/free/png-256/vscode-4069952-3365471.png">
  169.                         </div>
  170.                         <div class="logo">
  171.                         <i class="fas fa-copy"></i>
  172.                     </div>
  173.                         <div class="logo">
  174.                         <i class="fas fa-magnifying-glass"></i>
  175.                         </div>
  176.                     <div class="logo">
  177.                     <i class="fas fa-regular fa-code-fork"></i>
  178.                     </div>
  179.                     <div class="logo">
  180.                     <i class="fas fa-regular fa-bug"></i>
  181.                     </div>
  182.                    
  183.                     <div class="logo">
  184.                     <i class="fas fa-brands fa-github"></i>
  185.                     </div>
  186.                 </div>
  187.                 <div>
  188.                     <div class="logo">
  189.                     <i class="fas fa-regular fa-user-large"></i>
  190.                     </div>
  191.                     <div class="logo" >
  192.                     <i class="fas fa-regular fa-gear"></i>
  193.                     </div>
  194.                 </div>
  195.         </div>
  196.         <!--header e textarea do codigo-->
  197.         <div id="editor_full">
  198.     <div class="barra_menus">
  199.         <ul>
  200.             <li id="salvar_exporte">Salvar</li>
  201.             <li>Exportar</li>
  202.             <li>Editar</li>
  203.             <li>Terminal</li>
  204.             <li>Ajuda</li>
  205.         </ul>
  206.         </div>
  207.     <div id="editor">
  208.    
  209.     </div>
  210.     <div class="footer">
  211.       <button><a href="../">Voltar</a></button>
  212.       <input type="button" id="homebtn2" onclick="window.location.href = 'index.html';" value="Home">
  213.       <button id="formatar">Formatar</button>
  214.       <button id="button">salvar</button>
  215.       <label class="abrir">Abrir:</label>
  216.       <input type="file" id="openbtn" onchange="openCode(this.files)" value="Open">
  217.         <label class="abrir">Tema:</label>
  218.        <select id="menu_tema" onChange="mudaTemas()">
  219.        <option value="dracula">Dracula</option>
  220.         <option value="tomorrow_night">Tema Dark</option>
  221.         <option value="github">Tema claro</option>
  222.         <option value="vibrant_ink">Dark City</option>
  223.         <option value="terminal">Terminal</option>
  224.   </select>
  225.    <label class="abrir">Linguagem:</label>
  226.    <select id="menu_linguage" onChange="mudaLinguagem()">
  227.        <option value="javascript">Javascrip</option>
  228.         <option value="css">CSS</option>
  229.         <option value="html">html</option>
  230.         <option value="c">C</option>
  231.         </select>
  232.         <!--Selecionar tamanho da fonte-->
  233.       <label class="abrir">Fonte:</label>
  234.    <select id="menu_fonte" onChange="mudaFonte()">
  235.        <option value="18px">18px</option>
  236.         <option value="20px">20px</option>
  237.         <option value="22px">22px</option>
  238.         <option value="24px">24px</option>
  239.         </select>
  240.               <label class="abrir">Fundo:</label>
  241.    <select id="menu_fundo" onChange="mudaFundo()">
  242.         <option value="#282A36">LightViolet</option>
  243.        <option value="#333333">Cinza</option>
  244.         <option value="#323050">NightViolet</option>
  245.         <option value="#1E1E1E">Black</option>
  246.         </select>
  247.     </div>
  248.     </div>
  249.    
  250.     </div>
  251.  
  252.     <!-- conteudo para exportar e salva o codigo -->  
  253.       <div id="fecha_exportar">
  254.       <div class="head">   
  255.       <div class="nome_baixar_arquivo"><i class="fas fa-floppy-disk"></i> Salvar</div>
  256.       <div id="xxx" class="nome_baixar_arq"><i class="fas fa-square-xmark"></i>
  257.        </div>
  258.        </div>
  259.        <div class="campo_nome_u">
  260.       <p class="nome_baixar_arquivo">Nome do Arquivo:
  261.        </p>
  262.       <input id="nome_arquivo" value="index.html" type="text" alt="Informe o nome do arquivo e o tipo, Ex.: index.html" required></input>
  263.       </div>
  264.       <p class="nome_baixar_arquivo">Informe o nome do arquivo e o tipo.<b>Ex.: index.html, index.css ou index.js</b></p>
  265.       <button id="salvar_final">Salvar</button>
  266.       </div>
  267.      
  268. </body>
  269. <script>
  270. //INFORMAÇÕES:
  271. //Link Ace Editor para emplementar no projeto:
  272. //https://ace.c9.io/
  273. //Temas para editor:
  274. //https://gist.github.com/RyanNutt/cb8d60997d97905f0b2aea6c3b5c8ee0
  275. //https://pt.stackoverflow.com/questions/418443/textarea-semelhante-a-um-editor-de-texto-ex-  
  276.  
  277. //Editor de texto Ace Edito for VS Code
  278.  
  279. var editor = ace.edit("editor");
  280. //MUDAR TAMANHO DA FONTE
  281.     document.getElementById('editor').style.fontSize = '18px';
  282.    
  283.     function mudaFonte() {
  284.     var menu = document.getElementById("menu_fonte");
  285.     var fonte = menu.options[menu.selectedIndex].value;
  286.     var linkFonte = fonte;
  287.     return document.getElementById('editor').style.fontSize = linkFonte;
  288.     }
  289.     mudaFonte();
  290.    
  291.     editor.setTheme("ace/theme/dracula");
  292.    
  293.  //MUDAR TEMAS  
  294.     editor.setTheme("ace/theme/dracula");
  295.    
  296.     function mudaTemas() {
  297.     var menu = document.getElementById("menu_tema");
  298.     var cor = menu.options[menu.selectedIndex].value;
  299.     var link = `ace/theme/${cor}`;
  300.     return editor.setTheme(link);
  301.     console.log(link)
  302.     }
  303.     mudaTemas();
  304.     //MUDAR FUNDO
  305.     function mudaFundo() {
  306.     var menu = document.getElementById("menu_fundo");
  307.     var fundoCor = menu.options[menu.selectedIndex].value;
  308.     console.log(fundoCor);
  309.     document.body.style.backgroundColor = fundoCor;
  310.    
  311.     }
  312.      mudaFundo();
  313.  //MUDAR LIGUAGEM
  314.     editor.session.setMode("ace/mode/javascript");
  315.     function mudaLinguagem() {
  316.     var menu = document.getElementById("menu_linguage");
  317.     var lingua = menu.options[menu.selectedIndex].value;
  318.     var linkLing = `ace/mode/${lingua}`;
  319.     return editor.session.setMode(linkLing);
  320.     console.log(linkLing)
  321.     }
  322.     mudaLinguagem();
  323.    
  324.     editor.session.setTabSize(4);
  325.    
  326.     editor.setOptions({
  327.       autoScrollEditorIntoView: true,
  328.       copyWithEmptySelection: true,
  329.     });
  330.    
  331.     setTimeout(() => {
  332.       var beautify = ace.require("ace/ext/beautify"); // get reference to extension
  333.       beautify.beautify(editor.session);
  334.     }, 500);
  335.    
  336.     //beautify.beautify(editor.session);
  337.     document.getElementById("formatar").onclick = function() {
  338.       var beautify = ace.require("ace/ext/beautify"); // get reference to extension
  339.       beautify.beautify(editor.session);
  340.      
  341.     }
  342.    
  343.       //Salvar arquivo
  344.       function download(content, fileName, contentType) {
  345.           var a = document.createElement("a");
  346.           var file = new Blob([content], {type: contentType + encodeURIComponent(content)});
  347.           a.href = URL.createObjectURL(file);
  348.           a.download = fileName;
  349.           a.click();
  350.         }
  351.        
  352.         //Nome do arquivo na entrada
  353.         //var nomeFile = document.getElementById("nome_arquivo").value;
  354.         //Função para biaxar o arquivo
  355.         var textoSave = editor.getValue();
  356.        
  357.         var button = document.getElementById("salvar_final");
  358.  
  359.     button.addEventListener("click", function() {
  360.     var textoSave = editor.getValue();
  361.     if(document.getElementById("nome_arquivo").value !== ""){
  362.       if( confirm("Deseja salvar o Codigo?")){
  363.       var content =  textoSave;
  364.       var fileName = document.getElementById("nome_arquivo").value;
  365.       var contentType = "text/html";
  366.       download(content, fileName, contentType);
  367.     }else{alert("Cancelado!")}
  368.     }else{alert("Informe o nome do arquivo e o tipo, Ex.: index.html")}});
  369.    
  370.     // Ativar pagina oculta para salvar arquivo
  371.  
  372.     var buttonFecha = document.getElementById("xxx");
  373.    
  374.    
  375.     buttonFecha.addEventListener("click", function(){
  376.     console.log("cliclou");
  377.     if(confirm("deseja sair sem salvar?")){var telaExporte = document.getElementById("exportar");
  378.     telaExporte.setAttribute("id", "fecha_exportar");
  379.    
  380.     }})
  381.    
  382.     var buttonSalvaEx = document.getElementById("salvar_exporte");
  383.    
  384.     buttonSalvaEx.addEventListener("click", function(){
  385.     console.log("cliclou");
  386.     var telaSalvaExporte = document.getElementById("fecha_exportar");
  387.     telaSalvaExporte.setAttribute("id", "exportar");
  388.    
  389.     })
  390.  //Open file in Ace editor
  391.  //https://stackoverflow.com/questions/59004560/how-can-i-open-a-file-into-ace-text-editor
  392.  
  393.   function openCode(files) {
  394.                 var file = files[0]
  395.                 if (!file) return;
  396.                 var modelist = ace.require("ace/ext/modelist")
  397.                 var modeName = modelist.getModeForPath(file.name).mode
  398.                 editor.session.setMode(modeName)
  399.                 reader = new FileReader();
  400.                 reader.onload = function() {
  401.                     editor.session.setValue(reader.result)
  402.                 }  
  403.                 reader.readAsText(file)
  404.             }
  405.  
  406.     </script>
  407.    
  408.     <script src="https://kit.fontawesome.com/32a7e6bf5d.js" crossorigin="anonymous"></script>
  409.    
  410.     <script src="http://ajaxorg.github.io/ace-builds/src/ext-modelist.js" type="text/javascript" charset="utf-8"></script>
  411.         <script>
  412. </html>
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement