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;
|
2013-09-12 22:02:55 +02:00
|
|
|
var narrow_window = false;
|
2013-07-16 20:00:47 +02:00
|
|
|
|
|
|
|
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-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-12-09 20:15:33 +01:00
|
|
|
start_data = find_boundary_tr($(startc.parents('div.selectable_row')[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-12-09 20:15:33 +01:00
|
|
|
initial_end_tr = $("div.message_row:last");
|
2013-01-09 23:42:43 +01:00
|
|
|
skip_same_td_check = true;
|
|
|
|
} else {
|
2013-12-09 20:15:33 +01:00
|
|
|
initial_end_tr = $(endc.parents('div.selectable_row')[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 &&
|
2013-12-09 20:15:33 +01:00
|
|
|
startc.parents('div.selectable_row>div')[0] === endc.parents('div.selectable_row>div')[0]) {
|
2013-01-09 23:42:43 +01:00
|
|
|
|
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));
|
2013-09-09 19:06:10 +02:00
|
|
|
if (message && message.sent_by_me) {
|
2013-08-15 23:43:16 +02:00
|
|
|
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;
|
2013-08-27 23:54:13 +02:00
|
|
|
var edit_content_button = '<span class="edit_content"><i class="icon-vector-pencil edit_content_button"></i></span>';
|
2013-08-15 23:43:16 +02:00
|
|
|
if (current_message_hover && message_row && current_message_hover.attr("zid") === message_row.attr("zid")) {
|
|
|
|
return;
|
|
|
|
}
|
2014-01-24 18:01:12 +01:00
|
|
|
// Don't allow on-hover editing for local-only messages
|
|
|
|
if (message_row.hasClass('local')) {
|
|
|
|
return;
|
|
|
|
}
|
2013-08-15 23:43:16 +02:00
|
|
|
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-11-30 22:03:12 +01:00
|
|
|
if (message && message.sent_by_me && !message.status_message && !feature_flags.disable_message_editing) {
|
2013-08-16 20:23:30 +02:00
|
|
|
message_row.find('.message_content').find('p:last').append(edit_content_button);
|
2013-08-15 23:43:16 +02:00
|
|
|
}
|
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-12-06 18:02:50 +01:00
|
|
|
function confine_to_range(lo, val, hi) {
|
|
|
|
if (val < lo) {
|
|
|
|
return lo;
|
|
|
|
}
|
|
|
|
if (val > hi) {
|
|
|
|
return hi;
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2013-12-06 17:19:14 +01:00
|
|
|
function size_blocks(blocks, usable_height) {
|
2013-12-06 19:48:17 +01:00
|
|
|
var n = blocks.length;
|
|
|
|
|
|
|
|
var sum_height = 0;
|
|
|
|
_.each(blocks, function (block) {
|
|
|
|
sum_height += block.real_height;
|
|
|
|
});
|
|
|
|
|
|
|
|
_.each(blocks, function (block) {
|
|
|
|
var ratio = block.real_height / sum_height;
|
|
|
|
block.max_height = confine_to_range(40, usable_height * ratio, 1.2 * block.real_height);
|
|
|
|
});
|
2013-12-06 17:19:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function set_user_list_heights(res, usable_height, user_presences, group_pms) {
|
|
|
|
// Calculate these heights:
|
|
|
|
// res.user_presences_max_height
|
|
|
|
// res.group_pms_max_height
|
|
|
|
var blocks = [
|
|
|
|
{
|
|
|
|
real_height: user_presences.prop('scrollHeight')
|
|
|
|
},
|
|
|
|
{
|
|
|
|
real_height: group_pms.prop('scrollHeight')
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
size_blocks(blocks, usable_height);
|
2013-12-06 16:46:34 +01:00
|
|
|
|
|
|
|
res.user_presences_max_height = blocks[0].max_height;
|
|
|
|
res.group_pms_max_height = blocks[1].max_height;
|
|
|
|
}
|
|
|
|
|
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-08-20 23:07:08 +02:00
|
|
|
var invite_user_link_height = $("#invite-user-link").outerHeight(true) || 0;
|
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-11-15 19:25:48 +01:00
|
|
|
res.bottom_sidebar_height = viewport_height - top_navbar_height - 40;
|
2013-05-10 17:18:06 +02:00
|
|
|
|
2013-09-12 22:02:55 +02:00
|
|
|
res.right_sidebar_height = viewport_height - parseInt($("#right-sidebar").css("marginTop"), 10);
|
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
|
|
|
|
2013-11-13 19:44:25 +01:00
|
|
|
// RIGHT SIDEBAR
|
|
|
|
var user_presences = $('#user_presences').expectOne();
|
|
|
|
var group_pms = $('#group-pms').expectOne();
|
|
|
|
|
|
|
|
var usable_height =
|
|
|
|
res.right_sidebar_height
|
|
|
|
- $("#feedback_section").outerHeight(true)
|
|
|
|
- parseInt(user_presences.css("marginTop"),10)
|
|
|
|
- parseInt(user_presences.css("marginBottom"), 10)
|
|
|
|
- $("#userlist-header").outerHeight(true)
|
|
|
|
- invite_user_link_height
|
|
|
|
- parseInt(group_pms.css("marginTop"),10)
|
|
|
|
- parseInt(group_pms.css("marginBottom"), 10)
|
|
|
|
- $("#group-pm-header").outerHeight(true);
|
|
|
|
|
2013-12-06 16:46:34 +01:00
|
|
|
// set these
|
|
|
|
// res.user_presences_max_height
|
|
|
|
// res.group_pms_max_height
|
|
|
|
set_user_list_heights(
|
|
|
|
res,
|
|
|
|
usable_height,
|
|
|
|
user_presences,
|
|
|
|
group_pms
|
|
|
|
);
|
2013-09-12 22:02:55 +02:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
function left_userlist_get_new_heights() {
|
|
|
|
|
|
|
|
var res = {};
|
|
|
|
var viewport_height = viewport.height();
|
|
|
|
var viewport_width = viewport.width();
|
|
|
|
var top_navbar_height = $(".header").outerHeight(true);
|
|
|
|
|
2013-12-06 17:00:14 +01:00
|
|
|
var stream_filters = $('#stream_filters').expectOne();
|
|
|
|
var user_presences = $('#user_presences').expectOne();
|
2013-12-06 20:21:44 +01:00
|
|
|
var group_pms = $('#group-pms').expectOne();
|
2013-12-06 17:00:14 +01:00
|
|
|
|
|
|
|
var stream_filters_real_height = stream_filters.prop("scrollHeight");
|
|
|
|
var user_list_real_height = user_presences.prop("scrollHeight");
|
2013-12-06 20:21:44 +01:00
|
|
|
var group_pms_real_height = group_pms.prop("scrollHeight");
|
2013-09-12 22:02:55 +02:00
|
|
|
|
|
|
|
res.bottom_whitespace_height = viewport_height * 0.4;
|
|
|
|
|
|
|
|
res.main_div_min_height = viewport_height - top_navbar_height;
|
|
|
|
|
|
|
|
res.bottom_sidebar_height = viewport_height
|
|
|
|
- parseInt($("#left-sidebar").css("marginTop"),10)
|
|
|
|
- parseInt($(".bottom_sidebar").css("marginTop"),10);
|
|
|
|
|
|
|
|
|
|
|
|
res.total_leftlist_height = res.bottom_sidebar_height
|
|
|
|
- $("#global_filters").outerHeight(true)
|
|
|
|
- $("#streams_header").outerHeight(true)
|
|
|
|
- $("#userlist-header").outerHeight(true)
|
2013-12-06 20:21:44 +01:00
|
|
|
- $("#group-pm-header").outerHeight(true)
|
2013-12-06 17:00:14 +01:00
|
|
|
- parseInt(stream_filters.css("marginBottom"),10)
|
|
|
|
- parseInt(user_presences.css("marginTop"), 10)
|
|
|
|
- parseInt(user_presences.css("marginBottom"), 10)
|
2013-12-06 20:21:44 +01:00
|
|
|
- parseInt(group_pms.css("marginTop"), 10)
|
|
|
|
- parseInt(group_pms.css("marginBottom"), 10)
|
2013-09-12 22:02:55 +02:00
|
|
|
- 15;
|
|
|
|
|
2013-12-06 17:48:43 +01:00
|
|
|
var blocks = [
|
|
|
|
{
|
|
|
|
real_height: stream_filters_real_height
|
|
|
|
},
|
|
|
|
{
|
|
|
|
real_height: user_list_real_height
|
2013-12-06 20:21:44 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
real_height: group_pms_real_height
|
2013-12-06 17:48:43 +01:00
|
|
|
}
|
|
|
|
];
|
2013-09-19 00:17:14 +02:00
|
|
|
|
2013-12-06 17:48:43 +01:00
|
|
|
size_blocks(blocks, res.total_leftlist_height);
|
2013-09-12 22:02:55 +02:00
|
|
|
|
2013-12-06 17:48:43 +01:00
|
|
|
res.stream_filters_max_height = blocks[0].max_height;
|
|
|
|
res.user_presences_max_height = blocks[1].max_height;
|
2013-12-06 20:21:44 +01:00
|
|
|
res.group_pms_max_height = blocks[2].max_height;
|
2013-09-12 22:02:55 +02:00
|
|
|
|
|
|
|
res.viewport_height = viewport_height;
|
|
|
|
res.viewport_width = viewport_width;
|
2013-05-10 17:18:06 +02:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-12-07 00:17:39 +01:00
|
|
|
exports.resize_bottom_whitespace = function (h) {
|
|
|
|
if (page_params.autoscroll_forever) {
|
|
|
|
$("#bottom_whitespace").height($("#compose-container")[0].offsetHeight);
|
|
|
|
} else if (h !== undefined) {
|
|
|
|
$("#bottom_whitespace").height(h.bottom_whitespace_height);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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-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-09-12 22:02:55 +02:00
|
|
|
var h;
|
2013-11-13 17:28:49 +01:00
|
|
|
var sidebar;
|
2013-09-12 22:02:55 +02:00
|
|
|
|
2013-12-12 18:46:09 +01:00
|
|
|
if (feature_flags.left_side_userlist) {
|
2013-12-12 19:13:37 +01:00
|
|
|
var css_narrow_mode = viewport.is_narrow();
|
|
|
|
|
|
|
|
if (css_narrow_mode && !narrow_window) {
|
|
|
|
// move stuff to the left sidebar (skinny mode)
|
2013-12-12 18:46:09 +01:00
|
|
|
narrow_window = true;
|
|
|
|
popovers.set_userlist_placement("left");
|
|
|
|
sidebar = $(".bottom_sidebar").expectOne();
|
|
|
|
sidebar.append($("#user-list").expectOne());
|
|
|
|
sidebar.append($("#group-pm-list").expectOne());
|
|
|
|
sidebar.append($("#share-the-love").expectOne());
|
|
|
|
$("#user_presences").css("margin", "0px");
|
|
|
|
$("#group-pms").css("margin", "0px");
|
|
|
|
$("#userlist-toggle").css("display", "none");
|
|
|
|
$("#invite-user-link").hide();
|
|
|
|
}
|
2013-12-12 19:13:37 +01:00
|
|
|
else if (!css_narrow_mode && narrow_window) {
|
|
|
|
// move stuff to the right sidebar (wide mode)
|
2013-12-12 18:46:09 +01:00
|
|
|
narrow_window = false;
|
|
|
|
popovers.set_userlist_placement("right");
|
|
|
|
sidebar = $("#right-sidebar").expectOne();
|
|
|
|
sidebar.append($("#user-list").expectOne());
|
|
|
|
sidebar.append($("#group-pm-list").expectOne());
|
|
|
|
$("#user_presences").css("margin", '');
|
|
|
|
$("#group-pms").css("margin", '');
|
|
|
|
$("#userlist-toggle").css("display", '');
|
|
|
|
$("#invite-user-link").show();
|
|
|
|
}
|
2013-09-12 22:02:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
h = narrow_window ? left_userlist_get_new_heights() : get_new_heights();
|
2013-02-12 16:18:22 +01:00
|
|
|
|
2013-12-07 00:17:39 +01:00
|
|
|
exports.resize_bottom_whitespace(h);
|
2013-05-10 17:18:06 +02:00
|
|
|
$("#stream_filters").css('max-height', h.stream_filters_max_height);
|
|
|
|
$("#user_presences").css('max-height', h.user_presences_max_height);
|
2013-11-13 19:44:25 +01:00
|
|
|
$("#group-pms").css('max-height', h.group_pms_max_height);
|
2013-08-06 21:09:01 +02:00
|
|
|
};
|
|
|
|
|
2013-12-09 17:43:20 +01:00
|
|
|
var _old_width = $(window).width();
|
|
|
|
|
2013-08-06 21:09:01 +02:00
|
|
|
function resizehandler(e) {
|
2013-12-09 17:43:20 +01:00
|
|
|
var new_width = $(window).width();
|
|
|
|
|
|
|
|
if (new_width !== _old_width) {
|
|
|
|
_old_width = new_width;
|
|
|
|
exports.clear_message_content_height_cache();
|
|
|
|
}
|
|
|
|
|
2013-09-19 00:17:14 +02:00
|
|
|
popovers.hide_all();
|
2013-08-06 21:09:01 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2013-12-09 20:15:33 +01:00
|
|
|
$("#current_label_stream .message_header_colorblock").css(
|
2012-12-01 04:37:52 +01:00
|
|
|
"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
|
|
|
}
|
2013-12-09 20:15:33 +01:00
|
|
|
new_label.find(".right_part").replaceWith(header.clone());
|
2012-11-21 20:41:57 +01:00
|
|
|
other_label.css('display', 'none');
|
2013-12-09 20:15:33 +01:00
|
|
|
new_label.css('display', 'block');
|
2013-02-09 19:52:16 +01:00
|
|
|
new_label.attr("zid", rows.id(desired_label));
|
2012-11-21 20:41:57 +01:00
|
|
|
|
2013-10-04 18:01:49 +02:00
|
|
|
new_label.toggleClass('faded', desired_label.hasClass('faded'));
|
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
|
|
|
|
|
|
|
// 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
|
|
|
|
2014-01-06 20:42:49 +01:00
|
|
|
var batched_updaters = {};
|
|
|
|
|
2014-01-23 17:51:17 +01:00
|
|
|
function sync_message_flag(messages, flag_name, set_flag) {
|
2014-01-06 20:42:49 +01:00
|
|
|
var op = set_flag ? 'add' : 'remove';
|
|
|
|
var flag_key = flag_name + '_' + op;
|
|
|
|
var updater;
|
|
|
|
|
|
|
|
if (batched_updaters.hasOwnProperty(flag_key)) {
|
|
|
|
updater = batched_updaters[flag_key];
|
|
|
|
} else {
|
2014-01-30 18:13:14 +01:00
|
|
|
updater = batched_flag_updater(flag_name, op, true);
|
2014-01-06 20:42:49 +01:00
|
|
|
batched_updaters[flag_key] = updater;
|
|
|
|
}
|
|
|
|
|
|
|
|
_.each(messages, function (message) {
|
|
|
|
updater(message);
|
|
|
|
});
|
2013-05-08 23:17:49 +02:00
|
|
|
}
|
|
|
|
|
2014-01-23 17:51:17 +01:00
|
|
|
function sync_message_collapse(message, collapsed) {
|
|
|
|
sync_message_flag([message], "collapsed", collapsed);
|
2013-05-10 23:35:50 +02:00
|
|
|
}
|
|
|
|
|
2014-01-23 17:51:17 +01:00
|
|
|
function sync_message_star(message, starred) {
|
|
|
|
sync_message_flag([message], "starred", starred);
|
2013-03-27 18:30:02 +01:00
|
|
|
}
|
|
|
|
|
2013-12-19 17:03:08 +01:00
|
|
|
function update_message_in_all_views(message_id, callback) {
|
|
|
|
_.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-12-19 17:03:08 +01:00
|
|
|
var row = list.get_row(message_id);
|
2013-03-27 18:30:02 +01:00
|
|
|
if (row === undefined) {
|
2013-12-19 17:03:08 +01:00
|
|
|
// The row may not exist, e.g. if you do an action on a message in
|
|
|
|
// a narrowed view
|
2013-03-27 18:30:02 +01:00
|
|
|
return;
|
|
|
|
}
|
2013-12-19 17:03:08 +01:00
|
|
|
callback(row);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-01-28 22:44:34 +01:00
|
|
|
function find_message(message_id) {
|
|
|
|
// Try to find the message object. It might be in the narrow list
|
|
|
|
// (if it was loaded when narrowed), or only in the all_msg_list
|
|
|
|
// (if received from the server while in a different narrow)
|
|
|
|
var message;
|
|
|
|
_.each([all_msg_list, home_msg_list, narrowed_msg_list], function (msg_list) {
|
|
|
|
if (msg_list !== undefined && message === undefined) {
|
|
|
|
message = msg_list.get(message_id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
2013-12-19 17:03:08 +01:00
|
|
|
exports.update_starred = function (message_id, starred) {
|
|
|
|
// Update the message object pointed to by the various message
|
|
|
|
// lists.
|
2014-01-28 22:44:34 +01:00
|
|
|
var message = find_message(message_id);
|
2013-12-19 17:03:08 +01:00
|
|
|
|
|
|
|
mark_message_as_read(message);
|
|
|
|
|
2014-01-30 18:08:02 +01:00
|
|
|
message.starred = starred;
|
2013-12-19 17:03:08 +01:00
|
|
|
|
|
|
|
// Avoid a full re-render, but update the star in each message
|
|
|
|
// table in which it is visible.
|
|
|
|
update_message_in_all_views(message_id, function update_row(row) {
|
2014-01-23 17:52:28 +01:00
|
|
|
var elt = row.find(".message_star");
|
|
|
|
if (starred) {
|
|
|
|
elt.addClass("icon-vector-star").removeClass("icon-vector-star-empty").removeClass("empty-star");
|
|
|
|
} else {
|
|
|
|
elt.removeClass("icon-vector-star").addClass("icon-vector-star-empty").addClass("empty-star");
|
|
|
|
}
|
2013-04-14 05:04:47 +02:00
|
|
|
var title_state = message.starred ? "Unstar" : "Star";
|
2014-01-23 17:52:28 +01:00
|
|
|
elt.attr("title", title_state + " this message");
|
2013-03-27 18:30:02 +01:00
|
|
|
});
|
2014-01-23 17:52:28 +01:00
|
|
|
};
|
2013-03-27 18:30:02 +01:00
|
|
|
|
2014-01-23 17:52:28 +01:00
|
|
|
function toggle_star(message_id) {
|
|
|
|
// Update the message object pointed to by the various message
|
|
|
|
// lists.
|
2014-01-28 22:44:34 +01:00
|
|
|
var message = find_message(message_id);
|
|
|
|
|
2014-01-23 17:52:28 +01:00
|
|
|
mark_message_as_read(message);
|
|
|
|
exports.update_starred(message.id, message.starred !== true);
|
2014-01-23 17:51:17 +01:00
|
|
|
sync_message_star(message, message.starred);
|
2013-03-27 18:30:02 +01:00
|
|
|
}
|
|
|
|
|
2013-12-19 17:03:08 +01:00
|
|
|
var local_messages_to_show = [];
|
|
|
|
var show_message_timestamps = _.throttle(function () {
|
|
|
|
_.each(local_messages_to_show, function (message_id) {
|
|
|
|
update_message_in_all_views(message_id, function update_row(row) {
|
|
|
|
row.find('.message_time').toggleClass('notvisible', false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
local_messages_to_show = [];
|
|
|
|
}, 100);
|
|
|
|
|
|
|
|
exports.show_local_message_arrived = function (message_id) {
|
|
|
|
local_messages_to_show.push(message_id);
|
|
|
|
show_message_timestamps();
|
|
|
|
};
|
|
|
|
|
2014-01-02 17:34:16 +01:00
|
|
|
exports.show_message_failed = function (message_id, failed_msg) {
|
2013-12-19 17:03:08 +01:00
|
|
|
// Failed to send message, so display inline retry/cancel
|
|
|
|
update_message_in_all_views(message_id, function update_row(row) {
|
2014-01-02 17:34:16 +01:00
|
|
|
var failed_div = row.find('.message_failed');
|
|
|
|
failed_div.toggleClass('notvisible', false);
|
|
|
|
failed_div.find('.failed_text').attr('title', failed_msg);
|
2013-12-19 17:03:08 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.show_failed_message_success = function (message_id) {
|
|
|
|
// Previously failed message succeeded
|
|
|
|
update_message_in_all_views(message_id, function update_row(row) {
|
|
|
|
row.find('.message_failed').toggleClass('notvisible', true);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
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
|
2013-11-19 17:15:48 +01:00
|
|
|
// avatar 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-11-19 17:15:48 +01:00
|
|
|
url += "&stamp=" + settings.avatar_stamp;
|
2013-06-13 23:48:23 +02:00
|
|
|
}
|
|
|
|
return url;
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
2012-11-16 16:45:39 +01:00
|
|
|
};
|
|
|
|
|
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-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");
|
2014-01-23 17:51:17 +01:00
|
|
|
sync_message_collapse(message, false);
|
2013-05-08 23:17:49 +02:00
|
|
|
|
|
|
|
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;
|
2014-01-23 17:51:17 +01:00
|
|
|
sync_message_collapse(message, true);
|
2013-05-08 23:17:49 +02:00
|
|
|
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) {
|
2013-09-24 21:59:33 +02:00
|
|
|
return current_msg_list.get(id);
|
2013-08-08 00:12:27 +02:00
|
|
|
});
|
|
|
|
|
2013-08-20 22:05:56 +02:00
|
|
|
_.each(messages, function (msg){
|
2013-08-23 01:04:34 +02:00
|
|
|
msg.flags = _.without(msg.flags, 'force_collapse');
|
2013-08-20 22:05:56 +02:00
|
|
|
msg.flags.push('force_expand');
|
|
|
|
});
|
2014-01-23 17:51:17 +01:00
|
|
|
sync_message_flag(messages, 'force_expand', true);
|
|
|
|
sync_message_flag(messages, 'force_collapse', false);
|
2013-08-08 00:12:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
//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]);
|
|
|
|
};
|
|
|
|
|
2013-08-23 01:04:34 +02:00
|
|
|
exports.collapse_recipient_group = function (row) {
|
|
|
|
var message_ids = row.attr('data-messages').split(',');
|
|
|
|
var messages = _.map(message_ids, function (id) {
|
|
|
|
return all_msg_list.get(id);
|
|
|
|
});
|
|
|
|
|
|
|
|
_.each(messages, function (msg){
|
|
|
|
msg.flags = _.without(msg.flags, 'force_expand');
|
|
|
|
msg.flags.push('force_collapse');
|
|
|
|
});
|
2014-01-23 17:51:17 +01:00
|
|
|
sync_message_flag(messages, 'force_collapse', true);
|
|
|
|
sync_message_flag(messages, 'force_expand', false);
|
2013-08-23 01:04:34 +02:00
|
|
|
|
|
|
|
//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]);
|
|
|
|
};
|
|
|
|
|
2013-12-04 17:54:45 +01:00
|
|
|
/* EXPERIMENTS */
|
|
|
|
|
2013-12-05 20:23:02 +01:00
|
|
|
/* This method allows an advanced user to use the console
|
|
|
|
* to switch the application to span full width of the browser.
|
|
|
|
*/
|
|
|
|
exports.switchToFullWidth = function () {
|
|
|
|
$("#full-width-style").remove();
|
|
|
|
$('head').append('<style id="full-width-style" type="text/css">' +
|
|
|
|
'#home .alert-bar, .recipient-bar-content, #compose-container, .app-main, .header-main { max-width: none; }' +
|
|
|
|
'</style>');
|
|
|
|
return ("Switched to full width");
|
|
|
|
};
|
|
|
|
|
2013-12-04 17:54:45 +01:00
|
|
|
/* END OF EXPERIMENTS */
|
|
|
|
|
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
|
|
|
|
2014-01-29 19:04:51 +01:00
|
|
|
viewport.message_pane.mousewheel(function (e, delta) {
|
2012-11-30 18:28:23 +01:00
|
|
|
// 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();
|
2013-11-13 23:27:08 +01:00
|
|
|
|
|
|
|
// The -1 fudge factor is important here due to rounding errors. Better
|
|
|
|
// to err on the side of not scrolling.
|
|
|
|
var max_scroll = this.scrollHeight - self.innerHeight() - 1;
|
|
|
|
|
2012-11-30 18:28:23 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
if ( ((delta > 0) && (scroll <= 0))
|
2013-11-13 23:27:08 +01:00
|
|
|
|| ((delta < 0) && (scroll >= max_scroll))) {
|
2012-11-30 18:28:23 +01:00
|
|
|
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('');
|
|
|
|
}
|
|
|
|
|
2014-01-22 01:43:11 +01:00
|
|
|
admin.show_or_hide_menu_item();
|
|
|
|
|
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');
|
2013-12-07 00:17:39 +01:00
|
|
|
exports.resize_bottom_whitespace();
|
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
|
|
|
});
|
|
|
|
|
2013-10-25 23:52:45 +02:00
|
|
|
var settings_status = $('#settings-status').expectOne();
|
|
|
|
var notify_settings_status = $('#notify-settings-status').expectOne();
|
2013-12-12 22:36:16 +01:00
|
|
|
// does this make me a bad person?
|
|
|
|
var ui_settings_status = feature_flags.show_autoscroll_forever_option && $('#ui-settings-status').expectOne();
|
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);
|
|
|
|
}
|
|
|
|
|
2013-10-25 22:41:35 +02:00
|
|
|
$("form.your-account-settings").expectOne().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) {
|
2013-11-04 23:42:31 +01:00
|
|
|
if (page_params.password_auth_enabled !== false) {
|
|
|
|
// 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 !== '') {
|
|
|
|
var password_ok = password_quality(new_pw);
|
|
|
|
if (password_ok === undefined) {
|
|
|
|
// 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;
|
|
|
|
} else if (!password_ok) {
|
|
|
|
settings_change_error('New password is too weak');
|
|
|
|
return false;
|
|
|
|
}
|
2013-04-04 00:55:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2013-10-25 22:41:35 +02:00
|
|
|
settings_status.removeClass(status_classes)
|
|
|
|
.addClass('alert-success')
|
|
|
|
.text(message).stop(true).fadeTo(0,1);
|
|
|
|
},
|
|
|
|
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_change_error(response);
|
|
|
|
},
|
|
|
|
complete: function (xhr, statusText) {
|
|
|
|
// Whether successful or not, clear the password boxes.
|
|
|
|
// TODO: Clear these earlier, while the request is still pending.
|
|
|
|
clear_password_change();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$("form.notify-settings").expectOne().ajaxForm({
|
|
|
|
dataType: 'json', // This seems to be ignored. We still get back an xhr.
|
|
|
|
|
|
|
|
success: function (resp, statusText, xhr, form) {
|
|
|
|
var message = "Updated notification settings!";
|
|
|
|
var result = $.parseJSON(xhr.responseText);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-10-16 17:24:52 +02:00
|
|
|
if (result.enable_offline_push_notifications !== undefined) {
|
|
|
|
page_params.enable_offline_push_notifications = result.enable_offline_push_notifications;
|
|
|
|
}
|
|
|
|
|
2013-12-02 02:00:23 +01:00
|
|
|
if (result.enable_digest_emails !== undefined) {
|
|
|
|
page_params.enable_digest_emails = result.enable_digest_emails;
|
|
|
|
}
|
|
|
|
|
2013-10-25 23:52:45 +02:00
|
|
|
notify_settings_status.removeClass(status_classes)
|
2012-10-03 22:35:35 +02:00
|
|
|
.addClass('alert-success')
|
|
|
|
.text(message).stop(true).fadeTo(0,1);
|
|
|
|
},
|
|
|
|
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-10-25 23:52:45 +02:00
|
|
|
|
|
|
|
notify_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-12 00:48:37 +02:00
|
|
|
|
2013-12-12 22:36:16 +01:00
|
|
|
if (feature_flags.show_autoscroll_forever_option) {
|
|
|
|
$("form.ui-settings").expectOne().ajaxForm({
|
|
|
|
dataType: 'json',
|
2013-12-03 21:01:37 +01:00
|
|
|
|
2013-12-12 22:36:16 +01:00
|
|
|
success: function (resp, statusText, xhr, form) {
|
2013-12-16 16:25:26 +01:00
|
|
|
var message = "Updated Zulip Labs settings!";
|
2013-12-12 22:36:16 +01:00
|
|
|
var result = $.parseJSON(xhr.responseText);
|
2013-12-03 21:01:37 +01:00
|
|
|
|
2013-12-12 22:36:16 +01:00
|
|
|
if (result.autoscroll_forever !== undefined) {
|
|
|
|
page_params.autoscroll_forever = result.autoscroll_forever;
|
|
|
|
exports.resize_page_components();
|
|
|
|
}
|
2013-12-03 21:01:37 +01:00
|
|
|
|
2013-12-12 22:36:16 +01:00
|
|
|
ui_settings_status.removeClass(status_classes)
|
|
|
|
.addClass('alert-success')
|
|
|
|
.text(message).stop(true).fadeTo(0,1);
|
|
|
|
},
|
|
|
|
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-12-03 21:01:37 +01:00
|
|
|
|
2013-12-12 22:36:16 +01:00
|
|
|
ui_settings_status.removeClass(status_classes)
|
|
|
|
.addClass('alert-error')
|
|
|
|
.text(response).stop(true).fadeTo(0,1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-12-03 21:01:37 +01: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-10-09 00:37:07 +02:00
|
|
|
if (!feature_flags.left_side_userlist) {
|
|
|
|
$("#navbar-buttons").addClass("right-userlist");
|
|
|
|
}
|
|
|
|
|
2013-07-25 22:08:16 +02:00
|
|
|
if (feature_flags.summarize_read_while_narrowed) {
|
2013-09-11 20:42:25 +02:00
|
|
|
$("#main_div").on("click", ".summary_row .messages-expand", function (e) {
|
2013-09-11 19:24:16 +02:00
|
|
|
exports.expand_summary_row($(e.target).closest('.summary_row').expectOne());
|
2013-07-25 22:08:16 +02:00
|
|
|
e.stopImmediatePropagation();
|
|
|
|
});
|
2013-09-11 20:42:25 +02:00
|
|
|
$("#main_div").on("click", ".recipient_row .messages-collapse", function (e) {
|
2013-09-11 19:24:16 +02:00
|
|
|
exports.collapse_recipient_group($(e.target).closest('.recipient_row').expectOne());
|
2013-08-23 01:04:34 +02:00
|
|
|
e.stopImmediatePropagation();
|
|
|
|
});
|
2013-07-25 22:08:16 +02:00
|
|
|
}
|
|
|
|
|
2013-08-17 00:42:46 +02:00
|
|
|
function is_clickable_message_element(target) {
|
|
|
|
return 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") ||
|
2013-08-27 23:54:13 +02:00
|
|
|
target.is("i.edit_content_button");
|
2013-08-17 00:42:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$("#main_div").on("click", ".messagebox", function (e) {
|
|
|
|
if (is_clickable_message_element($(e.target))) {
|
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-12-09 23:07:14 +01:00
|
|
|
} else if (content.hasClass("condensed")) {
|
2013-05-08 23:17:49 +02:00
|
|
|
// 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
|
|
|
});
|
|
|
|
|
2013-10-10 15:08:17 +02:00
|
|
|
function get_row_id_for_narrowing(narrow_link_elem) {
|
2013-10-03 23:05:46 +02:00
|
|
|
var row = rows.get_closest_row(narrow_link_elem);
|
|
|
|
|
2013-08-27 17:09:27 +02:00
|
|
|
var nearest = current_msg_list.get(rows.id(row));
|
2013-02-15 00:23:56 +01:00
|
|
|
var selected = current_msg_list.selected_message();
|
2013-02-26 23:09:15 +01:00
|
|
|
if (util.same_recipient(nearest, selected)) {
|
2013-10-03 23:05:46 +02:00
|
|
|
return selected.id;
|
2013-02-15 00:23:56 +01:00
|
|
|
} else {
|
2013-10-03 23:05:46 +02:00
|
|
|
return nearest.id;
|
2013-02-15 00:23:56 +01:00
|
|
|
}
|
2013-10-03 23:05:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$("#home").on("click", ".narrows_by_recipient", function (e) {
|
2013-10-10 23:30:39 +02:00
|
|
|
if (e.metaKey || e.ctrlKey) {
|
|
|
|
return;
|
|
|
|
}
|
2013-10-03 23:05:46 +02:00
|
|
|
e.preventDefault();
|
2013-10-10 15:08:17 +02:00
|
|
|
var row_id = get_row_id_for_narrowing(this);
|
2013-10-03 23:05:46 +02:00
|
|
|
narrow.by_recipient(row_id, {trigger: 'message header'});
|
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-10-10 23:30:39 +02:00
|
|
|
if (e.metaKey || e.ctrlKey) {
|
|
|
|
return;
|
|
|
|
}
|
2013-10-03 23:05:46 +02:00
|
|
|
e.preventDefault();
|
2013-10-10 15:08:17 +02:00
|
|
|
var row_id = get_row_id_for_narrowing(this);
|
2013-10-03 23:05:46 +02:00
|
|
|
narrow.by_subject(row_id, {trigger: 'message header'});
|
2012-11-14 23:33:13 +01:00
|
|
|
});
|
2013-01-04 21:05:18 +01:00
|
|
|
|
2013-08-22 20:17:07 +02:00
|
|
|
$("#userlist-toggle-button").on("click", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2013-08-23 21:33:43 +02:00
|
|
|
|
|
|
|
var sidebarHidden = !$(".app-main .column-right").hasClass("expanded");
|
|
|
|
popovers.hide_all();
|
|
|
|
if (sidebarHidden) {
|
|
|
|
popovers.show_userlist_sidebar();
|
2013-08-22 20:17:07 +02:00
|
|
|
}
|
2013-08-23 21:33:43 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$("#streamlist-toggle-button").on("click", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
var sidebarHidden = !$(".app-main .column-left").hasClass("expanded");
|
|
|
|
popovers.hide_all();
|
|
|
|
if (sidebarHidden) {
|
|
|
|
popovers.show_streamlist_sidebar();
|
2013-08-22 20:17:07 +02: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
|
2013-08-22 20:17:07 +02:00
|
|
|
$(document).on('click', "li[data-name='home']", function (e) {
|
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);
|
2013-08-22 20:17:07 +02:00
|
|
|
e.preventDefault();
|
2013-02-12 22:32:14 +01:00
|
|
|
});
|
|
|
|
|
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-10-31 18:01:52 +01:00
|
|
|
if (row.length === 0) {
|
|
|
|
blueslip.debug("message_selected missing selected row", {
|
|
|
|
previously_selected: event.previously_selected,
|
|
|
|
selected_id: event.id,
|
|
|
|
selected_idx: event.msg_list.selected_idx(),
|
|
|
|
selected_idx_exact: event.msg_list._items.indexOf(event.msg_list.get(event.id)),
|
|
|
|
render_start: event.msg_list.view._render_win_start,
|
|
|
|
render_end: event.msg_list.view._render_win_end
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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-10-18 00:56:49 +02:00
|
|
|
$('#user_presences').expectOne().on('click', '.selectable_sidebar_block', function (e) {
|
2013-08-12 23:05:20 +02:00
|
|
|
var email = $(e.target).parents('li').attr('data-email');
|
2013-12-02 21:16:00 +01:00
|
|
|
narrow.by('pm-with', email, {select_first_unread: true, trigger: 'sidebar'});
|
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-10-18 00:56:49 +02:00
|
|
|
$('#group-pms').expectOne().on('click', '.selectable_sidebar_block', function (e) {
|
|
|
|
var emails = $(e.target).parents('li').attr('data-emails');
|
2013-12-02 21:16:00 +01:00
|
|
|
narrow.by('pm-with', emails, {select_first_unread: true, trigger: 'sidebar'});
|
2013-10-18 00:56:49 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
|
|
|
});
|
|
|
|
|
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-06-28 22:38:40 +02:00
|
|
|
popovers.register_click_handlers();
|
2013-10-09 22:42:15 +02:00
|
|
|
notifications.register_click_handlers();
|
2013-05-14 21:02:10 +02:00
|
|
|
|
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
|
|
|
});
|
|
|
|
$('.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
|
|
|
});
|
|
|
|
|
|
|
|
$('.empty_feed_compose_stream').click(function (e) {
|
2013-05-20 23:35:41 +02:00
|
|
|
compose.start('stream', {trigger: 'empty feed message'});
|
2013-08-22 20:17:07 +02:00
|
|
|
e.preventDefault();
|
2013-04-02 20:47:18 +02:00
|
|
|
});
|
|
|
|
$('.empty_feed_compose_private').click(function (e) {
|
2013-05-20 23:35:41 +02:00
|
|
|
compose.start('private', {trigger: 'empty feed message'});
|
2013-08-22 20:17:07 +02:00
|
|
|
e.preventDefault();
|
2013-04-02 20:47:18 +02:00
|
|
|
});
|
|
|
|
$('.empty_feed_join').click(function (e) {
|
|
|
|
subs.show_and_focus_on_narrow();
|
2013-08-22 20:17:07 +02:00
|
|
|
e.preventDefault();
|
2013-04-02 20:47:18 +02:00
|
|
|
});
|
|
|
|
|
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();
|
|
|
|
});
|
2014-01-30 20:29:00 +01:00
|
|
|
$('.restart_get_events_button').click(function (e) {
|
|
|
|
server_events.restart_get_events({dont_block: true});
|
2013-04-02 20:47:18 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$('#api_key_button').click(function (e) {
|
2013-11-05 16:46:39 +01:00
|
|
|
if (page_params.password_auth_enabled !== false) {
|
|
|
|
$("#get_api_key_box").show();
|
|
|
|
} else {
|
|
|
|
// Skip the password prompt step
|
|
|
|
$("#get_api_key_box form").submit();
|
|
|
|
}
|
2013-04-08 20:06:43 +02:00
|
|
|
$("#api_key_button_box").hide();
|
2013-04-02 20:47:18 +02:00
|
|
|
});
|
|
|
|
|
2013-07-15 23:50:53 +02:00
|
|
|
var notification_docs = $("#notification-docs");
|
|
|
|
notification_docs.popover({"placement": "right",
|
2013-10-11 17:30:57 +02:00
|
|
|
"content": templates.render('notification_docs', {}),
|
2013-07-15 23:50:53 +02:00
|
|
|
"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-27 23:54:13 +02:00
|
|
|
$('body').on('click', '.edit_content_button', function (e) {
|
2013-08-15 23:43:16 +02:00
|
|
|
var row = current_msg_list.get_row(rows.id($(this).closest(".message_row")));
|
|
|
|
message_edit.start(row);
|
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
|
|
|
});
|
2013-11-07 00:20:14 +01:00
|
|
|
$('body').on('click','.always_visible_topic_edit,.on_hover_topic_edit', function (e) {
|
2013-08-16 23:45:13 +02:00
|
|
|
var recipient_row = $(this).closest(".recipient_row");
|
|
|
|
message_edit.start_topic_edit(recipient_row);
|
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
|
|
|
});
|
|
|
|
$("body").on("click", ".topic_edit_save", function (e) {
|
|
|
|
var recipient_row = $(this).closest(".recipient_row");
|
|
|
|
if (message_edit.save(recipient_row) === true) {
|
|
|
|
current_msg_list.hide_edit_topic(recipient_row);
|
|
|
|
}
|
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
|
|
|
});
|
|
|
|
$("body").on("click", ".topic_edit_cancel", function (e) {
|
|
|
|
var recipient_row = $(this).closest(".recipient_row");
|
|
|
|
current_msg_list.hide_edit_topic(recipient_row);
|
2013-05-21 00:00:28 +02:00
|
|
|
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");
|
2013-08-16 23:45:13 +02:00
|
|
|
if (message_edit.save(row) === true) {
|
2014-01-02 19:39:22 +01:00
|
|
|
// Re-fetch the message row in case .save() re-rendered the message list
|
|
|
|
message_edit.end($(this).closest(".message_row"));
|
2013-08-16 23:45:13 +02:00
|
|
|
}
|
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
|
|
|
});
|
|
|
|
$("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
|
|
|
|
2013-08-23 20:49:06 +02:00
|
|
|
// Webathena integration code
|
2013-08-27 21:15:15 +02:00
|
|
|
$('#right-sidebar, #top_navbar').on('click', '.webathena_login', function (e) {
|
2013-08-23 20:49:06 +02:00
|
|
|
$("#zephyr-mirror-error").hide();
|
|
|
|
var principal = ["zephyr", "zephyr"];
|
|
|
|
WinChan.open({
|
|
|
|
url: "https://webathena.mit.edu/#!request_ticket_v1",
|
|
|
|
relay_url: "https://webathena.mit.edu/relay.html",
|
|
|
|
params: {
|
|
|
|
realm: "ATHENA.MIT.EDU",
|
|
|
|
principal: principal
|
|
|
|
}
|
|
|
|
}, function (err, r) {
|
|
|
|
if (err) {
|
|
|
|
blueslip.warn(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (r.status !== "OK") {
|
|
|
|
blueslip.warn(r);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-12-18 19:55:18 +01:00
|
|
|
channel.post({
|
2013-08-23 20:49:06 +02:00
|
|
|
url: "/accounts/webathena_kerberos_login/",
|
|
|
|
data: {cred: JSON.stringify(r.session)},
|
|
|
|
success: function (data, success) {
|
|
|
|
$("#zephyr-mirror-error").hide();
|
|
|
|
},
|
|
|
|
error: function (data, success) {
|
|
|
|
$("#zephyr-mirror-error").show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2013-08-27 21:15:15 +02:00
|
|
|
$('#settings-dropdown').dropdown("toggle");
|
2013-08-23 20:49:06 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
// End Webathena code
|
|
|
|
|
2013-08-16 19:50:26 +02:00
|
|
|
$(document).on('click', function (e) {
|
2013-10-04 20:20:56 +02:00
|
|
|
if (e.button !== 0) {
|
|
|
|
// Firefox emits right click events on the document, but not on
|
|
|
|
// the child nodes, so the #compose stopPropagation doesn't get a
|
|
|
|
// chance to capture right clicks.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-10-25 19:45:25 +02:00
|
|
|
function handle_compose_click(e) {
|
2013-05-03 22:16:52 +02:00
|
|
|
// 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-08-22 20:17:07 +02:00
|
|
|
// Still hide the popovers, however
|
|
|
|
popovers.hide_all();
|
2013-10-25 19:45:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$("#compose_buttons").click(handle_compose_click);
|
|
|
|
$(".compose-content").click(handle_compose_click);
|
2013-04-02 20:47:18 +02:00
|
|
|
|
2013-06-12 23:57:43 +02:00
|
|
|
$("#compose_close").click(function (e) {
|
|
|
|
compose.cancel();
|
|
|
|
});
|
|
|
|
|
2013-08-19 19:02:52 +02:00
|
|
|
$(".bankruptcy_button").click(function (e) {
|
|
|
|
enable_unread_counts();
|
|
|
|
});
|
|
|
|
|
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-11-30 22:03:12 +01:00
|
|
|
if (feature_flags.disable_message_editing) {
|
|
|
|
$("#edit-message-hotkey-help").hide();
|
|
|
|
}
|
|
|
|
|
2013-11-28 22:13:01 +01:00
|
|
|
// Some MIT-specific customizations
|
|
|
|
if (page_params.domain === 'mit.edu') {
|
|
|
|
$("#user-list").hide();
|
|
|
|
$("#group-pm-list").hide();
|
|
|
|
}
|
|
|
|
|
2013-12-05 20:23:02 +01:00
|
|
|
if (feature_flags.full_width) {
|
|
|
|
exports.switchToFullWidth();
|
|
|
|
}
|
|
|
|
|
2013-05-03 22:12:58 +02:00
|
|
|
// initialize other stuff
|
|
|
|
composebox_typeahead.initialize();
|
|
|
|
search.initialize();
|
|
|
|
notifications.initialize();
|
|
|
|
hashchange.initialize();
|
|
|
|
invite.initialize();
|
|
|
|
activity.initialize();
|
|
|
|
tutorial.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 () {
|
2014-01-29 19:04:51 +01:00
|
|
|
viewport.message_pane.scroll($.throttle(50, function (e) {
|
2013-08-02 23:56:28 +02:00
|
|
|
process_visible_unread_messages();
|
|
|
|
scroll_finish();
|
|
|
|
}));
|
|
|
|
};
|
2013-08-02 23:41:40 +02: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-12-09 17:43:20 +01:00
|
|
|
var _message_content_height_cache = new Dict();
|
|
|
|
|
|
|
|
exports.clear_message_content_height_cache = function () {
|
|
|
|
_message_content_height_cache = new Dict();
|
|
|
|
};
|
2013-12-04 21:40:51 +01:00
|
|
|
|
2013-12-09 17:43:20 +01:00
|
|
|
exports.un_cache_message_content_height = function (message_id) {
|
|
|
|
_message_content_height_cache.del(message_id);
|
|
|
|
};
|
|
|
|
|
|
|
|
function get_message_height(elem, message_id) {
|
|
|
|
if (_message_content_height_cache.has(message_id)) {
|
|
|
|
return _message_content_height_cache.get(message_id);
|
2013-12-04 21:40:51 +01:00
|
|
|
}
|
|
|
|
|
2013-12-09 17:43:20 +01:00
|
|
|
var height = elem.getBoundingClientRect().height;
|
|
|
|
_message_content_height_cache.set(message_id, height);
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.condense_and_collapse = function (elems) {
|
|
|
|
var height_cutoff = viewport.height() * 0.65;
|
|
|
|
|
2013-12-04 22:02:34 +01:00
|
|
|
_.each(elems, function (elem) {
|
|
|
|
var content = $(elem).find(".message_content");
|
|
|
|
var message = current_msg_list.get(rows.id($(elem)));
|
|
|
|
if (content !== undefined && message !== undefined) {
|
2013-12-09 17:43:20 +01:00
|
|
|
var message_height = get_message_height(elem, message.id);
|
|
|
|
var long_message = message_height > height_cutoff;
|
2013-12-04 22:02:34 +01:00
|
|
|
if (long_message) {
|
|
|
|
// All long messages are flagged as such.
|
|
|
|
content.addClass("could-be-condensed");
|
2013-12-09 23:07:14 +01:00
|
|
|
} else {
|
|
|
|
content.removeClass("could-be-condensed");
|
2013-12-04 22:02:34 +01:00
|
|
|
}
|
2013-05-08 23:17:49 +02:00
|
|
|
|
2013-12-04 22:02:34 +01:00
|
|
|
// If message.condensed is defined, then the user has manually
|
|
|
|
// specified whether this message should be expanded or condensed.
|
|
|
|
if (message.condensed === true) {
|
|
|
|
condense($(elem));
|
|
|
|
return;
|
|
|
|
} else if (message.condensed === false) {
|
|
|
|
uncondense($(elem));
|
|
|
|
return;
|
|
|
|
} else if (long_message) {
|
|
|
|
// By default, condense a long message.
|
|
|
|
condense($(elem));
|
2013-12-09 23:07:14 +01:00
|
|
|
} else {
|
|
|
|
content.removeClass('condensed');
|
|
|
|
$(elem).find(".message_expander").hide();
|
2013-12-04 22:02:34 +01:00
|
|
|
}
|
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-12-04 22:02:34 +01:00
|
|
|
// Completely hide the message and replace it with a [More]
|
|
|
|
// link if the user has collapsed it.
|
|
|
|
if (message.collapsed) {
|
|
|
|
content.addClass("collapsed");
|
|
|
|
$(elem).find(".message_expander").show();
|
|
|
|
}
|
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-12-04 22:02:34 +01:00
|
|
|
});
|
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-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 () {
|
|
|
|
if (window.bridge !== undefined) {
|
2013-08-27 22:07:59 +02:00
|
|
|
// Disable "spellchecking" in our desktop app. The "spellchecking"
|
|
|
|
// in our Mac app is actually autocorrect, and frustrates our
|
|
|
|
// users.
|
2013-08-09 21:46:34 +02:00
|
|
|
$("#new_message_content").attr('spellcheck', 'false');
|
2013-08-27 22:07:59 +02:00
|
|
|
// Modify the zephyr mirroring error message in our desktop
|
|
|
|
// app, since it doesn't work from the desktop version.
|
|
|
|
$("#webathena_login_menu").hide();
|
|
|
|
$("#normal-zephyr-mirror-error-text").addClass("notdisplayed");
|
|
|
|
$("#desktop-zephyr-mirror-error-text").removeClass("notdisplayed");
|
2013-08-09 21:46:34 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-09-12 22:02:55 +02:00
|
|
|
|
2012-11-16 16:45:39 +01:00
|
|
|
return exports;
|
|
|
|
}());
|