@zjy4fun/json-open 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.html +11 -30
- package/package.json +1 -1
package/index.html
CHANGED
|
@@ -477,9 +477,7 @@
|
|
|
477
477
|
<div class="panel panel-left" id="panel-left">
|
|
478
478
|
<div class="panel-header">
|
|
479
479
|
<span class="label">Input</span>
|
|
480
|
-
<button id="btn-format" class="primary">✨ Format</button>
|
|
481
480
|
<button id="btn-copy">📋 Copy</button>
|
|
482
|
-
<button id="btn-clear">Clear</button>
|
|
483
481
|
<button id="btn-share">🔗 Share</button>
|
|
484
482
|
</div>
|
|
485
483
|
<textarea class="input-area" id="json-input" placeholder="Paste or type JSON here..." spellcheck="false"></textarea>
|
|
@@ -512,8 +510,8 @@
|
|
|
512
510
|
<div class="viewer" id="viewer">
|
|
513
511
|
<div class="empty-state">
|
|
514
512
|
<div class="icon">{ }</div>
|
|
515
|
-
<div>Paste JSON on the left
|
|
516
|
-
<div style="font-size:12px">
|
|
513
|
+
<div>Paste or type JSON on the left</div>
|
|
514
|
+
<div style="font-size:12px">It will format automatically</div>
|
|
517
515
|
</div>
|
|
518
516
|
</div>
|
|
519
517
|
</div>
|
|
@@ -661,9 +659,7 @@
|
|
|
661
659
|
// ===== Elements =====
|
|
662
660
|
var jsonInput = document.getElementById('json-input')
|
|
663
661
|
var viewer = document.getElementById('viewer')
|
|
664
|
-
var btnFormat = document.getElementById('btn-format')
|
|
665
662
|
var btnCopy = document.getElementById('btn-copy')
|
|
666
|
-
var btnClear = document.getElementById('btn-clear')
|
|
667
663
|
var btnShare = document.getElementById('btn-share')
|
|
668
664
|
var btnExpandAll = document.getElementById('expand-all')
|
|
669
665
|
var btnCollapseAll = document.getElementById('collapse-all')
|
|
@@ -685,7 +681,7 @@
|
|
|
685
681
|
function doFormat() {
|
|
686
682
|
var input = jsonInput.value.trim()
|
|
687
683
|
if (!input) {
|
|
688
|
-
viewer.innerHTML = '<div class="empty-state"><div class="icon">{ }</div><div>Paste JSON on the left
|
|
684
|
+
viewer.innerHTML = '<div class="empty-state"><div class="icon">{ }</div><div>Paste or type JSON on the left</div><div style="font-size:12px">It will format automatically</div></div>'
|
|
689
685
|
statusInfo.textContent = 'Ready'
|
|
690
686
|
statusSize.textContent = ''
|
|
691
687
|
toggleWrap.classList.add('hidden')
|
|
@@ -731,8 +727,6 @@
|
|
|
731
727
|
}
|
|
732
728
|
|
|
733
729
|
// ===== Buttons =====
|
|
734
|
-
btnFormat.addEventListener('click', doFormat)
|
|
735
|
-
|
|
736
730
|
btnCopy.addEventListener('click', function () {
|
|
737
731
|
var text = jsonInput.value.trim()
|
|
738
732
|
if (!text) return
|
|
@@ -743,17 +737,6 @@
|
|
|
743
737
|
})
|
|
744
738
|
})
|
|
745
739
|
|
|
746
|
-
btnClear.addEventListener('click', function () {
|
|
747
|
-
jsonInput.value = ''
|
|
748
|
-
viewer.innerHTML = '<div class="empty-state"><div class="icon">{ }</div><div>Paste JSON on the left and click <b>Format</b></div><div style="font-size:12px">or press Ctrl+Enter</div></div>'
|
|
749
|
-
statusInfo.textContent = 'Ready'
|
|
750
|
-
statusSize.textContent = ''
|
|
751
|
-
toggleWrap.classList.add('hidden')
|
|
752
|
-
currentParsed = null
|
|
753
|
-
currentDeepParsed = null
|
|
754
|
-
clearSearch()
|
|
755
|
-
})
|
|
756
|
-
|
|
757
740
|
// ===== Share =====
|
|
758
741
|
btnShare.addEventListener('click', function () {
|
|
759
742
|
var input = jsonInput.value.trim()
|
|
@@ -781,12 +764,8 @@
|
|
|
781
764
|
})
|
|
782
765
|
})
|
|
783
766
|
|
|
784
|
-
//
|
|
767
|
+
// Input behavior
|
|
785
768
|
jsonInput.addEventListener('keydown', function (e) {
|
|
786
|
-
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
|
|
787
|
-
e.preventDefault()
|
|
788
|
-
doFormat()
|
|
789
|
-
}
|
|
790
769
|
// Tab support
|
|
791
770
|
if (e.key === 'Tab') {
|
|
792
771
|
e.preventDefault()
|
|
@@ -988,11 +967,13 @@
|
|
|
988
967
|
}
|
|
989
968
|
})
|
|
990
969
|
|
|
991
|
-
// =====
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
970
|
+
// ===== Auto format on input =====
|
|
971
|
+
var inputDebounceTimer
|
|
972
|
+
jsonInput.addEventListener('input', function () {
|
|
973
|
+
clearTimeout(inputDebounceTimer)
|
|
974
|
+
inputDebounceTimer = setTimeout(function () {
|
|
975
|
+
doFormat()
|
|
976
|
+
}, 200)
|
|
996
977
|
})
|
|
997
978
|
|
|
998
979
|
// ===== Load from URL hash =====
|