2012-08-29 20:30:17 +02:00
|
|
|
function resize_main_div() {
|
|
|
|
// Resize main_div to exactly take up remaining vertical space.
|
|
|
|
var div = $('#main_div');
|
2012-08-29 22:31:01 +02:00
|
|
|
div.height(Math.max(200, div.height() + $(window).height() - $('body').height()));
|
2012-08-29 20:30:17 +02:00
|
|
|
}
|
|
|
|
$(function () {
|
|
|
|
resize_main_div();
|
|
|
|
$(window).resize(resize_main_div);
|
|
|
|
$('#zephyr-type-tabs a').on('shown', function (e) { resize_main_div(); });
|
|
|
|
});
|
|
|
|
|
2012-08-29 23:22:27 +02:00
|
|
|
$(function() {
|
|
|
|
$('#zephyr-type-tabs a[href="#class-message"]').on('shown', function (e) {
|
|
|
|
$('#class-message input:not(:hidden):first').focus().select();
|
|
|
|
});
|
|
|
|
$('#zephyr-type-tabs a[href="#personal-message"]').on('shown', function (e) {
|
|
|
|
$('#personal-message input:not(:hidden):first').focus().select();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-08-29 17:12:21 +02:00
|
|
|
$.ajaxSetup({
|
|
|
|
beforeSend: function(xhr, settings) {
|
|
|
|
function getCookie(name) {
|
|
|
|
var cookieValue = null;
|
|
|
|
if (document.cookie && document.cookie != '') {
|
|
|
|
var cookies = document.cookie.split(';');
|
|
|
|
for (var i = 0; i < cookies.length; i++) {
|
|
|
|
var cookie = jQuery.trim(cookies[i]);
|
|
|
|
// Does this cookie string begin with the name we want?
|
|
|
|
if (cookie.substring(0, name.length + 1) == (name + '=')) {
|
|
|
|
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cookieValue;
|
|
|
|
}
|
|
|
|
if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
|
|
|
|
// Only send the token to relative URLs i.e. locally.
|
|
|
|
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-08-30 17:28:15 +02:00
|
|
|
$(function() {
|
2012-08-30 18:24:16 +02:00
|
|
|
var status_classes = 'alert-error alert-success alert-info';
|
|
|
|
var send_status = $('#send-status');
|
|
|
|
var buttons = $('#class-message, #personal-message').find('input[type="submit"]');
|
2012-08-30 21:35:56 +02:00
|
|
|
|
2012-08-30 18:24:16 +02:00
|
|
|
var options = {
|
|
|
|
beforeSubmit: function (form, _options) {
|
|
|
|
send_status.removeClass(status_classes)
|
|
|
|
.addClass('alert-info')
|
|
|
|
.text('Sending')
|
|
|
|
.stop(true).fadeTo(0,1);
|
|
|
|
buttons.attr('disabled', 'disabled');
|
2012-08-31 22:28:37 +02:00
|
|
|
buttons.blur()
|
2012-08-30 18:24:16 +02:00
|
|
|
},
|
|
|
|
success: function (resp, statusText, xhr, form) {
|
|
|
|
form.find('textarea').val('');
|
|
|
|
send_status.removeClass(status_classes)
|
|
|
|
.addClass('alert-success')
|
|
|
|
.text('Sent message')
|
|
|
|
.stop(true).fadeTo(0,1).delay(1000).fadeOut(1000);
|
|
|
|
buttons.removeAttr('disabled');
|
|
|
|
},
|
|
|
|
error: function() {
|
|
|
|
send_status.removeClass(status_classes)
|
|
|
|
.addClass('alert-error')
|
2012-08-31 02:23:56 +02:00
|
|
|
.text('Error sending message ')
|
2012-08-30 21:35:56 +02:00
|
|
|
.append($('<span />')
|
|
|
|
.addClass('send-status-close').html('×')
|
|
|
|
.click(function () { send_status.stop(true).fadeOut(500); }))
|
2012-08-30 18:24:16 +02:00
|
|
|
.stop(true).fadeTo(0,1);
|
2012-08-30 21:35:56 +02:00
|
|
|
|
2012-08-30 18:24:16 +02:00
|
|
|
buttons.removeAttr('disabled');
|
|
|
|
}
|
|
|
|
};
|
2012-08-30 21:35:56 +02:00
|
|
|
|
2012-08-30 18:24:16 +02:00
|
|
|
send_status.hide();
|
|
|
|
$("#class-message form").ajaxForm(options);
|
|
|
|
$("#personal-message form").ajaxForm(options);
|
2012-08-30 17:28:15 +02:00
|
|
|
});
|
|
|
|
|
2012-08-29 21:14:55 +02:00
|
|
|
selected_tag = '<p id="selected">▶</p>'
|
2012-08-29 20:57:31 +02:00
|
|
|
|
2012-08-30 22:19:34 +02:00
|
|
|
var allow_hotkeys = true;
|
|
|
|
|
2012-09-05 16:26:26 +02:00
|
|
|
function select_zephyr(next_zephyr) {
|
2012-09-05 16:56:10 +02:00
|
|
|
if (next_zephyr.length == 0) {
|
|
|
|
// No match, e.g. bottom or top of page
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the previous arrow.
|
|
|
|
$("#selected").closest("td").empty();
|
|
|
|
|
|
|
|
next_zephyr.children("td:first").html(selected_tag);
|
|
|
|
$.post("update", {pointer: next_zephyr.attr("id")});
|
|
|
|
|
|
|
|
if (($(next_zephyr).offset().top < $("#main_div").offset().top) ||
|
|
|
|
($(next_zephyr).offset().top + $(next_zephyr).height() >
|
|
|
|
$("#main_div").offset().top + $("#main_div").height())) {
|
|
|
|
scroll_to_selected();
|
2012-08-31 17:10:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-30 22:19:34 +02:00
|
|
|
// NB: This just binds to current elements, and won't bind to elements
|
|
|
|
// created after ready() is called.
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
$('input, textarea, button').focus(function() {
|
|
|
|
allow_hotkeys = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
$('input, textarea, button').blur(function() {
|
|
|
|
allow_hotkeys = true;
|
|
|
|
});
|
2012-08-31 17:10:19 +02:00
|
|
|
$("body").delegate("p", "click", function(){
|
|
|
|
select_zephyr($(this).parent().parent());
|
|
|
|
});
|
2012-08-30 22:19:34 +02:00
|
|
|
});
|
2012-08-29 23:08:16 +02:00
|
|
|
|
2012-08-30 23:13:05 +02:00
|
|
|
var goto_pressed = false;
|
2012-08-29 17:12:21 +02:00
|
|
|
|
2012-08-31 17:10:19 +02:00
|
|
|
|
2012-08-30 23:13:05 +02:00
|
|
|
$(document).keydown(function(event) {
|
|
|
|
if (allow_hotkeys) {
|
|
|
|
|
|
|
|
if (event.keyCode == 38 || event.keyCode == 40) { // down or up arrow
|
2012-08-31 17:10:19 +02:00
|
|
|
|
2012-09-05 17:07:28 +02:00
|
|
|
var tr = $("#selected").closest("tr");
|
2012-08-30 23:13:05 +02:00
|
|
|
if (event.keyCode == 40) { // down arrow
|
|
|
|
// There are probably more verbose but more efficient ways to do this.
|
|
|
|
next_zephyr = tr.nextAll(":not(:hidden):first");
|
|
|
|
} else { // up arrow
|
|
|
|
next_zephyr = tr.prevAll(":not(:hidden):first");
|
2012-08-29 17:12:21 +02:00
|
|
|
}
|
2012-09-05 16:26:26 +02:00
|
|
|
select_zephyr(next_zephyr);
|
2012-08-31 22:20:20 +02:00
|
|
|
event.preventDefault();
|
2012-08-30 23:13:05 +02:00
|
|
|
} else if (event.keyCode == 82) { // 'r' keypress, for responding to a zephyr
|
|
|
|
var parent = $("#selected").parents("tr");
|
|
|
|
var zephyr_class = parent.find("span.zephyr_class").text();
|
2012-09-05 17:14:12 +02:00
|
|
|
var zephyr_huddle = parent.find("span.zephyr_huddle_recipient").text();
|
|
|
|
var zephyr_personal = parent.find("span.zephyr_personal_recipient").text();
|
2012-08-30 23:13:05 +02:00
|
|
|
var instance = parent.find("span.zephyr_instance").text();
|
2012-08-30 23:44:04 +02:00
|
|
|
if (zephyr_class != '') {
|
|
|
|
$('#zephyr-type-tabs a[href="#class-message"]').tab('show');
|
|
|
|
$("#class").val(zephyr_class);
|
|
|
|
$("#instance").val(instance);
|
|
|
|
$("#new_zephyr").focus();
|
|
|
|
$("#new_zephyr").select();
|
2012-09-05 17:14:12 +02:00
|
|
|
} else if (zephyr_huddle != '') {
|
|
|
|
var recipients = parent.find("span.zephyr_huddle_recipients_list").text();
|
|
|
|
$('#zephyr-type-tabs a[href="#personal-message"]').tab('show');
|
|
|
|
$("#recipient").val(recipients);
|
|
|
|
$("#new_personal_zephyr").focus();
|
|
|
|
$("#new_personal_zephyr").select();
|
|
|
|
} else if (zephyr_personal != '') {
|
2012-08-31 22:50:24 +02:00
|
|
|
var recipient = parent.find("span.zephyr_sender").text();
|
|
|
|
if (recipient == username) { // that is, we sent the original message
|
|
|
|
recipient = parent.find("span.zephyr_personal_recipient").text();
|
|
|
|
}
|
2012-09-05 16:31:43 +02:00
|
|
|
$('#zephyr-type-tabs a[href="#personal-message"]').tab('show');
|
|
|
|
$("#recipient").val(recipient);
|
2012-08-30 23:44:04 +02:00
|
|
|
$("#new_personal_zephyr").focus();
|
|
|
|
$("#new_personal_zephyr").select();
|
|
|
|
}
|
2012-08-30 23:13:05 +02:00
|
|
|
event.preventDefault();
|
|
|
|
} else if (event.keyCode == 71) { // 'g' keypress, set trigger for "go to"
|
|
|
|
goto_pressed = true;
|
|
|
|
event.preventDefault();
|
|
|
|
} else if (goto_pressed && event.keyCode == 67) { // 'c' keypress, for narrow-by-recipient
|
|
|
|
var parent = $("#selected").parents("tr");
|
|
|
|
var zephyr_class = parent.find("span.zephyr_class").text();
|
2012-09-05 16:56:59 +02:00
|
|
|
narrow_class(zephyr_class, parent.attr("id"));
|
2012-08-30 23:13:05 +02:00
|
|
|
event.preventDefault()
|
|
|
|
} else if (goto_pressed && event.keyCode == 73) { // 'i' keypress, for narrow-by-instance
|
|
|
|
var parent = $("#selected").parents("tr");
|
|
|
|
var zephyr_class = parent.find("span.zephyr_class").text();
|
|
|
|
var zephyr_instance = parent.find("span.zephyr_instance").text();
|
|
|
|
narrow_instance(zephyr_class, zephyr_instance, parent.attr("id"));
|
|
|
|
event.preventDefault()
|
|
|
|
} else if (goto_pressed && event.keyCode == 80) { // 'p' keypress, for narrow-to-personals
|
2012-09-05 17:00:47 +02:00
|
|
|
narrow_all_personals($("#selected").parents("tr").attr("id"));
|
2012-08-30 23:13:05 +02:00
|
|
|
event.preventDefault();
|
|
|
|
} else if (goto_pressed && event.keyCode == 65) { // 'a' keypress, for unnarrow
|
|
|
|
unhide();
|
|
|
|
event.preventDefault();
|
2012-08-29 17:12:21 +02:00
|
|
|
}
|
2012-08-30 23:13:05 +02:00
|
|
|
|
|
|
|
if (event.keyCode != 71) { // not 'g'
|
|
|
|
goto_pressed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (event.keyCode == 27) { // Esc pressed
|
|
|
|
$('input, textarea, button').blur();
|
|
|
|
event.preventDefault();
|
2012-08-29 17:12:21 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-08-31 22:20:20 +02:00
|
|
|
function scroll_to_selected() {
|
|
|
|
$('#main_div').scrollTop(0);
|
|
|
|
$('#main_div').scrollTop($("#selected").offset().top - $('#main_div').height()/1.5);
|
|
|
|
|
2012-08-29 17:12:21 +02:00
|
|
|
}
|
|
|
|
|
2012-09-04 16:56:48 +02:00
|
|
|
function home_view(element) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var current_view_predicate = home_view;
|
|
|
|
|
|
|
|
function current_view(element) {
|
|
|
|
if (current_view_predicate(element)) {
|
2012-09-04 18:45:51 +02:00
|
|
|
element.show();
|
2012-09-04 16:56:48 +02:00
|
|
|
} else {
|
2012-09-04 18:45:51 +02:00
|
|
|
element.hide();
|
2012-09-04 16:56:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-31 23:52:11 +02:00
|
|
|
function do_narrow(target_zephyr, description, filter_function) {
|
|
|
|
// We want the zephyr on which the narrow happened to stay in the same place if possible.
|
2012-08-29 22:23:56 +02:00
|
|
|
var old_top = $("#main_div").offset().top - $("#" + target_zephyr).offset().top;
|
2012-09-04 16:56:48 +02:00
|
|
|
current_view_predicate = filter_function;
|
|
|
|
$("tr").each(function() {
|
|
|
|
current_view($(this))
|
|
|
|
});
|
2012-08-29 22:23:56 +02:00
|
|
|
|
|
|
|
$("#selected").closest("td").empty();
|
|
|
|
$("#" + target_zephyr).children("td:first").html(selected_tag);
|
|
|
|
$.post("update", {pointer: target_zephyr});
|
2012-08-31 21:48:40 +02:00
|
|
|
|
2012-09-04 17:38:10 +02:00
|
|
|
scroll_to_selected();
|
2012-08-29 22:23:56 +02:00
|
|
|
|
|
|
|
$("#unhide").removeAttr("disabled");
|
2012-08-31 23:52:11 +02:00
|
|
|
$("#narrow_indicator").html(description);
|
2012-08-29 22:23:56 +02:00
|
|
|
}
|
|
|
|
|
2012-09-05 01:27:58 +02:00
|
|
|
function narrow_huddle(target_zephyr) {
|
2012-09-05 17:48:27 +02:00
|
|
|
var parent = $("#" + target_zephyr);
|
|
|
|
var recipients = parent.find("span.zephyr_huddle_recipients_list").text();
|
|
|
|
var message = "Showing group chats with " + recipients;
|
2012-09-05 01:27:58 +02:00
|
|
|
do_narrow(target_zephyr, message,
|
|
|
|
function(element) {
|
2012-09-05 17:48:27 +02:00
|
|
|
return (element.find("span.zephyr_huddle_recipient").length > 0 &&
|
|
|
|
element.find("span.zephyr_huddle_recipients_list").text() == recipients);
|
2012-09-05 01:27:58 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-09-05 17:00:47 +02:00
|
|
|
function narrow_all_personals(target_zephyr) {
|
|
|
|
// Narrow to all personals
|
2012-09-05 17:48:27 +02:00
|
|
|
var message = "Showing all personals";
|
2012-08-31 23:52:11 +02:00
|
|
|
do_narrow(target_zephyr, message,
|
2012-09-04 16:56:48 +02:00
|
|
|
function(element) {
|
|
|
|
return (element.find("span.zephyr_personal_recipient").length > 0);
|
2012-08-31 23:52:11 +02:00
|
|
|
}
|
2012-09-05 17:00:47 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function narrow_personals(target_zephyr) {
|
|
|
|
// Narrow to personals with a specific user
|
|
|
|
var target_recipient = $("#" + target_zephyr).find("span.zephyr_personal_recipient").text();
|
|
|
|
var target_sender = $("#" + target_zephyr).find("span.zephyr_sender").text();
|
2012-09-05 17:48:27 +02:00
|
|
|
var other_party;
|
|
|
|
if (target_recipient == username) {
|
|
|
|
other_party = target_sender;
|
|
|
|
} else {
|
|
|
|
other_party = target_recipient;
|
|
|
|
}
|
|
|
|
var message = "Showing personals with " + other_party;
|
2012-09-05 17:00:47 +02:00
|
|
|
do_narrow(target_zephyr, message,
|
|
|
|
function(element) {
|
|
|
|
var recipient = element.find("span.zephyr_personal_recipient");
|
|
|
|
var sender = element.find("span.zephyr_sender");
|
|
|
|
|
|
|
|
return ((recipient.length > 0) &&
|
|
|
|
((recipient.text() == target_recipient) && (sender.text() == target_sender)) ||
|
|
|
|
((recipient.text() == target_sender) && (sender.text() == target_recipient)));
|
|
|
|
}
|
|
|
|
);
|
2012-08-31 23:52:11 +02:00
|
|
|
}
|
2012-08-29 18:54:58 +02:00
|
|
|
|
2012-08-31 23:52:11 +02:00
|
|
|
function narrow_class(class_name, target_zephyr) {
|
|
|
|
var message = "Showing <span class='label zephyr_class'>" + class_name + "</span>";
|
|
|
|
do_narrow(target_zephyr, message,
|
2012-09-04 16:56:48 +02:00
|
|
|
function(element) {
|
|
|
|
return (element.find("span.zephyr_class").length > 0 &&
|
|
|
|
element.find("span.zephyr_class").text() == class_name);
|
2012-08-31 23:52:11 +02:00
|
|
|
}
|
|
|
|
);
|
2012-08-29 17:12:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function narrow_instance(class_name, instance, target_zephyr) {
|
2012-08-31 23:52:11 +02:00
|
|
|
var message = "Showing <span class='label zephyr_class'>" + class_name
|
|
|
|
+ "</span> <span class='label zephyr_instance'>" + instance + "</span>";
|
|
|
|
do_narrow(target_zephyr, message,
|
2012-09-04 16:56:48 +02:00
|
|
|
function(element) {
|
|
|
|
return (element.find("span.zephyr_class").length > 0 &&
|
|
|
|
element.find("span.zephyr_class").text() == class_name &&
|
|
|
|
element.find("span.zephyr_instance").text() == instance);
|
2012-08-31 23:52:11 +02:00
|
|
|
}
|
|
|
|
);
|
2012-08-29 17:12:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function unhide() {
|
2012-09-04 16:56:48 +02:00
|
|
|
current_view_predicate = home_view;
|
2012-08-29 17:12:21 +02:00
|
|
|
$("tr").show();
|
|
|
|
|
2012-08-31 22:20:20 +02:00
|
|
|
scroll_to_selected();
|
2012-08-29 18:54:58 +02:00
|
|
|
|
|
|
|
$("#unhide").attr("disabled", "disabled");
|
|
|
|
$("#narrow_indicator").html("");
|
2012-08-29 17:12:21 +02:00
|
|
|
}
|
|
|
|
|
2012-08-29 22:47:53 +02:00
|
|
|
function newline2br(content) {
|
|
|
|
return content.replace(/\n/g, '<br />');
|
|
|
|
}
|
|
|
|
|
2012-09-04 20:31:23 +02:00
|
|
|
function update_autocomplete() {
|
|
|
|
class_list.sort();
|
|
|
|
instance_list.sort();
|
|
|
|
people_list.sort();
|
|
|
|
|
|
|
|
$( "#class" ).autocomplete({
|
|
|
|
source: class_list
|
|
|
|
});
|
|
|
|
$( "#instance" ).autocomplete({
|
|
|
|
source: instance_list
|
|
|
|
});
|
|
|
|
$( "#recipient" ).autocomplete({
|
|
|
|
source: people_list
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-08-29 17:12:21 +02:00
|
|
|
function add_message(index, zephyr) {
|
2012-09-04 20:31:23 +02:00
|
|
|
if (zephyr.type == 'class') {
|
2012-09-04 23:20:21 +02:00
|
|
|
zephyr.is_class = true;
|
2012-09-04 20:31:23 +02:00
|
|
|
if ($.inArray(zephyr.display_recipient, class_list) == -1) {
|
|
|
|
class_list.push(zephyr.display_recipient);
|
|
|
|
update_autocomplete();
|
|
|
|
}
|
|
|
|
if ($.inArray(zephyr.instance, instance_list) == -1) {
|
|
|
|
instance_list.push(zephyr.instance);
|
|
|
|
update_autocomplete();
|
|
|
|
}
|
2012-09-04 23:20:21 +02:00
|
|
|
} else if (zephyr.type == "huddle") {
|
|
|
|
zephyr.is_huddle = true;
|
2012-09-04 20:31:23 +02:00
|
|
|
} else {
|
2012-09-04 18:20:07 +02:00
|
|
|
zephyr.is_personal = true;
|
2012-09-04 20:31:23 +02:00
|
|
|
|
|
|
|
if (zephyr.display_recipient != username &&
|
|
|
|
$.inArray(zephyr.display_recipient, people_list) == -1) {
|
|
|
|
people_list.push(zephyr.display_recipient);
|
|
|
|
update_autocomplete();
|
|
|
|
}
|
|
|
|
if (zephyr.sender != username &&
|
|
|
|
$.inArray(zephyr.sender, people_list) == -1) {
|
|
|
|
people_list.push(zephyr.sender);
|
|
|
|
update_autocomplete();
|
|
|
|
}
|
2012-08-29 18:53:03 +02:00
|
|
|
}
|
2012-09-04 18:20:07 +02:00
|
|
|
zephyr.html_content = newline2br(zephyr.content);
|
2012-08-30 20:24:29 +02:00
|
|
|
|
2012-09-04 18:20:07 +02:00
|
|
|
var new_tr = $('<tr />').attr('id', zephyr.id);
|
|
|
|
$('#table').append(new_tr);
|
|
|
|
new_tr.append(ich.zephyr(zephyr));
|
|
|
|
current_view(new_tr);
|
2012-08-29 17:12:21 +02:00
|
|
|
}
|
|
|
|
|
2012-09-04 18:20:07 +02:00
|
|
|
$(function () {
|
|
|
|
/* We can't easily embed this client-side template in index.html,
|
|
|
|
because its syntax conflicts with Django's. */
|
|
|
|
$.get('/static/templates/zephyr.html', function (template) {
|
|
|
|
ich.addTemplate('zephyr', template);
|
|
|
|
$(initial_zephyr_json).each(add_message);
|
2012-09-05 17:15:14 +02:00
|
|
|
|
|
|
|
var selected = $("#" + initial_pointer);
|
|
|
|
if (selected.length == 0) {
|
|
|
|
// initial_pointer names a zephyr we can't see
|
|
|
|
selected = $("tr:first");
|
|
|
|
}
|
|
|
|
select_zephyr(selected);
|
|
|
|
|
2012-09-04 18:20:07 +02:00
|
|
|
get_updates_longpoll();
|
|
|
|
});
|
2012-08-30 19:56:15 +02:00
|
|
|
});
|
|
|
|
|
2012-08-31 21:33:04 +02:00
|
|
|
var longpoll_failures = 0;
|
|
|
|
|
2012-09-05 20:06:08 +02:00
|
|
|
function get_updates_longpoll() {
|
2012-09-04 17:46:02 +02:00
|
|
|
var last_received = 0;
|
|
|
|
if ($("tr:last").attr("id")) {
|
|
|
|
last_received = $("tr:last").attr("id");
|
|
|
|
}
|
2012-09-05 20:00:56 +02:00
|
|
|
console.log(new Date() + ': longpoll started');
|
2012-08-31 21:33:04 +02:00
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: 'get_updates_longpoll',
|
|
|
|
data: { last_received: last_received },
|
|
|
|
dataType: 'json',
|
|
|
|
success: function (data) {
|
2012-09-05 20:00:56 +02:00
|
|
|
console.log(new Date() + ': longpoll success');
|
2012-08-31 21:33:04 +02:00
|
|
|
longpoll_failures = 0;
|
2012-09-05 20:06:08 +02:00
|
|
|
if (data && data.zephyrs) {
|
|
|
|
$.each(data.zephyrs, add_message);
|
|
|
|
}
|
2012-09-05 20:06:19 +02:00
|
|
|
setTimeout(get_updates_longpoll, 0);
|
2012-08-31 21:33:04 +02:00
|
|
|
},
|
|
|
|
error: function () {
|
|
|
|
longpoll_failures += 1;
|
2012-09-05 20:00:56 +02:00
|
|
|
console.log(new Date() + ': longpoll failed (' + longpoll_failures + ' failures)');
|
2012-08-31 21:33:04 +02:00
|
|
|
if (longpoll_failures >= 6) {
|
2012-09-05 20:00:56 +02:00
|
|
|
console.log(new Date() + ': longpoll giving up')
|
2012-08-31 21:33:04 +02:00
|
|
|
$('#connection-error').show();
|
|
|
|
resize_main_div();
|
|
|
|
} else {
|
2012-09-05 20:00:56 +02:00
|
|
|
console.log(new Date() + ': longpoll retrying')
|
2012-08-31 21:33:04 +02:00
|
|
|
setTimeout(get_updates_longpoll, 5*1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2012-08-29 17:12:21 +02:00
|
|
|
}
|
2012-09-04 20:31:23 +02:00
|
|
|
|
|
|
|
$(function() {
|
|
|
|
update_autocomplete();
|
|
|
|
});
|