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
|
2014-01-29 05:19:20 +01:00
|
|
|
* javelin-behavior-device
|
2012-06-11 18:37:06 +02:00
|
|
|
*/
|
|
|
|
|
Allow only one global top menu to be open at a time
Summary: Fixes T3715. Makes "visible" global instead of per-menu, so all the menus share a visible state.
Test Plan: For menus A and B, clicked "A, A", "A, B, A", "A, B, B", "A, B, B, A", etc. Couldn't figure out a way to break it.
Reviewers: btrahan, chad
Reviewed By: chad
CC: aran
Maniphest Tasks: T3715
Differential Revision: https://secure.phabricator.com/D6745
2013-08-13 23:57:52 +02:00
|
|
|
JX.behavior('aphlict-dropdown', function(config, statics) {
|
|
|
|
// Track the current globally visible menu.
|
|
|
|
statics.visible = statics.visible || null;
|
|
|
|
|
2012-07-31 01:09:14 +02:00
|
|
|
var dropdown = JX.$(config.dropdownID);
|
2012-11-27 23:03:25 +01:00
|
|
|
var bubble = JX.$(config.bubbleID);
|
2014-01-29 05:19:20 +01:00
|
|
|
|
|
|
|
var count;
|
|
|
|
if (config.countID) {
|
|
|
|
count = JX.$(config.countID);
|
|
|
|
}
|
|
|
|
|
2012-06-12 02:49:32 +02:00
|
|
|
var request = null;
|
2014-01-29 05:19:20 +01:00
|
|
|
var dirty = config.local ? false : 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;
|
|
|
|
}
|
Allow only one global top menu to be open at a time
Summary: Fixes T3715. Makes "visible" global instead of per-menu, so all the menus share a visible state.
Test Plan: For menus A and B, clicked "A, A", "A, B, A", "A, B, B", "A, B, B, A", etc. Couldn't figure out a way to break it.
Reviewers: btrahan, chad
Reviewed By: chad
CC: aran
Maniphest Tasks: T3715
Differential Revision: https://secure.phabricator.com/D6745
2013-08-13 23:57:52 +02:00
|
|
|
|
2013-08-08 22:43:33 +02:00
|
|
|
request = new JX.Request(config.uri, function(response) {
|
2014-06-23 19:35:39 +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);
|
Allow only one global top menu to be open at a time
Summary: Fixes T3715. Makes "visible" global instead of per-menu, so all the menus share a visible state.
Test Plan: For menus A and B, clicked "A, A", "A, B, A", "A, B, B", "A, B, B, A", etc. Couldn't figure out a way to break it.
Reviewers: btrahan, chad
Reviewed By: chad
CC: aran
Maniphest Tasks: T3715
Differential Revision: https://secure.phabricator.com/D6745
2013-08-13 23:57:52 +02:00
|
|
|
statics.visible = null;
|
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;
|
|
|
|
}
|
|
|
|
|
2014-06-24 01:26:16 +02:00
|
|
|
if (!e.getNode('notification')) {
|
|
|
|
// User clicked somewhere in the dead area of the menu, like the header
|
|
|
|
// or footer.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-08 01:26:43 +01:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2014-01-29 05:19:20 +01:00
|
|
|
if (config.desktop && JX.Device.getDevice() != 'desktop') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Allow only one global top menu to be open at a time
Summary: Fixes T3715. Makes "visible" global instead of per-menu, so all the menus share a visible state.
Test Plan: For menus A and B, clicked "A, A", "A, B, A", "A, B, B", "A, B, B, A", etc. Couldn't figure out a way to break it.
Reviewers: btrahan, chad
Reviewed By: chad
CC: aran
Maniphest Tasks: T3715
Differential Revision: https://secure.phabricator.com/D6745
2013-08-13 23:57:52 +02:00
|
|
|
e.kill();
|
2012-11-27 23:03:25 +01:00
|
|
|
|
Allow only one global top menu to be open at a time
Summary: Fixes T3715. Makes "visible" global instead of per-menu, so all the menus share a visible state.
Test Plan: For menus A and B, clicked "A, A", "A, B, A", "A, B, B", "A, B, B, A", etc. Couldn't figure out a way to break it.
Reviewers: btrahan, chad
Reviewed By: chad
CC: aran
Maniphest Tasks: T3715
Differential Revision: https://secure.phabricator.com/D6745
2013-08-13 23:57:52 +02:00
|
|
|
// If a menu is currently open, close it.
|
|
|
|
if (statics.visible) {
|
|
|
|
var previously_visible = statics.visible;
|
|
|
|
JX.DOM.hide(statics.visible);
|
|
|
|
statics.visible = null;
|
2012-06-14 15:13:53 +02:00
|
|
|
|
Allow only one global top menu to be open at a time
Summary: Fixes T3715. Makes "visible" global instead of per-menu, so all the menus share a visible state.
Test Plan: For menus A and B, clicked "A, A", "A, B, A", "A, B, B", "A, B, B, A", etc. Couldn't figure out a way to break it.
Reviewers: btrahan, chad
Reviewed By: chad
CC: aran
Maniphest Tasks: T3715
Differential Revision: https://secure.phabricator.com/D6745
2013-08-13 23:57:52 +02:00
|
|
|
// If the menu we just closed was the menu attached to the clicked
|
|
|
|
// icon, we're all done -- clicking the icon for an open menu just
|
|
|
|
// closes it. Otherwise, we closed some other menu and still need to
|
|
|
|
// open the one the user just clicked.
|
|
|
|
if (previously_visible === dropdown) {
|
|
|
|
return;
|
|
|
|
}
|
2012-06-11 18:37:06 +02:00
|
|
|
}
|
Allow only one global top menu to be open at a time
Summary: Fixes T3715. Makes "visible" global instead of per-menu, so all the menus share a visible state.
Test Plan: For menus A and B, clicked "A, A", "A, B, A", "A, B, B", "A, B, B, A", etc. Couldn't figure out a way to break it.
Reviewers: btrahan, chad
Reviewed By: chad
CC: aran
Maniphest Tasks: T3715
Differential Revision: https://secure.phabricator.com/D6745
2013-08-13 23:57:52 +02:00
|
|
|
|
|
|
|
if (dirty) {
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
var p = JX.$V(bubble);
|
2014-01-29 05:19:20 +01:00
|
|
|
JX.DOM.show(dropdown);
|
|
|
|
|
Allow only one global top menu to be open at a time
Summary: Fixes T3715. Makes "visible" global instead of per-menu, so all the menus share a visible state.
Test Plan: For menus A and B, clicked "A, A", "A, B, A", "A, B, B", "A, B, B, A", etc. Couldn't figure out a way to break it.
Reviewers: btrahan, chad
Reviewed By: chad
CC: aran
Maniphest Tasks: T3715
Differential Revision: https://secure.phabricator.com/D6745
2013-08-13 23:57:52 +02:00
|
|
|
p.y = null;
|
2014-01-29 05:19:20 +01:00
|
|
|
if (config.right) {
|
|
|
|
p.x -= (JX.Vector.getDim(dropdown).x - JX.Vector.getDim(bubble).x);
|
|
|
|
} else {
|
|
|
|
p.x -= 6;
|
|
|
|
}
|
Allow only one global top menu to be open at a time
Summary: Fixes T3715. Makes "visible" global instead of per-menu, so all the menus share a visible state.
Test Plan: For menus A and B, clicked "A, A", "A, B, A", "A, B, B", "A, B, B, A", etc. Couldn't figure out a way to break it.
Reviewers: btrahan, chad
Reviewed By: chad
CC: aran
Maniphest Tasks: T3715
Differential Revision: https://secure.phabricator.com/D6745
2013-08-13 23:57:52 +02:00
|
|
|
p.setPos(dropdown);
|
|
|
|
|
|
|
|
statics.visible = dropdown;
|
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() {
|
2014-01-29 05:19:20 +01:00
|
|
|
if (config.local) {
|
|
|
|
return;
|
|
|
|
}
|
2013-01-29 02:34:59 +01:00
|
|
|
dirty = true;
|
|
|
|
refresh();
|
|
|
|
});
|
2012-06-11 18:37:06 +02:00
|
|
|
});
|