Skip to content

Commit

Permalink
Merge pull request #152 from Stivo182/feature/connector-http
Browse files Browse the repository at this point in the history
Конвертация при изменении селектора, восстановление дефолтного результата
  • Loading branch information
alei1180 authored Jan 21, 2025
2 parents 3b8f484 + 32b35bd commit a7de2de
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions src/interface/view/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,23 @@
import { createHighlighterCore } from '/static/shiki/core.js';
import { createOnigurumaEngine } from '/static/shiki/engine/oniguruma.js';

let outputText = 'Соединение = Новый HTTPСоединение("example.com", 80);\n'
+ 'HTTPЗапрос = Новый HTTPЗапрос("/");\n\n'
+ 'HTTPОтвет = Соединение.ВызватьHTTPМетод("GET", HTTPЗапрос);';
let defaultOutputs = {
'1c':
'Соединение = Новый HTTPСоединение("example.com", 80);\n'
+ 'HTTPЗапрос = Новый HTTPЗапрос("/");\n\n'
+ 'HTTPОтвет = Соединение.ВызватьHTTPМетод("GET", HTTPЗапрос);',
'connector':
'Результат = КоннекторHTTP.Get("http://example.com")'
};

let outputText = "";
let convertButton = document.getElementById("convert");
let convertInput = document.getElementById("command");

function convert(command, lang) {
function convert() {
let command = getCommand();
let lang = getLang();

if (!isAllowedRequests()) return;
hideErrors();

Expand Down Expand Up @@ -421,7 +431,7 @@
}

function getLang() {
let radios = document.getElementsByName('syntax');
let radios = document.getElementsByName('lang');

for (let i = 0; i < radios.length; i++) {
if (radios[i].checked) {
Expand All @@ -433,28 +443,42 @@
}

convertButton.addEventListener("click", function (e) {
let command = getCommand();
let lang = getLang();
convert(command, lang);
convert();
});

document.getElementById("copy").addEventListener("click", function (e) {
copyToClipboard(outputText);
});

convertInput.addEventListener("input", function (e) {
if(!getCommand()) {
setOutput(defaultOutputs[getLang()]);
}
})

document.addEventListener("keyup", function (e) {
if (e.keyCode == 13 && e.ctrlKey) {
convertButton.click();
}
});

document.getElementsByName("lang").forEach(function(e) {
e.addEventListener("change", function(e) {
if(getCommand()) {
convert();
} else {
setOutput(defaultOutputs[getLang()]);
}
});
});

const highlighter = await createHighlighterCore({
themes: [theme],
langs: [lang],
engine: createOnigurumaEngine(import('/static/shiki/wasm.js'))
});

setOutput(outputText);
setOutput(defaultOutputs[getLang()]);
enableRequests();
</script>
</head>
Expand All @@ -479,12 +503,12 @@
ontouchend="this.classList.remove('hoveredbutton')">
<div class="checkboxgroup" style="">
<div class="singlecheckbox">
<input type="radio" id="onec" name="syntax" value="1c"
<input type="radio" id="onec" name="lang" value="1c"
checked="checked" />
<label for="onec"></label>
</div>
<div class="singlecheckbox last">
<input type="radio" id="connector" name="syntax" value="connector" />
<input type="radio" id="connector" name="lang" value="connector" />
<label for="connector">Connector</label>
</div>
</div>
Expand Down

0 comments on commit a7de2de

Please sign in to comment.