Skip to content

Commit 403754c

Browse files
committed
Add close button
1 parent 3e8182a commit 403754c

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed

background.js

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ function readConf() {
107107
'.k', '{color:' + opts.property + '}' +
108108
'.e', '{color:' + opts.error + '}' +
109109
'.o', '{color:' + opts.null + '}' +
110+
'.g', '{float:right;margin:-4px -14px;border-radius:4px;border:1px solid ' + opts.info + ';background:#ddd}' +
111+
'.gb', '{font: 20px/20px serif;cursor:pointer;padding:0 2px}' +
112+
'.gb', ':hover{background:#ccc}' +
113+
'.gb', ':active{background:#999}' +
110114
'.e', ',.b', '{font-weight:bold}' +
111115
'div.e', '{white-space:normal;font-size:120%;margin:0 0 1em}'
112116
].join(rand)
@@ -355,26 +359,6 @@ function func(rand, opts, op, msg) {
355359
}
356360
}
357361

358-
function onClick(e) {
359-
var target = e.target
360-
, isCollapsed = target.classList.contains(COLL)
361-
e.stopPropagation()
362-
if (target.tagName === "I") {
363-
if (target.classList.contains("m" + rand)) {
364-
target.previousSibling.appendChild(target.nextSibling.firstChild)
365-
target.parentNode.removeChild(target.nextSibling)
366-
target.parentNode.removeChild(target)
367-
} else if (e.altKey) {
368-
changeSiblings(target, COLL, !isCollapsed)
369-
} else if (e[mod]) {
370-
isCollapsed = target.nextSibling.querySelector("i")
371-
if (isCollapsed) change(target.nextSibling, "i", COLL, !isCollapsed.classList.contains(COLL))
372-
} else {
373-
target.classList[isCollapsed ? "remove" : "add"](COLL)
374-
}
375-
}
376-
}
377-
378362
function draw(str, to, first, box) {
379363
var afterColon
380364
, spaces = ""
@@ -386,6 +370,7 @@ function func(rand, opts, op, msg) {
386370
, path = []
387371
, lineNo = 1
388372
, jsonp = /^([\/*&;='"$\w\s]{0,99}\b[$a-z_][$\w]{0,99}\s*\()([^]+)(\)[\s;]*)$/i.exec(str)
373+
, oldTxt = to.textContent
389374
colon.textContent = ": "
390375
comma.textContent = ",\n"
391376

@@ -395,6 +380,12 @@ function func(rand, opts, op, msg) {
395380
link.target = "_blank"
396381
}
397382

383+
if (first === 0) {
384+
var btnGroup = el("div", node, "g")
385+
, closeBtn = el("div", btnGroup, "gb")
386+
closeBtn.textContent = "⨯"
387+
}
388+
398389
if (to === body && opts.navInfo) try {
399390
var nav = performance.getEntriesByType("navigation")[0]
400391
, endNames = { request: "responseStart" }
@@ -408,7 +399,29 @@ function func(rand, opts, op, msg) {
408399
el("div", node, "e").textContent = e
409400
}
410401

411-
node.addEventListener("click", onClick, true)
402+
node.addEventListener("click", onClick, false)
403+
function onClick(e) {
404+
var target = e.target
405+
, isCollapsed = target.classList.contains(COLL)
406+
e.stopPropagation()
407+
if (target.tagName === "I") {
408+
if (target.classList.contains("m" + rand)) {
409+
target.previousSibling.appendChild(target.nextSibling.firstChild)
410+
target.parentNode.removeChild(target.nextSibling)
411+
target.parentNode.removeChild(target)
412+
} else if (e.altKey) {
413+
changeSiblings(target, COLL, !isCollapsed)
414+
} else if (e[mod]) {
415+
isCollapsed = target.nextSibling.querySelector("i")
416+
if (isCollapsed) change(target.nextSibling, "i", COLL, !isCollapsed.classList.contains(COLL))
417+
} else {
418+
target.classList[isCollapsed ? "remove" : "add"](COLL)
419+
}
420+
} else if (target === closeBtn) {
421+
to.textContent = oldTxt
422+
}
423+
}
424+
412425
if (first) {
413426
to.replaceChild(box = node, first)
414427
} else {

0 commit comments

Comments
 (0)