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.8KB

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