This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
FunctionProject/scripts/execute-function/convertEncoding_DOM.js

25 lines
1.4 KiB
JavaScript
Raw Normal View History

import { decimalToBinary, binaryToDecimal, decimalToHexadecimal, hexadecimalToDecimal, binaryToHexadecimal, hexadecimalToBinary, textToNumberUnicode, numberUnicodeToText, textToBinary, binaryToText, textToHexadecimal, hexadecimalToText } from '../functions/fonctions_principales/convertEncoding_Functions.js';
import { isEmptyValue } from '../functions/fonctions_annexes/isEmptyValue_Function.js';
$(function () {
$("#convertEncodingForm").submit((event) => {
event.preventDefault();
const value = $('#value').val();
const option = $("#option option:selected").val();
if(isEmptyValue(value)) {
$('.results').html(messageError);
}
else {
// Objet qui recense toutes les fonctions de convertEncoding
const convertEncoding = { decimalToBinary, binaryToDecimal, decimalToHexadecimal, hexadecimalToDecimal, binaryToHexadecimal, hexadecimalToBinary, textToNumberUnicode, numberUnicodeToText, textToBinary, binaryToText, textToHexadecimal, hexadecimalToText };
try {
function executionFunction(option, value) {
return convertEncoding[option](value);
}
$('.results').html(executionFunction(option, value));
} catch (error) {
$('.results').html(messageError);
}
}
});
});