2013-07-08 23:33:47 +02:00
|
|
|
var tab_bar = (function () {
|
2013-05-09 21:12:53 +02:00
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
function make_tab(title, hash, data, extra_class) {
|
|
|
|
return {active: "inactive",
|
|
|
|
cls: extra_class || "",
|
|
|
|
title: title,
|
|
|
|
hash: hash,
|
|
|
|
data: data};
|
|
|
|
}
|
|
|
|
|
|
|
|
function make_tab_data() {
|
|
|
|
var tabs = [];
|
|
|
|
|
|
|
|
if (narrow.active() && narrow.operators().length > 0) {
|
2013-06-13 20:29:58 +02:00
|
|
|
var stream, ops = narrow.operators();
|
|
|
|
var filter = narrow.filter();
|
2013-05-09 21:12:53 +02:00
|
|
|
var hash = hashchange.operators_to_hash(ops);
|
|
|
|
|
|
|
|
// Root breadcrumb item: Either Home or All Messages
|
2013-06-13 20:29:58 +02:00
|
|
|
if ((filter.has_operator("stream") &&
|
|
|
|
!subs.in_home_view(filter.operands("stream")[0])) ||
|
|
|
|
filter.has_operand("in", "all")) {
|
2013-05-09 21:12:53 +02:00
|
|
|
tabs.push(make_tab("All Messages", "#narrow/in/all", undefined, "root"));
|
|
|
|
} else {
|
|
|
|
tabs.push(make_tab("Home", "#", "home", "root"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-05-09 21:12:53 +02:00
|
|
|
var names = $.map(emails, function (email) {
|
2013-05-23 16:15:58 +02:00
|
|
|
if (! people_dict[email]) {
|
|
|
|
return email;
|
|
|
|
}
|
2013-05-09 21:12:53 +02:00
|
|
|
return people_dict[email].full_name;
|
|
|
|
});
|
|
|
|
|
|
|
|
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-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];
|
|
|
|
if (people_dict[sender]) {
|
|
|
|
sender = people_dict[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") &&
|
|
|
|
filter.has_operator("subject")) {
|
|
|
|
stream = filter.operands("stream")[0];
|
|
|
|
var subject = filter.operands("subject")[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
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Just the home view
|
|
|
|
tabs.push(make_tab("Home", '#', "home", "root"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Last tab is not a link
|
|
|
|
tabs[tabs.length - 1].hash = false;
|
|
|
|
|
|
|
|
return tabs;
|
|
|
|
}
|
|
|
|
|
2013-07-08 23:33:47 +02:00
|
|
|
exports.colorize_tab_bar = function () {
|
2013-05-09 21:12:53 +02:00
|
|
|
// The stream tab, if it exists, should be the same color as that stream's chosen color
|
|
|
|
// Likewise, the border and outline should be the stream color as well
|
|
|
|
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
|
|
|
|
2013-05-09 21:12:53 +02:00
|
|
|
var stream_color = subs.get_color(stream_name);
|
|
|
|
|
|
|
|
if (!stream_tab.hasClass('active')) {
|
2013-07-04 22:55:26 +02:00
|
|
|
stream_tab.css('border-color', stream_color);
|
2013-05-09 21:12:53 +02:00
|
|
|
}
|
|
|
|
|
2013-07-05 23:18:08 +02:00
|
|
|
$('#tab_list li.active').css('border-color', stream_color);
|
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();
|
|
|
|
|
|
|
|
// Insert the narrow spacer between each tab
|
|
|
|
if (tabs.length > 1) {
|
|
|
|
var idx = -1;
|
|
|
|
while (Math.abs(idx) < tabs.length) {
|
|
|
|
tabs.splice(idx, 0, {cls: "narrow_spacer", icon: true});
|
|
|
|
idx -= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 () {
|
|
|
|
$(document).on('narrow_activated.zephyr', function (event) {
|
|
|
|
build_tab_bar();
|
|
|
|
});
|
|
|
|
$(document).on('narrow_deactivated.zephyr', function (event) {
|
|
|
|
build_tab_bar();
|
|
|
|
});
|
|
|
|
|
|
|
|
build_tab_bar();
|
|
|
|
});
|
|
|
|
|
2013-07-08 23:33:47 +02:00
|
|
|
return exports;
|
|
|
|
|
2013-05-09 21:12:53 +02:00
|
|
|
}());
|