Last active
July 8, 2022 04:49
-
-
Save phongjalvn/0f843ca180e2b93d99b5c9281a4b9266 to your computer and use it in GitHub Desktop.
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
var s = document.createElement("script"); | |
s.src = "https://unpkg.com/jsoneditor@9.1.4/dist/jsoneditor.min.js"; | |
document.getElementsByTagName("body")[0].appendChild(s); | |
var b = document.createElement("link"); | |
b.rel = "stylesheet"; | |
b.type = "text/css"; | |
b.href = "https://unpkg.com/jsoneditor@9.1.4/dist/jsoneditor.min.css"; | |
document.getElementsByTagName("body")[0].appendChild(b); | |
function getJSON() { | |
var a = editor.get(); | |
input.value = JSON.stringify(a, null, 2); | |
} | |
function eventHandle(e){ | |
var input = e.target; | |
init(input) | |
} | |
function bindEvent(){ | |
window.addEventListener('click', eventHandle) | |
} | |
function unbindEvent(){ | |
window.removeEventListener('click', eventHandle) | |
} | |
function init(input){ | |
var container = input.parentNode, | |
value = JSON.parse(input.value), | |
options = { onChange: getJSON, modes: ["tree", "code"] }, | |
editor; | |
editor = new JSONEditor(container, options); | |
editor.set(value); | |
unbindEvent() | |
} | |
s.onload = function () { | |
bindEvent(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment