2012-11-16 16:45:39 +01:00
|
|
|
var ui = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
2013-07-16 20:00:47 +02:00
|
|
|
var actively_scrolling = false;
|
|
|
|
|
|
|
|
exports.actively_scrolling = function () {
|
|
|
|
return actively_scrolling;
|
|
|
|
};
|
|
|
|
|
2012-12-03 20:54:29 +01:00
|
|
|
// What, if anything, obscures the home tab?
|
|
|
|
exports.home_tab_obscured = function () {
|
2013-08-01 17:47:48 +02:00
|
|
|
if ($('.modal:visible').length > 0) {
|
2012-12-03 20:54:29 +01:00
|
|
|
return 'modal';
|
2013-08-01 17:47:48 +02:00
|
|
|
}
|
|
|
|
if (! $('#home').hasClass('active')) {
|
2012-12-03 20:54:29 +01:00
|
|
|
return 'other_tab';
|
2013-08-01 17:47:48 +02:00
|
|
|
}
|
2012-12-03 20:54:29 +01:00
|
|
|
return false;
|
2012-11-30 18:28:23 +01:00
|
|
|
};
|
|
|
|
|
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-11-06 23:06:47 +01:00
|
|
|
var gravatar_stamp = 1;
|
2012-10-05 20:25:27 +02:00
|
|
|
|
2012-12-19 21:19:29 +01:00
|
|
|
exports.change_tab_to = function (tabname) {
|
2013-01-16 21:42:35 +01:00
|
|
|
$('#gear-menu a[href="' + tabname + '"]').tab('show');
|
2012-12-19 21:19:29 +01:00
|
|
|
};
|
|
|
|
|
2012-11-16 16:45:39 +01:00
|
|
|
exports.focus_on = function (field_id) {
|
2012-10-09 17:41:34 +02:00
|
|
|
// Call after autocompleting on a field, to advance the focus to
|
|
|
|
// the next input field.
|
|
|
|
|
|
|
|
// Bootstrap's typeahead does not expose a callback for when an
|
|
|
|
// autocomplete selection has been made, so we have to do this
|
|
|
|
// manually.
|
|
|
|
$("#" + field_id).focus();
|
2012-11-16 16:45:39 +01:00
|
|
|
};
|
2012-10-09 17:41:34 +02:00
|
|
|
|
2013-05-10 21:06:40 +02:00
|
|
|
function amount_to_paginate() {
|
|
|
|
// Some day we might have separate versions of this function
|
|
|
|
// for Page Up vs. Page Down, but for now it's the same
|
|
|
|
// strategy in either direction.
|
2013-06-06 16:10:12 +02:00
|
|
|
var info = viewport.message_viewport_info();
|
2013-05-20 22:26:20 +02:00
|
|
|
var page_size = info.visible_height;
|
2013-05-10 21:06:40 +02:00
|
|
|
|
2013-08-06 21:32:15 +02:00
|
|
|
// We don't want to page up a full page, because Zulip users
|
2013-05-10 21:06:40 +02:00
|
|
|
// are especially worried about missing messages, so we want
|
|
|
|
// a little bit of the old page to stay on the screen. The
|
|
|
|
// value chosen here is roughly 2 or 3 lines of text, but there
|
|
|
|
// is nothing sacred about it, and somebody more anal than me
|
|
|
|
// might wish to tie this to the size of some particular DOM
|
|
|
|
// element.
|
|
|
|
var overlap_amount = 55;
|
|
|
|
|
|
|
|
var delta = page_size - overlap_amount;
|
|
|
|
|
|
|
|
// If the user has shrunk their browser a whole lot, pagination
|
|
|
|
// is not going to be very pleasant, but we can at least
|
|
|
|
// ensure they go in the right direction.
|
2013-08-01 17:47:48 +02:00
|
|
|
if (delta < 1) {
|
|
|
|
delta = 1;
|
|
|
|
}
|
2013-05-10 21:06:40 +02:00
|
|
|
|
|
|
|
return delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.page_up_the_right_amount = function () {
|
|
|
|
// This function's job is to scroll up the right amount,
|
|
|
|
// after the user hits Page Up. We do this ourselves
|
|
|
|
// because we can't rely on the browser to account for certain
|
|
|
|
// page elements, like the compose box, that sit in fixed
|
|
|
|
// positions above the message pane. For other scrolling
|
|
|
|
// related adjustements, try to make those happen in the
|
|
|
|
// scroll handlers, not here.
|
|
|
|
var delta = amount_to_paginate();
|
|
|
|
viewport.scrollTop(viewport.scrollTop() - delta);
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.page_down_the_right_amount = function () {
|
|
|
|
// see also: page_up_the_right_amount
|
|
|
|
var delta = amount_to_paginate();
|
|
|
|
viewport.scrollTop(viewport.scrollTop() + delta);
|
|
|
|
};
|
|
|
|
|
2013-03-06 20:08:50 +01:00
|
|
|
function find_boundary_tr(initial_tr, iterate_row) {
|
|
|
|
var j, skip_same_td_check = false;
|
|
|
|
var tr = initial_tr;
|
|
|
|
|
|
|
|
// If the selection boundary is somewhere that does not have a
|
|
|
|
// parent tr, we should let the browser handle the copy-paste
|
|
|
|
// entirely on its own
|
|
|
|
if (tr.length === 0) {
|
2013-03-13 23:07:41 +01:00
|
|
|
return undefined;
|
2013-03-06 20:08:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the selection bounary is on a table row that does not have an
|
|
|
|
// associated message id (because the user clicked between messages),
|
|
|
|
// then scan downwards until we hit a table row with a message id.
|
|
|
|
// To ensure we can't enter an infinite loop, bail out (and let the
|
|
|
|
// browser handle the copy-paste on its own) if we don't hit what we
|
|
|
|
// are looking for within 10 rows.
|
|
|
|
for (j = 0; (!tr.is('.message_row')) && j < 10; j++) {
|
|
|
|
tr = iterate_row(tr);
|
|
|
|
}
|
|
|
|
if (j === 10) {
|
2013-03-13 23:07:41 +01:00
|
|
|
return undefined;
|
2013-03-06 20:08:50 +01:00
|
|
|
} else if (j !== 0) {
|
|
|
|
// If we updated tr, then we are not dealing with a selection
|
|
|
|
// that is entirely within one td, and we can skip the same td
|
|
|
|
// check (In fact, we need to because it won't work correctly
|
|
|
|
// in this case)
|
|
|
|
skip_same_td_check = true;
|
|
|
|
}
|
|
|
|
return [rows.id(tr), skip_same_td_check];
|
|
|
|
}
|
|
|
|
|
2013-07-23 00:25:25 +02:00
|
|
|
exports.replace_emoji_with_text = function (element) {
|
|
|
|
element.find(".emoji").replaceWith(function () {
|
|
|
|
return $(this).attr("alt");
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-05-16 22:47:53 +02:00
|
|
|
function copy_handler(e) {
|
2013-01-09 23:42:43 +01:00
|
|
|
var selection = window.getSelection();
|
2013-03-06 20:08:50 +01:00
|
|
|
var i, range, ranges = [], startc, endc, initial_end_tr, start_id, end_id, row, message;
|
|
|
|
var start_data, end_data;
|
2013-01-09 23:42:43 +01:00
|
|
|
var skip_same_td_check = false;
|
2013-04-25 23:16:40 +02:00
|
|
|
var div = $('<div>'), content;
|
2013-01-09 23:42:43 +01:00
|
|
|
for (i = 0; i < selection.rangeCount; i++) {
|
|
|
|
range = selection.getRangeAt(i);
|
|
|
|
ranges.push(range);
|
|
|
|
|
|
|
|
startc = $(range.startContainer);
|
2013-07-05 17:43:56 +02:00
|
|
|
start_data = find_boundary_tr($(startc.parents('tr')[0]), function (row) {
|
2013-03-06 20:08:50 +01:00
|
|
|
return row.next();
|
|
|
|
});
|
2013-03-13 23:07:41 +01:00
|
|
|
if (start_data === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
2013-03-06 20:08:50 +01:00
|
|
|
start_id = start_data[0];
|
2013-01-09 23:42:43 +01:00
|
|
|
|
|
|
|
endc = $(range.endContainer);
|
|
|
|
// If the selection ends in the bottom whitespace, we should act as
|
|
|
|
// though the selection ends on the final message
|
|
|
|
if (endc.attr('id') === "bottom_whitespace") {
|
2013-03-06 20:08:50 +01:00
|
|
|
initial_end_tr = $("tr.message_row:last");
|
2013-01-09 23:42:43 +01:00
|
|
|
skip_same_td_check = true;
|
|
|
|
} else {
|
2013-03-06 20:08:50 +01:00
|
|
|
initial_end_tr = $(endc.parents('tr')[0]);
|
2013-01-09 23:42:43 +01:00
|
|
|
}
|
2013-07-05 17:43:56 +02:00
|
|
|
end_data = find_boundary_tr(initial_end_tr, function (row) {
|
2013-03-06 20:08:50 +01:00
|
|
|
return row.prev();
|
|
|
|
});
|
2013-03-13 23:07:41 +01:00
|
|
|
if (end_data === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
2013-03-06 20:08:50 +01:00
|
|
|
end_id = end_data[0];
|
2013-01-09 23:42:43 +01:00
|
|
|
|
2013-03-06 20:08:50 +01:00
|
|
|
if (start_data[1] || end_data[1]) {
|
2013-01-09 23:42:43 +01:00
|
|
|
skip_same_td_check = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the selection starts and ends in the same td,
|
2013-07-23 18:23:19 +02:00
|
|
|
// we want to let the browser handle the copy-paste mostly on its own
|
2013-01-09 23:42:43 +01:00
|
|
|
if (!skip_same_td_check &&
|
|
|
|
startc.parents('td')[0] === endc.parents('td')[0]) {
|
|
|
|
|
2013-07-23 18:23:19 +02:00
|
|
|
// If the user is not running the desktop app, let the browser handle
|
|
|
|
// the copy entirely on its own
|
|
|
|
if (window.bridge === undefined) {
|
|
|
|
return;
|
2013-01-09 23:42:43 +01:00
|
|
|
}
|
|
|
|
|
2013-07-23 18:23:19 +02:00
|
|
|
// If the user is running the desktop app, we still create "div"
|
|
|
|
// so that we can replace emoji with their text
|
|
|
|
div.append(range.cloneContents());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
// Construct a div for what we want to copy (div)
|
2013-08-14 22:00:32 +02:00
|
|
|
for (row = current_msg_list.get_row(start_id);
|
2013-07-23 18:23:19 +02:00
|
|
|
rows.id(row) <= end_id;
|
|
|
|
row = rows.next_visible(row))
|
|
|
|
{
|
|
|
|
if (row.prev().hasClass("recipient_row")) {
|
|
|
|
content = $('<div>').text(row.prev().children(".right_part").text()
|
|
|
|
.replace(/\s+/g, " ")
|
|
|
|
.replace(/^\s/, "").replace(/\s$/, ""));
|
|
|
|
div.append($('<p>').append($('<strong>').text(content.text())));
|
|
|
|
}
|
|
|
|
|
|
|
|
message = current_msg_list.get(rows.id(row));
|
|
|
|
|
|
|
|
var message_firstp = $(message.content).slice(0, 1);
|
|
|
|
message_firstp.prepend(message.sender_full_name + ": ");
|
|
|
|
div.append(message_firstp);
|
|
|
|
div.append($(message.content).slice(1));
|
|
|
|
}
|
2013-01-09 23:42:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-23 00:25:25 +02:00
|
|
|
if (window.bridge !== undefined) {
|
|
|
|
// If the user is running the desktop app,
|
|
|
|
// convert emoji images to plain text for
|
|
|
|
// copy-paste purposes.
|
|
|
|
exports.replace_emoji_with_text(div);
|
|
|
|
}
|
|
|
|
|
2013-01-09 23:42:43 +01:00
|
|
|
// Select div so that the browser will copy it
|
|
|
|
// instead of copying the original selection
|
|
|
|
div.css({position: 'absolute', 'left': '-99999px'})
|
|
|
|
.attr('id', 'copytempdiv');
|
|
|
|
$('body').append(div);
|
|
|
|
selection.selectAllChildren(div[0]);
|
|
|
|
|
|
|
|
// After the copy has happened, delete the div and
|
|
|
|
// change the selection back to the original selection
|
2013-07-05 17:43:56 +02:00
|
|
|
window.setTimeout(function () {
|
2013-01-09 23:42:43 +01:00
|
|
|
selection = window.getSelection();
|
|
|
|
selection.removeAllRanges();
|
2013-07-30 00:35:44 +02:00
|
|
|
_.each(ranges, function (range) {
|
2013-01-09 23:42:43 +01:00
|
|
|
selection.addRange(range);
|
|
|
|
});
|
2013-04-26 00:11:56 +02:00
|
|
|
$('#copytempdiv').remove();
|
2013-01-09 23:42:43 +01:00
|
|
|
},0);
|
2013-05-16 22:47:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$(function () {
|
|
|
|
$(document).bind('copy', copy_handler);
|
2013-01-09 23:42:43 +01:00
|
|
|
});
|
|
|
|
|
2012-10-03 21:44:07 +02:00
|
|
|
/* 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. */
|
|
|
|
|
2013-02-09 04:33:06 +01:00
|
|
|
var current_message_hover;
|
|
|
|
function message_unhover() {
|
2013-08-15 23:43:16 +02:00
|
|
|
var message;
|
2013-08-01 17:47:48 +02:00
|
|
|
if (current_message_hover === undefined) {
|
2013-02-09 04:33:06 +01:00
|
|
|
return;
|
2013-08-01 17:47:48 +02:00
|
|
|
}
|
2013-08-15 23:43:16 +02:00
|
|
|
message = current_msg_list.get(rows.id(current_message_hover));
|
|
|
|
if (feature_flags.edit_appears_on_hover && message && message.sent_by_me) {
|
|
|
|
current_message_hover.find('.message_content').find('span.edit_content').remove();
|
|
|
|
}
|
2013-02-09 04:33:06 +01:00
|
|
|
current_message_hover.removeClass('message_hovered');
|
|
|
|
current_message_hover = undefined;
|
2012-10-03 21:44:07 +02:00
|
|
|
}
|
|
|
|
|
2013-02-09 04:33:06 +01:00
|
|
|
function message_hover(message_row) {
|
2013-08-15 23:43:16 +02:00
|
|
|
var message;
|
|
|
|
var edit_content_button = '<span class="edit_content"> <i class="icon-vector-pencil edit_content"></i></span>';
|
|
|
|
if (current_message_hover && message_row && current_message_hover.attr("zid") === message_row.attr("zid")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
message = current_msg_list.get(rows.id(message_row));
|
2013-02-09 04:33:06 +01:00
|
|
|
message_unhover();
|
|
|
|
message_row.addClass('message_hovered');
|
2013-08-15 23:43:16 +02:00
|
|
|
if (feature_flags.edit_appears_on_hover && message && message.sent_by_me) {
|
|
|
|
message_row.find('.message_content').find('p').append(edit_content_button);
|
|
|
|
}
|
2013-02-09 04:33:06 +01:00
|
|
|
current_message_hover = message_row;
|
2012-10-03 21:44:07 +02:00
|
|
|
}
|
|
|
|
|
2012-11-16 16:45:39 +01:00
|
|
|
exports.report_message = function (response, status_box, cls) {
|
2013-08-01 17:47:48 +02:00
|
|
|
if (cls === undefined) {
|
2012-10-31 23:38:34 +01:00
|
|
|
cls = 'alert';
|
2013-08-01 17:47:48 +02:00
|
|
|
}
|
2012-10-31 23:38:34 +01:00
|
|
|
|
|
|
|
status_box.removeClass(status_classes).addClass(cls)
|
|
|
|
.text(response).stop(true).fadeTo(0, 1);
|
|
|
|
status_box.show();
|
2012-11-16 16:45:39 +01:00
|
|
|
};
|
2012-10-31 23:38:34 +01:00
|
|
|
|
2012-11-16 16:45:39 +01:00
|
|
|
exports.report_error = function (response, xhr, status_box) {
|
2012-10-03 21:44:07 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-11-16 16:45:39 +01:00
|
|
|
ui.report_message(response, status_box, 'alert-error');
|
|
|
|
};
|
2012-10-03 21:44:07 +02:00
|
|
|
|
2012-11-16 16:45:39 +01:00
|
|
|
exports.report_success = function (response, status_box) {
|
|
|
|
ui.report_message(response, status_box, 'alert-success');
|
|
|
|
};
|
2012-10-17 20:43:20 +02:00
|
|
|
|
2012-10-03 21:44:07 +02:00
|
|
|
var clicking = false;
|
|
|
|
var mouse_moved = false;
|
|
|
|
|
2012-10-10 16:21:40 +02:00
|
|
|
function mousedown() {
|
2012-10-03 21:44:07 +02:00
|
|
|
mouse_moved = false;
|
|
|
|
clicking = true;
|
|
|
|
}
|
|
|
|
|
2012-10-10 16:21:40 +02:00
|
|
|
function mousemove() {
|
2012-10-03 21:44:07 +02:00
|
|
|
if (clicking) {
|
|
|
|
mouse_moved = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Fix "resizing window breaks in Chrome" issue.
Ironically, I think this might've bee introduced by
commit ca35321c02d5e79e4f9c439a662805c016a333ed,
'Fix "resizing window breaks in Firefox" issue'.
Basically, when the window is 776px wide according to
window.innerWidth, that's the width not including the
scrollbar. However, in Chrome, the media query seems to ignore the
width of the scrollbar, so from the CSS's perspective, the window is
actually ~766px wide, so it goes into condensed mode.
But the rest of our code doesn't, which causes the break.
A bit more on this browser-specific difference at:
http://www.456bereastreet.com/archive/201101/media_queries_viewport_width_scrollbars_and_webkit_browsers/
So the issue we have is, to match the CSS's behavior:
* In Firefox, we should be listening to window.innerWidth
* In Chrome, we should be listening to window.width
We fix this hopefully once and for all by using window.matchMedia --
aka the exact same query that the CSS itself uses. As discussed in my
last commit, this feature is unavailable in IE<10, so we provide a
potentially more fragile fallback, i.e. what we did before this
commit.
(imported from commit d8e6425b81c90c8e0fdda28e7273988c9bfd67ec)
2012-12-04 20:17:56 +01:00
|
|
|
function need_skinny_mode() {
|
|
|
|
if (window.matchMedia !== undefined) {
|
|
|
|
return window.matchMedia("(max-width: 767px)").matches;
|
|
|
|
} else {
|
|
|
|
// IE<10 doesn't support window.matchMedia, so do this
|
|
|
|
// as best we can without it.
|
|
|
|
return window.innerWidth <= 767;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-10 17:18:06 +02:00
|
|
|
function get_new_heights() {
|
|
|
|
var res = {};
|
2013-07-11 21:36:42 +02:00
|
|
|
var viewport_height = viewport.height();
|
2013-07-26 16:51:02 +02:00
|
|
|
var top_navbar_height = $("#top_navbar").outerHeight(true);
|
2013-05-10 17:18:06 +02:00
|
|
|
|
2013-07-11 21:36:42 +02:00
|
|
|
res.bottom_whitespace_height = viewport_height * 0.4;
|
2013-05-10 17:18:06 +02:00
|
|
|
|
2013-07-11 21:36:42 +02:00
|
|
|
res.main_div_min_height = viewport_height - top_navbar_height;
|
2013-05-10 17:18:06 +02:00
|
|
|
|
2013-07-11 21:36:42 +02:00
|
|
|
res.bottom_sidebar_height = viewport_height - top_navbar_height
|
2013-07-26 16:51:02 +02:00
|
|
|
- $(".upper_sidebar").outerHeight(true)
|
2013-05-10 17:18:06 +02:00
|
|
|
- 40;
|
|
|
|
|
|
|
|
res.right_sidebar_height =
|
2013-07-11 21:36:42 +02:00
|
|
|
viewport_height - top_navbar_height
|
2013-07-26 16:51:02 +02:00
|
|
|
- $("#notifications-area").outerHeight(true)
|
|
|
|
- 14; // margin for right sidebar
|
2013-05-10 17:18:06 +02:00
|
|
|
|
|
|
|
res.stream_filters_max_height =
|
2013-07-26 16:51:02 +02:00
|
|
|
res.bottom_sidebar_height
|
|
|
|
- $("#global_filters").outerHeight(true)
|
|
|
|
- $("#streams_header").outerHeight(true)
|
2013-08-06 21:00:40 +02:00
|
|
|
- 10; // stream_filters margin-bottom
|
|
|
|
|
|
|
|
if ($("#share-the-love").is(":visible")) {
|
|
|
|
res.stream_filters_max_height -=
|
|
|
|
$("#share-the-love").outerHeight(true)
|
2013-08-15 22:44:34 +02:00
|
|
|
+ 20; // share-the-love margins + 10px of ??
|
2013-08-06 21:00:40 +02:00
|
|
|
}
|
2013-07-26 16:51:02 +02:00
|
|
|
|
|
|
|
// Don't let us crush the stream sidebar completely out of view
|
|
|
|
res.stream_filters_max_height = Math.max(40, res.stream_filters_max_height);
|
2013-05-10 17:18:06 +02:00
|
|
|
|
|
|
|
res.user_presences_max_height =
|
|
|
|
res.right_sidebar_height * 0.90;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-08-06 21:09:01 +02:00
|
|
|
exports.resize_page_components = function () {
|
2012-10-11 22:34:57 +02:00
|
|
|
var composebox = $("#compose");
|
2013-02-28 19:04:58 +01:00
|
|
|
var floating_recipient_bar = $("#floating_recipient_bar");
|
2013-05-09 21:12:53 +02:00
|
|
|
var tab_bar = $("#tab_bar");
|
|
|
|
var tab_bar_under = $("#tab_bar_underpadding");
|
2013-02-28 19:04:58 +01:00
|
|
|
var desired_width;
|
|
|
|
if (exports.home_tab_obscured() === 'other_tab') {
|
|
|
|
desired_width = $("div.tab-pane.active").outerWidth();
|
2012-10-11 22:34:57 +02:00
|
|
|
} else {
|
2013-02-28 19:04:58 +01:00
|
|
|
desired_width = $("#main_div").outerWidth();
|
2012-10-11 22:34:57 +02:00
|
|
|
}
|
2013-02-28 19:04:58 +01:00
|
|
|
composebox.width(desired_width);
|
|
|
|
floating_recipient_bar.width(desired_width);
|
2013-05-09 21:12:53 +02:00
|
|
|
tab_bar.width(desired_width);
|
|
|
|
tab_bar_under.width(desired_width);
|
2012-10-12 06:12:46 +02:00
|
|
|
|
2013-05-10 17:18:06 +02:00
|
|
|
var h = get_new_heights();
|
2013-02-12 16:18:22 +01:00
|
|
|
|
2013-05-10 17:18:06 +02:00
|
|
|
$("#bottom_whitespace").height(h.bottom_whitespace_height);
|
|
|
|
$(".bottom_sidebar").height(h.bottom_sidebar_height);
|
|
|
|
$("#right-sidebar").height(h.right_sidebar_height);
|
|
|
|
$("#stream_filters").css('max-height', h.stream_filters_max_height);
|
|
|
|
$("#user_presences").css('max-height', h.user_presences_max_height);
|
2013-08-06 21:09:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function resizehandler(e) {
|
|
|
|
exports.resize_page_components();
|
2013-02-06 19:48:26 +01:00
|
|
|
|
2012-10-12 06:12:46 +02:00
|
|
|
// This function might run onReady (if we're in a narrow window),
|
|
|
|
// but before we've loaded in the messages; in that case, don't
|
|
|
|
// try to scroll to one.
|
2013-02-20 18:26:50 +01:00
|
|
|
if (current_msg_list.selected_id() !== -1) {
|
2012-10-12 06:12:46 +02:00
|
|
|
scroll_to_selected();
|
|
|
|
}
|
Clean up code for unread counts and notifications.
The core simplification here is that zephyr.js no longer has:
* the global home_unread_messages
* the function unread_in_current_view() [which used the global]
The logic that used to be in zephyr is now in its proper home
of unread.js, which has these changes:
* the structure returned from unread.get_counts() includes
a new member called unread_in_current_view
* there's a helper function unread.num_unread_current_messages()
Deprecating zephyr.unread_in_current_view() affected two callers:
* notifications.update_title_count()
* notifications_bar.update()
The above functions used to call back to zephyr to get counts, but
there was no nice way to enforce that they were getting counts
at the right time in the code flow, because they depended on
functions like process_visible_unread_messages() to orchestrate
updating internal unread counts before pushing out counts to the DOM.
Now both of those function take a parameter with the unread count,
and we then had to change all of their callers appropriately. This
went hand in hand with another goal, which is that we want all the
unread-counts logic to funnel though basically one place, which
is zephyr.update_unread_counts(). So now that function always
calls notifications_bar.update() [NEW] as well as calling into
the modules unread.js, stream_list.js, and notifications.js [OLD].
Adding the call to notifications_bar.update() in update_unread_counts()
made it so that some other places in the code no longer needed to call
notifications_bar.update(), so you'll see some lines of code
removed. There are also cases where notifications.update_title_count()
was called redundantly, since the callers were already reaching
update_unread_counts() via other calls.
Finally, in ui.resizehandler, you'll see a simple case where the call
to notifications_bar.update() is preceded by an explicit call
to unread.get_counts().
(imported from commit ce84b9c8076c1f9bb20a61209913f0cb0dae098c)
2013-06-05 21:04:06 +02:00
|
|
|
|
|
|
|
// When the screen resizes, it can make it so that messages are
|
|
|
|
// now on the page, so we need to update the notifications bar.
|
|
|
|
// We may want to do more here in terms of updating unread counts,
|
|
|
|
// but it's possible that resize events can happen as part of
|
|
|
|
// screen resolution changes, so we might want to wait for a more
|
|
|
|
// intentional action to say that the user has "read" a message.
|
|
|
|
var res = unread.get_counts();
|
2013-07-18 21:55:43 +02:00
|
|
|
notifications_bar.update(res.home_unread_messages);
|
2012-10-11 22:34:57 +02:00
|
|
|
}
|
|
|
|
|
2013-02-06 19:48:26 +01:00
|
|
|
$(function () {
|
|
|
|
// When the user's profile picture loads this can change the height of the sidebar
|
|
|
|
$("img.gravatar-profile").bind('load', resizehandler);
|
|
|
|
});
|
|
|
|
|
2012-10-16 03:33:43 +02:00
|
|
|
var is_floating_recipient_bar_showing = false;
|
2013-02-18 20:37:17 +01:00
|
|
|
|
|
|
|
function show_floating_recipient_bar() {
|
|
|
|
if (!is_floating_recipient_bar_showing) {
|
2013-02-28 19:04:58 +01:00
|
|
|
$("#floating_recipient_bar").css('visibility', 'visible');
|
2013-02-18 20:37:17 +01:00
|
|
|
is_floating_recipient_bar_showing = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var old_label;
|
2012-10-16 03:33:43 +02:00
|
|
|
function replace_floating_recipient_bar(desired_label) {
|
2012-11-21 20:41:57 +01:00
|
|
|
var new_label, other_label, header;
|
2012-10-16 01:29:03 +02:00
|
|
|
if (desired_label !== old_label) {
|
2012-10-17 22:03:00 +02:00
|
|
|
if (desired_label.children(".message_header_stream").length !== 0) {
|
2012-11-21 20:41:57 +01:00
|
|
|
new_label = $("#current_label_stream");
|
2012-12-03 19:49:12 +01:00
|
|
|
other_label = $("#current_label_private_message");
|
2012-11-21 20:41:57 +01:00
|
|
|
header = desired_label.children(".message_header_stream.right_part");
|
2012-12-01 04:37:52 +01:00
|
|
|
|
|
|
|
$("#current_label_stream td:first").css(
|
|
|
|
"background-color",
|
2013-06-21 23:22:41 +02:00
|
|
|
desired_label.children(".message_header_colorblock")
|
2012-12-01 04:37:52 +01:00
|
|
|
.css("background-color"));
|
2012-10-16 01:29:03 +02:00
|
|
|
} else {
|
2012-12-03 19:49:12 +01:00
|
|
|
new_label = $("#current_label_private_message");
|
2012-11-21 20:41:57 +01:00
|
|
|
other_label = $("#current_label_stream");
|
2012-12-03 19:49:12 +01:00
|
|
|
header = desired_label.children(".message_header_private_message.right_part");
|
2012-10-16 01:29:03 +02:00
|
|
|
}
|
2012-11-21 20:41:57 +01:00
|
|
|
new_label.find("td:last").replaceWith(header.clone());
|
|
|
|
other_label.css('display', 'none');
|
|
|
|
new_label.css('display', 'table-row');
|
2013-02-09 19:52:16 +01:00
|
|
|
new_label.attr("zid", rows.id(desired_label));
|
2012-11-21 20:41:57 +01:00
|
|
|
|
2012-10-16 01:29:03 +02:00
|
|
|
old_label = desired_label;
|
|
|
|
}
|
2013-02-18 20:37:17 +01:00
|
|
|
show_floating_recipient_bar();
|
2012-10-14 04:13:27 +02:00
|
|
|
}
|
|
|
|
|
2012-10-16 03:33:43 +02:00
|
|
|
function hide_floating_recipient_bar() {
|
|
|
|
if (is_floating_recipient_bar_showing) {
|
2013-02-28 19:04:58 +01:00
|
|
|
$("#floating_recipient_bar").css('visibility', 'hidden');
|
2012-10-16 03:33:43 +02:00
|
|
|
is_floating_recipient_bar_showing = false;
|
2012-10-16 01:29:03 +02:00
|
|
|
}
|
2012-10-14 04:13:27 +02:00
|
|
|
}
|
|
|
|
|
2012-12-07 20:52:39 +01:00
|
|
|
exports.update_floating_recipient_bar = function () {
|
2013-02-28 19:04:58 +01:00
|
|
|
var floating_recipient_bar = $("#floating_recipient_bar");
|
|
|
|
var floating_recipient_bar_top = floating_recipient_bar.offset().top;
|
|
|
|
var floating_recipient_bar_bottom = floating_recipient_bar_top + floating_recipient_bar.outerHeight();
|
2012-10-14 04:13:27 +02:00
|
|
|
|
2012-10-15 18:21:05 +02:00
|
|
|
// Find the last message where the top of the recipient
|
2012-10-16 00:14:04 +02:00
|
|
|
// row is at least partially occluded by our box.
|
|
|
|
// Start with the pointer's current location.
|
2013-02-14 23:48:37 +01:00
|
|
|
var candidate = current_msg_list.selected_row();
|
2012-10-26 21:02:04 +02:00
|
|
|
if (candidate === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
2012-10-16 00:14:04 +02:00
|
|
|
while (true) {
|
|
|
|
candidate = candidate.prev();
|
|
|
|
if (candidate.length === 0) {
|
|
|
|
// We're at the top of the page and no labels are above us.
|
2012-10-16 03:33:43 +02:00
|
|
|
hide_floating_recipient_bar();
|
2012-10-16 00:14:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (candidate.is(".focused_table .recipient_row")) {
|
2013-02-28 19:04:58 +01:00
|
|
|
if (candidate.offset().top < floating_recipient_bar_bottom) {
|
2012-10-16 00:14:04 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-10-15 18:21:05 +02:00
|
|
|
}
|
2012-10-16 00:14:04 +02:00
|
|
|
var current_label = candidate;
|
2012-10-15 18:21:05 +02:00
|
|
|
|
|
|
|
// We now know what the floating stream/subject bar should say.
|
|
|
|
// Do we show it?
|
2012-10-14 04:13:27 +02:00
|
|
|
|
2012-10-15 18:21:05 +02:00
|
|
|
// Hide if the bottom of our floating stream/subject label is not
|
|
|
|
// lower than the bottom of current_label (since that means we're
|
|
|
|
// covering up a label that already exists).
|
2013-02-28 19:04:58 +01:00
|
|
|
if (floating_recipient_bar_bottom <=
|
2012-10-16 04:45:10 +02:00
|
|
|
(current_label.offset().top + current_label.outerHeight())) {
|
2012-10-16 03:33:43 +02:00
|
|
|
hide_floating_recipient_bar();
|
2012-10-14 04:13:27 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-10-15 18:21:05 +02:00
|
|
|
|
2013-07-10 23:47:31 +02:00
|
|
|
// Hide if the message is faded
|
2013-07-19 21:53:39 +02:00
|
|
|
if (current_label.hasClass('faded')) {
|
2013-07-10 23:47:31 +02:00
|
|
|
hide_floating_recipient_bar();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-15 18:21:05 +02:00
|
|
|
// Hide if our bottom is in our bookend (or one bookend-height
|
|
|
|
// above it). This means we're not showing any useful part of the
|
2012-11-02 22:04:56 +01:00
|
|
|
// message above us, so why bother showing the label?
|
2012-10-27 03:38:31 +02:00
|
|
|
var current_bookend = current_label.nextUntil(".bookend_tr")
|
|
|
|
.andSelf()
|
|
|
|
.next(".bookend_tr:first");
|
2012-10-15 18:21:05 +02:00
|
|
|
// (The last message currently doesn't have a bookend, which is why this might be 0).
|
2012-10-27 03:38:31 +02:00
|
|
|
if (current_bookend.length > 0) {
|
2013-02-28 19:04:58 +01:00
|
|
|
if (floating_recipient_bar_bottom >
|
2012-10-27 03:38:31 +02:00
|
|
|
(current_bookend.offset().top - current_bookend.outerHeight())) {
|
2012-10-16 03:33:43 +02:00
|
|
|
hide_floating_recipient_bar();
|
2012-10-15 18:21:05 +02:00
|
|
|
return;
|
2012-10-14 04:13:27 +02:00
|
|
|
}
|
|
|
|
}
|
2012-10-15 18:21:05 +02:00
|
|
|
|
2012-10-16 03:33:43 +02:00
|
|
|
replace_floating_recipient_bar(current_label);
|
2012-12-07 20:52:39 +01:00
|
|
|
};
|
|
|
|
|
2012-10-15 21:57:30 +02:00
|
|
|
function hack_for_floating_recipient_bar() {
|
|
|
|
// So, as of this writing, Firefox respects visibility: collapse,
|
|
|
|
// but WebKit does not (at least, my Chrome doesn't.) Instead it
|
|
|
|
// renders it basically as visibility: hidden, which leaves a
|
|
|
|
// slight gap that our messages peek through as they scroll
|
|
|
|
// by. This hack fixes this by programmatically measuring how big
|
|
|
|
// the gap is, and then moving our table up to compensate.
|
|
|
|
var gap = $("#floating_recipient_layout_row").outerHeight(true);
|
|
|
|
var floating_recipient = $(".floating_recipient");
|
|
|
|
var offset = floating_recipient.offset();
|
|
|
|
offset.top = offset.top - gap;
|
|
|
|
floating_recipient.offset(offset);
|
|
|
|
}
|
2012-10-14 04:13:27 +02:00
|
|
|
|
2013-07-25 22:08:16 +02:00
|
|
|
function update_message_flag(messages, flag_name, set_flag) {
|
2013-05-08 23:17:49 +02:00
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: '/json/update_message_flags',
|
2013-07-25 22:08:16 +02:00
|
|
|
data: {messages: JSON.stringify(_.pluck(messages, 'id')),
|
2013-05-10 23:35:50 +02:00
|
|
|
op: set_flag ? 'add' : 'remove',
|
|
|
|
flag: flag_name},
|
2013-05-08 23:17:49 +02:00
|
|
|
dataType: 'json'});
|
|
|
|
}
|
|
|
|
|
2013-05-10 23:35:50 +02:00
|
|
|
function change_message_collapse(message, collapsed) {
|
2013-07-25 22:08:16 +02:00
|
|
|
update_message_flag([message], "collapsed", collapsed);
|
2013-05-10 23:35:50 +02:00
|
|
|
}
|
|
|
|
|
2013-03-27 18:30:02 +01:00
|
|
|
function change_message_star(message, starred) {
|
2013-07-25 22:08:16 +02:00
|
|
|
update_message_flag([message], "starred", starred);
|
2013-03-27 18:30:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function toggle_star(row_id) {
|
|
|
|
// Update the message object pointed to by the various message
|
|
|
|
// lists.
|
|
|
|
var message = current_msg_list.get(row_id);
|
2013-07-09 15:57:20 +02:00
|
|
|
|
|
|
|
mark_message_as_read(message);
|
|
|
|
|
2013-03-27 18:30:02 +01:00
|
|
|
if (message.starred === true) {
|
|
|
|
message.starred = false;
|
|
|
|
} else {
|
|
|
|
message.starred = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Avoid a full re-render, but update the star in each message
|
|
|
|
// table in which it is visible.
|
2013-07-30 00:35:44 +02:00
|
|
|
_.each([all_msg_list, home_msg_list, narrowed_msg_list], function (list) {
|
|
|
|
if (list === undefined) {
|
2013-03-27 18:30:02 +01:00
|
|
|
return;
|
|
|
|
}
|
2013-08-14 22:00:32 +02:00
|
|
|
var row = list.get_row(row_id);
|
2013-03-27 18:30:02 +01:00
|
|
|
if (row === undefined) {
|
|
|
|
// The row may not exist, e.g. if you star a message in the all
|
|
|
|
// messages table from a stream that isn't in your home view.
|
|
|
|
return;
|
|
|
|
}
|
2013-05-10 22:48:02 +02:00
|
|
|
var favorite_image = row.find(".message_star");
|
2013-05-21 17:47:44 +02:00
|
|
|
favorite_image.toggleClass("empty-star");
|
2013-04-14 05:04:47 +02:00
|
|
|
var title_state = message.starred ? "Unstar" : "Star";
|
|
|
|
favorite_image.attr("title", title_state + " this message");
|
2013-03-27 18:30:02 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Save the star change.
|
|
|
|
change_message_star(message, message.starred);
|
|
|
|
}
|
|
|
|
|
2012-11-16 16:45:39 +01:00
|
|
|
function update_gravatars() {
|
2013-07-30 00:35:44 +02:00
|
|
|
_.each($(".gravatar-profile"), function (profile) {
|
2013-06-13 19:39:29 +02:00
|
|
|
// Avatar URLs will have at least one param, so & is safe here.
|
2013-07-30 00:35:44 +02:00
|
|
|
$(profile).attr('src', $(profile).attr('src') + '&stamp=' + gravatar_stamp);
|
2012-11-16 16:45:39 +01:00
|
|
|
});
|
|
|
|
gravatar_stamp += 1;
|
2012-10-31 20:01:21 +01:00
|
|
|
}
|
|
|
|
|
2012-11-16 16:45:39 +01:00
|
|
|
function poll_for_gravatar_update(start_time, url) {
|
2013-06-13 20:32:08 +02:00
|
|
|
// Give users 5 minutes to update their picture on gravatar.com,
|
|
|
|
// during which we try to auto-update their image on our site. If
|
|
|
|
// they take longer than that, we'll update when they press the
|
|
|
|
// save button.
|
2012-11-16 16:45:39 +01:00
|
|
|
$.ajax({
|
|
|
|
type: "HEAD",
|
|
|
|
url: url,
|
|
|
|
async: false,
|
|
|
|
cache: false,
|
|
|
|
success: function (resp, statusText, xhr) {
|
|
|
|
if (new Date(xhr.getResponseHeader('Last-Modified')) > start_time) {
|
|
|
|
update_gravatars();
|
2013-06-13 20:32:08 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (($.now() - start_time) < 1000 * 60 * 5) {
|
|
|
|
setTimeout(function () {
|
|
|
|
poll_for_gravatar_update(start_time, url);
|
|
|
|
}, 1500);
|
|
|
|
}
|
2012-11-16 16:45:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-13 23:48:23 +02:00
|
|
|
exports.small_avatar_url = function (message) {
|
2013-08-02 21:14:08 +02:00
|
|
|
// Try to call this function in all places where we need 25px
|
|
|
|
// gravatar images, so that the browser can help
|
2013-06-13 23:48:23 +02:00
|
|
|
// us avoid unnecessary network trips. (For user-uploaded avatars,
|
2013-08-02 21:14:08 +02:00
|
|
|
// the s=25 parameter is essentially ignored, but it's harmless.)
|
2013-06-13 23:48:23 +02:00
|
|
|
//
|
2013-08-02 21:14:08 +02:00
|
|
|
// We actually request these at s=50, so that we look better
|
|
|
|
// on retina displays.
|
2013-06-13 23:48:23 +02:00
|
|
|
if (message.avatar_url) {
|
2013-08-02 21:14:08 +02:00
|
|
|
var url = message.avatar_url + "&s=50";
|
2013-06-14 17:46:01 +02:00
|
|
|
if (message.sent_by_me) {
|
2013-06-13 23:48:23 +02:00
|
|
|
url += "&stamp=" + gravatar_stamp;
|
|
|
|
}
|
|
|
|
return url;
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
2012-11-16 16:45:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.wait_for_gravatar = function () {
|
|
|
|
poll_for_gravatar_update($.now(), $(".gravatar-profile").attr("src"));
|
|
|
|
};
|
|
|
|
|
2013-01-16 19:50:18 +01:00
|
|
|
var loading_more_messages_indicator_showing = false;
|
|
|
|
exports.show_loading_more_messages_indicator = function () {
|
|
|
|
if (! loading_more_messages_indicator_showing) {
|
2013-07-12 18:31:26 +02:00
|
|
|
util.make_loading_indicator($('#loading_more_messages_indicator'),
|
|
|
|
{abs_positioned: true});
|
2013-01-16 19:50:18 +01:00
|
|
|
loading_more_messages_indicator_showing = true;
|
2012-11-28 22:17:57 +01:00
|
|
|
hide_floating_recipient_bar();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-16 19:50:18 +01:00
|
|
|
exports.hide_loading_more_messages_indicator = function () {
|
|
|
|
if (loading_more_messages_indicator_showing) {
|
|
|
|
util.destroy_loading_indicator($("#loading_more_messages_indicator"));
|
|
|
|
loading_more_messages_indicator_showing = false;
|
2012-11-28 22:17:57 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-07-11 21:17:23 +02:00
|
|
|
function could_be_condensed(elem) {
|
|
|
|
return elem.getBoundingClientRect().height > viewport.height() * 0.65;
|
2013-05-08 23:17:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function show_more_link(row) {
|
|
|
|
row.find(".message_condenser").hide();
|
|
|
|
row.find(".message_expander").show();
|
|
|
|
}
|
|
|
|
|
|
|
|
function show_condense_link(row) {
|
|
|
|
row.find(".message_expander").hide();
|
|
|
|
row.find(".message_condenser").show();
|
|
|
|
}
|
|
|
|
|
|
|
|
function condense(row) {
|
|
|
|
var content = row.find(".message_content");
|
|
|
|
content.addClass("condensed");
|
|
|
|
show_more_link(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
function uncondense(row) {
|
|
|
|
var content = row.find(".message_content");
|
|
|
|
content.removeClass("condensed");
|
|
|
|
show_condense_link(row);
|
|
|
|
}
|
|
|
|
|
2013-06-28 22:38:40 +02:00
|
|
|
exports.uncollapse = function (row) {
|
2013-05-08 23:17:49 +02:00
|
|
|
// Uncollapse a message, restoring the condensed message [More] or
|
|
|
|
// [Condense] link if necessary.
|
|
|
|
var message = current_msg_list.get(rows.id(row));
|
|
|
|
var content = row.find(".message_content");
|
|
|
|
message.collapsed = false;
|
|
|
|
content.removeClass("collapsed");
|
|
|
|
change_message_collapse(message, false);
|
|
|
|
|
|
|
|
if (message.condensed === true) {
|
|
|
|
// This message was condensed by the user, so re-show the
|
|
|
|
// [More] link.
|
|
|
|
condense(row);
|
|
|
|
} else if (message.condensed === false) {
|
|
|
|
// This message was un-condensed by the user, so re-show the
|
|
|
|
// [Condense] link.
|
|
|
|
uncondense(row);
|
|
|
|
} else if (content.hasClass("could-be-condensed")) {
|
|
|
|
// By default, condense a long message.
|
|
|
|
condense(row);
|
|
|
|
} else {
|
|
|
|
// This was a short message, no more need for a [More] link.
|
|
|
|
row.find(".message_expander").hide();
|
|
|
|
}
|
2013-06-28 22:38:40 +02:00
|
|
|
};
|
2013-05-08 23:17:49 +02:00
|
|
|
|
2013-06-28 22:38:40 +02:00
|
|
|
exports.collapse = function (row) {
|
2013-05-08 23:17:49 +02:00
|
|
|
// Collapse a message, hiding the condensed message [More] or
|
|
|
|
// [Condense] link if necessary.
|
|
|
|
var message = current_msg_list.get(rows.id(row));
|
|
|
|
message.collapsed = true;
|
|
|
|
change_message_collapse(message, true);
|
|
|
|
row.find(".message_content").addClass("collapsed");
|
|
|
|
show_more_link(row);
|
2013-05-14 21:02:10 +02:00
|
|
|
};
|
|
|
|
|
2013-08-08 00:12:27 +02:00
|
|
|
exports.expand_summary_row = function (row) {
|
|
|
|
var message_ids = row.attr('data-messages').split(' ');
|
|
|
|
var messages = _.map(message_ids, function (id) {
|
|
|
|
return all_msg_list.get(id);
|
|
|
|
});
|
|
|
|
|
|
|
|
function remove_flag(flag) {
|
|
|
|
_.each(messages, function (msg){
|
|
|
|
msg.flags = _.without(msg.flags, flag);
|
|
|
|
});
|
|
|
|
update_message_flag(messages, flag, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
remove_flag('summarize_in_stream');
|
|
|
|
if (!narrow.active()) {
|
|
|
|
remove_flag('summarize_in_home');
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: Avoid a full re-render
|
|
|
|
home_msg_list.rerender();
|
|
|
|
if (current_msg_list !== home_msg_list) {
|
|
|
|
current_msg_list.rerender();
|
|
|
|
}
|
|
|
|
|
|
|
|
current_msg_list.select_id(message_ids[0]);
|
|
|
|
};
|
|
|
|
|
2012-10-03 21:44:07 +02:00
|
|
|
$(function () {
|
|
|
|
// NB: This just binds to current elements, and won't bind to elements
|
|
|
|
// created after ready() is called.
|
2013-02-01 17:04:23 +01:00
|
|
|
$('#send-status .send-status-close').click(
|
|
|
|
function () { $('#send-status').stop(true).fadeOut(500); }
|
|
|
|
);
|
2012-10-03 21:44:07 +02:00
|
|
|
|
2012-11-30 18:50:16 +01:00
|
|
|
var throttled_mousewheelhandler = $.throttle(50, function (e, delta) {
|
2012-10-16 03:49:51 +02:00
|
|
|
// Most of the mouse wheel's work will be handled by the
|
|
|
|
// scroll handler, but when we're at the top or bottom of the
|
|
|
|
// page, the pointer may still need to move.
|
2013-08-02 17:41:00 +02:00
|
|
|
|
|
|
|
if (delta > 0) {
|
|
|
|
if (viewport.at_top()) {
|
|
|
|
navigate.up();
|
|
|
|
}
|
|
|
|
} else if (delta < 0) {
|
|
|
|
if (viewport.at_bottom()) {
|
|
|
|
navigate.down();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-28 19:16:48 +01:00
|
|
|
last_viewport_movement_direction = delta;
|
2012-10-16 03:49:51 +02:00
|
|
|
});
|
2012-11-30 18:28:23 +01:00
|
|
|
|
|
|
|
$(window).mousewheel(function (e, delta) {
|
|
|
|
// Ignore mousewheel events if a modal is visible. It's weird if the
|
|
|
|
// user can scroll the main view by wheeling over the greyed-out area.
|
|
|
|
// Similarly, ignore events on settings page etc.
|
|
|
|
//
|
|
|
|
// We don't handle the compose box here, because it *should* work to
|
|
|
|
// select the compose box and then wheel over the message stream.
|
2012-12-03 20:55:17 +01:00
|
|
|
var obscured = exports.home_tab_obscured();
|
|
|
|
if (!obscured) {
|
2012-11-30 18:28:23 +01:00
|
|
|
throttled_mousewheelhandler(e, delta);
|
2012-12-03 20:55:17 +01:00
|
|
|
} else if (obscured === 'modal') {
|
|
|
|
// The modal itself has a handler invoked before this one (see below).
|
|
|
|
// preventDefault here so that the tab behind the modal doesn't scroll.
|
|
|
|
//
|
|
|
|
// This needs to include the events that would be ignored by throttling.
|
|
|
|
// That's why this code can't be moved into throttled_mousewheelhandler.
|
2012-11-30 18:28:23 +01:00
|
|
|
e.preventDefault();
|
|
|
|
}
|
2012-12-03 20:55:17 +01:00
|
|
|
// If on another tab, we neither handle the event nor preventDefault, allowing
|
|
|
|
// the tab to scroll normally.
|
2012-11-30 18:28:23 +01:00
|
|
|
});
|
2012-10-16 03:49:51 +02:00
|
|
|
|
2012-11-30 18:49:42 +01:00
|
|
|
$(window).resize($.throttle(50, resizehandler));
|
2012-10-11 22:34:57 +02:00
|
|
|
|
2013-02-12 16:31:55 +01:00
|
|
|
// Scrolling in modals, input boxes, and other elements that
|
|
|
|
// explicitly scroll should not scroll the main view. Stop
|
|
|
|
// propagation in all cases. Also, ignore the event if the
|
|
|
|
// element is already at the top or bottom. Otherwise we get a
|
|
|
|
// new scroll event on the parent (?).
|
|
|
|
$('.modal-body, .scrolling_list, input, textarea').mousewheel(function (e, delta) {
|
2012-11-30 18:28:23 +01:00
|
|
|
var self = $(this);
|
|
|
|
var scroll = self.scrollTop();
|
|
|
|
e.stopPropagation();
|
|
|
|
if ( ((delta > 0) && (scroll <= 0))
|
|
|
|
|| ((delta < 0) && (scroll >= (this.scrollHeight - self.innerHeight())))) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Ignore wheel events in the compose area which weren't already handled above.
|
|
|
|
$('#compose').mousewheel(function (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2012-11-02 22:02:40 +01:00
|
|
|
function clear_password_change() {
|
|
|
|
// Clear the password boxes so that passwords don't linger in the DOM
|
|
|
|
// for an XSS attacker to find.
|
|
|
|
$('#old_password, #new_password, #confirm_password').val('');
|
|
|
|
}
|
|
|
|
|
2013-01-16 21:42:35 +01:00
|
|
|
$('#gear-menu a[data-toggle="tab"]').on('show', function (e) {
|
2012-10-05 20:25:27 +02:00
|
|
|
// Save the position of our old tab away, before we switch
|
|
|
|
var old_tab = $(e.relatedTarget).attr('href');
|
|
|
|
scroll_positions[old_tab] = viewport.scrollTop();
|
|
|
|
});
|
2013-01-16 21:42:35 +01:00
|
|
|
$('#gear-menu a[data-toggle="tab"]').on('shown', function (e) {
|
2012-10-05 20:25:27 +02:00
|
|
|
var target_tab = $(e.target).attr('href');
|
2012-10-09 21:44:29 +02:00
|
|
|
|
|
|
|
// Hide all our error messages when switching tabs
|
|
|
|
$('.alert-error').hide();
|
|
|
|
$('.alert-success').hide();
|
|
|
|
$('.alert-info').hide();
|
|
|
|
$('.alert').hide();
|
2012-10-10 20:06:59 +02:00
|
|
|
|
2012-10-17 22:26:59 +02:00
|
|
|
$("#api_key_value").text("");
|
|
|
|
$("#get_api_key_box").hide();
|
|
|
|
$("#show_api_key_box").hide();
|
|
|
|
$("#api_key_button_box").show();
|
|
|
|
|
2012-11-02 22:02:40 +01:00
|
|
|
clear_password_change();
|
|
|
|
|
2012-10-10 20:06:59 +02:00
|
|
|
// Set the URL bar title to show the sub-page you're currently on.
|
2012-10-27 03:45:05 +02:00
|
|
|
var browser_url = target_tab;
|
2012-10-10 20:06:59 +02:00
|
|
|
if (browser_url === "#home") {
|
2012-12-19 21:19:29 +01:00
|
|
|
browser_url = "";
|
2012-10-10 20:06:59 +02:00
|
|
|
}
|
2012-12-19 21:19:29 +01:00
|
|
|
hashchange.changehash(browser_url);
|
2013-01-22 00:51:15 +01:00
|
|
|
|
|
|
|
// After we show the new tab, restore its old scroll position
|
|
|
|
// (we apparently have to do this after setting the hash,
|
|
|
|
// because otherwise that action may scroll us somewhere.)
|
|
|
|
if (scroll_positions.hasOwnProperty(target_tab)) {
|
|
|
|
viewport.scrollTop(scroll_positions[target_tab]);
|
|
|
|
} else {
|
2013-01-26 00:13:02 +01:00
|
|
|
if (target_tab === '#home') {
|
|
|
|
scroll_to_selected();
|
|
|
|
} else {
|
|
|
|
viewport.scrollTop(0);
|
|
|
|
}
|
2013-01-22 00:51:15 +01:00
|
|
|
}
|
2012-10-05 20:25:27 +02:00
|
|
|
});
|
|
|
|
|
2013-06-19 20:52:17 +02:00
|
|
|
var subs_link = $('#gear-menu a[href="#subscriptions"]');
|
|
|
|
|
|
|
|
// If the streams page is shown by clicking directly on the "Streams"
|
|
|
|
// link (in the gear menu), then focus the new stream textbox.
|
|
|
|
subs_link.on('click', function (e) {
|
2013-07-25 22:48:55 +02:00
|
|
|
$(document).one('subs_page_loaded.zulip', function (e) {
|
2013-06-19 20:52:17 +02:00
|
|
|
$('#create_stream_name').focus().select();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Whenever the streams page comes up (from anywhere), populate it.
|
|
|
|
subs_link.on('shown', subs.setup_page);
|
2012-10-03 22:35:35 +02:00
|
|
|
|
2013-08-12 23:31:23 +02:00
|
|
|
var admin_link = $('#gear-menu a[href="#administration"]');
|
|
|
|
admin_link.on('shown', admin.setup_page);
|
|
|
|
|
2013-04-08 20:03:21 +02:00
|
|
|
$('#pw_change_link').on('click', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
$('#pw_change_link').hide();
|
|
|
|
$('#pw_change_controls').show();
|
|
|
|
});
|
|
|
|
|
2013-04-04 00:55:36 +02:00
|
|
|
$('#new_password').on('change keyup', function () {
|
2013-04-08 20:21:20 +02:00
|
|
|
password_quality($('#new_password').val(), $('#pw_strength .bar'));
|
2013-04-04 00:55:36 +02:00
|
|
|
});
|
|
|
|
|
2012-10-03 22:35:35 +02:00
|
|
|
var settings_status = $('#settings-status');
|
2013-04-04 00:55:36 +02:00
|
|
|
|
|
|
|
function settings_change_error(message) {
|
2013-04-08 19:37:52 +02:00
|
|
|
// Scroll to the top so the error message is visible.
|
|
|
|
// We would scroll anyway if we end up submitting the form.
|
|
|
|
viewport.scrollTop(0);
|
2013-04-04 00:55:36 +02:00
|
|
|
settings_status.removeClass(status_classes)
|
|
|
|
.addClass('alert-error')
|
|
|
|
.text(message).stop(true).fadeTo(0,1);
|
|
|
|
}
|
|
|
|
|
2012-10-17 22:26:59 +02:00
|
|
|
$("#settings-change-box form").ajaxForm({
|
2012-10-03 22:35:35 +02:00
|
|
|
dataType: 'json', // This seems to be ignored. We still get back an xhr.
|
2013-04-04 00:55:36 +02:00
|
|
|
beforeSubmit: function (arr, form, options) {
|
|
|
|
// FIXME: Check that the two password fields match
|
|
|
|
// FIXME: Use the same jQuery validation plugin as the signup form?
|
|
|
|
var new_pw = $('#new_password').val();
|
|
|
|
if (new_pw !== '') {
|
2013-04-08 20:21:20 +02:00
|
|
|
var password_ok = password_quality(new_pw);
|
|
|
|
if (password_ok === undefined) {
|
2013-04-04 00:55:36 +02:00
|
|
|
// zxcvbn.js didn't load, for whatever reason.
|
|
|
|
settings_change_error(
|
|
|
|
'An internal error occurred; try reloading the page. ' +
|
|
|
|
'Sorry for the trouble!');
|
|
|
|
return false;
|
2013-04-08 20:21:20 +02:00
|
|
|
} else if (!password_ok) {
|
2013-04-04 00:55:36 +02:00
|
|
|
settings_change_error('New password is too weak');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
2012-10-03 22:35:35 +02:00
|
|
|
success: function (resp, statusText, xhr, form) {
|
|
|
|
var message = "Updated settings!";
|
|
|
|
var result = $.parseJSON(xhr.responseText);
|
2012-11-05 23:51:27 +01:00
|
|
|
|
|
|
|
if (result.full_name !== undefined) {
|
|
|
|
$(".my_fullname").text(result.full_name);
|
2012-10-03 22:35:35 +02:00
|
|
|
}
|
2012-11-05 23:51:27 +01:00
|
|
|
update_gravatars();
|
|
|
|
|
2012-11-23 23:53:38 +01:00
|
|
|
if (result.enable_desktop_notifications !== undefined) {
|
2013-03-25 23:26:14 +01:00
|
|
|
page_params.desktop_notifications_enabled = result.enable_desktop_notifications;
|
2012-11-23 23:53:38 +01:00
|
|
|
}
|
2013-05-03 21:49:01 +02:00
|
|
|
if (result.enable_sounds !== undefined) {
|
|
|
|
page_params.sounds_enabled = result.enable_sounds;
|
|
|
|
}
|
2012-11-23 23:53:38 +01:00
|
|
|
|
2013-05-07 23:19:52 +02:00
|
|
|
if (result.enable_offline_email_notifications !== undefined) {
|
|
|
|
page_params.enable_offline_email_notifications = result.enable_offline_email_notifications;
|
|
|
|
}
|
|
|
|
|
2012-10-03 22:35:35 +02:00
|
|
|
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;
|
|
|
|
}
|
2013-04-04 00:55:36 +02:00
|
|
|
settings_change_error(response);
|
2012-10-30 21:08:58 +01:00
|
|
|
},
|
|
|
|
complete: function (xhr, statusText) {
|
2012-11-02 22:02:40 +01:00
|
|
|
// Whether successful or not, clear the password boxes.
|
2012-10-30 21:08:58 +01:00
|
|
|
// TODO: Clear these earlier, while the request is still pending.
|
2012-11-02 22:02:40 +01:00
|
|
|
clear_password_change();
|
2012-10-03 23:22:51 +02:00
|
|
|
}
|
2012-10-03 22:35:35 +02:00
|
|
|
});
|
2012-10-12 00:48:37 +02:00
|
|
|
|
2012-10-17 22:26:59 +02:00
|
|
|
$("#get_api_key_box").hide();
|
|
|
|
$("#show_api_key_box").hide();
|
|
|
|
$("#get_api_key_box 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);
|
|
|
|
$("#get_api_key_password").val("");
|
|
|
|
$("#api_key_value").text(result.api_key);
|
|
|
|
$("#show_api_key_box").show();
|
|
|
|
$("#get_api_key_box").hide();
|
|
|
|
settings_status.hide();
|
|
|
|
},
|
|
|
|
error: function (xhr, error_type, xhn) {
|
|
|
|
var response = "Error getting API key";
|
|
|
|
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);
|
|
|
|
$("#show_api_key_box").hide();
|
|
|
|
$("#get_api_key_box").show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-02-28 19:04:58 +01:00
|
|
|
// A little hackish, because it doesn't seem to totally get us the
|
|
|
|
// exact right width for the floating_recipient_bar and compose
|
|
|
|
// box, but, close enough for now.
|
2012-10-12 00:48:37 +02:00
|
|
|
resizehandler();
|
2012-10-15 21:57:30 +02:00
|
|
|
hack_for_floating_recipient_bar();
|
2012-10-12 17:26:04 +02:00
|
|
|
|
2013-07-25 22:08:16 +02:00
|
|
|
if (feature_flags.summarize_read_while_narrowed) {
|
|
|
|
$("#main_div").on("click", ".summary_row", function (e) {
|
2013-08-08 00:12:27 +02:00
|
|
|
exports.expand_summary_row($(e.target).closest('.summary_row'));
|
2013-07-25 22:08:16 +02:00
|
|
|
e.stopImmediatePropagation();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-11-14 23:33:13 +01:00
|
|
|
$("#main_div").on("click", ".messagebox", function (e) {
|
2013-03-11 18:21:39 +01:00
|
|
|
var target = $(e.target);
|
2013-03-13 22:47:38 +01:00
|
|
|
if (target.is("a") || target.is("img.message_inline_image") || target.is("img.twitter-avatar") ||
|
2013-08-15 23:43:16 +02:00
|
|
|
target.is("div.message_length_controller") || target.is("textarea") || target.is("input") ||
|
|
|
|
target.is("i.edit_content")) {
|
2012-11-14 23:33:13 +01:00
|
|
|
// If this click came from a hyperlink, don't trigger the
|
|
|
|
// reply action. The simple way of doing this is simply
|
|
|
|
// to call e.stopPropagation() from within the link's
|
|
|
|
// click handler.
|
|
|
|
//
|
|
|
|
// Unfortunately, on Firefox, this breaks Ctrl-click and
|
|
|
|
// Shift-click, because those are (apparently) implemented
|
|
|
|
// by adding an event listener on link clicks, and
|
|
|
|
// stopPropagation prevents them from being called.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!(clicking && mouse_moved)) {
|
|
|
|
// Was a click (not a click-and-drag).
|
|
|
|
var row = $(this).closest(".message_row");
|
2013-06-11 18:54:07 +02:00
|
|
|
var id = rows.id(row);
|
|
|
|
|
|
|
|
if (message_edit.is_editing(id)) {
|
|
|
|
// Clicks on a message being edited shouldn't trigger a reply.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
current_msg_list.select_id(id);
|
2013-05-20 23:35:41 +02:00
|
|
|
respond_to_message({trigger: 'message click'});
|
2013-05-03 22:16:52 +02:00
|
|
|
e.stopPropagation();
|
2013-07-09 00:02:10 +02:00
|
|
|
popovers.hide_all();
|
2012-11-14 23:33:13 +01:00
|
|
|
}
|
|
|
|
mouse_moved = false;
|
|
|
|
clicking = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#main_div").on("mousedown", ".messagebox", mousedown);
|
|
|
|
$("#main_div").on("mousemove", ".messagebox", mousemove);
|
2013-05-21 17:47:44 +02:00
|
|
|
$("#main_div").on("mouseover", ".message_row", function (e) {
|
2013-08-15 23:43:16 +02:00
|
|
|
var row = $(this).closest(".message_row");
|
2013-02-09 04:33:06 +01:00
|
|
|
message_hover(row);
|
2012-11-14 23:33:13 +01:00
|
|
|
});
|
|
|
|
|
2013-08-15 23:43:16 +02:00
|
|
|
$("#main_div").on("mouseleave", ".message_row", function (e) {
|
2013-02-09 04:33:06 +01:00
|
|
|
message_unhover();
|
2012-11-14 23:33:13 +01:00
|
|
|
});
|
|
|
|
|
2013-07-11 23:06:58 +02:00
|
|
|
$("#main_div").on("mouseover", ".message_sender", function (e) {
|
2012-11-14 23:33:13 +01:00
|
|
|
var row = $(this).closest(".message_row");
|
2013-07-11 23:06:58 +02:00
|
|
|
row.addClass("sender_name_hovered");
|
2012-11-14 23:33:13 +01:00
|
|
|
});
|
|
|
|
|
2013-07-11 23:06:58 +02:00
|
|
|
$("#main_div").on("mouseout", ".message_sender", function (e) {
|
2012-11-14 23:33:13 +01:00
|
|
|
var row = $(this).closest(".message_row");
|
2013-07-11 23:06:58 +02:00
|
|
|
row.removeClass("sender_name_hovered");
|
2012-11-14 23:33:13 +01:00
|
|
|
});
|
|
|
|
|
2013-03-27 18:30:02 +01:00
|
|
|
$("#main_div").on("click", ".star", function (e) {
|
|
|
|
e.stopPropagation();
|
2013-07-09 00:02:10 +02:00
|
|
|
popovers.hide_all();
|
2013-03-27 18:30:02 +01:00
|
|
|
toggle_star(rows.id($(this).closest(".message_row")));
|
|
|
|
});
|
|
|
|
|
2013-03-13 22:47:38 +01:00
|
|
|
$("#home").on("click", ".message_expander", function (e) {
|
2013-05-08 23:17:49 +02:00
|
|
|
// Expanding a message can mean either uncollapsing or
|
|
|
|
// uncondensing it.
|
2013-03-13 22:47:38 +01:00
|
|
|
var row = $(this).closest(".message_row");
|
2013-05-08 23:17:49 +02:00
|
|
|
var message = current_msg_list.get(rows.id(row));
|
|
|
|
var content = row.find(".message_content");
|
|
|
|
if (message.collapsed) {
|
|
|
|
// Uncollapse.
|
2013-06-28 22:38:40 +02:00
|
|
|
ui.uncollapse(row);
|
2013-05-08 23:17:49 +02:00
|
|
|
} else if (content.hasClass("could-be-condensed")) {
|
|
|
|
// Uncondense (show the full long message).
|
|
|
|
message.condensed = false;
|
|
|
|
content.removeClass("condensed");
|
|
|
|
$(this).hide();
|
|
|
|
row.find(".message_condenser").show();
|
|
|
|
}
|
2013-03-13 22:47:38 +01:00
|
|
|
});
|
|
|
|
|
2013-05-01 23:21:45 +02:00
|
|
|
$("#home").on("click", ".message_condenser", function (e) {
|
2013-03-13 22:47:38 +01:00
|
|
|
var row = $(this).closest(".message_row");
|
2013-05-01 23:21:45 +02:00
|
|
|
current_msg_list.get(rows.id(row)).condensed = true;
|
2013-05-08 23:17:49 +02:00
|
|
|
condense(row);
|
2013-03-13 22:47:38 +01:00
|
|
|
});
|
|
|
|
|
2012-11-21 20:22:20 +01:00
|
|
|
$("#home").on("click", ".narrows_by_recipient", function (e) {
|
2013-02-15 00:23:56 +01:00
|
|
|
var nearest = current_msg_list.get(rows.id($(this).closest(".recipient_row")));
|
|
|
|
var selected = current_msg_list.selected_message();
|
2013-02-26 23:09:15 +01:00
|
|
|
if (util.same_recipient(nearest, selected)) {
|
2013-05-21 19:34:15 +02:00
|
|
|
narrow.by_recipient(selected.id, {trigger: 'message header'});
|
2013-02-15 00:23:56 +01:00
|
|
|
} else {
|
2013-05-21 19:34:15 +02:00
|
|
|
narrow.by_recipient(nearest.id, {trigger: 'message header'});
|
2013-02-15 00:23:56 +01:00
|
|
|
}
|
2012-11-14 23:33:13 +01:00
|
|
|
});
|
|
|
|
|
2012-11-21 20:22:20 +01:00
|
|
|
$("#home").on("click", ".narrows_by_subject", function (e) {
|
2013-02-15 00:23:56 +01:00
|
|
|
var nearest = current_msg_list.get(rows.id($(this).closest(".recipient_row")));
|
|
|
|
var selected = current_msg_list.selected_message();
|
2013-04-22 19:35:23 +02:00
|
|
|
if (util.same_recipient(nearest, selected)) {
|
2013-05-21 19:34:15 +02:00
|
|
|
narrow.by_subject(selected.id, {trigger: 'message header'});
|
2013-02-15 00:23:56 +01:00
|
|
|
} else {
|
2013-05-21 19:34:15 +02:00
|
|
|
narrow.by_subject(nearest.id, {trigger: 'message header'});
|
2013-02-15 00:23:56 +01:00
|
|
|
}
|
2012-11-14 23:33:13 +01:00
|
|
|
});
|
2013-01-04 21:05:18 +01:00
|
|
|
|
|
|
|
$("#subscriptions_table").on("mouseover", ".subscription_header", function (e) {
|
|
|
|
$(this).addClass("active");
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#subscriptions_table").on("mouseout", ".subscription_header", function (e) {
|
|
|
|
$(this).removeClass("active");
|
|
|
|
});
|
2013-01-15 18:48:53 +01:00
|
|
|
|
2013-01-15 22:19:38 +01:00
|
|
|
$("#stream").on('blur', function () { compose.decorate_stream_bar(this.value); });
|
2013-01-22 01:34:44 +01:00
|
|
|
|
2013-05-09 21:12:53 +02:00
|
|
|
// Capture both the left-sidebar Home click and the tab breadcrumb Home
|
|
|
|
$(document).on('click', "li[data-name='home']", function () {
|
2013-02-12 22:32:14 +01:00
|
|
|
ui.change_tab_to('#home');
|
|
|
|
narrow.deactivate();
|
|
|
|
// We need to maybe scroll to the selected message
|
|
|
|
// once we have the proper viewport set up
|
|
|
|
setTimeout(maybe_scroll_to_selected, 0);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2013-02-21 12:43:13 +01:00
|
|
|
$(".brand").on('click', function (e) {
|
2013-01-22 01:34:44 +01:00
|
|
|
if (exports.home_tab_obscured()) {
|
|
|
|
ui.change_tab_to('#home');
|
|
|
|
} else {
|
|
|
|
narrow.restore_home_state();
|
|
|
|
}
|
2013-02-12 22:32:14 +01:00
|
|
|
maybe_scroll_to_selected();
|
2013-01-22 01:34:44 +01:00
|
|
|
e.preventDefault();
|
|
|
|
});
|
2013-02-12 20:52:33 +01:00
|
|
|
|
|
|
|
$(window).on('blur', function () {
|
|
|
|
$(document.body).addClass('window_blurred');
|
|
|
|
});
|
|
|
|
|
|
|
|
$(window).on('focus', function () {
|
|
|
|
$(document.body).removeClass('window_blurred');
|
|
|
|
});
|
2013-02-20 20:49:49 +01:00
|
|
|
|
2013-07-25 22:48:55 +02:00
|
|
|
$(document).on('message_selected.zulip', function (event) {
|
2013-02-20 20:49:49 +01:00
|
|
|
if (current_msg_list !== event.msg_list) {
|
|
|
|
return;
|
|
|
|
}
|
2013-05-30 00:10:10 +02:00
|
|
|
if (event.id === -1) {
|
|
|
|
// If the message list is empty, don't do anything
|
|
|
|
return;
|
|
|
|
}
|
2013-08-14 22:00:32 +02:00
|
|
|
var row = event.msg_list.get_row(event.id);
|
2013-02-20 20:49:49 +01:00
|
|
|
$('.selected_message').removeClass('selected_message');
|
2013-06-19 17:10:49 +02:00
|
|
|
row.addClass('selected_message');
|
2013-02-20 20:49:49 +01:00
|
|
|
|
|
|
|
if (event.then_scroll) {
|
2013-07-03 19:32:16 +02:00
|
|
|
// Scroll to place the message within the current view;
|
|
|
|
// but if this is the initial placement of the pointer,
|
|
|
|
// just place it in the very center
|
|
|
|
recenter_view(row, {from_scroll: event.from_scroll,
|
|
|
|
force_center: event.previously_selected === -1});
|
2013-02-20 20:49:49 +01:00
|
|
|
}
|
|
|
|
});
|
2013-03-05 00:18:04 +01:00
|
|
|
|
|
|
|
$("#main_div").on("mouseenter", ".message_time", function (e) {
|
|
|
|
var time_elem = $(e.target);
|
|
|
|
var row = time_elem.closest(".message_row");
|
|
|
|
var message = current_msg_list.get(rows.id(row));
|
|
|
|
timerender.set_full_datetime(message, time_elem);
|
|
|
|
});
|
2013-03-07 20:12:27 +01:00
|
|
|
|
2013-08-12 23:05:20 +02:00
|
|
|
$('#user_presences').on('click', '.selectable_sidebar_block', function (e) {
|
|
|
|
var email = $(e.target).parents('li').attr('data-email');
|
2013-05-24 21:42:42 +02:00
|
|
|
narrow.by('pm-with', email, {trigger: 'presence list'});
|
2013-05-20 23:35:41 +02:00
|
|
|
compose.start('private', {private_message_recipient: email,
|
|
|
|
trigger: 'presence list'});
|
2013-05-03 22:16:52 +02:00
|
|
|
// The preventDefault is necessary so that clicking the
|
|
|
|
// link doesn't jump us to the top of the page.
|
2013-03-07 20:12:27 +01:00
|
|
|
e.preventDefault();
|
2013-05-03 22:16:52 +02:00
|
|
|
// The stopPropagation is necessary so that we don't
|
|
|
|
// see the following sequence of events:
|
|
|
|
// 1. This click "opens" the composebox
|
|
|
|
// 2. This event propagates to the body, which says "oh, hey, the
|
|
|
|
// composebox is open and you clicked out of it, you must want to
|
|
|
|
// stop composing!"
|
|
|
|
e.stopPropagation();
|
2013-07-09 00:02:10 +02:00
|
|
|
// Since we're stopping propagation we have to manually close any
|
|
|
|
// open popovers.
|
|
|
|
popovers.hide_all();
|
2013-03-07 20:12:27 +01:00
|
|
|
});
|
2013-04-02 20:47:18 +02:00
|
|
|
|
2013-07-12 17:00:32 +02:00
|
|
|
$('#streams_inline_cog').tooltip({ placement: 'left',
|
|
|
|
animation: false });
|
|
|
|
|
|
|
|
$('#streams_header a').click(function (e) {
|
|
|
|
exports.change_tab_to('#subscriptions');
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2013-08-06 00:31:06 +02:00
|
|
|
$('#stream_filters li').on('click', '.subscription_block', function (e) {
|
2013-05-08 23:53:27 +02:00
|
|
|
if (exports.home_tab_obscured()) {
|
|
|
|
ui.change_tab_to('#home');
|
|
|
|
}
|
2013-05-02 18:50:24 +02:00
|
|
|
var stream = $(e.target).parents('li').attr('data-name');
|
2013-05-21 19:34:15 +02:00
|
|
|
narrow.by('stream', stream, {select_first_unread: true, trigger: 'sidebar'});
|
2013-04-02 20:47:18 +02:00
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2013-06-28 22:38:40 +02:00
|
|
|
popovers.register_click_handlers();
|
2013-05-14 21:02:10 +02:00
|
|
|
|
2013-08-06 00:31:06 +02:00
|
|
|
$('#stream_filters').on('click', '.subject_box', function (e) {
|
2013-05-08 23:53:27 +02:00
|
|
|
if (exports.home_tab_obscured()) {
|
|
|
|
ui.change_tab_to('#home');
|
|
|
|
}
|
2013-05-02 18:50:24 +02:00
|
|
|
var stream = $(e.target).parents('ul').attr('data-stream');
|
|
|
|
var subject = $(e.target).parents('li').attr('data-name');
|
2013-04-10 22:24:15 +02:00
|
|
|
|
|
|
|
narrow.activate([['stream', stream],
|
2013-07-16 22:52:02 +02:00
|
|
|
['topic', subject]],
|
2013-05-21 19:34:15 +02:00
|
|
|
{select_first_unread: true, trigger: 'sidebar'});
|
2013-04-02 20:47:18 +02:00
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2013-04-10 22:24:15 +02:00
|
|
|
$('#stream_filters').on('click', '.streamlist_expand', function (e) {
|
|
|
|
var stream_li = $(e.target).parents('li');
|
|
|
|
|
|
|
|
$('ul.expanded_subjects', stream_li).toggleClass('hidden');
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2013-04-02 20:47:18 +02:00
|
|
|
$('.compose_stream_button').click(function (e) {
|
2013-07-12 23:16:07 +02:00
|
|
|
compose.start('stream');
|
2013-04-02 20:47:18 +02:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$('.compose_private_button').click(function (e) {
|
2013-07-12 23:16:07 +02:00
|
|
|
compose.start('private');
|
2013-04-02 20:47:18 +02:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.empty_feed_compose_stream').click(function (e) {
|
2013-05-20 23:35:41 +02:00
|
|
|
compose.start('stream', {trigger: 'empty feed message'});
|
2013-04-02 20:47:18 +02:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$('.empty_feed_compose_private').click(function (e) {
|
2013-05-20 23:35:41 +02:00
|
|
|
compose.start('private', {trigger: 'empty feed message'});
|
2013-04-02 20:47:18 +02:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$('.empty_feed_join').click(function (e) {
|
|
|
|
subs.show_and_focus_on_narrow();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2013-05-13 23:03:50 +02:00
|
|
|
// Keep these 2 feedback bot triggers separate because they have to
|
|
|
|
// propagate the event differently.
|
|
|
|
$('.feedback').click(function (e) {
|
2013-07-24 20:23:35 +02:00
|
|
|
compose.start('private', { 'private_message_recipient': 'feedback@zulip.com',
|
2013-05-20 23:35:41 +02:00
|
|
|
trigger: 'feedback menu item' });
|
2013-05-13 23:03:50 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
$('#feedback_button').click(function (e) {
|
|
|
|
e.stopPropagation();
|
2013-07-09 00:02:10 +02:00
|
|
|
popovers.hide_all();
|
2013-07-24 20:23:35 +02:00
|
|
|
compose.start('private', { 'private_message_recipient': 'feedback@zulip.com',
|
2013-05-20 23:35:41 +02:00
|
|
|
trigger: 'feedback button' });
|
2013-05-13 23:03:50 +02:00
|
|
|
|
2013-04-02 20:47:18 +02:00
|
|
|
});
|
|
|
|
$('.logout_button').click(function (e) {
|
|
|
|
$('#logout_form').submit();
|
|
|
|
});
|
|
|
|
$('.restart_get_updates_button').click(function (e) {
|
|
|
|
restart_get_updates({dont_block: true});
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#api_key_button').click(function (e) {
|
2013-04-08 20:06:43 +02:00
|
|
|
$("#get_api_key_box").show();
|
|
|
|
$("#api_key_button_box").hide();
|
2013-04-02 20:47:18 +02:00
|
|
|
});
|
|
|
|
$('.change_gravatar_button').click(function (e) {
|
|
|
|
ui.wait_for_gravatar();
|
|
|
|
});
|
|
|
|
|
2013-07-15 23:50:53 +02:00
|
|
|
var notification_docs = $("#notification-docs");
|
|
|
|
notification_docs.popover({"placement": "right",
|
|
|
|
"content": templates.render('notification_docs'),
|
|
|
|
"trigger": "manual"});
|
|
|
|
$("body").on("mouseover", "#notification-docs", function (e) {
|
|
|
|
notification_docs.popover('show');
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
$("body").on("mouseout", "#notification-docs", function (e) {
|
|
|
|
notification_docs.popover('hide');
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2013-08-15 23:43:16 +02:00
|
|
|
$('body').on('click', '.edit_content', function (e) {
|
|
|
|
var row = current_msg_list.get_row(rows.id($(this).closest(".message_row")));
|
|
|
|
message_edit.start(row);
|
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
|
|
|
});
|
2013-05-21 00:00:28 +02:00
|
|
|
$('body').on('click', '.edit_subject', function (e) {
|
2013-08-14 22:00:32 +02:00
|
|
|
var row = current_msg_list.get_row(rows.id($(this).closest(".recipient_row")));
|
2013-05-21 00:00:28 +02:00
|
|
|
message_edit.start(row);
|
|
|
|
e.stopPropagation();
|
2013-07-09 00:02:10 +02:00
|
|
|
popovers.hide_all();
|
2013-05-21 00:00:28 +02:00
|
|
|
});
|
2013-05-15 00:22:16 +02:00
|
|
|
$("body").on("click", ".message_edit_save", function (e) {
|
|
|
|
var row = $(this).closest(".message_row");
|
|
|
|
message_edit.save(row);
|
|
|
|
e.stopPropagation();
|
2013-07-09 00:02:10 +02:00
|
|
|
popovers.hide_all();
|
2013-05-15 00:22:16 +02:00
|
|
|
});
|
|
|
|
$("body").on("click", ".message_edit_cancel", function (e) {
|
|
|
|
var row = $(this).closest(".message_row");
|
2013-05-22 19:04:11 +02:00
|
|
|
message_edit.end(row);
|
2013-05-15 00:22:16 +02:00
|
|
|
e.stopPropagation();
|
2013-07-09 00:02:10 +02:00
|
|
|
popovers.hide_all();
|
2013-05-15 00:22:16 +02:00
|
|
|
});
|
2013-04-02 20:47:18 +02:00
|
|
|
|
|
|
|
$("body").on('click', function (e) {
|
2013-06-28 22:38:40 +02:00
|
|
|
// Dismiss popovers if the user has clicked outside them
|
2013-07-08 23:35:06 +02:00
|
|
|
if ($('.popover-inner').has(e.target).length === 0) {
|
2013-06-28 22:38:40 +02:00
|
|
|
popovers.hide_all();
|
2013-04-02 20:47:18 +02:00
|
|
|
}
|
2013-05-03 22:16:52 +02:00
|
|
|
|
2013-05-10 19:47:19 +02:00
|
|
|
// Unfocus our compose area if we click out of it. Don't let exits out
|
2013-07-17 21:31:19 +02:00
|
|
|
// of modals or selecting text (for copy+paste) trigger cancelling.
|
2013-05-10 19:47:19 +02:00
|
|
|
if (compose.composing() && !$(e.target).is("a") &&
|
2013-07-17 21:31:19 +02:00
|
|
|
($(e.target).closest(".modal").length === 0) &&
|
|
|
|
window.getSelection().toString() === "") {
|
2013-05-03 22:16:52 +02:00
|
|
|
compose.cancel();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#compose").click(function (e) {
|
|
|
|
// Don't let clicks in the compose area count as
|
|
|
|
// "unfocusing" our compose -- in other words, e.g.
|
|
|
|
// clicking "Press enter to send" should not
|
|
|
|
// trigger the composebox-closing code above.
|
2013-05-07 21:22:25 +02:00
|
|
|
// But do allow our formatting link.
|
|
|
|
if (!$(e.target).is("a")) {
|
|
|
|
e.stopPropagation();
|
|
|
|
}
|
2013-04-02 20:47:18 +02:00
|
|
|
});
|
|
|
|
|
2013-06-12 23:57:43 +02:00
|
|
|
$("#compose_close").click(function (e) {
|
|
|
|
compose.cancel();
|
|
|
|
});
|
|
|
|
|
2013-06-19 16:27:55 +02:00
|
|
|
$('#yes-bankrupt').click(function (e) {
|
2013-06-19 17:36:48 +02:00
|
|
|
fast_forward_pointer();
|
|
|
|
$("#yes-bankrupt").hide();
|
|
|
|
$("#no-bankrupt").hide();
|
|
|
|
$(this).after($("<div>").addClass("alert alert-info settings_committed")
|
|
|
|
.text("Bringing you to your latest messages…"));
|
2013-06-19 16:27:55 +02:00
|
|
|
});
|
|
|
|
|
2013-05-03 22:12:58 +02:00
|
|
|
// initialize other stuff
|
|
|
|
composebox_typeahead.initialize();
|
|
|
|
search.initialize();
|
|
|
|
notifications.initialize();
|
|
|
|
hashchange.initialize();
|
|
|
|
invite.initialize();
|
|
|
|
activity.initialize();
|
2013-07-31 21:18:40 +02:00
|
|
|
subs.update_all_messages_link();
|
2013-05-03 22:12:58 +02:00
|
|
|
tutorial.initialize();
|
2013-07-03 22:43:13 +02:00
|
|
|
onboarding.initialize();
|
2012-10-03 21:44:07 +02:00
|
|
|
});
|
2012-11-05 23:51:27 +01:00
|
|
|
|
2013-08-02 23:41:40 +02:00
|
|
|
|
|
|
|
var scroll_start_message;
|
|
|
|
|
|
|
|
function scroll_finished() {
|
|
|
|
actively_scrolling = false;
|
|
|
|
|
|
|
|
if ($('#home').hasClass('active')) {
|
|
|
|
if (!suppress_scroll_pointer_update) {
|
|
|
|
keep_pointer_in_view();
|
|
|
|
} else {
|
|
|
|
suppress_scroll_pointer_update = false;
|
|
|
|
}
|
|
|
|
exports.update_floating_recipient_bar();
|
|
|
|
if (viewport.scrollTop() === 0 &&
|
|
|
|
have_scrolled_away_from_top) {
|
|
|
|
have_scrolled_away_from_top = false;
|
|
|
|
load_more_messages(current_msg_list);
|
|
|
|
} else if (!have_scrolled_away_from_top) {
|
|
|
|
have_scrolled_away_from_top = true;
|
|
|
|
}
|
|
|
|
// When the window scrolls, it may cause some messages to
|
|
|
|
// enter the screen and become read. Calling
|
|
|
|
// process_visible_unread_messages will update necessary
|
|
|
|
// data structures and DOM elements.
|
|
|
|
setTimeout(process_visible_unread_messages, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var scroll_timer;
|
|
|
|
function scroll_finish() {
|
|
|
|
actively_scrolling = true;
|
|
|
|
clearTimeout(scroll_timer);
|
|
|
|
scroll_timer = setTimeout(scroll_finished, 100);
|
|
|
|
}
|
|
|
|
|
2013-08-02 23:56:28 +02:00
|
|
|
exports.register_scroll_handler = function () {
|
|
|
|
$(window).scroll($.throttle(50, function (e) {
|
|
|
|
process_visible_unread_messages();
|
|
|
|
scroll_finish();
|
|
|
|
}));
|
|
|
|
};
|
2013-08-02 23:41:40 +02:00
|
|
|
|
2013-02-17 19:22:26 +01:00
|
|
|
var presence_descriptions = {
|
2013-08-02 22:26:46 +02:00
|
|
|
active: 'is active',
|
|
|
|
away: 'was recently active',
|
|
|
|
idle: 'is not active'
|
2013-02-17 19:22:26 +01:00
|
|
|
};
|
|
|
|
|
2013-02-17 19:12:35 +01:00
|
|
|
exports.set_presence_list = function (users, presence_info) {
|
2013-08-01 17:47:48 +02:00
|
|
|
if (page_params.domain === 'mit.edu') {
|
2013-07-10 23:50:47 +02:00
|
|
|
return; // MIT realm doesn't have a presence list
|
2013-08-01 17:47:48 +02:00
|
|
|
}
|
2013-07-10 23:50:47 +02:00
|
|
|
|
|
|
|
var my_info = {
|
|
|
|
name: page_params.fullname,
|
|
|
|
email: page_params.email,
|
|
|
|
type: 'active',
|
|
|
|
type_desc: presence_descriptions.active,
|
|
|
|
my_fullname: true
|
|
|
|
};
|
|
|
|
|
|
|
|
function info_for(email) {
|
|
|
|
var presence = presence_info[email];
|
|
|
|
return {
|
2013-08-07 23:56:51 +02:00
|
|
|
name: people_dict.get(email).full_name,
|
2013-07-10 23:50:47 +02:00
|
|
|
email: email,
|
|
|
|
type: presence,
|
|
|
|
type_desc: presence_descriptions[presence]
|
|
|
|
};
|
2013-02-19 22:37:03 +01:00
|
|
|
}
|
2013-02-14 16:19:32 +01:00
|
|
|
|
2013-07-29 22:49:42 +02:00
|
|
|
var user_emails = _.filter(users, function (email) {
|
2013-08-07 23:56:51 +02:00
|
|
|
return people_dict.has(email);
|
2013-02-07 19:57:45 +01:00
|
|
|
});
|
2013-07-10 23:50:47 +02:00
|
|
|
|
2013-07-29 23:35:36 +02:00
|
|
|
var user_info = [my_info].concat(_.map(user_emails, info_for));
|
2013-07-10 23:50:47 +02:00
|
|
|
|
|
|
|
$('#user_presences').html(templates.render('user_presence_rows', {users: user_info}));
|
2013-02-07 19:57:45 +01:00
|
|
|
};
|
|
|
|
|
2013-02-18 08:16:57 +01:00
|
|
|
// Save the compose content cursor position and restore when we
|
|
|
|
// shift-tab back in (see hotkey.js).
|
|
|
|
var saved_compose_cursor = 0;
|
|
|
|
|
|
|
|
$(function () {
|
|
|
|
$('#new_message_content').blur(function () {
|
|
|
|
saved_compose_cursor = $(this).caret().start;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
exports.restore_compose_cursor = function () {
|
|
|
|
// Restore as both the start and end point, i.e.
|
|
|
|
// nothing selected.
|
|
|
|
$('#new_message_content')
|
|
|
|
.focus()
|
|
|
|
.caret(saved_compose_cursor, saved_compose_cursor);
|
|
|
|
};
|
|
|
|
|
2013-07-30 00:35:44 +02:00
|
|
|
exports.process_condensing = function (elem) {
|
2013-05-01 23:21:45 +02:00
|
|
|
var content = $(elem).find(".message_content");
|
Process message condensing in narrow.activate rather than hashchange.
Previously, we were having this problem where:
* You narrow to something
* That causes message_list.js:process_collapsing to run on all of the
elements in the view, which changes some of their sizes
* That causes the pane to scroll and either push the content up or
down, depending (since stuff on top of where you were is now a
different size)
* That triggers keep_pointer_in_view, which moves your pointer
Moving process_collapsing into narrow.activate doesn't obviously
fix any of this, but it does seem to mitigate the issue a bit.
In particular, we (a) process it less frequently, and (b) process it
immediately after we show the narrowed view table, which seems to
reduce the raciness of the overall experience.
This does, however, introduce a regression:
* If you receive a long message when you're on
#settings, e.g., and then go back to Home,
the message does not properly get a [More] appended
to it.
(imported from commit b1440d656cc7b71eca8af736f2f7b3aa7e0cca14)
2013-05-01 21:36:04 +02:00
|
|
|
var message = current_msg_list.get(rows.id($(elem)));
|
|
|
|
if (content !== undefined && message !== undefined) {
|
2013-07-11 21:17:23 +02:00
|
|
|
var long_message = could_be_condensed(elem);
|
|
|
|
if (long_message) {
|
2013-05-08 23:17:49 +02:00
|
|
|
// All long messages are flagged as such.
|
|
|
|
content.addClass("could-be-condensed");
|
|
|
|
}
|
|
|
|
|
2013-05-01 23:21:45 +02:00
|
|
|
// If message.condensed is defined, then the user has manually
|
|
|
|
// specified whether this message should be expanded or condensed.
|
|
|
|
if (message.condensed === true) {
|
2013-05-08 23:17:49 +02:00
|
|
|
condense($(elem));
|
2013-05-01 23:21:45 +02:00
|
|
|
return;
|
|
|
|
} else if (message.condensed === false) {
|
2013-05-08 23:17:49 +02:00
|
|
|
uncondense($(elem));
|
Process message condensing in narrow.activate rather than hashchange.
Previously, we were having this problem where:
* You narrow to something
* That causes message_list.js:process_collapsing to run on all of the
elements in the view, which changes some of their sizes
* That causes the pane to scroll and either push the content up or
down, depending (since stuff on top of where you were is now a
different size)
* That triggers keep_pointer_in_view, which moves your pointer
Moving process_collapsing into narrow.activate doesn't obviously
fix any of this, but it does seem to mitigate the issue a bit.
In particular, we (a) process it less frequently, and (b) process it
immediately after we show the narrowed view table, which seems to
reduce the raciness of the overall experience.
This does, however, introduce a regression:
* If you receive a long message when you're on
#settings, e.g., and then go back to Home,
the message does not properly get a [More] appended
to it.
(imported from commit b1440d656cc7b71eca8af736f2f7b3aa7e0cca14)
2013-05-01 21:36:04 +02:00
|
|
|
return;
|
2013-07-11 21:17:23 +02:00
|
|
|
} else if (long_message) {
|
2013-05-08 23:17:49 +02:00
|
|
|
// By default, condense a long message.
|
|
|
|
condense($(elem));
|
Process message condensing in narrow.activate rather than hashchange.
Previously, we were having this problem where:
* You narrow to something
* That causes message_list.js:process_collapsing to run on all of the
elements in the view, which changes some of their sizes
* That causes the pane to scroll and either push the content up or
down, depending (since stuff on top of where you were is now a
different size)
* That triggers keep_pointer_in_view, which moves your pointer
Moving process_collapsing into narrow.activate doesn't obviously
fix any of this, but it does seem to mitigate the issue a bit.
In particular, we (a) process it less frequently, and (b) process it
immediately after we show the narrowed view table, which seems to
reduce the raciness of the overall experience.
This does, however, introduce a regression:
* If you receive a long message when you're on
#settings, e.g., and then go back to Home,
the message does not properly get a [More] appended
to it.
(imported from commit b1440d656cc7b71eca8af736f2f7b3aa7e0cca14)
2013-05-01 21:36:04 +02:00
|
|
|
}
|
|
|
|
|
2013-05-08 23:17:49 +02:00
|
|
|
// Completely hide the message and replace it with a [More]
|
|
|
|
// link if the user has collapsed it.
|
|
|
|
if (message.collapsed) {
|
|
|
|
content.addClass("collapsed");
|
Process message condensing in narrow.activate rather than hashchange.
Previously, we were having this problem where:
* You narrow to something
* That causes message_list.js:process_collapsing to run on all of the
elements in the view, which changes some of their sizes
* That causes the pane to scroll and either push the content up or
down, depending (since stuff on top of where you were is now a
different size)
* That triggers keep_pointer_in_view, which moves your pointer
Moving process_collapsing into narrow.activate doesn't obviously
fix any of this, but it does seem to mitigate the issue a bit.
In particular, we (a) process it less frequently, and (b) process it
immediately after we show the narrowed view table, which seems to
reduce the raciness of the overall experience.
This does, however, introduce a regression:
* If you receive a long message when you're on
#settings, e.g., and then go back to Home,
the message does not properly get a [More] appended
to it.
(imported from commit b1440d656cc7b71eca8af736f2f7b3aa7e0cca14)
2013-05-01 21:36:04 +02:00
|
|
|
$(elem).find(".message_expander").show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-07-24 19:43:45 +02:00
|
|
|
$(function () {
|
|
|
|
// Workaround for Bootstrap issue #5900, which basically makes dropdowns
|
|
|
|
// unclickable on mobile devices.
|
|
|
|
// https://github.com/twitter/bootstrap/issues/5900
|
|
|
|
$('a.dropdown-toggle, .dropdown-menu a').on('touchstart', function (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-08-09 21:46:34 +02:00
|
|
|
$(function () {
|
|
|
|
// Disable "spellchecking" in our desktop app. The "spellchecking"
|
|
|
|
// in our Mac app is actually autocorrect, and frustrates our
|
|
|
|
// users.
|
|
|
|
if (window.bridge !== undefined) {
|
|
|
|
$("#new_message_content").attr('spellcheck', 'false');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-11-16 16:45:39 +01:00
|
|
|
return exports;
|
|
|
|
}());
|