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-01-31 21:09:23 +01:00
|
|
|
if (disabled)
|
|
|
|
return; // we should never show the bar when disabled
|
|
|
|
|
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-01-31 21:09:23 +01:00
|
|
|
if (!displayed)
|
|
|
|
return; // don't unnecessarily add to the element's fx queue
|
|
|
|
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-03 17:45:41 +02:00
|
|
|
if (rows.last_visible().offset() !== null // otherwise the next line will error
|
2013-05-03 22:16:52 +02:00
|
|
|
&& rows.last_visible().offset().top + rows.last_visible().height() > viewport.scrollTop() + viewport.height() - $("#compose").height()
|
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
|
|
|
&& num_unread > 0)
|
2013-06-03 17:45:41 +02:00
|
|
|
show();
|
2013-01-30 21:49:56 +01:00
|
|
|
else
|
|
|
|
hide();
|
|
|
|
};
|
|
|
|
|
|
|
|
// We disable the notifications bar if it overlaps with the composebox
|
|
|
|
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-01-30 21:49:56 +01:00
|
|
|
exports.enable = function() {
|
|
|
|
disabled = false;
|
|
|
|
exports.update();
|
|
|
|
};
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
}());
|