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) {
|
2018-03-20 04:10:20 +01:00
|
|
|
var perfectScrollbar = new PerfectScrollbar(element[0], {
|
2017-08-02 16:06:38 +02:00
|
|
|
suppressScrollX: true,
|
|
|
|
useKeyboard: false,
|
|
|
|
wheelSpeed: 0.68,
|
2018-03-20 04:10:20 +01:00
|
|
|
scrollingThreshold: 50,
|
2018-04-02 19:33:48 +02:00
|
|
|
minScrollbarLength: 40,
|
2017-08-02 16:06:38 +02:00
|
|
|
});
|
2018-03-20 04:10:20 +01:00
|
|
|
element[0].perfectScrollbar = perfectScrollbar;
|
2017-08-02 16:06:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.update_scrollbar = function (element) {
|
|
|
|
element.scrollTop = 0;
|
2018-03-20 04:10:20 +01:00
|
|
|
if (element[0].perfectScrollbar !== undefined) {
|
|
|
|
element[0].perfectScrollbar.update();
|
|
|
|
}
|
2017-08-02 16:06:38 +02:00
|
|
|
};
|
|
|
|
|
2018-03-12 03:01:11 +01:00
|
|
|
exports.destroy_scrollbar = function (element) {
|
2018-03-20 04:10:20 +01:00
|
|
|
element[0].perfectScrollbar.destroy();
|
2018-03-12 03:01:11 +01:00
|
|
|
};
|
|
|
|
|
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
|
2018-05-16 00:55:28 +02:00
|
|
|
if (typeof(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);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-04-02 01:19:47 +02:00
|
|
|
var shown_deprecation_notices = [];
|
2018-02-08 15:17:26 +01:00
|
|
|
exports.maybe_show_deprecation_notice = function (key) {
|
|
|
|
var message;
|
|
|
|
if (key === 'C') {
|
|
|
|
message = i18n.t('We\'ve replaced the "C" hotkey with "x" to make this common shortcut easier to trigger.');
|
2018-06-02 15:48:15 +02:00
|
|
|
} else if (key === '*') {
|
|
|
|
message = i18n.t('We\'ve replaced the "*" hotkey with "Ctrl + s" to make this common shortcut easier to trigger.');
|
2018-02-08 15:17:26 +01:00
|
|
|
} else {
|
2018-04-02 01:19:47 +02:00
|
|
|
blueslip.error("Unexpected deprecation notice for hotkey:", key);
|
2018-02-08 15:17:26 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-02 01:19:47 +02:00
|
|
|
// Here we handle the tracking for showing deprecation notices,
|
|
|
|
// whether or not local storage is available.
|
|
|
|
if (localstorage.supported()) {
|
|
|
|
var notices_from_storage = JSON.parse(localStorage.getItem('shown_deprecation_notices'));
|
|
|
|
if (notices_from_storage !== null) {
|
|
|
|
shown_deprecation_notices = notices_from_storage;
|
|
|
|
} else {
|
|
|
|
shown_deprecation_notices = [];
|
|
|
|
}
|
2018-02-08 15:17:26 +01:00
|
|
|
}
|
2018-04-02 01:19:47 +02:00
|
|
|
|
2018-02-08 15:17:26 +01:00
|
|
|
if (shown_deprecation_notices.indexOf(key) === -1) {
|
|
|
|
$('#deprecation-notice-modal').modal('show');
|
|
|
|
$('#deprecation-notice-message').text(message);
|
|
|
|
shown_deprecation_notices.push(key);
|
2018-04-02 01:19:47 +02:00
|
|
|
if (localstorage.supported()) {
|
|
|
|
localStorage.setItem('shown_deprecation_notices', JSON.stringify(shown_deprecation_notices));
|
|
|
|
}
|
2018-02-08 15:17:26 +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-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;
|
|
|
|
|
2018-05-15 20:43:14 +02:00
|
|
|
exports.set_compose_textarea_handlers = 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");
|
|
|
|
});
|
2018-05-15 20:43:14 +02:00
|
|
|
};
|
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
|
|
|
|
2017-08-08 02:16:35 +02:00
|
|
|
exports.initialize = function () {
|
2018-05-15 20:43:14 +02:00
|
|
|
exports.set_compose_textarea_handlers();
|
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;
|
|
|
|
}
|