Fixed the send button in the webclient; made the prompt command work with the webclient (still not displaying correctly)
This commit is contained in:
parent
aa1b8357d8
commit
039bb0c540
3 changed files with 25 additions and 17 deletions
|
|
@ -156,10 +156,12 @@ class WebSocketClient(Protocol, Session):
|
||||||
text = args[0]
|
text = args[0]
|
||||||
if text is None:
|
if text is None:
|
||||||
return
|
return
|
||||||
|
else:
|
||||||
|
return
|
||||||
flags = self.protocol_flags
|
flags = self.protocol_flags
|
||||||
text = to_str(text, force_string=True)
|
text = to_str(text, force_string=True)
|
||||||
|
|
||||||
options = kwargs.get("options", {})
|
options = kwargs.pop("options", {})
|
||||||
raw = options.get("raw", False)
|
raw = options.get("raw", False)
|
||||||
nomarkup = options.get("nomarkup", False)
|
nomarkup = options.get("nomarkup", False)
|
||||||
screenreader = options.get("screenreader", flags.get("SCREENREADER", False))
|
screenreader = options.get("screenreader", flags.get("SCREENREADER", False))
|
||||||
|
|
@ -174,6 +176,7 @@ class WebSocketClient(Protocol, Session):
|
||||||
args[0] = text
|
args[0] = text
|
||||||
else:
|
else:
|
||||||
args[0] = parse_html(text, strip_ansi=nomarkup)
|
args[0] = parse_html(text, strip_ansi=nomarkup)
|
||||||
|
print "send_text:", cmd, args, kwargs
|
||||||
|
|
||||||
# send to client on required form [cmdname, args, kwargs]
|
# send to client on required form [cmdname, args, kwargs]
|
||||||
self.sendLine(json.dumps([cmd, args, kwargs]))
|
self.sendLine(json.dumps([cmd, args, kwargs]))
|
||||||
|
|
|
||||||
|
|
@ -55,14 +55,14 @@ var input_history = function() {
|
||||||
history_pos = 0;
|
history_pos = 0;
|
||||||
return history[history.length -1];
|
return history[history.length -1];
|
||||||
}
|
}
|
||||||
|
|
||||||
var scratch = function (input) {
|
var scratch = function (input) {
|
||||||
// Put the input into the last history entry (which is normally empty)
|
// Put the input into the last history entry (which is normally empty)
|
||||||
// without making the array larger as with add.
|
// without making the array larger as with add.
|
||||||
// Allows for in-progress editing to be saved.
|
// Allows for in-progress editing to be saved.
|
||||||
history[history.length-1] = input;
|
history[history.length-1] = input;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {back: back,
|
return {back: back,
|
||||||
fwd: fwd,
|
fwd: fwd,
|
||||||
add: add,
|
add: add,
|
||||||
|
|
@ -103,8 +103,8 @@ function onKeydown (event) {
|
||||||
if (code === 13) { // Enter key sends text
|
if (code === 13) { // Enter key sends text
|
||||||
doSendText();
|
doSendText();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
else if (inputfield[0].selectionStart == inputfield.val().length) {
|
else if (inputfield[0].selectionStart == inputfield.val().length) {
|
||||||
// Only process up/down arrow if cursor is at the end of the line.
|
// Only process up/down arrow if cursor is at the end of the line.
|
||||||
if (code === 38) { // Arrow up
|
if (code === 38) { // Arrow up
|
||||||
history_entry = input_history.back();
|
history_entry = input_history.back();
|
||||||
|
|
@ -112,8 +112,8 @@ function onKeydown (event) {
|
||||||
else if (code === 40) { // Arrow down
|
else if (code === 40) { // Arrow down
|
||||||
history_entry = input_history.fwd();
|
history_entry = input_history.fwd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (history_entry !== null) {
|
if (history_entry !== null) {
|
||||||
// Doing a history navigation; replace the text in the input.
|
// Doing a history navigation; replace the text in the input.
|
||||||
inputfield.val(history_entry);
|
inputfield.val(history_entry);
|
||||||
|
|
@ -133,7 +133,7 @@ var resizeInputField = function () {
|
||||||
var min_height = 50;
|
var min_height = 50;
|
||||||
var max_height = 300;
|
var max_height = 300;
|
||||||
var prev_text_len = 0;
|
var prev_text_len = 0;
|
||||||
|
|
||||||
// Check to see if we should change the height of the input area
|
// Check to see if we should change the height of the input area
|
||||||
return function () {
|
return function () {
|
||||||
var inputfield = $("#inputfield");
|
var inputfield = $("#inputfield");
|
||||||
|
|
@ -141,21 +141,21 @@ var resizeInputField = function () {
|
||||||
var clienth = inputfield.prop("clientHeight");
|
var clienth = inputfield.prop("clientHeight");
|
||||||
var newh = 0;
|
var newh = 0;
|
||||||
var curr_text_len = inputfield.val().length;
|
var curr_text_len = inputfield.val().length;
|
||||||
|
|
||||||
if (scrollh > clienth && scrollh <= max_height) {
|
if (scrollh > clienth && scrollh <= max_height) {
|
||||||
// Need to make it bigger
|
// Need to make it bigger
|
||||||
newh = scrollh;
|
newh = scrollh;
|
||||||
}
|
}
|
||||||
else if (curr_text_len < prev_text_len) {
|
else if (curr_text_len < prev_text_len) {
|
||||||
// There is less text in the field; try to make it smaller
|
// There is less text in the field; try to make it smaller
|
||||||
// To avoid repaints, we draw the text in an offscreen element and
|
// To avoid repaints, we draw the text in an offscreen element and
|
||||||
// determine its dimensions.
|
// determine its dimensions.
|
||||||
var sizer = $('#inputsizer')
|
var sizer = $('#inputsizer')
|
||||||
.css("width", inputfield.prop("clientWidth"))
|
.css("width", inputfield.prop("clientWidth"))
|
||||||
.text(inputfield.val());
|
.text(inputfield.val());
|
||||||
newh = sizer.prop("scrollHeight");
|
newh = sizer.prop("scrollHeight");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newh != 0) {
|
if (newh != 0) {
|
||||||
newh = Math.min(newh, max_height);
|
newh = Math.min(newh, max_height);
|
||||||
if (clienth != newh) {
|
if (clienth != newh) {
|
||||||
|
|
@ -173,7 +173,7 @@ function doWindowResize() {
|
||||||
var message_scrollh = $("#messagewindow").prop("scrollHeight");
|
var message_scrollh = $("#messagewindow").prop("scrollHeight");
|
||||||
$("#messagewindow")
|
$("#messagewindow")
|
||||||
.css({"bottom": formh}) // leave space for the input form
|
.css({"bottom": formh}) // leave space for the input form
|
||||||
.scrollTop(message_scrollh); // keep the output window scrolled to the bottom
|
.scrollTop(message_scrollh); // keep the output window scrolled to the bottom
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle text coming from the server
|
// Handle text coming from the server
|
||||||
|
|
@ -190,11 +190,11 @@ function onText(args, kwargs) {
|
||||||
// Handle prompt output from the server
|
// Handle prompt output from the server
|
||||||
function onPrompt(args, kwargs) {
|
function onPrompt(args, kwargs) {
|
||||||
// show prompt
|
// show prompt
|
||||||
$('prompt').replaceWith(
|
$('#prompt').replaceWith(
|
||||||
"<div id='prompt' class='msg out'>" + args[0] + "</div>");
|
"<div id='prompt'>" + args[0] + "</div>");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle silencing events we don't do anything with.
|
// Silences events we don't do anything with.
|
||||||
function onSilence(cmdname, args, kwargs) {}
|
function onSilence(cmdname, args, kwargs) {}
|
||||||
|
|
||||||
// Handle unrecognized commands from server
|
// Handle unrecognized commands from server
|
||||||
|
|
@ -224,6 +224,9 @@ $(document).keydown(onKeydown)
|
||||||
.bind("paste", resizeInputField)
|
.bind("paste", resizeInputField)
|
||||||
.bind("cut", resizeInputField);
|
.bind("cut", resizeInputField);
|
||||||
|
|
||||||
|
// Pressing the send button
|
||||||
|
$("#inputsend").bind("click", doSendText);
|
||||||
|
|
||||||
// Event when client finishes loading
|
// Event when client finishes loading
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// This is safe to call, it will always only
|
// This is safe to call, it will always only
|
||||||
|
|
@ -237,6 +240,8 @@ $(document).ready(function() {
|
||||||
Evennia.emitter.on("connection_open", onSilence);
|
Evennia.emitter.on("connection_open", onSilence);
|
||||||
Evennia.emitter.on("connection_close", onSilence);
|
Evennia.emitter.on("connection_close", onSilence);
|
||||||
|
|
||||||
|
// Handle pressing the send button
|
||||||
|
$("#inputsend").bind("click", doSendText);
|
||||||
// Event when closing window (have to have Evennia initialized)
|
// Event when closing window (have to have Evennia initialized)
|
||||||
$(window).bind("beforeunload", Evennia.connection.close);
|
$(window).bind("beforeunload", Evennia.connection.close);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
<div id="prompt"></div>
|
<div id="prompt"></div>
|
||||||
<div id="inputcontrol">
|
<div id="inputcontrol">
|
||||||
<textarea id="inputfield" type="text"></textarea>
|
<textarea id="inputfield" type="text"></textarea>
|
||||||
<input id="inputsend" type="button" onClick="doSendText()" value=">"/>
|
<input id="inputsend" type="button" value=">"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="inputsizer"></div>
|
<div id="inputsizer"></div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue