2013-07-08 23:33:47 +02:00
|
|
|
var tab_bar = (function () {
|
2013-05-09 21:12:53 +02:00
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
2014-01-08 16:12:22 +01:00
|
|
|
function make_tab(title, hash, data, extra_class, home) {
|
2013-05-09 21:12:53 +02:00
|
|
|
return {active: "inactive",
|
|
|
|
cls: extra_class || "",
|
|
|
|
title: title,
|
|
|
|
hash: hash,
|
2014-01-08 16:12:22 +01:00
|
|
|
data: data,
|
|
|
|
home: home || false };
|
2013-05-09 21:12:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function make_tab_data() {
|
|
|
|
var tabs = [];
|
2017-04-25 15:25:31 +02:00
|
|
|
var filter = narrow_state.filter();
|
2013-12-13 22:15:00 +01:00
|
|
|
|
2017-05-13 20:54:53 +02:00
|
|
|
function filtered_to_non_home_view_stream() {
|
|
|
|
if (!filter.has_operator('stream')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
var stream_name = filter.operands('stream')[0];
|
|
|
|
var stream_id = stream_data.get_stream_id(stream_name);
|
|
|
|
if (!stream_id) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !stream_data.in_home_view(stream_id);
|
|
|
|
}
|
|
|
|
|
2017-08-12 21:30:48 +02:00
|
|
|
function in_all() {
|
2018-06-06 18:19:09 +02:00
|
|
|
return filter !== undefined &&
|
2017-08-12 21:30:48 +02:00
|
|
|
(filtered_to_non_home_view_stream() ||
|
2018-06-06 18:19:09 +02:00
|
|
|
filter.has_operand("in", "all"));
|
2017-08-12 21:30:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (in_all()) {
|
2013-12-13 22:15:00 +01:00
|
|
|
tabs.push(make_tab("All Messages", "#narrow/in/all", undefined, "root"));
|
2013-12-13 23:12:13 +01:00
|
|
|
} else if (page_params.narrow !== undefined) {
|
|
|
|
tabs.push(make_tab("Stream " + page_params.narrow_stream,
|
2014-01-17 00:18:21 +01:00
|
|
|
hashchange.operators_to_hash([page_params.narrow[0]]),
|
2013-12-13 23:12:13 +01:00
|
|
|
page_params.narrow_stream, 'stream'));
|
2014-01-17 00:18:21 +01:00
|
|
|
if (page_params.narrow_topic !== undefined) {
|
|
|
|
tabs.push(make_tab("Topic " + page_params.narrow_topic,
|
|
|
|
hashchange.operators_to_hash(page_params.narrow),
|
|
|
|
null));
|
|
|
|
}
|
2013-12-13 22:15:00 +01:00
|
|
|
}
|
2013-05-09 21:12:53 +02:00
|
|
|
|
2017-04-25 15:25:31 +02:00
|
|
|
if (narrow_state.active() && narrow_state.operators().length > 0) {
|
2016-12-02 17:09:31 +01:00
|
|
|
var stream;
|
2017-04-25 15:25:31 +02:00
|
|
|
var ops = narrow_state.operators();
|
2013-05-09 21:12:53 +02:00
|
|
|
// Second breadcrumb item
|
|
|
|
var hashed = hashchange.operators_to_hash(ops.slice(0, 1));
|
2013-06-13 20:29:58 +02:00
|
|
|
if (filter.has_operator("stream")) {
|
|
|
|
stream = filter.operands("stream")[0];
|
|
|
|
tabs.push(make_tab(stream, hashed, stream, 'stream'));
|
|
|
|
} else if (filter.has_operator("pm-with") ||
|
2013-07-10 03:22:34 +02:00
|
|
|
filter.has_operand("is", "private")) {
|
2013-05-09 21:12:53 +02:00
|
|
|
|
2013-07-10 03:22:34 +02:00
|
|
|
tabs.push(make_tab("Private Messages", '#narrow/is/private',
|
2018-05-06 21:43:17 +02:00
|
|
|
undefined, 'private_message '));
|
2013-05-09 21:12:53 +02:00
|
|
|
|
2013-06-13 20:29:58 +02:00
|
|
|
if (filter.has_operator("pm-with")) {
|
|
|
|
var emails = filter.operands("pm-with")[0].split(',');
|
2013-07-29 23:35:36 +02:00
|
|
|
var names = _.map(emails, function (email) {
|
2018-06-04 21:09:11 +02:00
|
|
|
if (!people.get_by_email(email)) {
|
2013-05-23 16:15:58 +02:00
|
|
|
return email;
|
|
|
|
}
|
2014-01-30 22:42:19 +01:00
|
|
|
return people.get_by_email(email).full_name;
|
2013-05-09 21:12:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
tabs.push(make_tab(names.join(', '), hashed));
|
|
|
|
}
|
|
|
|
|
2017-06-04 01:51:53 +02:00
|
|
|
} else if (filter.has_operator("group-pm-with")) {
|
|
|
|
|
|
|
|
tabs.push(make_tab("Group Private", '#narrow/group-pm-with',
|
2018-05-06 21:43:17 +02:00
|
|
|
undefined, 'private_message '));
|
2017-06-04 01:51:53 +02:00
|
|
|
|
|
|
|
|
2013-06-13 20:29:58 +02:00
|
|
|
} else if (filter.has_operand("is", "starred")) {
|
2013-05-09 21:12:53 +02:00
|
|
|
tabs.push(make_tab("Starred", hashed));
|
2013-07-31 20:33:38 +02:00
|
|
|
} else if (filter.has_operator("near")) {
|
|
|
|
tabs.push(make_tab("Near " + filter.operands("near")[0], hashed));
|
2013-07-31 20:54:51 +02:00
|
|
|
} else if (filter.has_operator("id")) {
|
|
|
|
tabs.push(make_tab("ID " + filter.operands("id")[0], hashed));
|
2013-07-10 03:07:01 +02:00
|
|
|
} else if (filter.has_operand("is", "mentioned")) {
|
2013-05-29 00:33:03 +02:00
|
|
|
tabs.push(make_tab("Mentions", hashed));
|
2013-06-13 20:29:58 +02:00
|
|
|
} else if (filter.has_operator("sender")) {
|
|
|
|
var sender = filter.operands("sender")[0];
|
2014-01-30 22:42:19 +01:00
|
|
|
if (people.get_by_email(sender)) {
|
|
|
|
sender = people.get_by_email(sender).full_name;
|
2013-05-30 21:49:26 +02:00
|
|
|
}
|
2013-05-09 21:12:53 +02:00
|
|
|
tabs.push(make_tab("Sent by " + sender, hashed));
|
2013-06-13 20:29:58 +02:00
|
|
|
} else if (filter.has_operator("search")) {
|
2013-05-09 21:12:53 +02:00
|
|
|
// Search is not a clickable link, since we don't have
|
|
|
|
// a search narrow
|
2013-07-04 22:55:26 +02:00
|
|
|
tabs.push(make_tab("Search results", false));
|
2013-05-09 21:12:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Third breadcrumb item for stream-subject naarrows
|
2013-06-13 20:29:58 +02:00
|
|
|
if (filter.has_operator("stream") &&
|
2013-07-16 22:52:02 +02:00
|
|
|
filter.has_operator("topic")) {
|
|
|
|
var subject = filter.operands("topic")[0];
|
2013-05-09 21:12:53 +02:00
|
|
|
hashed = hashchange.operators_to_hash(ops.slice(0, 2));
|
|
|
|
|
2013-07-04 22:55:26 +02:00
|
|
|
tabs.push(make_tab(subject, hashed, null));
|
2013-05-09 21:12:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-12 22:13:58 +02:00
|
|
|
if (tabs.length === 0) {
|
2017-08-08 07:37:39 +02:00
|
|
|
tabs.push(make_tab('All messages', "#", "home", "root", true));
|
2017-08-12 22:13:58 +02:00
|
|
|
}
|
|
|
|
|
2013-05-09 21:12:53 +02:00
|
|
|
// Last tab is not a link
|
2014-01-08 16:12:22 +01:00
|
|
|
tabs[tabs.length - 1].hash = null;
|
2017-08-12 22:13:58 +02:00
|
|
|
|
2013-05-09 21:12:53 +02:00
|
|
|
return tabs;
|
|
|
|
}
|
|
|
|
|
2013-07-08 23:33:47 +02:00
|
|
|
exports.colorize_tab_bar = function () {
|
2013-05-09 21:12:53 +02:00
|
|
|
var stream_tab = $('#tab_list .stream');
|
|
|
|
if (stream_tab.length > 0) {
|
|
|
|
var stream_name = stream_tab.data('name');
|
2013-05-22 21:18:31 +02:00
|
|
|
if (stream_name === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
2013-06-06 16:55:43 +02:00
|
|
|
stream_name = stream_name.toString();
|
2013-05-22 21:18:31 +02:00
|
|
|
|
2014-01-08 16:12:22 +01:00
|
|
|
var color_for_stream = stream_data.get_color(stream_name);
|
|
|
|
var stream_dark = stream_color.get_color_class(color_for_stream);
|
2014-01-09 16:58:51 +01:00
|
|
|
var stream_light = colorspace.getHexColor(
|
2018-05-06 21:43:17 +02:00
|
|
|
colorspace.getLighterColor(
|
|
|
|
colorspace.getDecimalColor(color_for_stream), 0.2));
|
2014-01-08 16:12:22 +01:00
|
|
|
|
|
|
|
if (stream_tab.hasClass("stream")) {
|
2017-08-12 22:51:06 +02:00
|
|
|
stream_tab.css('background-color', color_for_stream);
|
2014-01-08 16:12:22 +01:00
|
|
|
if (stream_tab.hasClass("inactive")) {
|
2018-05-06 21:43:17 +02:00
|
|
|
stream_tab.hover (
|
|
|
|
function () {
|
|
|
|
$(this).css('background-color', stream_light);
|
|
|
|
}, function () {
|
|
|
|
$(this).css('background-color', color_for_stream);
|
|
|
|
}
|
|
|
|
);
|
2014-01-08 16:12:22 +01:00
|
|
|
}
|
2014-02-07 22:01:10 +01:00
|
|
|
stream_tab.removeClass(stream_color.color_classes);
|
2014-01-08 16:12:22 +01:00
|
|
|
stream_tab.addClass(stream_dark);
|
2013-05-09 21:12:53 +02:00
|
|
|
}
|
|
|
|
}
|
2013-07-08 23:33:47 +02:00
|
|
|
};
|
2013-05-09 21:12:53 +02:00
|
|
|
|
|
|
|
function build_tab_bar() {
|
|
|
|
var tabs = make_tab_data();
|
|
|
|
|
|
|
|
var tab_bar = $("#tab_bar");
|
|
|
|
tab_bar.empty();
|
|
|
|
|
|
|
|
tabs[tabs.length - 1].active = "active";
|
|
|
|
var rendered = templates.render('tab_bar', {tabs: tabs});
|
|
|
|
|
|
|
|
tab_bar.append(rendered);
|
2013-07-08 23:33:47 +02:00
|
|
|
exports.colorize_tab_bar();
|
2013-05-09 21:12:53 +02:00
|
|
|
tab_bar.removeClass('notdisplayed');
|
|
|
|
}
|
|
|
|
|
2018-05-15 22:03:14 +02:00
|
|
|
exports.initialize = function () {
|
2016-12-02 14:06:06 +01:00
|
|
|
$(document).on('narrow_activated.zulip', function () {
|
2013-05-09 21:12:53 +02:00
|
|
|
build_tab_bar();
|
|
|
|
});
|
2016-12-02 14:06:06 +01:00
|
|
|
$(document).on('narrow_deactivated.zulip', function () {
|
2013-05-09 21:12:53 +02:00
|
|
|
build_tab_bar();
|
|
|
|
});
|
|
|
|
|
|
|
|
build_tab_bar();
|
2018-05-15 22:03:14 +02:00
|
|
|
};
|
2013-05-09 21:12:53 +02:00
|
|
|
|
2013-07-08 23:33:47 +02:00
|
|
|
return exports;
|
|
|
|
|
2013-05-09 21:12:53 +02:00
|
|
|
}());
|
2016-12-04 08:59:56 +01:00
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = tab_bar;
|
|
|
|
}
|
2018-05-28 08:04:36 +02:00
|
|
|
window.tab_bar = tab_bar;
|