ui.toolbar.strategy.drop_down_menu.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * DevExtreme (ui/toolbar/ui.toolbar.strategy.drop_down_menu.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. var extend = require("../../core/utils/extend").extend;
  11. var ToolbarStrategy = require("./ui.toolbar.strategy");
  12. var ToolbarMenu = require("./ui.toolbar.menu");
  13. var DropDownMenu = require("../drop_down_menu");
  14. var MENU_INVISIBLE_CLASS = "dx-state-invisible";
  15. var DropDownMenuStrategy = ToolbarStrategy.inherit({
  16. NAME: "dropDownMenu",
  17. render: function() {
  18. if (!this._hasVisibleMenuItems()) {
  19. return
  20. }
  21. this._renderMenuButtonContainer();
  22. this._renderWidget()
  23. },
  24. renderMenuItems: function() {
  25. if (!this._menu) {
  26. this.render()
  27. }
  28. this.callBase();
  29. if (this._menu && !this._menu.option("items").length) {
  30. this._menu.close()
  31. }
  32. },
  33. _menuWidgetClass: function() {
  34. return DropDownMenu
  35. },
  36. _widgetOptions: function() {
  37. var that = this;
  38. return extend(this.callBase(), {
  39. deferRendering: true,
  40. container: that._toolbar.option("menuContainer"),
  41. menuWidget: ToolbarMenu,
  42. onOptionChanged: function(e) {
  43. if ("items" === e.name) {
  44. that._updateMenuVisibility(e.value)
  45. }
  46. },
  47. popupPosition: {
  48. at: "bottom right",
  49. my: "top right"
  50. }
  51. })
  52. },
  53. _updateMenuVisibility: function(menuItems) {
  54. var items = menuItems || this._getMenuItems();
  55. var isMenuVisible = items.length && this._hasVisibleMenuItems(items);
  56. this._toggleMenuVisibility(isMenuVisible)
  57. },
  58. _toggleMenuVisibility: function(value) {
  59. if (!this._menuContainer()) {
  60. return
  61. }
  62. this._menuContainer().toggleClass(MENU_INVISIBLE_CLASS, !value)
  63. },
  64. _menuContainer: function() {
  65. return this._$menuButtonContainer
  66. }
  67. });
  68. module.exports = DropDownMenuStrategy;