Skip to content

Commit

Permalink
Merge pull request Tencent#64 from Maizify/dev
Browse files Browse the repository at this point in the history
panel will not scroll to bottom if it is not in the bottom
  • Loading branch information
Maizify authored Aug 29, 2016
2 parents 40215d0 + a17c4cf commit 0371779
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 9 deletions.
6 changes: 3 additions & 3 deletions dist/vconsole.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vconsole",
"version": "2.4.0-pre",
"version": "2.4.0-pre2",
"description": "A lightweight, extendable front-end developer tool for mobile web page.",
"homepage": "https://github.com/WechatFE/vConsole",
"main": "dist/vconsole.min.js",
Expand Down
10 changes: 6 additions & 4 deletions src/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ class VConsole {
let that = this;
// 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';
let $panel = $.one('.vc-panel', this.$dom);
$panel.style.display = 'block';

// set 10ms delay to fix confict between display and transition
setTimeout(function() {
Expand All @@ -392,9 +392,11 @@ class VConsole {
$.removeClass(this.$dom, 'vc-toggle');
this._triggerPluginsEvent('hideConsole');

let $mask = $.one('.vc-mask', this.$dom);
let $mask = $.one('.vc-mask', this.$dom),
$panel = $.one('.vc-panel', this.$dom);
$.bind($mask, 'transitionend', function(evnet) {
$mask.style.display = 'none';
$panel.style.display = 'none';
});
}

Expand All @@ -410,7 +412,7 @@ class VConsole {
$.removeClass($.all('.vc-logbox', this.$dom), 'vc-actived');
$.addClass($logbox, 'vc-actived');
// scroll to bottom
$.one('.vc-content', this.$dom).scrollTop = $.one('.vc-content', this.$dom).scrollHeight;
// $.one('.vc-content', this.$dom).scrollTop = $.one('.vc-content', this.$dom).scrollHeight;
// show toolbar
$.removeClass($.all('.vc-tool', this.$dom), 'vc-actived');
$.addClass($.all('.vc-tool-' + tabID, this.$dom), 'vc-actived');
Expand Down
2 changes: 2 additions & 0 deletions src/core/core.less
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
}

.vc-mask {
display: none;
position: fixed;
top: 0;
left: 0;
Expand All @@ -48,6 +49,7 @@
}

.vc-panel {
display: none;
position: fixed;
min-height: 85%;
left: 0;
Expand Down
43 changes: 42 additions & 1 deletion src/log/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ class VConsoleLogTab extends VConsolePlugin {
this.allowUnformattedLog = true; // `[xxx]` format log

this.isReady = false;
this.isShow = false;
this.$tabbox = null;
this.console = {};
this.logList = [];
this.isInBottom = true; // whether the panel is in the bottom

this.mockConsole();
}
Expand Down Expand Up @@ -68,6 +70,7 @@ class VConsoleLogTab extends VConsolePlugin {
onReady() {
let that = this;

// log type filter
let $subTabs = $.all('.vc-subtab', that.$tabbox);
$.bind($subTabs, 'click', function(e) {
e.preventDefault();
Expand All @@ -90,6 +93,40 @@ class VConsoleLogTab extends VConsolePlugin {
$.addClass($log, 'vc-log-partly-' + logType);
}
});

let $content = $.one('.vc-content');
$.bind($content, 'scroll', function(e) {
if (!that.isShow) {
return;
}
if ($content.scrollTop + $content.offsetHeight >= $content.scrollHeight) {
that.isInBottom = true;
} else {
that.isInBottom = false;
}
});
}

onShow() {
this.isShow = true;
if (this.isInBottom == true) {
this.scrollToBottom();
}
}

onHide() {
this.isShow = false;
}

onShowConsole() {
if (this.isInBottom == true) {
this.scrollToBottom();
}
}

scrollToBottom() {
let $box = $.one('.vc-content');
$box.scrollTop = $box.scrollHeight - $box.offsetHeight;
}

/**
Expand Down Expand Up @@ -239,7 +276,11 @@ class VConsoleLogTab extends VConsolePlugin {

// render to panel
$.one('.vc-log', this.$tabbox).appendChild($line);
$.one('.vc-content').scrollTop = $.one('.vc-content').scrollHeight;

// scroll to bottom if it is in the bottom before
if (this.isInBottom) {
this.scrollToBottom();
}

// print log to origin console
if (!item.noOrigin) {
Expand Down

0 comments on commit 0371779

Please sign in to comment.