Skip to content

Commit

Permalink
Fix: Json key display
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Sep 4, 2016
1 parent 1db569c commit 5611e3a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
19 changes: 11 additions & 8 deletions src/lib/JsonViewer.es6
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ function createEl(key, val, firstLevel)
close = ']';
}

function wrapKey(key)
{
if (firstLevel) return '';

var keyClass = 'eruda-key';
if (util.contain(LIGHTER_KEY, key)) keyClass = 'eruda-key-lighter';

return `<span class="${keyClass}">${encode(key)}</span>: `;
}

if (val === null)
{
return `<li>
Expand All @@ -81,7 +91,7 @@ function createEl(key, val, firstLevel)
{
var obj = `<li>
<span class="eruda-expanded ${firstLevel ? '' : 'eruda-collapsed'}"></span>
${firstLevel ? '' : wrapKey(key)}
${wrapKey(key)}
<span class="eruda-open">${open} ${(val['erudaObjAbstract'] || '')}</span>
<ul class="eruda-${type}" ${firstLevel ? '' : 'style="display:none"'}>`;
obj += jsonToHtml(val);
Expand Down Expand Up @@ -115,13 +125,6 @@ function createEl(key, val, firstLevel)
</li>`;
}

function wrapKey(key)
{
var keyClass = 'eruda-key';
if (util.contain(LIGHTER_KEY, key)) keyClass = 'eruda-key-lighter';

return `<span class="${keyClass}">${encode(key)}</span>: `;
}

const LIGHTER_KEY = ['__proto__', 'constructor', 'toString', 'valueOf'];

Expand Down
3 changes: 1 addition & 2 deletions src/lib/json.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
position: relative;
white-space: nowrap;
}
& > li > .key,
& .array .key {
& > li > .key {
display: none;
}
.array .object .key {
Expand Down

0 comments on commit 5611e3a

Please sign in to comment.