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 = [];
|
2013-12-13 22:15:00 +01:00
|
|
|
var filter = narrow.filter();
|
|
|
|
|
|
|
|
// Root breadcrumb item: Either Home or All Messages
|
|
|
|
if (filter !== undefined &&
|
|
|
|
((filter.has_operator("stream") &&
|
|
|
|
!stream_data.in_home_view(filter.operands("stream")[0])) ||
|
|
|
|
filter.has_operand("in", "all"))) {
|
|
|
|
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
|
|
|
} else {
|
2014-01-08 16:12:22 +01:00
|
|
|
tabs.push(make_tab('Home', "#", "home", "root", true));
|
2013-12-13 22:15:00 +01:00
|
|
|
}
|
2013-05-09 21:12:53 +02:00
|
|
|
|
|
|
|
if (narrow.active() && narrow.operators().length > 0) {
|
2013-06-13 20:29:58 +02:00
|
|
|
var stream, ops = narrow.operators();
|
2013-05-09 21:12:53 +02:00
|
|
|
var hash = hashchange.operators_to_hash(ops);
|
|
|
|
// 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',
|
2013-07-04 22:55:26 +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) {
|
2014-01-30 22:42:19 +01: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));
|
|
|
|
}
|
|
|
|
|
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")) {
|
2013-06-13 20:29:58 +02:00
|
|
|
stream = filter.operands("stream")[0];
|
2013-07-16 22:52:02 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Last tab is not a link
|
2014-01-08 16:12:22 +01:00
|
|
|
tabs[tabs.length - 1].hash = null;
|
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(
|
|
|
|
colorspace.getLighterColor(
|
|
|
|
colorspace.getDecimalColor(color_for_stream), 0.2));
|
2014-01-08 16:12:22 +01:00
|
|
|
|
|
|
|
if (stream_tab.hasClass("stream")) {
|
2014-01-09 16:58:51 +01:00
|
|
|
stream_tab.css('border-left-color',
|
|
|
|
color_for_stream).css('background-color',
|
|
|
|
color_for_stream);
|
2014-01-08 16:12:22 +01:00
|
|
|
if (stream_tab.hasClass("inactive")) {
|
|
|
|
stream_tab.hover (
|
|
|
|
function () {
|
2014-01-09 16:58:51 +01:00
|
|
|
$(this).css('border-left-color',
|
|
|
|
stream_light).css('background-color',
|
|
|
|
stream_light);
|
2014-01-08 16:12:22 +01:00
|
|
|
}, function () {
|
2014-01-09 16:58:51 +01:00
|
|
|
$(this).css('border-left-color',
|
|
|
|
color_for_stream).css('background-color',
|
|
|
|
color_for_stream);
|
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');
|
|
|
|
}
|
|
|
|
|
|
|
|
$(function () {
|
2013-07-25 22:48:55 +02:00
|
|
|
$(document).on('narrow_activated.zulip', function (event) {
|
2013-05-09 21:12:53 +02:00
|
|
|
build_tab_bar();
|
|
|
|
});
|
2013-07-25 22:48:55 +02:00
|
|
|
$(document).on('narrow_deactivated.zulip', function (event) {
|
2013-05-09 21:12:53 +02:00
|
|
|
build_tab_bar();
|
|
|
|
});
|
|
|
|
|
|
|
|
build_tab_bar();
|
|
|
|
});
|
|
|
|
|
2013-07-08 23:33:47 +02:00
|
|
|
return exports;
|
|
|
|
|
2013-05-09 21:12:53 +02:00
|
|
|
}());
|