您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

functions.web.js 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import SideContainerToggler
  2. from '../../../modules/UI/side_pannels/SideContainerToggler';
  3. import defaultToolbarButtons from './defaultToolbarButtons';
  4. type MapOfAttributes = { [key: string]: * };
  5. declare var $: Function;
  6. declare var AJS: Object;
  7. declare var interfaceConfig: Object;
  8. export { abstractMapStateToProps } from './functions.native';
  9. /* eslint-disable flowtype/space-before-type-colon */
  10. /**
  11. * Takes toolbar button props and maps them to HTML attributes to set.
  12. *
  13. * @param {Object} props - Props set to the React component.
  14. * @returns {MapOfAttributes}
  15. */
  16. export function getButtonAttributesByProps(props: Object = {})
  17. : MapOfAttributes {
  18. // XXX Make sure to not modify props.classNames because that'd be bad
  19. // practice.
  20. const classNames = (props.classNames && [ ...props.classNames ]) || [];
  21. props.toggled && classNames.push('toggled');
  22. props.unclickable && classNames.push('unclickable');
  23. const result: MapOfAttributes = {
  24. className: classNames.join(' '),
  25. 'data-container': 'body',
  26. 'data-placement': 'bottom',
  27. id: props.id
  28. };
  29. if (!props.enabled) {
  30. result.disabled = 'disabled';
  31. }
  32. if (props.hidden) {
  33. result.style = { display: 'none' };
  34. }
  35. return result;
  36. }
  37. /* eslint-enable flowtype/space-before-type-colon */
  38. /**
  39. * Returns an object which contains the default buttons for the primary and
  40. * secondary toolbars.
  41. *
  42. * @param {Object} buttonHandlers - Contains additional toolbox button
  43. * handlers.
  44. * @returns {Object}
  45. */
  46. export function getDefaultToolboxButtons(buttonHandlers: Object): Object {
  47. let toolbarButtons = {
  48. primaryToolbarButtons: new Map(),
  49. secondaryToolbarButtons: new Map()
  50. };
  51. if (typeof interfaceConfig !== 'undefined'
  52. && interfaceConfig.TOOLBAR_BUTTONS) {
  53. const { filmStripOnly } = interfaceConfig;
  54. toolbarButtons
  55. = interfaceConfig.TOOLBAR_BUTTONS.reduce(
  56. (acc, buttonName) => {
  57. let button = defaultToolbarButtons[buttonName];
  58. const currentButtonHandlers = buttonHandlers[buttonName];
  59. if (button) {
  60. const place = _getToolbarButtonPlace(buttonName);
  61. button.buttonName = buttonName;
  62. if (currentButtonHandlers) {
  63. button = {
  64. ...button,
  65. ...currentButtonHandlers
  66. };
  67. }
  68. // In filmstrip-only mode we only add a button if it's
  69. // filmstrip-only enabled.
  70. if (!filmStripOnly || button.filmstripOnlyEnabled) {
  71. acc[place].set(buttonName, button);
  72. }
  73. }
  74. return acc;
  75. },
  76. toolbarButtons);
  77. }
  78. return toolbarButtons;
  79. }
  80. /**
  81. * Returns toolbar class names to add while rendering.
  82. *
  83. * @param {Object} props - Props object pass to React component.
  84. * @returns {Object}
  85. * @private
  86. */
  87. export function getToolbarClassNames(props: Object) {
  88. const primaryToolbarClassNames = [
  89. interfaceConfig.filmStripOnly
  90. ? 'toolbar_filmstrip-only'
  91. : 'toolbar_primary'
  92. ];
  93. const secondaryToolbarClassNames = [ 'toolbar_secondary' ];
  94. if (props._visible) {
  95. const slideInAnimation
  96. = SideContainerToggler.isVisible ? 'slideInExtX' : 'slideInX';
  97. primaryToolbarClassNames.push('fadeIn');
  98. secondaryToolbarClassNames.push(slideInAnimation);
  99. } else {
  100. const slideOutAnimation
  101. = SideContainerToggler.isVisible ? 'slideOutExtX' : 'slideOutX';
  102. primaryToolbarClassNames.push('fadeOut');
  103. secondaryToolbarClassNames.push(slideOutAnimation);
  104. }
  105. return {
  106. primaryToolbarClassName: primaryToolbarClassNames.join(' '),
  107. secondaryToolbarClassName: secondaryToolbarClassNames.join(' ')
  108. };
  109. }
  110. /**
  111. * Show custom popup/tooltip for a specified button.
  112. *
  113. * @param {string} popupSelectorID - The selector id of the popup to show.
  114. * @param {boolean} show - True or false/show or hide the popup.
  115. * @param {number} timeout - The time to show the popup.
  116. * @returns {void}
  117. */
  118. export function showCustomToolbarPopup(
  119. popupSelectorID: string,
  120. show: boolean,
  121. timeout: number) {
  122. AJS.$(popupSelectorID).tooltip({
  123. gravity: $(popupSelectorID).attr('data-popup'),
  124. html: true,
  125. title: 'title',
  126. trigger: 'manual'
  127. });
  128. if (show) {
  129. AJS.$(popupSelectorID).tooltip('show');
  130. setTimeout(
  131. () => {
  132. // hide the tooltip
  133. AJS.$(popupSelectorID).tooltip('hide');
  134. },
  135. timeout);
  136. } else {
  137. AJS.$(popupSelectorID).tooltip('hide');
  138. }
  139. }
  140. /**
  141. * Get place for toolbar button. Now it can be in the primary Toolbar or in the
  142. * secondary Toolbar.
  143. *
  144. * @param {string} btn - Button name.
  145. * @private
  146. * @returns {string}
  147. */
  148. function _getToolbarButtonPlace(btn) {
  149. return (
  150. interfaceConfig.MAIN_TOOLBAR_BUTTONS.includes(btn)
  151. ? 'primaryToolbarButtons'
  152. : 'secondaryToolbarButtons');
  153. }