47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
var TextEditor = function(terminal) {
|
|
|
|
var self = this;
|
|
|
|
this.terminal = terminal;
|
|
|
|
this.node = document.createElement('div');
|
|
|
|
this.name = document.createElement('div');
|
|
this.node.appendChild(this.name);
|
|
|
|
this.area = document.createElement('textarea');
|
|
this.node.appendChild(this.area);
|
|
this.node.appendChild(document.createElement('br'));
|
|
|
|
this.saveButton = document.createElement('button');
|
|
this.saveButton.textContent = 'Save';
|
|
|
|
this.saveCallback = function(packet, args) {
|
|
if (packet.opcode == 'Result') {
|
|
self.terminal.ui.println('Saved');
|
|
} else if (packet.opcode == 'FileException') {
|
|
self.terminal.ui.println(packet.type);
|
|
}
|
|
};
|
|
|
|
this.save = function(e) {
|
|
var id = self.terminal.nextID();
|
|
self.terminal.callbacks[id.toString()] = self.saveCallback;
|
|
self.terminal.ws.webSocket.send(JSON.stringify(
|
|
{ id: id, opcode: 'FileAPI', args: [ 'save', self.terminal.session.toAbsolutePath(self.name.textContent), Base64.encode(Unicode.toUTF8(self.area.value)) ] }
|
|
));
|
|
};
|
|
this.saveButton.onclick = this.save;
|
|
this.node.appendChild(this.saveButton);
|
|
|
|
this.closeButton = document.createElement('button');
|
|
this.closeButton.textContent = 'Close';
|
|
this.close = function(e) {
|
|
self.node.parentNode.removeChild(self.node);
|
|
self.terminal.ui.input.focus();
|
|
};
|
|
this.closeButton.onclick = this.close;
|
|
this.node.appendChild(this.closeButton);
|
|
|
|
};
|