2012-06-11 18:37:06 +02:00
|
|
|
/**
|
|
|
|
* @provides javelin-behavior-aphlict-dropdown
|
|
|
|
* @requires javelin-behavior
|
|
|
|
* javelin-request
|
|
|
|
* javelin-stratcom
|
2012-06-14 15:13:53 +02:00
|
|
|
* javelin-vector
|
|
|
|
* javelin-dom
|
2012-06-11 18:37:06 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
JX.behavior('aphlict-dropdown', function(config) {
|
2012-07-31 01:09:14 +02:00
|
|
|
var dropdown = JX.$(config.dropdownID);
|
2012-11-27 23:03:25 +01:00
|
|
|
var count = JX.$(config.countID);
|
|
|
|
var bubble = JX.$(config.bubbleID);
|
2012-06-11 18:37:06 +02:00
|
|
|
var visible = false;
|
2012-06-12 02:49:32 +02:00
|
|
|
var request = null;
|
2012-06-11 18:37:06 +02:00
|
|
|
|
2012-06-12 02:49:32 +02:00
|
|
|
function refresh() {
|
|
|
|
if (request) { //already fetching
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
request = new JX.Request('/notification/panel/', function(response) {
|
2012-11-27 23:03:25 +01:00
|
|
|
var display = (response.number > 999)
|
|
|
|
? "\u221E"
|
|
|
|
: response.number;
|
|
|
|
|
|
|
|
JX.DOM.setContent(count, display);
|
2012-06-12 02:49:32 +02:00
|
|
|
if (response.number == 0) {
|
2012-11-27 23:03:25 +01:00
|
|
|
JX.DOM.alterClass(bubble, 'alert-unread', false);
|
2012-06-12 02:49:32 +02:00
|
|
|
} else {
|
2012-11-27 23:03:25 +01:00
|
|
|
JX.DOM.alterClass(bubble, 'alert-unread', true);
|
2012-06-12 02:49:32 +02:00
|
|
|
}
|
2012-06-11 18:37:06 +02:00
|
|
|
JX.DOM.setContent(dropdown, JX.$H(response.content));
|
2012-06-12 02:49:32 +02:00
|
|
|
request = null;
|
|
|
|
});
|
|
|
|
request.send();
|
|
|
|
}
|
2012-06-11 18:37:06 +02:00
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
|
|
|
'click',
|
|
|
|
null,
|
|
|
|
function(e) {
|
2012-07-31 01:09:14 +02:00
|
|
|
if(e.getNode('phabricator-notification-menu')) {
|
|
|
|
// Click is inside the dropdown.
|
2012-06-11 18:37:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
JX.DOM.hide(dropdown);
|
|
|
|
visible = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
JX.DOM.listen(
|
2012-11-27 23:03:25 +01:00
|
|
|
bubble,
|
2012-06-11 18:37:06 +02:00
|
|
|
'click',
|
|
|
|
null,
|
|
|
|
function(e) {
|
2012-11-27 23:03:25 +01:00
|
|
|
if (!e.isNormalClick()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-14 15:13:53 +02:00
|
|
|
if (visible) {
|
2012-06-11 18:37:06 +02:00
|
|
|
JX.DOM.hide(dropdown);
|
|
|
|
} else {
|
2012-11-27 23:03:25 +01:00
|
|
|
refresh();
|
|
|
|
|
|
|
|
var p = JX.$V(bubble);
|
2012-06-14 15:13:53 +02:00
|
|
|
p.y = null;
|
|
|
|
p.x -= 6;
|
|
|
|
p.setPos(dropdown);
|
|
|
|
|
2012-06-11 18:37:06 +02:00
|
|
|
JX.DOM.show(dropdown);
|
|
|
|
}
|
|
|
|
visible = !visible;
|
2012-06-14 15:13:53 +02:00
|
|
|
e.kill();
|
2012-06-11 18:37:06 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2012-06-12 02:49:32 +02:00
|
|
|
JX.Stratcom.listen('notification-panel-update', null, refresh);
|
2012-06-11 18:37:06 +02:00
|
|
|
});
|