Commit 68cc841d authored by Taddeüs Kroes's avatar Taddeüs Kroes

Code cleanup + error message improvement + autofocus on input area

parent b847b423
...@@ -36,6 +36,10 @@ ...@@ -36,6 +36,10 @@
input_textarea.focus(); input_textarea.focus();
}); });
// Put cursor at end of textarea
var old_val = input_textarea.val();
input_textarea.val('').focus().val(old_val);
var STATUS_FAILURE = 0, var STATUS_FAILURE = 0,
STATUS_NOPROGRESS = 1, STATUS_NOPROGRESS = 1,
STATUS_SUCCESS = 2, STATUS_SUCCESS = 2,
...@@ -200,35 +204,37 @@ ...@@ -200,35 +204,37 @@
var error = $('#error'), var error = $('#error'),
loader = $('#loader'); loader = $('#loader');
error.find('.close').click(function() {
error.hide();
});
function report_error(e) { function report_error(e) {
error.show().find('.text').text(e.error); var msg = e.error;
if ('statusText' in e)
msg = e.status + ' ' + e.statusText;
error.show().find('.text').text(msg);
if (console && console.log) if (console && console.log)
console.log('error:', e); console.log('error:', e);
loader.hide(); hide_loader();
}; }
function clear_error() { function clear_error() {
error.hide(); error.hide();
}; }
error.find('.close').click(clear_error);
var pending_request = false; var pending_request = false;
function show_loader() { function show_loader() {
pending_request = true; pending_request = true;
loader.css('visibility', 'visible'); loader.css('visibility', 'visible');
}; }
function hide_loader() { function hide_loader() {
pending_request = false; pending_request = false;
loader.css('visibility', 'hidden'); loader.css('visibility', 'hidden');
clear_error(); }
};
function append_hint(hint) { function append_hint(hint) {
pretty_print.find('div').last().filter('.hint').remove(); pretty_print.find('div').last().filter('.hint').remove();
...@@ -238,11 +244,11 @@ ...@@ -238,11 +244,11 @@
elem.append('<div class="icon icon-info-sign"/>'); elem.append('<div class="icon icon-info-sign"/>');
pretty_print.append(elem); pretty_print.append(elem);
QUEUE.Push(['Typeset', MathJax.Hub, elem[0]]); QUEUE.Push(['Typeset', MathJax.Hub, elem[0]]);
}; }
function append_input(input) { function append_input(input) {
input_textarea.val(input_textarea.val() + '\n' + input); input_textarea.val(input_textarea.val() + '\n' + input);
}; }
$('#btn-clear').click(function() { $('#btn-clear').click(function() {
input_textarea.val(''); input_textarea.val('');
...@@ -262,6 +268,7 @@ ...@@ -262,6 +268,7 @@
} }
show_loader(); show_loader();
clear_error();
// TODO: disable input box and enable it when this ajax request is done // TODO: disable input box and enable it when this ajax request is done
// (on failure and success). // (on failure and success).
...@@ -274,6 +281,7 @@ ...@@ -274,6 +281,7 @@
handler(response); handler(response);
hide_loader(); hide_loader();
clear_error();
}, 'json').error(report_error); }, 'json').error(report_error);
}); });
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment