mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-23 15:22:41 +01:00
56d3197fe0
Summary: Ref T11179. Alternative to D16152. I think this turned out a bit better than the other one did. Currently, we render two copies of the menu (one for mobile, one for desktop). A big chunk of this is sharing the nodes instead: when you open the mobile dropdown menu, it steals the nodes from the document. When you close it, it puts them back. Magic! Sneaky! Test Plan: {F1695499} {F1695500} Reviewers: chad Reviewed By: chad Maniphest Tasks: T11179 Differential Revision: https://secure.phabricator.com/D16157
59 lines
1.2 KiB
JavaScript
59 lines
1.2 KiB
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();
|
|
|
|
JX.DOM.listen(list, 'click', 'tag:a', function(e) {
|
|
if (!e.isNormalClick()) {
|
|
return;
|
|
}
|
|
|
|
if (JX.Stratcom.pass()) {
|
|
return;
|
|
}
|
|
|
|
data.menu.close();
|
|
});
|
|
});
|
|
|
|
});
|