mirror of https://github.com/zulip/zulip.git
click_handlers: Move and refactor is_clickable_message_element.
This commit is contained in:
parent
dd3767981d
commit
7f298147c0
|
@ -16,15 +16,6 @@ exports.initialize = function () {
|
||||||
|
|
||||||
// MESSAGE CLICKING
|
// 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") ||
|
|
||||||
// For spoilers, allow clicking either the header or elements within it
|
|
||||||
target.is(".spoiler-header") || target.parents(".spoiler-header").length > 0 ||
|
|
||||||
target.is(".highlight") && target.parent().is("a");
|
|
||||||
}
|
|
||||||
|
|
||||||
function initialize_long_tap() {
|
function initialize_long_tap() {
|
||||||
const MS_DELAY = 750;
|
const MS_DELAY = 750;
|
||||||
const meta = {
|
const meta = {
|
||||||
|
@ -77,6 +68,47 @@ exports.initialize = function () {
|
||||||
initialize_long_tap();
|
initialize_long_tap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function is_clickable_message_element(target) {
|
||||||
|
// This function defines all the elements within a message
|
||||||
|
// body that have UI behavior other than starting a reply.
|
||||||
|
if (target.is("a")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Forms for message editing contain input elements
|
||||||
|
if (target.is("textarea") || target.is("input")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Widget for adjusting the height of a message.
|
||||||
|
if (target.is("div.message_length_controller")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inline image and twitter previews.
|
||||||
|
if (target.is("img.message_inline_image") || target.is("img.twitter-avatar")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// UI elements for triggering message editing or viewing edit history.
|
||||||
|
if (target.is("i.edit_content_button") || target.is(".message_edit_notice")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For spoilers, allow clicking either the header or elements within it
|
||||||
|
if (target.is(".spoiler-header") || target.parents(".spoiler-header").length > 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Arguably this should just be the second condition, but this
|
||||||
|
// case is for when possible for a link is split by search highlight syntax.
|
||||||
|
if (target.is(".highlight") && target.parent().is("a")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const select_message_function = function (e) {
|
const select_message_function = function (e) {
|
||||||
if (is_clickable_message_element($(e.target))) {
|
if (is_clickable_message_element($(e.target))) {
|
||||||
// If this click came from a hyperlink, don't trigger the
|
// If this click came from a hyperlink, don't trigger the
|
||||||
|
@ -91,10 +123,6 @@ exports.initialize = function () {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($(e.target).is(".message_edit_notice")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (document.getSelection().type === "Range") {
|
if (document.getSelection().type === "Range") {
|
||||||
// Drags on the message (to copy message text) shouldn't trigger a reply.
|
// Drags on the message (to copy message text) shouldn't trigger a reply.
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue