Skip to content

Commit b55c1d3

Browse files
committed
Merge pull request #4 from YaroslavShapoval/scroll-bottom
Scrolling shell down after entered command
2 parents fe81164 + e18fea6 commit b55c1d3

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

views/default/index.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
$this->registerJs(
1414
<<<JS
1515
jQuery(function($) {
16-
$('#webshell').terminal(
16+
var webshell = $('#webshell');
17+
18+
webshell.terminal(
1719
function(command, term) {
1820
if (command.indexOf('yii') === 0 || command.indexOf('yii') === 3) {
1921
$.jrpc('{$endpoint}', 'yii', [command.replace(/^yii ?/, '')], function(json) {
2022
term.echo(json.result);
23+
scrollDown();
2124
});
2225
} else if (command === 'help') {
2326
term.echo('Available commands are:');
@@ -26,16 +29,20 @@ function(command, term) {
2629
term.echo('help\tThis help text');
2730
term.echo('yii\tyii command');
2831
term.echo('quit\tQuit web shell');
32+
scrollDown();
2933
} else if (command === 'quit') {
3034
var exitUrl = '{$quitUrl}';
3135
if (exitUrl) {
3236
term.echo('Bye!');
37+
scrollDown();
3338
location.replace(exitUrl);
3439
} else {
3540
term.echo('There is no exit.');
41+
scrollDown();
3642
}
3743
} else {
3844
term.echo('Unknown command.');
45+
scrollDown();
3946
}
4047
},
4148
{
@@ -45,9 +52,13 @@ function(command, term) {
4552
}
4653
);
4754
48-
$('html').on('keydown', function(){
49-
$('#webshell').click();
55+
$('html').on('keydown', function(e) {
56+
webshell.click();
5057
});
58+
59+
function scrollDown() {
60+
$('html, body').animate({ scrollTop: webshell.height() }, 'fast');
61+
}
5162
});
5263
JS
5364
);

0 commit comments

Comments
 (0)