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);
|
|
|
|
var indicator = JX.$(config.indicatorID);
|
|
|
|
var menu = JX.$(config.menuID);
|
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-06-12 14:45:23 +02:00
|
|
|
JX.DOM.setContent(indicator, response.number);
|
2012-06-12 02:49:32 +02:00
|
|
|
if (response.number == 0) {
|
2012-06-12 14:45:23 +02:00
|
|
|
JX.DOM.alterClass(indicator,
|
2012-07-31 01:09:14 +02:00
|
|
|
"phabricator-main-menu-alert-indicator-unread", false);
|
2012-06-12 02:49:32 +02:00
|
|
|
} else {
|
2012-06-12 14:45:23 +02:00
|
|
|
JX.DOM.alterClass(indicator,
|
2012-07-31 01:09:14 +02:00
|
|
|
"phabricator-main-menu-alert-indicator-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
|
|
|
|
2012-06-12 02:49:32 +02:00
|
|
|
refresh();
|
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-06-14 15:13:53 +02:00
|
|
|
menu,
|
2012-06-11 18:37:06 +02:00
|
|
|
'click',
|
|
|
|
null,
|
|
|
|
function(e) {
|
2012-06-14 15:13:53 +02:00
|
|
|
if (visible) {
|
2012-06-11 18:37:06 +02:00
|
|
|
JX.DOM.hide(dropdown);
|
|
|
|
} else {
|
2012-06-14 15:13:53 +02:00
|
|
|
var p = JX.$V(menu);
|
|
|
|
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
|
|
|
});
|