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 ++++++++++------ _tools/speed-gpon-eth.md | 161 ++++++++++++++++++++++++----------------------- 2 files changed, 119 insertions(+), 95 deletions(-) (limited to '_tools') 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)); + }); diff --git a/_tools/speed-gpon-eth.md b/_tools/speed-gpon-eth.md index f01b623..2a1b333 100644 --- a/_tools/speed-gpon-eth.md +++ b/_tools/speed-gpon-eth.md @@ -8,9 +8,9 @@ layout: default

Ethernet calculator

- +
- +
@@ -25,20 +25,20 @@ layout: default
- + - + - + @@ -62,7 +62,7 @@ layout: default

Gpon calculator

-
+
@@ -82,14 +82,14 @@ layout: default
@@ -121,43 +121,47 @@ layout: default }); }); form.addEventListener('submit',(event) => { + if (!form.checkValidity()) { + event.preventDefault(); + } else { + event.preventDefault(); - var formdata = new FormData(form); - event.preventDefault(); - var overheadipv4 = { - "ipoe" : 20, - "pppoe" : 28, - "map-t" : 40, - "map-e" : 60, - }; - var overheadipv6 = { - "ipoe" : 40, - "pppoe" : 48, - }; - var overheadtcp = 20; - var overheadeth = 14; - var overheadfcs = 4; - var overheadgap = { - '10' : 5.875, - '100' : 12, - '200' : 8, - '500' : 8, - '1000' : 8, - '2500' : 5, - '5000' : 5, - '10000' : 5, - }; - var preamble = 8; - var cip = formdata.get('ip'); - var coverheadip = formdata.get('ip') === '4' ? overheadipv4[formdata.get('ipv4protocol')] : overheadipv6[formdata.get('ipv6protocol')]; - var mtu = formdata.get('mtu'); - var mss = mtu - coverheadip; - var overhead = overheadtcp + overheadeth + overheadfcs + overheadgap[formdata.get('speed')] + preamble + coverheadip; - document.getElementById('overhead').value = overhead/mss * 100; - var th = mss /(overhead + mss); - - document.getElementById('maxSpeed').value = th * formdata.get('speed'); - + var formdata = new FormData(form); + var overheadipv4 = { + "ipoe" : 20, + "pppoe" : 28, + "map-t" : 40, + "map-e" : 60, + }; + var overheadipv6 = { + "ipoe" : 40, + "pppoe" : 48, + }; + var overheadtcp = 20; + var overheadeth = 14; + var overheadfcs = 4; + var overheadgap = { + '10' : 5.875, + '100' : 12, + '200' : 8, + '500' : 8, + '1000' : 8, + '2500' : 5, + '5000' : 5, + '10000' : 5, + }; + var preamble = 8; + var cip = formdata.get('ip'); + var coverheadip = formdata.get('ip') === '4' ? overheadipv4[formdata.get('ipv4protocol')] : overheadipv6[formdata.get('ipv6protocol')]; + var mtu = formdata.get('mtu'); + var mss = mtu - coverheadip; + var overhead = overheadtcp + overheadeth + overheadfcs + overheadgap[formdata.get('speed')] + preamble + coverheadip; + document.getElementById('overhead').value = overhead/mss * 100; + var th = mss /(overhead + mss); + + document.getElementById('maxSpeed').value = th * formdata.get('speed'); + } + [...form.elements].map(e => e.parentNode).forEach(e => e.classList.toggle('was-validated', true)); }); var formgpon = document.getElementById('gpon-speed-mtu'); var radioIp = document.getElementsByName('gpon-ip'); @@ -169,37 +173,40 @@ layout: default }); }); formgpon.addEventListener('submit',(event) => { - - var formdata = new FormData(formgpon); - event.preventDefault(); - var gtc = 38880; - var overheadgem = 5; - var overheadpcbd = 30 + 8*formdata.get('gpon-ont'); - var overheadipv4 = { - "ipoe" : 20, - "pppoe" : 28, - "map-t" : 40, - "map-e" : 60, - }; - var overheadipv6 = { - "ipoe" : 40, - "pppoe" : 48, - }; - var overheadtcp = 20; - var overheadeth = 14; - var overheadfcs = 4; - var cip = formdata.get('gpon-ip'); - var coverheadip = formdata.get('gpon-ip') === '4' ? overheadipv4[formdata.get('gpon-ipv4protocol')] : overheadipv6[formdata.get('gpon-ipv6protocol')]; - var overheadframeeth = overheadtcp + overheadeth + overheadfcs + coverheadip; - var overheadgtc = overheadgem + formdata.get('gpon-gem') * (overheadpcbd+overheadframeeth); - var payload = gtc - overheadgtc; - document.getElementById('gpon-average-packet-size').value = payload/formdata.get('gpon-gem'); + if (!formgpon.checkValidity()) { + event.preventDefault(); + } else { + event.preventDefault(); + var formdata = new FormData(formgpon); + var gtc = 38880; + var overheadgem = 5; + var overheadpcbd = 30 + 8*formdata.get('gpon-ont'); + var overheadipv4 = { + "ipoe" : 20, + "pppoe" : 28, + "map-t" : 40, + "map-e" : 60, + }; + var overheadipv6 = { + "ipoe" : 40, + "pppoe" : 48, + }; + var overheadtcp = 20; + var overheadeth = 14; + var overheadfcs = 4; + var cip = formdata.get('gpon-ip'); + var coverheadip = formdata.get('gpon-ip') === '4' ? overheadipv4[formdata.get('gpon-ipv4protocol')] : overheadipv6[formdata.get('gpon-ipv6protocol')]; + var overheadframeeth = overheadtcp + overheadeth + overheadfcs + coverheadip; + var overheadgtc = overheadgem + formdata.get('gpon-gem') * (overheadpcbd+overheadframeeth); + var payload = gtc - overheadgtc; + document.getElementById('gpon-average-packet-size').value = payload/formdata.get('gpon-gem'); - document.getElementById('gpon-overhead').value = overheadgtc/payload * 100; - var th = payload /gtc; - - document.getElementById('gpon-maxSpeed').value = th * 2.48832; - + document.getElementById('gpon-overhead').value = overheadgtc/payload * 100; + var th = payload /gtc; + + document.getElementById('gpon-maxSpeed').value = th * 2.48832; + } + [...formgpon.elements].map(e => e.parentNode).forEach(e => e.classList.toggle('was-validated', true)); }); -- cgit v1.2.3