2014-03-14 15:30:29 +01:00
|
|
|
var click_handlers = (function () {
|
|
|
|
|
|
|
|
// We don't actually export anything yet; this is just for consistency.
|
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
// You won't find every click handler here, but it's a good place to start!
|
|
|
|
|
|
|
|
$(function () {
|
|
|
|
|
2017-04-14 01:14:50 +02:00
|
|
|
// MOUSE MOVING VS DRAGGING FOR SELECTION DATA TRACKING
|
2014-03-14 15:30:29 +01:00
|
|
|
|
2017-04-14 01:14:50 +02:00
|
|
|
var drag = (function () {
|
|
|
|
var start;
|
|
|
|
var time;
|
2014-03-14 15:30:29 +01:00
|
|
|
|
2017-04-14 01:14:50 +02:00
|
|
|
return {
|
|
|
|
start: function (e) {
|
|
|
|
start = { x: e.offsetX, y: e.offsetY };
|
|
|
|
time = new Date().getTime();
|
|
|
|
},
|
|
|
|
|
|
|
|
end: function (e) {
|
|
|
|
var end = { x: e.offsetX, y: e.offsetY };
|
|
|
|
|
2017-04-26 21:15:14 +02:00
|
|
|
var dist;
|
|
|
|
if (start) {
|
|
|
|
// get the linear difference between two coordinates on the screen.
|
|
|
|
dist = Math.sqrt(Math.pow(end.x - start.x, 2) + Math.pow(end.y - start.y, 2));
|
|
|
|
} else {
|
|
|
|
// this usually happens if someone started dragging from outside of
|
|
|
|
// a message and finishes their drag inside the message. The intent
|
|
|
|
// in that case is clearly to select an area, not click a message;
|
|
|
|
// setting dist to Infinity here will ensure that.
|
|
|
|
dist = Infinity;
|
|
|
|
}
|
2017-04-14 01:14:50 +02:00
|
|
|
|
|
|
|
this.val = dist;
|
|
|
|
this.time = new Date().getTime() - time;
|
2014-03-14 15:30:29 +01:00
|
|
|
|
2017-04-14 01:14:50 +02:00
|
|
|
start = undefined;
|
|
|
|
|
|
|
|
return dist;
|
|
|
|
},
|
|
|
|
val: null,
|
|
|
|
};
|
|
|
|
}());
|
|
|
|
|
|
|
|
$("#main_div").on("mousedown", ".messagebox", function (e) {
|
|
|
|
drag.start(e);
|
|
|
|
});
|
|
|
|
$("#main_div").on("mouseup", ".messagebox", function (e) {
|
|
|
|
drag.end(e);
|
|
|
|
});
|
2014-03-14 15:30:29 +01:00
|
|
|
|
|
|
|
// MESSAGE CLICKING
|
|
|
|
|
|
|
|
function is_clickable_message_element(target) {
|
|
|
|
return target.is("a") || target.is("img.message_inline_image") || target.is("img.twitter-avatar") ||
|
|
|
|
target.is("div.message_length_controller") || target.is("textarea") || target.is("input") ||
|
2017-05-08 20:00:28 +02:00
|
|
|
target.is("i.edit_content_button") ||
|
|
|
|
(target.is(".highlight") && target.parent().is("a"));
|
2014-03-14 15:30:29 +01:00
|
|
|
}
|
|
|
|
|
2017-07-31 21:45:39 +02:00
|
|
|
function initialize_long_tap() {
|
|
|
|
var MS_DELAY = 750;
|
|
|
|
var meta = {
|
|
|
|
touchdown: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
$("#main_div").on("touchstart", ".messagebox", function () {
|
|
|
|
meta.touchdown = true;
|
|
|
|
meta.invalid = false;
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
if (meta.touchdown === true && !meta.invalid) {
|
|
|
|
$(this).trigger("longtap");
|
|
|
|
}
|
|
|
|
}.bind(this), MS_DELAY);
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#main_div").on("touchend", ".messagebox", function () {
|
|
|
|
meta.touchdown = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#main_div").on("touchmove", ".messagebox", function () {
|
|
|
|
meta.invalid = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#main_div").on("contextmenu", ".messagebox", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// this initializes the trigger that will give off the longtap event, which
|
|
|
|
// there is no point in running if we are on desktop since this isn't a
|
|
|
|
// standard event that we would want to support.
|
|
|
|
if (util.is_mobile()) {
|
|
|
|
initialize_long_tap();
|
|
|
|
}
|
|
|
|
|
|
|
|
var select_message_function = function (e) {
|
2014-03-14 15:30:29 +01:00
|
|
|
if (is_clickable_message_element($(e.target))) {
|
|
|
|
// 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;
|
|
|
|
}
|
2017-04-14 01:14:50 +02:00
|
|
|
|
|
|
|
// A tricky issue here is distinguishing hasty clicks (where
|
|
|
|
// the mouse might still move a few pixels between mouseup and
|
|
|
|
// mousedown) from selecting-for-copy. We handle this issue
|
|
|
|
// by treating it as a click if distance is very small
|
|
|
|
// (covering the long-click case), or fairly small and over a
|
|
|
|
// short time (covering the hasty click case). This seems to
|
|
|
|
// work nearly perfectly. Once we no longer need to support
|
|
|
|
// older browsers, we may be able to use the window.selection
|
|
|
|
// API instead.
|
|
|
|
if ((drag.val < 5 && drag.time < 150) || drag.val < 2) {
|
2014-03-14 15:30:29 +01:00
|
|
|
var row = $(this).closest(".message_row");
|
|
|
|
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);
|
2017-04-14 19:27:12 +02:00
|
|
|
compose_actions.respond_to_message({trigger: 'message click'});
|
2014-03-14 15:30:29 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
|
|
|
}
|
2017-07-31 21:45:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// if on normal non-mobile experience, a `click` event should run the message
|
|
|
|
// selection function which will open the compose box and select the message.
|
|
|
|
if (!util.is_mobile()) {
|
|
|
|
$("#main_div").on("click", ".messagebox", select_message_function);
|
|
|
|
// on the other hand, on mobile it should be done with a long tap.
|
|
|
|
} else {
|
2017-09-15 22:43:12 +02:00
|
|
|
$("#main_div").on("longtap", ".messagebox", function (e) {
|
|
|
|
// find the correct selection API for the browser.
|
|
|
|
var sel = window.getSelection ? window.getSelection() : document.selection;
|
|
|
|
// if one matches, remove the current selections.
|
|
|
|
// after a longtap that is valid, there should be no text selected.
|
|
|
|
if (sel) {
|
|
|
|
if (sel.removeAllRanges) {
|
|
|
|
sel.removeAllRanges();
|
|
|
|
} else if (sel.empty) {
|
|
|
|
sel.empty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
select_message_function.call(this, e);
|
|
|
|
});
|
2017-07-31 21:45:39 +02:00
|
|
|
}
|
2014-03-14 15:30:29 +01:00
|
|
|
|
|
|
|
function toggle_star(message_id) {
|
|
|
|
// Update the message object pointed to by the various message
|
|
|
|
// lists.
|
|
|
|
var message = ui.find_message(message_id);
|
|
|
|
|
2017-03-18 01:41:56 +01:00
|
|
|
unread_ops.mark_message_as_read(message);
|
2014-03-14 15:30:29 +01:00
|
|
|
ui.update_starred(message.id, message.starred !== true);
|
|
|
|
message_flags.send_starred([message], message.starred);
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#main_div").on("click", ".star", function (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
|
|
|
toggle_star(rows.id($(this).closest(".message_row")));
|
|
|
|
});
|
|
|
|
|
2016-12-02 13:23:23 +01:00
|
|
|
$("#main_div").on("click", ".message_reaction", function (e) {
|
|
|
|
e.stopPropagation();
|
2017-10-31 22:33:28 +01:00
|
|
|
var local_id = $(this).attr('data-reaction-id');
|
2017-07-19 14:01:06 +02:00
|
|
|
var message_id = rows.get_message_id(this);
|
2017-10-31 22:33:28 +01:00
|
|
|
reactions.process_reaction_click(message_id, local_id);
|
2016-12-02 13:23:23 +01:00
|
|
|
});
|
|
|
|
|
2016-11-18 10:18:08 +01:00
|
|
|
$("#main_div").on("click", "a.stream", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var stream = stream_data.get_sub_by_id($(this).attr('data-stream-id'));
|
|
|
|
if (stream) {
|
2017-03-18 18:29:20 +01:00
|
|
|
window.location.href = '/#narrow/stream/' + hash_util.encodeHashComponent(stream.name);
|
2016-11-18 10:18:08 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
window.location.href = $(this).attr('href');
|
|
|
|
});
|
|
|
|
|
2016-12-28 03:41:20 +01:00
|
|
|
// NOTIFICATION CLICK
|
|
|
|
|
|
|
|
$('body').on('click', '.notification', function () {
|
|
|
|
var payload = $(this).data("narrow");
|
2017-03-18 21:35:35 +01:00
|
|
|
ui_util.change_tab_to('#home');
|
2016-12-28 03:41:20 +01:00
|
|
|
narrow.activate(payload.raw_operators, payload.opts_notif);
|
|
|
|
});
|
|
|
|
|
2014-03-14 15:30:29 +01:00
|
|
|
// MESSAGE EDITING
|
|
|
|
|
|
|
|
$('body').on('click', '.edit_content_button', function (e) {
|
|
|
|
var row = current_msg_list.get_row(rows.id($(this).closest(".message_row")));
|
|
|
|
current_msg_list.select_id(rows.id(row));
|
|
|
|
message_edit.start(row);
|
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
|
|
|
});
|
|
|
|
$('body').on('click','.always_visible_topic_edit,.on_hover_topic_edit', function (e) {
|
|
|
|
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");
|
2016-10-26 01:12:12 +02:00
|
|
|
message_edit.save(recipient_row, true);
|
2014-03-14 15:30:29 +01:00
|
|
|
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);
|
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
|
|
|
});
|
|
|
|
$("body").on("click", ".message_edit_save", function (e) {
|
|
|
|
var row = $(this).closest(".message_row");
|
2016-10-26 01:12:12 +02:00
|
|
|
message_edit.save(row, false);
|
2014-03-14 15:30:29 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
|
|
|
});
|
|
|
|
$("body").on("click", ".message_edit_cancel", function (e) {
|
|
|
|
var row = $(this).closest(".message_row");
|
|
|
|
message_edit.end(row);
|
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
|
|
|
});
|
2016-10-22 02:38:56 +02:00
|
|
|
$("body").on("click", ".message_edit_close", function (e) {
|
|
|
|
var row = $(this).closest(".message_row");
|
|
|
|
message_edit.end(row);
|
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
|
|
|
});
|
2017-01-17 20:51:30 +01:00
|
|
|
$("body").on("click", ".copy_message", function (e) {
|
|
|
|
var row = $(this).closest(".message_row");
|
|
|
|
message_edit.end(row);
|
2017-03-27 11:07:04 +02:00
|
|
|
row.find(".alert-copied").css("display", "block");
|
|
|
|
row.find(".alert-copied").delay(1000).fadeOut(300);
|
2017-01-17 20:51:30 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
2016-12-15 07:26:09 +01:00
|
|
|
$("body").on("click", "a", function () {
|
2016-12-14 23:34:08 +01:00
|
|
|
if (document.activeElement === this) {
|
2017-03-18 21:35:35 +01:00
|
|
|
ui_util.blur_active_element();
|
2016-12-14 23:34:08 +01:00
|
|
|
}
|
|
|
|
});
|
2014-03-14 15:30:29 +01:00
|
|
|
|
2016-11-22 09:20:20 +01:00
|
|
|
// MUTING
|
|
|
|
|
|
|
|
$('body').on('click', '.on_hover_topic_mute', function (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
var stream_id = $(e.currentTarget).attr('data-stream-id');
|
|
|
|
var topic = $(e.currentTarget).attr('data-topic-name');
|
|
|
|
var stream = stream_data.get_sub_by_id(stream_id);
|
2017-03-23 06:57:36 +01:00
|
|
|
muting_ui.mute(stream.name, topic);
|
2016-11-22 09:20:20 +01:00
|
|
|
});
|
|
|
|
|
2014-03-14 15:30:29 +01:00
|
|
|
// RECIPIENT BARS
|
|
|
|
|
|
|
|
function get_row_id_for_narrowing(narrow_link_elem) {
|
|
|
|
var group = rows.get_closest_group(narrow_link_elem);
|
|
|
|
var msg_id = rows.id_for_recipient_row(group);
|
|
|
|
|
|
|
|
var nearest = current_msg_list.get(msg_id);
|
|
|
|
var selected = current_msg_list.selected_message();
|
|
|
|
if (util.same_recipient(nearest, selected)) {
|
|
|
|
return selected.id;
|
|
|
|
}
|
2016-12-02 21:34:35 +01:00
|
|
|
return nearest.id;
|
2014-03-14 15:30:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$("#home").on("click", ".narrows_by_recipient", function (e) {
|
|
|
|
if (e.metaKey || e.ctrlKey) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
e.preventDefault();
|
|
|
|
var row_id = get_row_id_for_narrowing(this);
|
|
|
|
narrow.by_recipient(row_id, {trigger: 'message header'});
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#home").on("click", ".narrows_by_subject", function (e) {
|
|
|
|
if (e.metaKey || e.ctrlKey) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
e.preventDefault();
|
|
|
|
var row_id = get_row_id_for_narrowing(this);
|
|
|
|
narrow.by_subject(row_id, {trigger: 'message header'});
|
|
|
|
});
|
|
|
|
|
|
|
|
// SIDEBARS
|
|
|
|
|
|
|
|
$("#userlist-toggle-button").on("click", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
var sidebarHidden = !$(".app-main .column-right").hasClass("expanded");
|
|
|
|
popovers.hide_all();
|
|
|
|
if (sidebarHidden) {
|
|
|
|
popovers.show_userlist_sidebar();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#streamlist-toggle-button").on("click", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
var sidebarHidden = !$(".app-main .column-left").hasClass("expanded");
|
|
|
|
popovers.hide_all();
|
|
|
|
if (sidebarHidden) {
|
2017-03-08 23:39:39 +01:00
|
|
|
stream_popover.show_streamlist_sidebar();
|
2014-03-14 15:30:29 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#user_presences').expectOne().on('click', '.selectable_sidebar_block', function (e) {
|
2016-11-17 23:16:29 +01:00
|
|
|
var user_id = $(e.target).parents('li').attr('data-user-id');
|
|
|
|
var email = people.get_person_from_user_id(user_id).email;
|
2017-03-18 17:45:09 +01:00
|
|
|
activity.escape_search();
|
2014-03-14 15:30:29 +01:00
|
|
|
narrow.by('pm-with', email, {select_first_unread: true, trigger: 'sidebar'});
|
|
|
|
// The preventDefault is necessary so that clicking the
|
|
|
|
// link doesn't jump us to the top of the page.
|
|
|
|
e.preventDefault();
|
|
|
|
// 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();
|
|
|
|
// Since we're stopping propagation we have to manually close any
|
|
|
|
// open popovers.
|
|
|
|
popovers.hide_all();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#group-pms').expectOne().on('click', '.selectable_sidebar_block', function (e) {
|
2016-11-17 23:16:29 +01:00
|
|
|
var user_ids_string = $(e.target).parents('li').attr('data-user-ids');
|
|
|
|
var emails = people.user_ids_string_to_emails_string(user_ids_string);
|
2014-03-14 15:30:29 +01:00
|
|
|
narrow.by('pm-with', emails, {select_first_unread: true, trigger: 'sidebar'});
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
|
|
|
});
|
|
|
|
|
2016-11-01 22:32:10 +01:00
|
|
|
$("#subscriptions_table").on("click", ".exit, #subscription_overlay", function (e) {
|
|
|
|
if ($(e.target).is(".exit, .exit-sign, #subscription_overlay, #subscription_overlay > .flex")) {
|
2017-01-19 23:23:25 +01:00
|
|
|
subs.close();
|
2016-11-01 22:32:10 +01:00
|
|
|
}
|
|
|
|
});
|
2017-02-22 02:34:05 +01:00
|
|
|
|
2014-03-14 15:30:29 +01:00
|
|
|
// HOME
|
|
|
|
|
2017-08-08 07:37:39 +02:00
|
|
|
// Capture both the left-sidebar All Messages click and the tab breadcrumb All Messages
|
2017-01-16 16:43:02 +01:00
|
|
|
$(document).on('click', ".home-link[data-name='home']", function (e) {
|
2017-03-18 21:35:35 +01:00
|
|
|
ui_util.change_tab_to('#home');
|
2014-03-14 15:30:29 +01:00
|
|
|
narrow.deactivate();
|
2017-09-08 18:25:29 +02:00
|
|
|
search.update_button_visibility();
|
2014-03-14 15:30:29 +01:00
|
|
|
// We need to maybe scroll to the selected message
|
|
|
|
// once we have the proper viewport set up
|
2016-05-25 13:24:33 +02:00
|
|
|
setTimeout(navigate.maybe_scroll_to_selected, 0);
|
2014-03-14 15:30:29 +01:00
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".brand").on('click', function (e) {
|
2017-05-27 15:40:54 +02:00
|
|
|
if (overlays.is_active()) {
|
2017-03-18 21:35:35 +01:00
|
|
|
ui_util.change_tab_to('#home');
|
2014-03-14 15:30:29 +01:00
|
|
|
} else {
|
|
|
|
narrow.restore_home_state();
|
|
|
|
}
|
2016-05-25 13:24:33 +02:00
|
|
|
navigate.maybe_scroll_to_selected();
|
2014-03-14 15:30:29 +01:00
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
|
|
|
// MISC
|
|
|
|
|
2016-09-29 21:56:50 +02:00
|
|
|
(function () {
|
|
|
|
var sel = ["#group-pm-list", "#stream_filters", "#global_filters", "#user_presences"].join(", ");
|
|
|
|
|
|
|
|
$(sel).on("click", "a", function () {
|
|
|
|
this.blur();
|
|
|
|
});
|
|
|
|
}());
|
|
|
|
|
2014-03-14 15:30:29 +01:00
|
|
|
popovers.register_click_handlers();
|
2017-04-27 07:27:25 +02:00
|
|
|
emoji_picker.register_click_handlers();
|
2017-03-05 17:28:40 +01:00
|
|
|
stream_popover.register_click_handlers();
|
2014-03-14 15:30:29 +01:00
|
|
|
notifications.register_click_handlers();
|
|
|
|
|
2016-12-03 01:12:52 +01:00
|
|
|
$('body').on('click', '.logout_button', function () {
|
2014-03-14 15:30:29 +01:00
|
|
|
$('#logout_form').submit();
|
|
|
|
});
|
2016-12-03 01:12:52 +01:00
|
|
|
|
2016-12-02 14:06:06 +01:00
|
|
|
$('.restart_get_events_button').click(function () {
|
2014-03-14 15:30:29 +01:00
|
|
|
server_events.restart_get_events({dont_block: true});
|
|
|
|
});
|
|
|
|
|
2017-03-23 20:37:08 +01:00
|
|
|
// this will hide the alerts that you click "x" on.
|
|
|
|
$("body").on("click", ".alert .exit", function () {
|
|
|
|
var $alert = $(this).closest(".alert");
|
|
|
|
$alert.addClass("fade-out");
|
|
|
|
setTimeout(function () {
|
|
|
|
$alert.removeClass("fade-out show");
|
|
|
|
}, 300);
|
|
|
|
});
|
|
|
|
|
2014-03-14 15:30:29 +01:00
|
|
|
|
|
|
|
// COMPOSE
|
|
|
|
|
|
|
|
// NB: This just binds to current elements, and won't bind to elements
|
|
|
|
// created after ready() is called.
|
2017-11-26 20:01:37 +01:00
|
|
|
$('#compose-send-status .compose-send-status-close').click(
|
2017-11-26 19:58:36 +01:00
|
|
|
function () { $('#compose-send-status').stop(true).fadeOut(500); }
|
2014-03-14 15:30:29 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
|
2016-12-02 14:06:06 +01:00
|
|
|
$('.compose_stream_button').click(function () {
|
2017-03-18 17:41:47 +01:00
|
|
|
compose_actions.start('stream', {trigger: 'new topic button'});
|
2014-03-14 15:30:29 +01:00
|
|
|
});
|
2016-12-02 14:06:06 +01:00
|
|
|
$('.compose_private_button').click(function () {
|
2017-03-18 17:41:47 +01:00
|
|
|
compose_actions.start('private');
|
2014-03-14 15:30:29 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
$('.empty_feed_compose_stream').click(function (e) {
|
2017-03-18 17:41:47 +01:00
|
|
|
compose_actions.start('stream', {trigger: 'empty feed message'});
|
2014-03-14 15:30:29 +01:00
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
$('.empty_feed_compose_private').click(function (e) {
|
2017-03-18 17:41:47 +01:00
|
|
|
compose_actions.start('private', {trigger: 'empty feed message'});
|
2014-03-14 15:30:29 +01:00
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2017-01-05 21:11:45 +01:00
|
|
|
$("body").on("click", "[data-overlay-trigger]", function () {
|
|
|
|
ui.show_info_overlay($(this).attr("data-overlay-trigger"));
|
|
|
|
});
|
|
|
|
|
2014-03-14 15:30:29 +01:00
|
|
|
function handle_compose_click(e) {
|
2017-04-27 07:27:25 +02:00
|
|
|
// Emoji clicks should be handled by their own click handler in emoji_picker.js
|
2017-04-29 09:43:13 +02:00
|
|
|
if ($(e.target).is("#emoji_map, img.emoji, .drag")) {
|
2015-10-15 22:34:30 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-03-14 15:30:29 +01: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.
|
|
|
|
// But do allow our formatting link.
|
|
|
|
if (!$(e.target).is("a")) {
|
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
// Still hide the popovers, however
|
|
|
|
popovers.hide_all();
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#compose_buttons").click(handle_compose_click);
|
|
|
|
$(".compose-content").click(handle_compose_click);
|
|
|
|
|
2016-12-02 14:06:06 +01:00
|
|
|
$("#compose_close").click(function () {
|
2017-03-18 17:55:11 +01:00
|
|
|
compose_actions.cancel();
|
2014-03-14 15:30:29 +01:00
|
|
|
});
|
|
|
|
|
2017-01-30 23:45:52 +01:00
|
|
|
$("#join_unsub_stream").click(function (e) {
|
|
|
|
e.stopPropagation();
|
2017-03-09 00:20:22 +01:00
|
|
|
window.location.hash = "streams/all";
|
2017-01-12 00:03:20 +01:00
|
|
|
});
|
|
|
|
|
2017-09-09 15:00:00 +02:00
|
|
|
$("#streams_inline_cog").click(function (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
window.location.hash = "streams";
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#streams_filter_icon").click(function (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
stream_list.toggle_filter_displayed(e);
|
|
|
|
});
|
|
|
|
|
2017-04-20 21:49:12 +02:00
|
|
|
$("body").on("click", ".default_stream_row .remove-default-stream", function () {
|
|
|
|
var row = $(this).closest(".default_stream_row");
|
|
|
|
var stream_name = row.attr("id");
|
|
|
|
|
|
|
|
channel.del({
|
|
|
|
url: "/json/default_streams" + "?" + $.param({ stream_name: stream_name }),
|
|
|
|
error: function (xhr) {
|
|
|
|
var button = row.find("button");
|
|
|
|
if (xhr.status.toString().charAt(0) === "4") {
|
|
|
|
button.closest("td").html(
|
|
|
|
$("<p>").addClass("text-error").text(JSON.parse(xhr.responseText).msg)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
button.text(i18n.t("Failed!"));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
success: function () {
|
|
|
|
row.remove();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-03-14 15:30:29 +01:00
|
|
|
// FEEDBACK
|
|
|
|
|
|
|
|
// Keep these 2 feedback bot triggers separate because they have to
|
|
|
|
// propagate the event differently.
|
2016-12-02 14:06:06 +01:00
|
|
|
$('.feedback').click(function () {
|
2017-03-18 17:41:47 +01:00
|
|
|
compose_actions.start('private', {
|
|
|
|
private_message_recipient: 'feedback@zulip.com',
|
|
|
|
trigger: 'feedback menu item'});
|
2014-03-14 15:30:29 +01:00
|
|
|
|
|
|
|
});
|
|
|
|
$('#feedback_button').click(function (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
2017-03-18 17:41:47 +01:00
|
|
|
compose_actions.start('private', {
|
|
|
|
private_message_recipient: 'feedback@zulip.com',
|
|
|
|
trigger: 'feedback button'});
|
2014-03-14 15:30:29 +01:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// WEBATHENA
|
|
|
|
|
2017-05-01 06:30:55 +02:00
|
|
|
$('body').on('click', '.webathena_login', function (e) {
|
2017-04-05 23:33:14 +02:00
|
|
|
$("#zephyr-mirror-error").removeClass("show");
|
2014-03-14 15:30:29 +01:00
|
|
|
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",
|
2017-01-12 00:17:43 +01:00
|
|
|
principal: principal,
|
|
|
|
},
|
2014-03-14 15:30:29 +01:00
|
|
|
}, function (err, r) {
|
|
|
|
if (err) {
|
|
|
|
blueslip.warn(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (r.status !== "OK") {
|
|
|
|
blueslip.warn(r);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
channel.post({
|
|
|
|
url: "/accounts/webathena_kerberos_login/",
|
|
|
|
data: {cred: JSON.stringify(r.session)},
|
2016-12-02 14:06:06 +01:00
|
|
|
success: function () {
|
2017-04-05 23:33:14 +02:00
|
|
|
$("#zephyr-mirror-error").removeClass("show");
|
2014-03-14 15:30:29 +01:00
|
|
|
},
|
2016-12-02 14:06:06 +01:00
|
|
|
error: function () {
|
2017-04-05 23:33:14 +02:00
|
|
|
$("#zephyr-mirror-error").addClass("show");
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2014-03-14 15:30:29 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
$('#settings-dropdown').dropdown("toggle");
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
// End Webathena code
|
|
|
|
|
2016-12-17 03:44:15 +01:00
|
|
|
(function () {
|
|
|
|
var map = {
|
2017-04-24 04:11:25 +02:00
|
|
|
".stream-description-editable": stream_edit.change_stream_description,
|
|
|
|
".stream-name-editable": stream_edit.change_stream_name,
|
2016-12-17 03:44:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// http://stackoverflow.com/questions/4233265/contenteditable-set-caret-at-the-end-of-the-text-cross-browser
|
|
|
|
function place_caret_at_end(el) {
|
|
|
|
el.focus();
|
|
|
|
|
|
|
|
if (typeof window.getSelection !== "undefined"
|
|
|
|
&& typeof document.createRange !== "undefined") {
|
|
|
|
var range = document.createRange();
|
|
|
|
range.selectNodeContents(el);
|
|
|
|
range.collapse(false);
|
|
|
|
var sel = window.getSelection();
|
|
|
|
sel.removeAllRanges();
|
|
|
|
sel.addRange(range);
|
|
|
|
} else if (typeof document.body.createTextRange !== "undefined") {
|
|
|
|
var textRange = document.body.createTextRange();
|
|
|
|
textRange.moveToElementText(el);
|
|
|
|
textRange.collapse(false);
|
|
|
|
textRange.select();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-16 19:50:08 +01:00
|
|
|
$(document).on("keydown", ".editable-section", function (e) {
|
|
|
|
e.stopPropagation();
|
2017-03-22 07:00:13 +01:00
|
|
|
// Cancel editing description if Escape key is pressed.
|
|
|
|
if (e.which === 27) {
|
|
|
|
$("[data-finish-editing='.stream-description-editable']").hide();
|
|
|
|
$(this).attr("contenteditable", false);
|
|
|
|
$(this).text($(this).attr("data-prev-text"));
|
|
|
|
$("[data-make-editable]").html("");
|
2017-03-22 20:10:15 +01:00
|
|
|
} else if (e.which === 13) {
|
|
|
|
$(this).siblings(".checkmark").click();
|
2017-03-22 07:00:13 +01:00
|
|
|
}
|
2017-02-16 19:50:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
$(document).on("drop", ".editable-section", function () {
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).on("input", ".editable-section", function () {
|
|
|
|
// if there are any child nodes, inclusive of <br> which means you
|
|
|
|
// have lines in your description or title, you're doing something
|
|
|
|
// wrong.
|
2017-03-22 19:42:54 +01:00
|
|
|
for (var x = 0; x < this.childNodes.length; x += 1) {
|
|
|
|
if (this.childNodes[x].nodeType !== 3) {
|
|
|
|
this.innerText = this.innerText.replace(/\n/, "");
|
|
|
|
break;
|
|
|
|
}
|
2017-02-16 19:50:08 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-17 03:44:15 +01:00
|
|
|
$("body").on("click", "[data-make-editable]", function () {
|
|
|
|
var selector = $(this).attr("data-make-editable");
|
|
|
|
var edit_area = $(this).parent().find(selector);
|
|
|
|
if (edit_area.attr("contenteditable") === "true") {
|
|
|
|
$("[data-finish-editing='" + selector + "']").hide();
|
|
|
|
edit_area.attr("contenteditable", false);
|
|
|
|
edit_area.text(edit_area.attr("data-prev-text"));
|
|
|
|
$(this).html("");
|
|
|
|
} else {
|
|
|
|
$("[data-finish-editing='" + selector + "']").show();
|
2016-12-17 03:53:12 +01:00
|
|
|
|
|
|
|
edit_area.attr("data-prev-text", edit_area.text().trim())
|
|
|
|
.attr("contenteditable", true);
|
|
|
|
|
|
|
|
place_caret_at_end(edit_area[0]);
|
|
|
|
|
2016-12-17 03:44:15 +01:00
|
|
|
$(this).html("×");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$("body").on("click", "[data-finish-editing]", function (e) {
|
|
|
|
var selector = $(this).attr("data-finish-editing");
|
|
|
|
if (map[selector]) {
|
|
|
|
map[selector](e);
|
|
|
|
$(this).hide();
|
|
|
|
$(this).parent().find(selector).attr("contenteditable", false);
|
|
|
|
$("[data-make-editable='" + selector + "']").html("");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}());
|
|
|
|
|
2017-07-14 03:21:30 +02:00
|
|
|
|
|
|
|
// HOTSPOTS
|
|
|
|
|
|
|
|
// open
|
|
|
|
$('body').on('click', '.hotspot-icon', function (e) {
|
|
|
|
// hide icon
|
|
|
|
$(this).animate({ opacity: 0 }, {
|
|
|
|
duration: 300,
|
|
|
|
done: function () {
|
|
|
|
$(this).css({ display: 'none' });
|
|
|
|
}.bind(this),
|
|
|
|
});
|
|
|
|
|
|
|
|
// show popover
|
|
|
|
var hotspot_name = $(e.target).closest('.hotspot-icon')
|
|
|
|
.attr('id')
|
|
|
|
.replace('hotspot_', '')
|
|
|
|
.replace('_icon', '');
|
|
|
|
var overlay_name = 'hotspot_' + hotspot_name + '_overlay';
|
|
|
|
|
|
|
|
overlays.open_overlay({
|
|
|
|
name: overlay_name,
|
|
|
|
overlay: $('#' + overlay_name),
|
|
|
|
on_close: function () {
|
|
|
|
// close popover
|
|
|
|
$(this).css({ display: 'block' });
|
|
|
|
$(this).animate({ opacity: 1 }, {
|
|
|
|
duration: 300,
|
|
|
|
});
|
|
|
|
}.bind(this),
|
|
|
|
});
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
// confirm
|
|
|
|
$('body').on('click', '.hotspot.overlay .hotspot-confirm', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
var overlay_name = $(this).closest('.hotspot.overlay').attr('id');
|
|
|
|
|
|
|
|
var hotspot_name = overlay_name
|
|
|
|
.replace('hotspot_', '')
|
|
|
|
.replace('_overlay', '');
|
|
|
|
|
|
|
|
// Comment below to disable marking hotspots as read in production
|
|
|
|
hotspots.post_hotspot_as_read(hotspot_name);
|
|
|
|
|
|
|
|
overlays.close_overlay(overlay_name);
|
|
|
|
$('#hotspot_' + hotspot_name + '_icon').remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
// stop propagation
|
|
|
|
$('body').on('click', '.hotspot.overlay .hotspot-popover', function (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-03-14 15:30:29 +01:00
|
|
|
// MAIN CLICK HANDLER
|
|
|
|
|
|
|
|
$(document).on('click', function (e) {
|
2016-10-15 07:21:30 +02:00
|
|
|
if (e.button !== 0 || $(e.target).is(".drag")) {
|
2014-03-14 15:30:29 +01:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dismiss popovers if the user has clicked outside them
|
2017-07-19 00:28:56 +02:00
|
|
|
if ($('.popover-inner, .emoji-info-popover').has(e.target).length === 0) {
|
2014-03-14 15:30:29 +01:00
|
|
|
popovers.hide_all();
|
|
|
|
}
|
|
|
|
|
2017-09-08 20:44:23 +02:00
|
|
|
if (compose_state.composing()) {
|
|
|
|
if ($(e.target).is("a")) {
|
|
|
|
// Refocus compose message text box if link is clicked
|
2017-11-26 20:37:44 +01:00
|
|
|
$("#compose-textarea").focus();
|
2017-09-08 20:44:23 +02:00
|
|
|
} else if (!$(e.target).closest(".overlay").length &&
|
|
|
|
!window.getSelection().toString() &&
|
|
|
|
!$(e.target).closest('.popover-content').length) {
|
|
|
|
// Unfocus our compose area if we click out of it. Don't let exits out
|
|
|
|
// of overlays or selecting text (for copy+paste) trigger cancelling.
|
|
|
|
compose_actions.cancel();
|
|
|
|
}
|
2014-03-14 15:30:29 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
});
|
2016-12-03 01:12:52 +01:00
|
|
|
|
|
|
|
$("#settings_overlay_container .sidebar").on("click", "li[data-section]", function () {
|
|
|
|
var $this = $(this);
|
|
|
|
|
|
|
|
$("#settings_overlay_container .sidebar li").removeClass("active no-border");
|
2017-05-05 20:38:15 +02:00
|
|
|
$this.addClass("active").prev().addClass("no-border");
|
|
|
|
|
|
|
|
var $settings_overlay_container = $("#settings_overlay_container");
|
|
|
|
$settings_overlay_container.find(".right").addClass("show");
|
|
|
|
$settings_overlay_container.find(".settings-header.mobile").addClass("slide-left");
|
2017-05-09 22:09:13 +02:00
|
|
|
|
|
|
|
settings.set_settings_header($(this).attr("data-section"));
|
2017-05-05 20:38:15 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$(".settings-header.mobile .icon-vector-chevron-left").on("click", function () {
|
|
|
|
$("#settings_page").find(".right").removeClass("show");
|
|
|
|
$(this).parent().removeClass("slide-left");
|
2016-12-03 01:12:52 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
$("#settings_overlay_container .sidebar").on("click", "li[data-section]", function () {
|
|
|
|
var $this = $(this);
|
|
|
|
var section = $this.data("section");
|
|
|
|
var sel = "[data-name='" + section + "']";
|
|
|
|
|
|
|
|
$("#settings_overlay_container .sidebar li").removeClass("active no-border");
|
|
|
|
$this.addClass("active");
|
|
|
|
$this.prev().addClass("no-border");
|
|
|
|
|
2017-04-17 16:51:27 +02:00
|
|
|
var is_org_section = $this.hasClass("admin");
|
|
|
|
|
|
|
|
if (is_org_section) {
|
2017-04-07 21:39:58 +02:00
|
|
|
window.location.hash = "organization/" + section;
|
2016-12-03 01:12:52 +01:00
|
|
|
} else {
|
|
|
|
window.location.hash = "settings/" + section;
|
|
|
|
}
|
|
|
|
|
|
|
|
$(".settings-section, .settings-wrapper").removeClass("show");
|
2017-04-17 16:51:27 +02:00
|
|
|
|
2017-06-14 10:39:10 +02:00
|
|
|
ui.update_scrollbar($("#settings_content"));
|
|
|
|
|
2017-04-17 16:51:27 +02:00
|
|
|
if (is_org_section) {
|
|
|
|
admin_sections.load_admin_section(section);
|
|
|
|
} else {
|
|
|
|
settings_sections.load_settings_section(section);
|
|
|
|
}
|
|
|
|
|
2016-12-03 01:12:52 +01:00
|
|
|
$(".settings-section" + sel + ", .settings-wrapper" + sel).addClass("show");
|
|
|
|
});
|
|
|
|
|
2017-08-08 02:56:36 +02:00
|
|
|
(i18n.ensure_i18n(function () {
|
2017-02-21 19:10:50 +01:00
|
|
|
var settings_toggle = components.toggle({
|
|
|
|
name: "settings-toggle",
|
|
|
|
values: [
|
2017-06-23 21:56:08 +02:00
|
|
|
{ label: i18n.t("Settings"), key: "settings" },
|
|
|
|
{ label: i18n.t("Organization"), key: "organization" },
|
2017-02-21 19:10:50 +01:00
|
|
|
],
|
2017-08-01 20:37:14 +02:00
|
|
|
callback: function (name, key, payload) {
|
2017-02-21 19:10:50 +01:00
|
|
|
$(".sidebar li").hide();
|
|
|
|
|
2017-04-07 21:39:58 +02:00
|
|
|
if (key === "organization") {
|
2017-02-21 19:10:50 +01:00
|
|
|
$("li.admin").show();
|
2017-08-01 20:37:14 +02:00
|
|
|
if (!payload.dont_switch_tab) {
|
2017-08-18 01:23:55 +02:00
|
|
|
$("li[data-section='organization-profile']").click();
|
2017-08-01 20:37:14 +02:00
|
|
|
}
|
2017-02-21 19:10:50 +01:00
|
|
|
} else {
|
2017-11-15 21:57:50 +01:00
|
|
|
$(".settings-list li:not(.admin)").show();
|
2017-08-01 20:37:14 +02:00
|
|
|
if (!payload.dont_switch_tab) {
|
|
|
|
$("li[data-section='your-account']").click();
|
|
|
|
}
|
2017-02-21 19:10:50 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}).get();
|
|
|
|
|
|
|
|
$("#settings_overlay_container .tab-container")
|
|
|
|
.append(settings_toggle);
|
2017-08-08 02:56:36 +02:00
|
|
|
}));
|
2014-03-14 15:30:29 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
|
|
|
|
}());
|
2016-12-04 08:59:56 +01:00
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = click_handlers;
|
|
|
|
}
|