2013-01-30 21:49:56 +01:00
|
|
|
var notifications_bar = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
2013-01-31 21:09:23 +01:00
|
|
|
var disabled = false; // true when the bar should be hidden (eg, it's blocking the composebox)
|
|
|
|
var displayed = false; // true when the bar is supposedly displayed (ignoring disabled-ness)
|
|
|
|
var bar_selector = "#notifications-bar"; // the selector jQuery can use to pick the notifications bar
|
|
|
|
var area_selector = "#notifications-area"; // the selector jQuery can use to pick the container
|
2013-01-30 21:49:56 +01:00
|
|
|
|
2013-06-03 17:45:41 +02:00
|
|
|
function show() {
|
2013-08-01 17:47:48 +02:00
|
|
|
if (disabled) {
|
2013-01-31 21:09:23 +01:00
|
|
|
return; // we should never show the bar when disabled
|
2013-08-01 17:47:48 +02:00
|
|
|
}
|
2013-01-31 21:09:23 +01:00
|
|
|
|
2013-06-03 17:45:41 +02:00
|
|
|
if (!displayed) {
|
2013-01-31 21:09:23 +01:00
|
|
|
// If the bar wasn't already displayed, simply show it
|
2013-06-03 17:45:41 +02:00
|
|
|
$(bar_selector).text("More messages below").slideDown(50);
|
2013-01-31 21:09:23 +01:00
|
|
|
displayed = true; // we need to set this flag
|
|
|
|
}
|
2013-01-30 21:49:56 +01:00
|
|
|
}
|
|
|
|
|
2013-01-31 21:09:23 +01:00
|
|
|
// Hide the notifications bar
|
2013-01-30 21:49:56 +01:00
|
|
|
function hide() {
|
2013-08-01 17:47:48 +02:00
|
|
|
if (!displayed) {
|
2013-01-31 21:09:23 +01:00
|
|
|
return; // don't unnecessarily add to the element's fx queue
|
2013-08-01 17:47:48 +02:00
|
|
|
}
|
2013-01-31 21:09:23 +01:00
|
|
|
displayed = false;
|
|
|
|
$(bar_selector).slideUp(50);
|
2013-01-30 21:49:56 +01:00
|
|
|
}
|
|
|
|
|
2013-01-31 21:09:23 +01:00
|
|
|
// If there's a custom message, or if the last message is off the bottom of the
|
|
|
|
// screen, then show the notifications bar.
|
Clean up code for unread counts and notifications.
The core simplification here is that zephyr.js no longer has:
* the global home_unread_messages
* the function unread_in_current_view() [which used the global]
The logic that used to be in zephyr is now in its proper home
of unread.js, which has these changes:
* the structure returned from unread.get_counts() includes
a new member called unread_in_current_view
* there's a helper function unread.num_unread_current_messages()
Deprecating zephyr.unread_in_current_view() affected two callers:
* notifications.update_title_count()
* notifications_bar.update()
The above functions used to call back to zephyr to get counts, but
there was no nice way to enforce that they were getting counts
at the right time in the code flow, because they depended on
functions like process_visible_unread_messages() to orchestrate
updating internal unread counts before pushing out counts to the DOM.
Now both of those function take a parameter with the unread count,
and we then had to change all of their callers appropriately. This
went hand in hand with another goal, which is that we want all the
unread-counts logic to funnel though basically one place, which
is zephyr.update_unread_counts(). So now that function always
calls notifications_bar.update() [NEW] as well as calling into
the modules unread.js, stream_list.js, and notifications.js [OLD].
Adding the call to notifications_bar.update() in update_unread_counts()
made it so that some other places in the code no longer needed to call
notifications_bar.update(), so you'll see some lines of code
removed. There are also cases where notifications.update_title_count()
was called redundantly, since the callers were already reaching
update_unread_counts() via other calls.
Finally, in ui.resizehandler, you'll see a simple case where the call
to notifications_bar.update() is preceded by an explicit call
to unread.get_counts().
(imported from commit ce84b9c8076c1f9bb20a61209913f0cb0dae098c)
2013-06-05 21:04:06 +02:00
|
|
|
exports.update = function (num_unread) {
|
2013-06-06 23:52:02 +02:00
|
|
|
var last_row = rows.last_visible();
|
|
|
|
if (last_row
|
|
|
|
&& last_row.offset() !== null // otherwise the next line will error
|
|
|
|
&& viewport.is_below_visible_bottom(last_row.offset().top + last_row.height())
|
2013-08-01 17:47:48 +02:00
|
|
|
&& num_unread > 0) {
|
2013-06-03 17:45:41 +02:00
|
|
|
show();
|
2013-08-01 17:47:48 +02:00
|
|
|
} else {
|
2013-01-30 21:49:56 +01:00
|
|
|
hide();
|
2013-08-01 17:47:48 +02:00
|
|
|
}
|
2013-01-30 21:49:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// We disable the notifications bar if it overlaps with the composebox
|
2013-07-05 17:43:56 +02:00
|
|
|
exports.maybe_disable = function () {
|
2013-01-31 21:09:23 +01:00
|
|
|
if ($("#compose").offset().left + $("#compose").width() > $(area_selector).offset().left) {
|
2013-01-30 21:49:56 +01:00
|
|
|
disabled = true;
|
2013-01-31 21:09:23 +01:00
|
|
|
hide();
|
2013-01-30 21:49:56 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-31 21:09:23 +01:00
|
|
|
// Un-disable the notifications bar, then call the update function to see if it should be displayed
|
2013-07-05 17:43:56 +02:00
|
|
|
exports.enable = function () {
|
2013-01-30 21:49:56 +01:00
|
|
|
disabled = false;
|
|
|
|
exports.update();
|
|
|
|
};
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
}());
|