1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-15 11:22:40 +01:00
phorge-phorge/webroot/rsrc/js/phui/behavior-phui-profile-menu.js
epriestley 88e2929411 Fix "choose icon" on profile menu items
Summary:
Ref T10054. This fix is a little rough but the "right" fix involves a ton of rewriting to `AphrontSideNavFilterView` and I don't want to open that can of worms up yet.

Specifically, the problem is:

  - we build the menu in order to populate the mobile/application menu;
  - as a side effect of building the menu (not rendering the menu), we initialize the menu collapse/expand behavior;
  - but we never actually render the menu, so the `JX.$()` call fails.

The right fix would be to initialize the behavior only when we render the menu, but then `AphorntSideNavFilterView` would need to know about profile menu behaviors. It probably should some day, but I think today is not that day.

Test Plan: Set icons on a link on a profile menu.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10054

Differential Revision: https://secure.phabricator.com/D15073
2016-01-21 10:05:14 -08:00

39 lines
1.1 KiB
JavaScript

/**
* @provides javelin-behavior-phui-profile-menu
* @requires javelin-behavior
* javelin-stratcom
* javelin-dom
*/
JX.behavior('phui-profile-menu', function(config) {
// NOTE: This behavior is not initialized in the rendering pipeline for the
// menu, so it can get initialized when we build but do not render a menu
// (for example, when a page like the panel edit page only has items in
// the mobile/application menu, and does not show the profile menu). For now,
// just bail if we can't find the menu.
try {
var menu_node = JX.$(config.menuID);
} catch (ex) {
return;
}
var collapse_node = JX.$(config.collapseID);
var is_collapsed = config.isCollapsed;
JX.DOM.listen(collapse_node, 'click', null, function(e) {
is_collapsed = !is_collapsed;
JX.DOM.alterClass(menu_node, 'phui-profile-menu-collapsed', is_collapsed);
JX.DOM.alterClass(menu_node, 'phui-profile-menu-expanded', !is_collapsed);
if (config.settingsURI) {
new JX.Request(config.settingsURI)
.setData({value: (is_collapsed ? 1 : 0)})
.send();
}
e.kill();
});
});