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 () {
|
|
|
|
|
|
|
|
// MOUSE MOVING DETECTION
|
|
|
|
var clicking = false;
|
|
|
|
var mouse_moved = false;
|
|
|
|
|
|
|
|
function mousedown() {
|
|
|
|
mouse_moved = false;
|
|
|
|
clicking = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function mousemove() {
|
|
|
|
if (clicking) {
|
|
|
|
mouse_moved = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#main_div").on("mousedown", ".messagebox", mousedown);
|
|
|
|
$("#main_div").on("mousemove", ".messagebox", mousemove);
|
|
|
|
|
|
|
|
// 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") ||
|
|
|
|
target.is("i.edit_content_button");
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#main_div").on("click", ".messagebox", function (e) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
if (!(clicking && mouse_moved)) {
|
|
|
|
// Was a click (not a click-and-drag).
|
|
|
|
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);
|
2016-06-29 00:27:50 +02:00
|
|
|
compose.respond_to_message({trigger: 'message click'});
|
2014-03-14 15:30:29 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
|
|
|
}
|
|
|
|
mouse_moved = false;
|
|
|
|
clicking = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
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();
|
|
|
|
var emoji_name = $(this).attr('data-emoji-name');
|
|
|
|
var message_id = $(this).parent().attr('data-message-id');
|
|
|
|
reactions.message_reaction_on_click(message_id, emoji_name);
|
|
|
|
});
|
|
|
|
|
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();
|
|
|
|
});
|
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-09 08:30:30 +01:00
|
|
|
stream_popover.topic_ops.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
|
|
|
|
|
|
|
|
// Capture both the left-sidebar Home click and the tab breadcrumb Home
|
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();
|
|
|
|
// 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-03-18 21:11:12 +01:00
|
|
|
if (ui_state.home_tab_obscured()) {
|
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-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});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// COMPOSE
|
|
|
|
|
|
|
|
// NB: This just binds to current elements, and won't bind to elements
|
|
|
|
// created after ready() is called.
|
|
|
|
$('#send-status .send-status-close').click(
|
|
|
|
function () { $('#send-status').stop(true).fadeOut(500); }
|
|
|
|
);
|
|
|
|
|
|
|
|
|
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) {
|
2015-10-15 22:34:30 +02:00
|
|
|
// Emoji clicks should be handled by their own click handler in popover.js
|
2016-11-17 00:04:30 +01:00
|
|
|
if ($(e.target).is("#emoji_map, .emoji_popover, .emoji_popover.inner, 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.preventDefault();
|
|
|
|
e.stopPropagation();
|
2017-02-21 18:13:32 +01:00
|
|
|
|
2017-03-09 00:20:22 +01:00
|
|
|
window.location.hash = "streams/all";
|
2017-01-12 00:03:20 +01:00
|
|
|
});
|
|
|
|
|
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
|
|
|
|
|
|
|
|
$('#right-sidebar, #top_navbar').on('click', '.webathena_login', function (e) {
|
|
|
|
$("#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",
|
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 () {
|
2014-03-14 15:30:29 +01:00
|
|
|
$("#zephyr-mirror-error").hide();
|
|
|
|
},
|
2016-12-02 14:06:06 +01:00
|
|
|
error: function () {
|
2014-03-14 15:30:29 +01:00
|
|
|
$("#zephyr-mirror-error").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
|
|
|
|
|
|
|
|
// BANKRUPTCY
|
|
|
|
|
2016-12-02 14:06:06 +01:00
|
|
|
$(".bankruptcy_button").click(function () {
|
2017-02-11 09:55:18 +01:00
|
|
|
unread_ui.enable();
|
2014-03-14 15:30:29 +01:00
|
|
|
});
|
|
|
|
|
2016-12-17 03:44:15 +01:00
|
|
|
(function () {
|
|
|
|
var map = {
|
2016-12-17 03:53:12 +01:00
|
|
|
".stream-description-editable": subs.change_stream_description,
|
2017-01-27 23:53:54 +01:00
|
|
|
".stream-name-editable": subs.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();
|
|
|
|
});
|
|
|
|
|
|
|
|
$(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.
|
|
|
|
if (this.hasChildNodes()) {
|
|
|
|
this.innerText = this.innerText;
|
|
|
|
place_caret_at_end(this);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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("");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}());
|
|
|
|
|
2016-12-02 14:06:06 +01:00
|
|
|
$('#yes-bankrupt').click(function () {
|
2016-04-12 17:38:47 +02:00
|
|
|
pointer.fast_forward_pointer();
|
2014-03-14 15:30:29 +01:00
|
|
|
$("#yes-bankrupt").hide();
|
|
|
|
$("#no-bankrupt").hide();
|
|
|
|
$(this).after($("<div>").addClass("alert alert-info settings_committed")
|
2017-03-01 05:36:51 +01:00
|
|
|
.text(i18n.t("Bringing you to your latest messages…")));
|
2014-03-14 15:30:29 +01:00
|
|
|
});
|
|
|
|
|
2016-09-22 02:05:24 +02:00
|
|
|
(function () {
|
|
|
|
$("#main_div").on("click", ".message_inline_image a", function (e) {
|
2017-03-18 21:01:16 +01:00
|
|
|
var $img = $(this).find("img");
|
2016-09-22 02:05:24 +02:00
|
|
|
|
|
|
|
// prevent the link from opening in a new page.
|
|
|
|
e.preventDefault();
|
|
|
|
// prevent the message compose dialog from happening.
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2017-03-18 21:01:16 +01:00
|
|
|
lightbox.show_from_inline_image($img);
|
2016-09-22 02:05:24 +02:00
|
|
|
});
|
|
|
|
|
2017-03-18 00:53:58 +01:00
|
|
|
$("#lightbox_overlay .download").click(function () {
|
2016-09-29 22:33:08 +02:00
|
|
|
this.blur();
|
|
|
|
});
|
2016-09-22 02:05:24 +02:00
|
|
|
}());
|
|
|
|
|
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
|
|
|
|
if ($('.popover-inner').has(e.target).length === 0) {
|
|
|
|
popovers.hide_all();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unfocus our compose area if we click out of it. Don't let exits out
|
|
|
|
// of modals or selecting text (for copy+paste) trigger cancelling.
|
2017-03-18 18:48:43 +01:00
|
|
|
if (compose_state.composing() && !$(e.target).is("a") &&
|
2014-03-14 15:30:29 +01:00
|
|
|
($(e.target).closest(".modal").length === 0) &&
|
2015-10-15 22:34:30 +02:00
|
|
|
window.getSelection().toString() === "" &&
|
|
|
|
($(e.target).closest('#emoji_map').length === 0)) {
|
2017-03-18 17:55:11 +01:00
|
|
|
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");
|
|
|
|
$this.addClass("active");
|
|
|
|
$this.prev().addClass("no-border");
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#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");
|
|
|
|
|
|
|
|
if ($this.hasClass("admin")) {
|
|
|
|
window.location.hash = "administration/" + section;
|
|
|
|
} else {
|
|
|
|
window.location.hash = "settings/" + section;
|
|
|
|
}
|
|
|
|
|
|
|
|
$(".settings-section, .settings-wrapper").removeClass("show");
|
|
|
|
$(".settings-section" + sel + ", .settings-wrapper" + sel).addClass("show");
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#settings_overlay_container").on("click", function (e) {
|
|
|
|
var $target = $(e.target);
|
|
|
|
if ($target.is(".exit-sign, .exit")) {
|
2017-03-13 19:42:10 +01:00
|
|
|
hashchange.exit_modal();
|
2016-12-03 01:12:52 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
(function () {
|
2017-02-21 19:10:50 +01:00
|
|
|
var settings_toggle = components.toggle({
|
|
|
|
name: "settings-toggle",
|
|
|
|
values: [
|
|
|
|
{ label: "Settings", key: "settings" },
|
|
|
|
{ label: "Administration", key: "administration" },
|
|
|
|
],
|
|
|
|
callback: function (name, key) {
|
|
|
|
$(".sidebar li").hide();
|
|
|
|
|
|
|
|
if (key === "administration") {
|
|
|
|
$("li.admin").show();
|
|
|
|
$("li[data-section='organization-settings']").click();
|
|
|
|
} else {
|
|
|
|
$("li:not(.admin)").show();
|
|
|
|
$("li[data-section='your-account']").click();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}).get();
|
|
|
|
|
|
|
|
$("#settings_overlay_container .tab-container")
|
|
|
|
.append(settings_toggle);
|
2016-12-03 01:12:52 +01: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;
|
|
|
|
}
|