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.
|
2013-01-30 21:49:56 +01:00
|
|
|
exports.update = function () {
|
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()
|
2013-03-19 21:53:49 +01:00
|
|
|
&& unread_in_current_view() > 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;
|
|
|
|
}());
|