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 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import SideContainerToggler
  2. from '../../../modules/UI/side_pannels/SideContainerToggler';
  3. import defaultToolbarButtons from './defaultToolbarButtons';
  4. declare var $: Function;
  5. declare var AJS: Object;
  6. declare var interfaceConfig: Object;
  7. export { abstractMapStateToProps } from './functions.native';
  8. /**
  9. * Returns an object which contains the default buttons for the primary and
  10. * secondary toolbars.
  11. *
  12. * @param {Object} buttonHandlers - Contains additional toolbox button
  13. * handlers.
  14. * @returns {Object}
  15. */
  16. export function getDefaultToolboxButtons(buttonHandlers: Object): Object {
  17. let toolbarButtons = {
  18. primaryToolbarButtons: new Map(),
  19. secondaryToolbarButtons: new Map()
  20. };
  21. if (typeof interfaceConfig !== 'undefined'
  22. && interfaceConfig.TOOLBAR_BUTTONS) {
  23. toolbarButtons
  24. = interfaceConfig.TOOLBAR_BUTTONS.reduce(
  25. (acc, buttonName) => {
  26. let button = defaultToolbarButtons[buttonName];
  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) {
  88. return interfaceConfig.TOOLBAR_BUTTONS.indexOf(name) !== -1
  89. || interfaceConfig.MAIN_TOOLBAR_BUTTONS.indexOf(name) !== -1;
  90. }
  91. /**
  92. * Show custom popup/tooltip for a specified button.
  93. *
  94. * @param {string} popupSelectorID - The selector id of the popup to show.
  95. * @param {boolean} show - True or false/show or hide the popup.
  96. * @param {number} timeout - The time to show the popup.
  97. * @returns {void}
  98. */
  99. export function showCustomToolbarPopup(
  100. popupSelectorID: string,
  101. show: boolean,
  102. timeout: number) {
  103. AJS.$(popupSelectorID).tooltip({
  104. gravity: $(popupSelectorID).attr('data-popup'),
  105. html: true,
  106. title: 'title',
  107. trigger: 'manual'
  108. });
  109. if (show) {
  110. AJS.$(popupSelectorID).tooltip('show');
  111. setTimeout(
  112. () => {
  113. // hide the tooltip
  114. AJS.$(popupSelectorID).tooltip('hide');
  115. },
  116. timeout);
  117. } else {
  118. AJS.$(popupSelectorID).tooltip('hide');
  119. }
  120. }
  121. /**
  122. * Get place for toolbar button. Now it can be in the primary Toolbar or in the
  123. * secondary Toolbar.
  124. *
  125. * @param {string} btn - Button name.
  126. * @private
  127. * @returns {string}
  128. */
  129. function _getToolbarButtonPlace(btn) {
  130. return (
  131. interfaceConfig.MAIN_TOOLBAR_BUTTONS.includes(btn)
  132. ? 'primaryToolbarButtons'
  133. : 'secondaryToolbarButtons');
  134. }