2012-11-16 16:45:39 +01:00
|
|
|
var ui = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
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-10-14 23:14:45 +02:00
|
|
|
if ($(this).is("img")) {
|
|
|
|
return $(this).attr("alt");
|
|
|
|
}
|
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');
|
|
|
|
};
|
|
|
|
|
2018-03-12 03:01:11 +01:00
|
|
|
exports.destroy_scrollbar = function (element) {
|
|
|
|
element.perfectScrollbar('destroy');
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2017-12-16 13:33:54 +01:00
|
|
|
exports.update_starred = function (message) {
|
|
|
|
var starred = message.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.
|
2017-12-16 13:33:54 +01:00
|
|
|
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-12-24 06:13:36 +01:00
|
|
|
function adjust_mac_shortcuts() {
|
2018-01-25 01:15:26 +01:00
|
|
|
var keys_map = [
|
2017-12-24 06:13:36 +01:00
|
|
|
['Backspace', 'Delete'],
|
|
|
|
['Enter', 'Return'],
|
|
|
|
['Home', 'Fn + Left'],
|
|
|
|
['End', 'Fn + Right'],
|
|
|
|
['PgUp', 'Fn + Up'],
|
|
|
|
['PgDn', 'Fn + Down'],
|
2018-01-25 01:15:26 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
$(".hotkeys_table").each(function () {
|
|
|
|
var html = $(this).html();
|
|
|
|
keys_map.forEach(function (pair) {
|
|
|
|
html = html.replace(new RegExp(pair[0]), pair[1]);
|
|
|
|
});
|
|
|
|
$(this).html(html);
|
2017-12-24 06:13:36 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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-12-24 06:13:36 +01:00
|
|
|
|
|
|
|
if (/Mac/i.test(navigator.userAgent)) {
|
|
|
|
adjust_mac_shortcuts();
|
|
|
|
}
|
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-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-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-11-26 20:37:44 +01:00
|
|
|
$('#compose-textarea').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 () {
|
2017-11-26 20:37:44 +01:00
|
|
|
$('#compose-textarea')
|
2013-02-18 08:16:57 +01:00
|
|
|
.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.
|
2017-11-26 20:37:44 +01:00
|
|
|
$("#compose-textarea").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-11-30 02:31:21 +01:00
|
|
|
|
|
|
|
if (page_params.night_mode) {
|
|
|
|
night_mode.enable();
|
|
|
|
}
|
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;
|
|
|
|
}
|