without jquery terminal output

This commit is contained in:
Vladimir Polyakov 2015-12-03 20:21:41 +03:00
parent 5c527b75fc
commit 6ff1eacdd4
3 changed files with 29 additions and 33 deletions

View File

@ -0,0 +1,9 @@
scm:
type: git
repository: /Users/vladimir/projects/fit/culture/frontend_node
rev: master
steps:
sync: npm run sync
test: nrun test -R dot
pack: nrun packSafe

View File

@ -1,4 +0,0 @@
.code-line
span.code-line_counter
.code-line_body!= this.props.row

View File

@ -7,19 +7,7 @@ define([
'app/stores/terminal', 'app/stores/terminal',
'ansi_up', 'ansi_up',
'templates/app/components/terminal/terminal', 'templates/app/components/terminal/terminal',
'templates/app/components/terminal/row' ], function(_, React, Reflux, terminalStore, ansiUp, template) {
], function(_, React, Reflux, terminalStore, ansiUp, template, rowTemplate) {
var TerminalRow = React.createClass({
render: rowTemplate,
shouldComponentUpdate: function(nextProps) {
return nextProps.row !== this.props.row;
}
});
template = template.locals({
Row: TerminalRow
});
var Component = React.createClass({ var Component = React.createClass({
mixins: [Reflux.ListenerMixin], mixins: [Reflux.ListenerMixin],
@ -32,10 +20,10 @@ define([
var node = document.getElementsByClassName('terminal')[0]; var node = document.getElementsByClassName('terminal')[0];
this.initialScrollPosition = node.getBoundingClientRect().top; this.initialScrollPosition = node.getBoundingClientRect().top;
$(window).on('scroll', this.onScroll); window.onscroll = this.onScroll;
}, },
componentWillUnmount: function() { componentWillUnmount: function() {
$(window).off('scroll', this.onScroll); window.onscroll = null;
}, },
prepareRow: function(row) { prepareRow: function(row) {
return ansiUp.ansi_to_html(row.replace('\r', '')); return ansiUp.ansi_to_html(row.replace('\r', ''));
@ -46,16 +34,24 @@ define([
return self.prepareRow(row); return self.prepareRow(row);
}); });
}, },
getTerminal: function() {
return document.getElementsByClassName('terminal')[0];
},
getBody: function() {
return document.getElementsByTagName('body')[0];
},
onScroll: function() { onScroll: function() {
var node = document.getElementsByClassName('terminal')[0], var node = this.getTerminal(),
body = document.getElementsByTagName('body')[0]; body = this.getBody();
this.shouldScrollBottom = window.innerHeight + body.scrollTop >= this.shouldScrollBottom = window.innerHeight + body.scrollTop >=
node.offsetHeight + this.initialScrollPosition; node.offsetHeight + this.initialScrollPosition;
}, },
ensureScrollPosition: function() { ensureScrollPosition: function() {
if (this.shouldScrollBottom) { if (this.shouldScrollBottom) {
var node = document.getElementsByClassName('terminal')[0], var node = this.getTerminal(),
body = document.getElementsByTagName('body')[0]; body = this.getBody();
body.scrollTop = this.initialScrollPosition + node.offsetHeight; body.scrollTop = this.initialScrollPosition + node.offsetHeight;
} }
}, },
@ -70,17 +66,17 @@ define([
renderBuffer: _.throttle(function() { renderBuffer: _.throttle(function() {
var data = this.data, var data = this.data,
currentLinesCount = data.length, currentLinesCount = data.length,
terminal = $('.terminal_code'), terminal = document.getElementsByClassName('terminal_code')[0],
rows = terminal.children(); rows = terminal.childNodes;
if (rows.length) { if (rows.length) {
// replace our last node // replace our last node
var index = this.linesCount - 1; var index = this.linesCount - 1;
$(rows[index]).html(this.makeCodeLineContent(data[index])); rows[index].innerHTML = this.makeCodeLineContent(data[index]);
} }
var self = this; var self = this;
terminal.append( terminal.insertAdjacentHTML('beforeend',
_(data.slice(this.linesCount)).map(function(line, index) { _(data.slice(this.linesCount)).map(function(line, index) {
return self.makeCodeLine(line, self.linesCount + index); return self.makeCodeLine(line, self.linesCount + index);
}).join('') }).join('')
@ -99,12 +95,7 @@ define([
shouldComponentUpdate: function() { shouldComponentUpdate: function() {
return false; return false;
}, },
render: template, render: template
getInitialState: function() {
return {
data: []
};
}
}); });
return Component; return Component;