'use strict'; define([ 'underscore', 'react', 'reflux', 'app/stores/terminal', 'ansi_up', 'templates/app/components/terminal/terminal', ], function(_, React, Reflux, terminalStore, ansiUp, template) { var Component = React.createClass({ mixins: [Reflux.ListenerMixin], shouldScrollBottom: true, data: [], linesCount: 0, componentDidMount: function() { this.listenTo(terminalStore, this.updateItems); var node = document.getElementsByClassName('terminal')[0]; this.initialScrollPosition = node.getBoundingClientRect().top; window.onscroll = this.onScroll; }, componentWillUnmount: function() { window.onscroll = null; }, prepareRow: function(row) { return ansiUp.ansi_to_html(row.replace('\r', '')); }, prepareOutput: function(output) { var self = this; return output.map(function(row) { return self.prepareRow(row); }); }, getTerminal: function() { return document.getElementsByClassName('terminal')[0]; }, getBody: function() { return document.getElementsByTagName('body')[0]; }, onScroll: function() { var node = this.getTerminal(), body = this.getBody(); this.shouldScrollBottom = window.innerHeight + body.scrollTop >= node.offsetHeight + this.initialScrollPosition; }, ensureScrollPosition: function() { if (this.shouldScrollBottom) { var node = this.getTerminal(), body = this.getBody(); body.scrollTop = this.initialScrollPosition + node.offsetHeight; } }, makeCodeLineContent: function(line) { return '' + '' + '