-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsoleText.js
More file actions
62 lines (56 loc) · 1.68 KB
/
consoleText.js
File metadata and controls
62 lines (56 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function ConsoleText (jobName, color) {
EventDispatcher.call(this);
ConsoleText.count++;
var colors = {
0: 'black',
1: 'red',
2: 'green',
3: 'yellow',
4: 'blue',
5: 'magenta',
6: 'cyan',
7: 'white'
};
var _replaceColors = function(text) {
$.each(colors, function (colorId, colorName) {
text = text.replace(new RegExp('\\[3' + colorId + ';1m(.+?)\\[0m', 'g'), '<span style="color:' + colorName + '">$1</span>');
});
text = text.replace(/\[41;37m(.+?)\[0m/g, '<span style="background-color:red;color:white">$1</span>');
return text;
};
// private vars
var $this = this,
_loaded = false,
_jobName = jobName,
_color = color,
_text;
$this.isLoaded = function() {
return _loaded;
};
$this.loadText = function() {
$.get(CONFIG.get('CONSOLE_URL') + '?job=' + _jobName, function(consoleText) {
_text = _replaceColors(consoleText);
_loaded = true;
$this.trigger(ConsoleText.events.LOADED, {consoleText: $this});
});
};
$this.getDto = function() {
if (!_loaded) {
throw new Error('ConsoleText is not loaded yet');
}
return {
name: _jobName,
consoleText: _text,
cssClass: 'text-' + _color + (ConsoleText.count == 1 ? ' full-screen' : '')
};
};
}
ConsoleText.prototype = new EventDispatcher();
ConsoleText.prototype.constructor = ConsoleText;
ConsoleText.events = {
LOADED: 'console.loaded'
};
ConsoleText.count = 0;
ConsoleText.clearCount = function() {
ConsoleText.count = 0;
};