2012-11-16 16:45:39 +01:00
|
|
|
var ui = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
2013-07-16 20:00:47 +02:00
|
|
|
var actively_scrolling = false;
|
|
|
|
|
|
|
|
exports.actively_scrolling = function () {
|
|
|
|
return actively_scrolling;
|
|
|
|
};
|
|
|
|
|
2012-12-03 20:54:29 +01:00
|
|
|
// What, if anything, obscures the home tab?
|
2012-11-30 18:28:23 +01:00
|
|
|
|
2013-07-23 00:25:25 +02:00
|
|
|
exports.replace_emoji_with_text = function (element) {
|
|
|
|
element.find(".emoji").replaceWith(function () {
|
2017-09-27 19:39:42 +02:00
|
|
|
return $(this).text();
|
2013-07-23 00:25:25 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-08-02 16:06:38 +02:00
|
|
|
exports.set_up_scrollbar = function (element) {
|
|
|
|
element.perfectScrollbar({
|
|
|
|
suppressScrollX: true,
|
|
|
|
useKeyboard: false,
|
|
|
|
wheelSpeed: 0.68,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.update_scrollbar = function (element) {
|
|
|
|
element.scrollTop = 0;
|
|
|
|
element.perfectScrollbar('update');
|
|
|
|
};
|
|
|
|
|
2013-12-19 17:03:08 +01:00
|
|
|
function update_message_in_all_views(message_id, callback) {
|
2016-04-25 23:45:25 +02:00
|
|
|
_.each([message_list.all, home_msg_list, message_list.narrowed], function (list) {
|
2013-12-19 17:03:08 +01:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-16 01:16:42 +02:00
|
|
|
exports.show_error_for_unsupported_platform = function () {
|
2017-09-20 14:14:37 +02:00
|
|
|
// Check if the user is using old desktop app
|
|
|
|
if (window.bridge !== undefined) {
|
2017-09-16 01:16:42 +02:00
|
|
|
// We don't internationalize this string because it is long,
|
|
|
|
// and few users will have both the old desktop app and an
|
|
|
|
// internationalized version of Zulip anyway.
|
|
|
|
var error = "Hello! You're using the unsupported old Zulip desktop app," +
|
|
|
|
" which is no longer developed. We recommend switching to the new, " +
|
|
|
|
"modern desktop app, which you can download at " +
|
|
|
|
"<a href='https://zulipchat.com/apps'>zulipchat.com/apps</a>.";
|
|
|
|
|
|
|
|
ui_report.generic_embed_error(error);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-03-14 15:30:29 +01:00
|
|
|
exports.find_message = function (message_id) {
|
2014-01-28 22:44:34 +01:00
|
|
|
// Try to find the message object. It might be in the narrow list
|
2016-04-21 22:49:23 +02:00
|
|
|
// (if it was loaded when narrowed), or only in the message_list.all
|
2014-01-28 22:44:34 +01:00
|
|
|
// (if received from the server while in a different narrow)
|
|
|
|
var message;
|
2016-04-25 23:45:25 +02:00
|
|
|
_.each([message_list.all, home_msg_list, message_list.narrowed], function (msg_list) {
|
2014-01-28 22:44:34 +01:00
|
|
|
if (msg_list !== undefined && message === undefined) {
|
|
|
|
message = msg_list.get(message_id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return message;
|
2014-03-14 15:30:29 +01:00
|
|
|
};
|
2014-01-28 22:44:34 +01:00
|
|
|
|
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-03-14 15:30:29 +01:00
|
|
|
var message = exports.find_message(message_id);
|
2013-12-19 17:03:08 +01:00
|
|
|
|
2017-01-23 05:38:57 +01:00
|
|
|
// If it isn't cached in the browser, no need to do anything
|
|
|
|
if (message === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-18 01:41:56 +01:00
|
|
|
unread_ops.mark_message_as_read(message);
|
2013-12-19 17:03:08 +01:00
|
|
|
|
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) {
|
2017-02-23 23:33:57 +01:00
|
|
|
var elt = row.find(".star");
|
2014-01-23 17:52:28 +01:00
|
|
|
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");
|
|
|
|
}
|
2017-06-29 08:35:33 +02:00
|
|
|
var title_state = starred ? i18n.t("Unstar") : i18n.t("Star");
|
|
|
|
elt.attr("title", i18n.t("__starred_status__ this message", {starred_status: title_state}));
|
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-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
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-05-14 21:14:26 +02:00
|
|
|
exports.remove_message = function (message_id) {
|
|
|
|
_.each([message_list.all, home_msg_list, message_list.narrowed], function (list) {
|
|
|
|
if (list === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var row = list.get_row(message_id);
|
|
|
|
if (row !== undefined) {
|
|
|
|
list.remove_and_rerender([{id: message_id}]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-08-08 02:16:35 +02:00
|
|
|
function _setup_info_overlay() {
|
2017-01-30 20:55:39 +01:00
|
|
|
var info_overlay_toggle = components.toggle({
|
|
|
|
name: "info-overlay-toggle",
|
|
|
|
selected: 0,
|
|
|
|
values: [
|
2017-06-23 21:56:08 +02:00
|
|
|
{ label: i18n.t("Keyboard shortcuts"), key: "keyboard-shortcuts" },
|
|
|
|
{ label: i18n.t("Message formatting"), key: "markdown-help" },
|
|
|
|
{ label: i18n.t("Search operators"), key: "search-operators" },
|
2017-01-30 20:55:39 +01:00
|
|
|
],
|
2017-01-30 21:55:06 +01:00
|
|
|
callback: function (name, key) {
|
|
|
|
$(".overlay-modal").hide();
|
|
|
|
$("#" + key).show();
|
2017-04-12 20:58:31 +02:00
|
|
|
$("#" + key).find(".modal-body").focus();
|
2017-01-30 21:55:06 +01:00
|
|
|
},
|
2017-01-30 20:55:39 +01:00
|
|
|
}).get();
|
|
|
|
|
|
|
|
$(".informational-overlays .overlay-tabs")
|
|
|
|
.append($(info_overlay_toggle).addClass("large"));
|
2017-08-08 02:16:35 +02:00
|
|
|
}
|
2017-01-30 20:55:39 +01:00
|
|
|
|
2017-01-05 21:11:45 +01:00
|
|
|
exports.show_info_overlay = function (target) {
|
2017-05-06 01:18:04 +02:00
|
|
|
var overlay = $(".informational-overlays");
|
2017-01-05 21:11:45 +01:00
|
|
|
|
2017-05-06 01:18:04 +02:00
|
|
|
if (!overlay.hasClass("show")) {
|
2017-05-27 15:40:54 +02:00
|
|
|
overlays.open_overlay({
|
2017-05-06 01:18:04 +02:00
|
|
|
name: 'informationalOverlays',
|
|
|
|
overlay: overlay,
|
2017-06-04 03:39:47 +02:00
|
|
|
on_close: function () {
|
|
|
|
hashchange.changehash("");
|
|
|
|
},
|
2017-05-06 01:18:04 +02:00
|
|
|
});
|
2017-01-05 21:11:45 +01:00
|
|
|
}
|
|
|
|
|
2017-01-30 21:55:06 +01:00
|
|
|
if (target) {
|
|
|
|
components.toggle.lookup("info-overlay-toggle").goto(target);
|
|
|
|
}
|
2017-01-05 21:11:45 +01:00
|
|
|
};
|
|
|
|
|
2017-06-15 16:11:17 +02:00
|
|
|
exports.maybe_show_keyboard_shortcuts = function () {
|
|
|
|
if (overlays.is_active()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (popovers.any_active()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ui.show_info_overlay("keyboard-shortcuts");
|
|
|
|
};
|
|
|
|
|
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) {
|
2014-03-13 15:03:01 +01:00
|
|
|
loading.make_indicator($('#loading_more_messages_indicator'),
|
2013-07-12 18:31:26 +02:00
|
|
|
{abs_positioned: true});
|
2013-01-16 19:50:18 +01:00
|
|
|
loading_more_messages_indicator_showing = true;
|
2014-03-13 21:14:33 +01:00
|
|
|
floating_recipient_bar.hide();
|
2012-11-28 22:17:57 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-16 19:50:18 +01:00
|
|
|
exports.hide_loading_more_messages_indicator = function () {
|
|
|
|
if (loading_more_messages_indicator_showing) {
|
2014-03-13 15:03:01 +01:00
|
|
|
loading.destroy_indicator($("#loading_more_messages_indicator"));
|
2013-01-16 19:50:18 +01:00
|
|
|
loading_more_messages_indicator_showing = false;
|
2012-11-28 22:17:57 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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 */
|
|
|
|
|
2013-08-02 23:41:40 +02:00
|
|
|
function scroll_finished() {
|
|
|
|
actively_scrolling = false;
|
|
|
|
|
|
|
|
if ($('#home').hasClass('active')) {
|
2016-04-12 17:38:47 +02:00
|
|
|
if (!pointer.suppress_scroll_pointer_update) {
|
2017-03-18 22:46:36 +01:00
|
|
|
message_viewport.keep_pointer_in_view();
|
2013-08-02 23:41:40 +02:00
|
|
|
} else {
|
2016-04-12 17:38:47 +02:00
|
|
|
pointer.suppress_scroll_pointer_update = false;
|
2013-08-02 23:41:40 +02:00
|
|
|
}
|
2014-03-13 21:14:33 +01:00
|
|
|
floating_recipient_bar.update();
|
2017-09-30 18:27:04 +02:00
|
|
|
if (message_viewport.scrollTop() === 0) {
|
2017-03-19 18:19:48 +01:00
|
|
|
message_fetch.load_more_messages(current_msg_list);
|
2013-08-02 23:41:40 +02:00
|
|
|
}
|
2017-09-30 18:27:04 +02:00
|
|
|
|
2013-08-02 23:41:40 +02:00
|
|
|
// When the window scrolls, it may cause some messages to
|
|
|
|
// enter the screen and become read. Calling
|
2017-03-18 01:41:56 +01:00
|
|
|
// unread_ops.process_visible will update necessary
|
2013-08-02 23:41:40 +02:00
|
|
|
// data structures and DOM elements.
|
2017-03-18 01:41:56 +01:00
|
|
|
setTimeout(unread_ops.process_visible, 0);
|
2013-08-02 23:41:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var scroll_timer;
|
|
|
|
function scroll_finish() {
|
|
|
|
actively_scrolling = true;
|
|
|
|
clearTimeout(scroll_timer);
|
|
|
|
scroll_timer = setTimeout(scroll_finished, 100);
|
|
|
|
}
|
|
|
|
|
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 () {
|
2017-03-10 23:48:51 +01:00
|
|
|
message_viewport.message_pane.scroll($.throttle(50, function () {
|
2017-03-18 01:41:56 +01:00
|
|
|
unread_ops.process_visible();
|
2014-01-31 00:00:33 +01:00
|
|
|
scroll_finish();
|
|
|
|
}));
|
|
|
|
|
2013-02-18 08:16:57 +01:00
|
|
|
$('#new_message_content').blur(function () {
|
2016-06-14 22:49:41 +02:00
|
|
|
saved_compose_cursor = $(this).caret();
|
2013-02-18 08:16:57 +01:00
|
|
|
});
|
2017-04-13 22:33:26 +02:00
|
|
|
|
|
|
|
// on the end of the modified-message fade in, remove the fade-in-message class.
|
|
|
|
var animationEnd = "webkitAnimationEnd oanimationend msAnimationEnd animationend";
|
|
|
|
$("body").on(animationEnd, ".fade-in-message", function () {
|
|
|
|
$(this).removeClass("fade-in-message");
|
|
|
|
});
|
2013-02-18 08:16:57 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
exports.restore_compose_cursor = function () {
|
|
|
|
$('#new_message_content')
|
|
|
|
.focus()
|
2016-06-14 22:49:41 +02:00
|
|
|
.caret(saved_compose_cursor);
|
2013-02-18 08:16:57 +01:00
|
|
|
};
|
2013-07-24 19:43:45 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-08-08 02:16:35 +02:00
|
|
|
exports.initialize = function () {
|
|
|
|
i18n.ensure_i18n(_setup_info_overlay);
|
2017-09-16 01:16:42 +02:00
|
|
|
exports.show_error_for_unsupported_platform();
|
2017-08-08 02:16:35 +02:00
|
|
|
};
|
|
|
|
|
2012-11-16 16:45:39 +01:00
|
|
|
return exports;
|
|
|
|
}());
|
2016-12-29 12:23:07 +01:00
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = ui;
|
|
|
|
}
|