woodpecker/server/app/scripts/commit_updates.js

66 lines
1.3 KiB
JavaScript
Raw Normal View History

;// Live commit updates
if(typeof(Drone) === 'undefined') { Drone = {}; }
(function () {
2014-07-12 02:10:18 +00:00
Drone.Console = function() {
this.lineFormatter = new Drone.LineFormatter();
}
2014-07-12 02:10:18 +00:00
Drone.Console.prototype = {
lineBuffer: "",
autoFollow: false,
2014-07-12 02:10:18 +00:00
start: function(el) {
if(typeof(el) === 'string') {
this.el = document.getElementById(el);
} else {
this.el = el;
}
2014-07-12 02:10:18 +00:00
this.update();
2014-03-02 07:08:30 +00:00
},
2014-07-12 02:10:18 +00:00
stop: function() {
2014-03-02 07:08:30 +00:00
this.stoppingRefresh = true;
},
2014-07-12 02:10:18 +00:00
update: function() {
if(this.lineBuffer.length > 0) {
this.el.innerHTML += this.lineBuffer;
this.lineBuffer = '';
if (this.autoFollow) {
window.scrollTo(0, document.body.scrollHeight);
}
}
2014-03-02 07:08:30 +00:00
if(this.stoppingRefresh) {
this.stoppingRefresh = false;
} else {
window.requestAnimationFrame(this.updateScreen.bind(this));
}
},
2014-07-12 02:10:18 +00:00
write: function(e) {
this.lineBuffer += this.lineFormatter.format(e.data);
}
};
// Polyfill rAF for older browsers
window.requestAnimationFrame = window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
function(callback, element) {
return window.setTimeout(function() {
callback(+new Date());
}, 1000 / 60);
};
2014-03-02 07:08:30 +00:00
window.cancelRequestAnimationFrame = window.cancelRequestAnimationFrame ||
window.cancelWebkitRequestAnimationFrame ||
function(fn) {
window.clearTimeout(fn);
};
})();