Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

functions.web.js 3.7KB

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