forked from unconed/TermKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commandview.js
59 lines (45 loc) · 1.46 KB
/
commandview.js
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
(function ($) {
/**
* Controller for command view.
*/
var cv = termkit.commandView = function (client, session) {
var self = this;
this.$element = this.$markup();
// Find structural markup.
this.$commands = $(this.$element).find('.commands');
this.$context = $(this.$element).find('.context');
this.activeCommand = 0;
this.commandList = new cv.commandList();
this.newCommand();
};
cv.prototype = {
// Return active markup for this widget.
$markup: function () {
var $commandView = $('<div class="termkitCommandView"><div class="commands"></div><div class="context"></div>').data('controller', this);
var self = this;
return $commandView;
},
// Refresh the given view by re-inserting all command elements.
updateElement: function () {
// Refresh commands.
var $commands = this.$commands.empty();
$.each(this.commandList.commands, function () {
$commands.append(this.$element);
});
// Refresh context bar.
var command = this.commandList.commands[this.activeCommand];
if (command && command.context) {
this.$context.empty().append(command.context.$element);
}
},
newCommand: function () {
this.commandList.add(new cv.command());
this.activeCommand = this.commandList.length - 1;
this.updateElement();
},
// Respond to mouse clicks.
//foo: function (event) {
//},
};
///////////////////////////////////////////////////////////////////////////////
})(jQuery);