Created
January 18, 2019 22:30
-
-
Save taterbase/00768f930e48899333d6b8463cd28331 to your computer and use it in GitHub Desktop.
x12 Viewer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<textarea id="edi-input" placeholder="Paste edi in here..."> | |
</textarea> | |
<br /> | |
<input id="search" placeholder="search segments and elements"> | |
<table id="edi-table" border="1"> | |
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.getElementById("edi-input").addEventListener("input", function() { | |
renderEDI(this.value) | |
}) | |
let foundElem = [] | |
document.getElementById('search').addEventListener("input", function() { | |
foundElem.forEach(elem => { | |
elem.classList.remove("found") | |
}) | |
foundElem = document.querySelectorAll(`.${this.value.toLowerCase()}`) | |
foundElem.forEach(elem => { | |
elem.classList.add("found") | |
}) | |
}) | |
let ediTable = document.getElementById("edi-table") | |
function renderEDI(edi) { | |
let html = edi.split("~").map((seg) => { | |
let row = '<tr>' | |
let elements = seg.split("*") | |
let identifier = elements[0] | |
row += elements.map((element, idx) => { | |
if (idx == 0) | |
return `<th class="${identifier.toLowerCase()}">${element}</th>` | |
else | |
return `<td title="${identifier}${leftpad(idx)}" class="${identifier.toLowerCase()} ${identifier.toLowerCase()}${leftpad(idx)}">${element}</td>` | |
}).join('') | |
row += '</tr>' | |
return row | |
}).join('') | |
ediTable.innerHTML = html | |
} | |
function leftpad(num) { | |
if (num < 10) | |
return "0" + num | |
return num | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
table { | |
cursor: pointer; | |
} | |
td:hover { | |
background: salmon; | |
} | |
.found { | |
background: #967BB6; | |
} | |
.not-found { | |
background-color: red; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment