From c6e9dc7a5c7c94e08ef0d88c6f4121d579851f4c Mon Sep 17 00:00:00 2001 From: Maiz Date: Tue, 18 Oct 2016 14:14:37 +0800 Subject: [PATCH] merge from #77 pull request --- src/core/core.js | 14 +++--- src/log/log.js | 106 +++++++++++++++++++++++++++++------------ src/network/network.js | 6 +-- 3 files changed, 86 insertions(+), 40 deletions(-) diff --git a/src/core/core.js b/src/core/core.js index bf948f52..73767113 100644 --- a/src/core/core.js +++ b/src/core/core.js @@ -76,7 +76,7 @@ class VConsole { if (! $.one(id)) { let e = document.createElement('div'); e.innerHTML = this.html; - document.documentElement.appendChild(e.children[0]); + document.documentElement.insertAdjacentElement('beforeend', e.children[0]); } this.$dom = $.one(id); @@ -118,7 +118,7 @@ class VConsole { touchHasMoved = false, targetElem = null; - this.$dom.addEventListener('touchstart', function(e) { // todo: if double click + this.$dom.addEventListener('touchstart', function(e) { // todo: if double click if (lastTouchStartTime === undefined) { let touch = e.targetTouches[0]; touchstartX = touch.pageX; @@ -336,7 +336,7 @@ class VConsole { that.tabList.push(plugin.id); // render tabbar let $tabbar = $.render(tplTabbar, {id: plugin.id, name: plugin.name}); - $.one('.vc-tabbar', that.$dom).appendChild($tabbar); + $.one('.vc-tabbar', that.$dom).insertAdjacentElement('beforeend', $tabbar); // render tabbox let $tabbox = $.render(tplTabbox, {id: plugin.id}); if (!!tabboxHTML) { @@ -345,10 +345,10 @@ class VConsole { } else if (tool.isFunction(tabboxHTML.appendTo)) { tabboxHTML.appendTo($tabbox); } else if (tool.isElement(tabboxHTML)) { - $tabbox.appendChild(tabboxHTML); + $tabbox.insertAdjacentElement('beforeend', tabboxHTML); } } - $.one('.vc-content', that.$dom).appendChild($tabbox); + $.one('.vc-content', that.$dom).insertAdjacentElement('beforeend', $tabbox); }); // render top bar plugin.trigger('addTopBar', function(btnList) { @@ -379,7 +379,7 @@ class VConsole { } }); } - $topbar.appendChild($item); + $topbar.insertAdjacentElement('beforeend', $item); } }); // render tool bar @@ -514,7 +514,7 @@ class VConsole { */ show() { let that = this; - // before show console panel, + // before show console panel, // trigger a transitionstart event to make panel's property 'display' change from 'none' to 'block' let $panel = $.one('.vc-panel', this.$dom); $panel.style.display = 'block'; diff --git a/src/log/log.js b/src/log/log.js index 9f8c937e..8ffcc1bf 100644 --- a/src/log/log.js +++ b/src/log/log.js @@ -15,7 +15,7 @@ class VConsoleLogTab extends VConsolePlugin { constructor(...args) { super(...args); - + this.tplTabbox = ''; // MUST be overwrite in child class this.allowUnformattedLog = true; // `[xxx]` format log @@ -30,7 +30,7 @@ class VConsoleLogTab extends VConsolePlugin { } /** - * when vConsole is ready, + * when vConsole is ready, * this event will be triggered (after 'add' event) * @public */ @@ -50,10 +50,12 @@ class VConsoleLogTab extends VConsolePlugin { let that = this; let types = ['All', 'Log', 'Info', 'Warn', 'Error']; let btnList = []; - for (let i=0; i'; } else if (tool.isObject(logs[i]) || tool.isArray(logs[i])) { // object or array - $log = this.getFoldedLine(logs[i]); + log = this.getFoldedLine(logs[i]); } else { // default - $log.innerHTML = ' ' + tool.htmlEncode(logs[i]).replace(/\n/g, '
'); + log = ' ' + tool.htmlEncode(logs[i]).replace(/\n/g, '
') + '
'; } } catch (e) { - $log.innerHTML = ' [' + (typeof logs[i]) + ']'; + log = ' [' + (typeof logs[i]) + ']'; } - if ($log) { - $content.appendChild($log); + if (log) { + if (typeof log === 'string') + $content.insertAdjacentHTML('beforeend', log); + else + $content.insertAdjacentElement('beforeend', log); } } + // generate content from item.content if (tool.isObject(item.content)) { - $content.appendChild(item.content); + $content.insertAdjacentElement('beforeend', item.content); } // render to panel - $.one('.vc-log', this.$tabbox).appendChild($line); + $.one('.vc-log', this.$tabbox).insertAdjacentElement('beforeend', $line); // scroll to bottom if it is in the bottom before if (this.isInBottom) { @@ -354,7 +385,10 @@ class VConsoleLogTab extends VConsolePlugin { } outer += ' ' + preview; } - let $line = $.render(tplFold, {outer: outer, lineType: 'obj'}); + let $line = $.render(tplFold, { + outer: outer, + lineType: 'obj' + }); $.bind($.one('.vc-fold-outer', $line), 'click', function(e) { e.preventDefault(); e.stopPropagation(); @@ -371,11 +405,11 @@ class VConsoleLogTab extends VConsolePlugin { if ($content.children.length == 0 && !!obj) { // render object's keys let keys = tool.getObjAllKeys(obj); - for (let i=0; i