You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.web.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import SideContainerToggler
  2. from '../../../modules/UI/side_pannels/SideContainerToggler';
  3. import getDefaultButtons from './defaultToolbarButtons';
  4. declare var interfaceConfig: Object;
  5. export { abstractMapStateToProps, getButton } from './functions.native';
  6. /**
  7. * Returns an object which contains the default buttons for the primary and
  8. * secondary toolbars.
  9. *
  10. * @param {Object} buttonHandlers - Contains additional toolbox button
  11. * handlers.
  12. * @returns {Object}
  13. */
  14. export function getDefaultToolboxButtons(buttonHandlers: Object): Object {
  15. let toolbarButtons = {
  16. primaryToolbarButtons: new Map(),
  17. secondaryToolbarButtons: new Map()
  18. };
  19. if (typeof interfaceConfig !== 'undefined'
  20. && interfaceConfig.TOOLBAR_BUTTONS) {
  21. toolbarButtons
  22. = interfaceConfig.TOOLBAR_BUTTONS.reduce(
  23. (acc, buttonName) => {
  24. const buttons = getDefaultButtons();
  25. let button = buttons ? buttons[buttonName] : null;
  26. const currentButtonHandlers = buttonHandlers[buttonName];
  27. if (button) {
  28. const place = _getToolbarButtonPlace(buttonName);
  29. button.buttonName = buttonName;
  30. if (currentButtonHandlers) {
  31. button = {
  32. ...button,
  33. ...currentButtonHandlers
  34. };
  35. }
  36. // If isDisplayed method is not defined, display the
  37. // button only for non-filmstripOnly mode
  38. if (button.isDisplayed()) {
  39. acc[place].set(buttonName, button);
  40. }
  41. }
  42. return acc;
  43. },
  44. toolbarButtons);
  45. }
  46. return toolbarButtons;
  47. }
  48. /**
  49. * Returns toolbar class names to add while rendering.
  50. *
  51. * @param {Object} props - Props object pass to React component.
  52. * @returns {Object}
  53. * @private
  54. */
  55. export function getToolbarClassNames(props: Object) {
  56. const primaryToolbarClassNames = [
  57. interfaceConfig.filmStripOnly
  58. ? 'toolbar_filmstrip-only'
  59. : 'toolbar_primary'
  60. ];
  61. const secondaryToolbarClassNames = [ 'toolbar_secondary' ];
  62. if (props._visible) {
  63. const slideInAnimation
  64. = SideContainerToggler.isVisible ? 'slideInExtX' : 'slideInX';
  65. primaryToolbarClassNames.push('fadeIn');
  66. secondaryToolbarClassNames.push(slideInAnimation);
  67. } else {
  68. const slideOutAnimation
  69. = SideContainerToggler.isVisible ? 'slideOutExtX' : 'slideOutX';
  70. primaryToolbarClassNames.push('fadeOut');
  71. secondaryToolbarClassNames.push(slideOutAnimation);
  72. }
  73. return {
  74. primaryToolbarClassName: primaryToolbarClassNames.join(' '),
  75. secondaryToolbarClassName: secondaryToolbarClassNames.join(' ')
  76. };
  77. }
  78. /**
  79. * Indicates if a toolbar button is enabled.
  80. *
  81. * @param {string} name - The name of the setting section as defined in
  82. * interface_config.js.
  83. * @returns {boolean} - True to indicate that the given toolbar button
  84. * is enabled, false - otherwise.
  85. */
  86. export function isButtonEnabled(name) {
  87. return interfaceConfig.TOOLBAR_BUTTONS.indexOf(name) !== -1
  88. || interfaceConfig.MAIN_TOOLBAR_BUTTONS.indexOf(name) !== -1;
  89. }
  90. /**
  91. * Get place for toolbar button. Now it can be in the primary Toolbar or in the
  92. * secondary Toolbar.
  93. *
  94. * @param {string} btn - Button name.
  95. * @private
  96. * @returns {string}
  97. */
  98. function _getToolbarButtonPlace(btn) {
  99. return (
  100. interfaceConfig.MAIN_TOOLBAR_BUTTONS.includes(btn)
  101. ? 'primaryToolbarButtons'
  102. : 'secondaryToolbarButtons');
  103. }