From 9b16504485a14b477aa00ae33a43d91e7e4ce9e6 Mon Sep 17 00:00:00 2001 From: Simone <26844016+simonebortolin@users.noreply.github.com> Date: Fri, 30 Dec 2022 17:54:00 +0100 Subject: Streamlining of customisations: migration of numerous functionalities to the JTD fork and add new functionalities implemented by JTD fork (#75) * use form validation by jdt * migrate theme-switch to new version of jtd * Use new feature of jdt * streamlining of customisations: migrate, aux button, modal and theme switch to fork JTD * fix * fix Co-authored-by: Simone Bortolin --- _tools/ascii-hex.md | 53 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 18 deletions(-) (limited to '_tools/ascii-hex.md') diff --git a/_tools/ascii-hex.md b/_tools/ascii-hex.md index 42d4311..ef0d8ef 100644 --- a/_tools/ascii-hex.md +++ b/_tools/ascii-hex.md @@ -7,10 +7,13 @@ layout: default ---

ASCII To Hex

-
+
- + +
+ Please provide a valid input text. +
@@ -25,10 +28,13 @@ layout: default

Hex To ASCII

-
+
- + +
+ Please provide a valid input text. +
@@ -53,24 +59,35 @@ layout: default var asciiToHexForm = document.getElementById('ascii-to-hex'); asciiToHexForm.addEventListener('submit',(event) => { - event.preventDefault(); - var fomrdata = new FormData(asciiToHexForm); - var str = fomrdata.get('ascii-to-hex'); - var glue = fomrdata.get('ascii-to-hex-glue'); - var prefixi = glue !== "" ? "0x" : ""; - var prefix = glue === "" ? "0x" : ""; - var hex = prefix + ([...str].map((elem, n) => prefixi+Number(str.charCodeAt(n)).toString(16)).join(glue)); - document.getElementById('hex-result').value = hex; + if (!asciiToHexForm.checkValidity()) { + event.preventDefault(); + } else { + event.preventDefault(); + var fomrdata = new FormData(asciiToHexForm); + var str = fomrdata.get('ascii-to-hex'); + var glue = fomrdata.get('ascii-to-hex-glue'); + var prefixi = glue !== "" ? "0x" : ""; + var prefix = glue === "" ? "0x" : ""; + var hex = prefix + ([...str].map((elem, n) => prefixi+Number(str.charCodeAt(n)).toString(16)).join(glue)); + document.getElementById('hex-result').value = hex; + } + [...asciiToHexForm.elements].map(e => e.parentNode).forEach(e => e.classList.toggle('was-validated', true)); }); var hexToAsciiForm = document.getElementById('hex-to-ascii'); hexToAsciiForm.addEventListener('submit',(event) => { - event.preventDefault(); - var fomrdata = new FormData(hexToAsciiForm); - var str = fomrdata.get('hex-to-ascii'); - var separator = fomrdata.get('hex-to-ascii-separator'); - var ascii = separator === "" ? getChunks(str.substring(2),2).map(el => String.fromCharCode(parseInt(el, 16))).join('') : str.split(separator).map(el => String.fromCharCode(Number(el))).join(''); - document.getElementById('ascii-result').value = ascii; + if (!hexToAsciiForm.checkValidity()) { + event.preventDefault(); + } else { + event.preventDefault(); + var fomrdata = new FormData(hexToAsciiForm); + var str = fomrdata.get('hex-to-ascii'); + var separator = fomrdata.get('hex-to-ascii-separator'); + var ascii = separator === "" ? getChunks(str.substring(2),2).map(el => String.fromCharCode(parseInt(el, 16))).join('') : str.split(separator).map(el => String.fromCharCode(Number(el))).join(''); + document.getElementById('ascii-result').value = ascii; + } + [...hexToAsciiForm.elements].map(e => e.parentNode).forEach(e => e.classList.toggle('was-validated', true)); + }); -- cgit v1.2.3