Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

functions.web.js 4.1KB

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