1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 09:18:48 +02:00
phorge-phorge/webroot/rsrc/js/phui/behavior-phui-dropdown-menu.js
epriestley 45c3aaeb26 Attempt to make dropdown item actions more consistent
Summary:
See D17210. Currently, this handler needs to be installed on each menu that doesn't build with the default behavior.

Rather than copy-pasting it to the user menu, try to make it a default behavior. This adds a new rule: don't close the menu if the item is a dynamic item built in JS with PHUIXActionView.

This allows dynamic items to control the menu themselves, while giving static items the desired default behavior.

Test Plan:
  - Opened menus on: dashboards, user menu, timeline comments. Clicked stuff. Menus went away.
  - Other menus still seemed to work right: Diffusion, Favorites, mobile menu.

Reviewers: chad

Reviewed By: chad

Differential Revision: https://secure.phabricator.com/D17222
2017-01-18 13:14:54 -08:00

47 lines
1,019 B
JavaScript

/**
* @provides javelin-behavior-phui-dropdown-menu
* @requires javelin-behavior
* javelin-stratcom
* javelin-dom
* phuix-dropdown-menu
*/
JX.behavior('phui-dropdown-menu', function() {
JX.Stratcom.listen('click', 'phui-dropdown-menu', function(e) {
var data = e.getNodeData('phui-dropdown-menu');
if (data.menu) {
return;
}
e.kill();
var list;
var placeholder;
if (data.items) {
list = JX.$H(data.items).getFragment().firstChild;
} else {
list = JX.$(data.menuID);
placeholder = JX.$N('span');
}
var icon = e.getNode('phui-dropdown-menu');
data.menu = new JX.PHUIXDropdownMenu(icon);
data.menu.listen('open', function() {
if (placeholder) {
JX.DOM.replace(list, placeholder);
}
data.menu.setContent(list);
});
data.menu.listen('close', function() {
if (placeholder) {
JX.DOM.replace(placeholder, list);
}
});
data.menu.open();
});
});