From 574871a1991ad8077dd3ae4abcc67a61cf1c39e1 Mon Sep 17 00:00:00 2001 From: Patrick Ruehle Date: Mon, 23 Apr 2018 12:25:59 +0200 Subject: [PATCH 1/2] fix for extension loading on html pages with check for pre tag and childnodes length, css style fix for output editor --- src/css/skeleton.css | 2 ++ src/ts/util/check-if-json.js | 35 +++-------------------------------- 2 files changed, 5 insertions(+), 32 deletions(-) diff --git a/src/css/skeleton.css b/src/css/skeleton.css index 863bf4b..b3d383b 100644 --- a/src/css/skeleton.css +++ b/src/css/skeleton.css @@ -637,6 +637,8 @@ button:active { #editorDiv { height: 85%; + width: 100%; + display: inline-block; } #json-editor-input { diff --git a/src/ts/util/check-if-json.js b/src/ts/util/check-if-json.js index c2b0755..6954c73 100644 --- a/src/ts/util/check-if-json.js +++ b/src/ts/util/check-if-json.js @@ -8,40 +8,11 @@ function allTextNodes(nodes) { function getPreWithSource() { var childNodes = document.body.childNodes; + var preNode = childNodes[0]; - if (childNodes.length === 0) { - return null + if (childNodes.length === 1 && preNode.nodeName === "PRE") { + return preNode; } - - if (childNodes.length > 1 && allTextNodes(childNodes)) { - if (process.env.NODE_ENV === 'development') { - console.debug("[bro/q] Loaded from a multiple text nodes, normalizing"); - } - - document.body.normalize() // concatenates adjacent text nodes - } - - var childNode = childNodes[0]; - var nodeName = childNode.nodeName - var textContent = childNode.textContent - - if (nodeName === "PRE") { - return childNode; - } - - // if Content-Type is text/html - if (nodeName === "#text" && textContent.trim().length > 0) { - if (process.env.NODE_ENV === 'development') { - console.debug("[bro/q] Loaded from a text node, this might have returned content-type: text/html"); - } - - var pre = document.createElement("pre"); - pre.textContent = textContent; - document.body.removeChild(childNode); - document.body.appendChild(pre); - return pre; - } - return null } From 5ad951ebe3224fc89c1beb049426cf05ff7bb8f2 Mon Sep 17 00:00:00 2001 From: Patrick Ruehle Date: Tue, 24 Apr 2018 12:30:55 +0200 Subject: [PATCH 2/2] changed check for childnodes of body --- src/ts/util/check-if-json.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ts/util/check-if-json.js b/src/ts/util/check-if-json.js index 6954c73..b7b253e 100644 --- a/src/ts/util/check-if-json.js +++ b/src/ts/util/check-if-json.js @@ -8,10 +8,9 @@ function allTextNodes(nodes) { function getPreWithSource() { var childNodes = document.body.childNodes; - var preNode = childNodes[0]; - if (childNodes.length === 1 && preNode.nodeName === "PRE") { - return preNode; + if (childNodes.length === 1 && childNodes[0].nodeName === "PRE") { + return childNodes[0]; } return null }