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-12-08 01:26:43 +01:00
|
|
|
* javelin-uri
|
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;
|
2013-01-29 02:34:59 +01:00
|
|
|
var dirty = true;
|
2012-06-11 18:37:06 +02:00
|
|
|
|
2012-06-12 02:49:32 +02:00
|
|
|
function refresh() {
|
2013-01-29 02:34:59 +01:00
|
|
|
if (dirty) {
|
|
|
|
JX.DOM.setContent(dropdown, config.loadingText);
|
|
|
|
JX.DOM.alterClass(
|
|
|
|
dropdown,
|
|
|
|
'phabricator-notification-menu-loading',
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
2012-06-12 02:49:32 +02:00
|
|
|
if (request) { //already fetching
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
request = new JX.Request('/notification/panel/', function(response) {
|
2013-05-19 02:04:22 +02:00
|
|
|
var display = (response.number > 999) ? "\u221E" : response.number;
|
2012-11-27 23:03:25 +01:00
|
|
|
|
|
|
|
JX.DOM.setContent(count, display);
|
2013-05-19 02:04:22 +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
|
|
|
}
|
2013-01-29 02:34:59 +01:00
|
|
|
dirty = false;
|
|
|
|
JX.DOM.alterClass(
|
|
|
|
dropdown,
|
|
|
|
'phabricator-notification-menu-loading',
|
|
|
|
false);
|
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-12-08 01:26:43 +01:00
|
|
|
if (!e.getNode('phabricator-notification-menu')) {
|
|
|
|
// Click outside the dropdown; hide it.
|
|
|
|
JX.DOM.hide(dropdown);
|
|
|
|
visible = false;
|
2012-06-11 18:37:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-08 01:26:43 +01:00
|
|
|
if (e.getNode('tag:a')) {
|
|
|
|
// User clicked a link, just follow the link.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the user clicked a notification (but missed a link) and it has a
|
|
|
|
// primary URI, go there.
|
|
|
|
var href = e.getNodeData('notification').href;
|
|
|
|
if (href) {
|
|
|
|
JX.$U(href).go();
|
|
|
|
e.kill();
|
|
|
|
}
|
2012-06-11 18:37:06 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
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 {
|
2013-01-29 02:34:59 +01:00
|
|
|
if (dirty) {
|
|
|
|
refresh();
|
|
|
|
}
|
2012-11-27 23:03:25 +01:00
|
|
|
|
|
|
|
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
|
|
|
}
|
2013-05-19 02:04:22 +02:00
|
|
|
);
|
2012-06-11 18:37:06 +02:00
|
|
|
|
2013-01-29 02:34:59 +01:00
|
|
|
JX.Stratcom.listen('notification-panel-update', null, function() {
|
|
|
|
dirty = true;
|
|
|
|
refresh();
|
|
|
|
});
|
2012-06-11 18:37:06 +02:00
|
|
|
});
|