2012-10-05 20:25:27 +02:00
|
|
|
// We want to remember how far we were scrolled on each 'tab'.
|
|
|
|
// To do so, we need to save away the old position of the
|
|
|
|
// scrollbar when we switch to a new tab (and restore it
|
|
|
|
// when we switch back.)
|
|
|
|
var scroll_positions = {};
|
|
|
|
|
2012-10-03 21:44:07 +02:00
|
|
|
function register_huddle_onclick(zephyr_row, sender) {
|
|
|
|
zephyr_row.find(".zephyr_sender").click(function (e) {
|
2012-10-04 23:58:42 +02:00
|
|
|
select_zephyr_by_id(zephyr_row.attr('zid'));
|
|
|
|
// populate the stream box
|
|
|
|
respond_to_zephyr();
|
|
|
|
// but we really want to be in huddle mode
|
2012-10-03 21:44:07 +02:00
|
|
|
prepare_huddle(sender);
|
|
|
|
// The sender span is inside the messagebox, which also has an
|
|
|
|
// onclick handler. We don't want to trigger the messagebox
|
|
|
|
// handler.
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
// switch to the replybox hotkey handler
|
2012-10-04 07:25:43 +02:00
|
|
|
set_keydown_in_input(true);
|
2012-10-03 21:44:07 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function register_onclick(zephyr_row, zephyr_id) {
|
|
|
|
zephyr_row.find(".messagebox").click(function (e) {
|
|
|
|
if (!(clicking && mouse_moved)) {
|
|
|
|
// Was a click (not a click-and-drag).
|
|
|
|
select_zephyr_by_id(zephyr_id);
|
|
|
|
respond_to_zephyr();
|
2012-10-05 22:20:53 +02:00
|
|
|
set_keydown_in_input(true);
|
2012-10-03 21:44:07 +02:00
|
|
|
}
|
|
|
|
mouse_moved = false;
|
|
|
|
clicking = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We use 'visibility' rather than 'display' and jQuery's show() / hide(),
|
|
|
|
because we want to reserve space for the email address. This avoids
|
|
|
|
things jumping around slightly when the email address is shown. */
|
|
|
|
|
|
|
|
function hide_email() {
|
|
|
|
$('.zephyr_sender_email').addClass('invisible');
|
|
|
|
}
|
|
|
|
|
|
|
|
function show_email(zephyr_id) {
|
|
|
|
hide_email();
|
|
|
|
get_zephyr_row(zephyr_id).find('.zephyr_sender_email').removeClass('invisible');
|
|
|
|
}
|
|
|
|
|
|
|
|
function report_error(response, xhr, status_box) {
|
|
|
|
if (xhr.status.toString().charAt(0) === "4") {
|
|
|
|
// Only display the error response for 4XX, where we've crafted
|
|
|
|
// a nice response.
|
|
|
|
response += ": " + $.parseJSON(xhr.responseText).msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_box.removeClass(status_classes).addClass('alert-error')
|
|
|
|
.text(response).stop(true).fadeTo(0, 1);
|
|
|
|
status_box.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
var clicking = false;
|
|
|
|
var mouse_moved = false;
|
|
|
|
|
|
|
|
function zephyr_mousedown() {
|
|
|
|
mouse_moved = false;
|
|
|
|
clicking = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function zephyr_mousemove() {
|
|
|
|
if (clicking) {
|
|
|
|
mouse_moved = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var autocomplete_needs_update = false;
|
|
|
|
|
|
|
|
function update_autocomplete() {
|
|
|
|
class_list.sort();
|
|
|
|
instance_list.sort();
|
|
|
|
people_list.sort();
|
|
|
|
|
|
|
|
// limit number of items so the list doesn't fall off the screen
|
|
|
|
$( "#class" ).typeahead({
|
|
|
|
source: class_list,
|
2012-10-03 23:22:51 +02:00
|
|
|
items: 3
|
2012-10-03 21:44:07 +02:00
|
|
|
});
|
|
|
|
$( "#instance" ).typeahead({
|
|
|
|
source: instance_list,
|
2012-10-03 23:22:51 +02:00
|
|
|
items: 2
|
2012-10-03 21:44:07 +02:00
|
|
|
});
|
|
|
|
$( "#recipient" ).typeahead({
|
|
|
|
source: people_list,
|
2012-10-03 23:22:51 +02:00
|
|
|
items: 4
|
2012-10-03 21:44:07 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
autocomplete_needs_update = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$(function () {
|
|
|
|
// NB: This just binds to current elements, and won't bind to elements
|
|
|
|
// created after ready() is called.
|
|
|
|
$('input, textarea, button').focus(function () {
|
2012-10-04 07:25:43 +02:00
|
|
|
set_keydown_in_input(true);
|
2012-10-03 21:44:07 +02:00
|
|
|
});
|
|
|
|
$('input, textarea, button').blur(function () {
|
2012-10-04 07:25:43 +02:00
|
|
|
set_keydown_in_input(false);
|
2012-10-03 21:44:07 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$('#zephyr-type-tabs a[href="#class-message"]').on('shown', function (e) {
|
2012-10-05 23:42:58 +02:00
|
|
|
$('#personal-message').hide();
|
|
|
|
$('#class-message').show();
|
|
|
|
$('#new_message_type').val('class');
|
2012-10-03 21:44:07 +02:00
|
|
|
});
|
|
|
|
$('#zephyr-type-tabs a[href="#personal-message"]').on('shown', function (e) {
|
2012-10-05 23:42:58 +02:00
|
|
|
$('#personal-message').show();
|
|
|
|
$('#class-message').hide();
|
|
|
|
$('#new_message_type').val('personal');
|
2012-10-03 21:44:07 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Prepare the click handler for subbing to a new class to which
|
|
|
|
// you have composed a zephyr.
|
|
|
|
$('#create-it').click(function () {
|
|
|
|
sub_from_home(compose_class_name(), $('#class-dne'));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Prepare the click handler for subbing to an existing class.
|
|
|
|
$('#sub-it').click(function () {
|
|
|
|
sub_from_home(compose_class_name(), $('#class-nosub'));
|
|
|
|
});
|
|
|
|
|
2012-10-05 21:35:36 +02:00
|
|
|
var throttled_scrollhandler = $.throttle(50, function() {
|
2012-10-05 19:22:43 +02:00
|
|
|
if ($('#home').hasClass('active')) {
|
|
|
|
keep_pointer_in_view();
|
2012-10-03 21:44:07 +02:00
|
|
|
}
|
2012-10-05 21:35:36 +02:00
|
|
|
});
|
|
|
|
$(window).mousewheel(throttled_scrollhandler);
|
|
|
|
$(window).scroll(throttled_scrollhandler);
|
2012-10-03 21:44:07 +02:00
|
|
|
|
2012-10-05 20:25:27 +02:00
|
|
|
$('#sidebar a[data-toggle="pill"]').on('show', function (e) {
|
|
|
|
// Save the position of our old tab away, before we switch
|
|
|
|
var viewport = $(window);
|
|
|
|
var old_tab = $(e.relatedTarget).attr('href');
|
|
|
|
scroll_positions[old_tab] = viewport.scrollTop();
|
|
|
|
});
|
|
|
|
$('#sidebar a[data-toggle="pill"]').on('shown', function (e) {
|
|
|
|
// Right after we show the new tab, restore its old scroll position
|
|
|
|
var viewport = $(window);
|
|
|
|
var target_tab = $(e.target).attr('href');
|
|
|
|
if (scroll_positions.hasOwnProperty(target_tab)) {
|
|
|
|
viewport.scrollTop(scroll_positions[target_tab]);
|
|
|
|
} else {
|
|
|
|
viewport.scrollTop(0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-10-03 21:44:07 +02:00
|
|
|
$('.button-slide').click(function () {
|
|
|
|
show_compose('class', $("#class"));
|
|
|
|
});
|
2012-10-03 22:24:17 +02:00
|
|
|
|
|
|
|
$('#sidebar a[href="#subscriptions"]').click(fetch_subs);
|
2012-10-03 22:35:35 +02:00
|
|
|
|
|
|
|
var settings_status = $('#settings-status');
|
|
|
|
settings_status.hide();
|
|
|
|
|
|
|
|
$("#current_settings form").ajaxForm({
|
|
|
|
dataType: 'json', // This seems to be ignored. We still get back an xhr.
|
|
|
|
success: function (resp, statusText, xhr, form) {
|
|
|
|
var message = "Updated settings!";
|
|
|
|
var result = $.parseJSON(xhr.responseText);
|
|
|
|
if ((result.full_name !== undefined) || (result.short_name !== undefined)) {
|
|
|
|
message = "Updated settings! You will need to reload the page for your changes to take effect.";
|
|
|
|
}
|
|
|
|
settings_status.removeClass(status_classes)
|
|
|
|
.addClass('alert-success')
|
|
|
|
.text(message).stop(true).fadeTo(0,1);
|
|
|
|
// TODO: In theory we should auto-reload or something if
|
|
|
|
// you changed the email address or other fields that show
|
|
|
|
// up on all screens
|
|
|
|
},
|
|
|
|
error: function (xhr, error_type, xhn) {
|
|
|
|
var response = "Error changing settings";
|
|
|
|
if (xhr.status.toString().charAt(0) === "4") {
|
|
|
|
// Only display the error response for 4XX, where we've crafted
|
|
|
|
// a nice response.
|
|
|
|
response += ": " + $.parseJSON(xhr.responseText).msg;
|
|
|
|
}
|
|
|
|
settings_status.removeClass(status_classes)
|
|
|
|
.addClass('alert-error')
|
|
|
|
.text(response).stop(true).fadeTo(0,1);
|
2012-10-03 23:22:51 +02:00
|
|
|
}
|
2012-10-03 22:35:35 +02:00
|
|
|
});
|
2012-10-03 21:44:07 +02:00
|
|
|
});
|