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

functions.web.js 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. * @returns {Object}
  43. */
  44. export function getDefaultToolboxButtons(): Object {
  45. let toolbarButtons = {
  46. primaryToolbarButtons: new Map(),
  47. secondaryToolbarButtons: new Map()
  48. };
  49. if (typeof interfaceConfig !== 'undefined'
  50. && interfaceConfig.TOOLBAR_BUTTONS) {
  51. const { filmStripOnly } = interfaceConfig;
  52. toolbarButtons
  53. = interfaceConfig.TOOLBAR_BUTTONS.reduce(
  54. (acc, buttonName) => {
  55. const button = defaultToolbarButtons[buttonName];
  56. if (button) {
  57. const place = _getToolbarButtonPlace(buttonName);
  58. button.buttonName = buttonName;
  59. // In filmstrip-only mode we only add a button if it's
  60. // filmstrip-only enabled.
  61. if (!filmStripOnly || button.filmstripOnlyEnabled) {
  62. acc[place].set(buttonName, button);
  63. }
  64. }
  65. return acc;
  66. },
  67. toolbarButtons);
  68. }
  69. return toolbarButtons;
  70. }
  71. /**
  72. * Get place for toolbar button. Now it can be in the primary Toolbar or in the
  73. * secondary Toolbar.
  74. *
  75. * @param {string} btn - Button name.
  76. * @private
  77. * @returns {string}
  78. */
  79. function _getToolbarButtonPlace(btn) {
  80. return (
  81. interfaceConfig.MAIN_TOOLBAR_BUTTONS.includes(btn)
  82. ? 'primaryToolbarButtons'
  83. : 'secondaryToolbarButtons');
  84. }
  85. /**
  86. * Returns toolbar class names to add while rendering.
  87. *
  88. * @param {Object} props - Props object pass to React component.
  89. * @returns {Object}
  90. * @private
  91. */
  92. export function getToolbarClassNames(props: Object) {
  93. const primaryToolbarClassNames = [
  94. interfaceConfig.filmStripOnly
  95. ? 'toolbar_filmstrip-only'
  96. : 'toolbar_primary'
  97. ];
  98. const secondaryToolbarClassNames = [ 'toolbar_secondary' ];
  99. if (props._visible) {
  100. const slideInAnimation
  101. = SideContainerToggler.isVisible ? 'slideInExtX' : 'slideInX';
  102. primaryToolbarClassNames.push('fadeIn');
  103. secondaryToolbarClassNames.push(slideInAnimation);
  104. } else {
  105. const slideOutAnimation
  106. = SideContainerToggler.isVisible ? 'slideOutExtX' : 'slideOutX';
  107. primaryToolbarClassNames.push('fadeOut');
  108. secondaryToolbarClassNames.push(slideOutAnimation);
  109. }
  110. return {
  111. primaryToolbarClassName: primaryToolbarClassNames.join(' '),
  112. secondaryToolbarClassName: secondaryToolbarClassNames.join(' ')
  113. };
  114. }
  115. /**
  116. * Show custom popup/tooltip for a specified button.
  117. *
  118. * @param {string} popupSelectorID - The selector id of the popup to show.
  119. * @param {boolean} show - True or false/show or hide the popup.
  120. * @param {number} timeout - The time to show the popup.
  121. * @returns {void}
  122. */
  123. export function showCustomToolbarPopup(
  124. popupSelectorID: string,
  125. show: boolean,
  126. timeout: number) {
  127. AJS.$(popupSelectorID).tooltip({
  128. gravity: $(popupSelectorID).attr('data-popup'),
  129. html: true,
  130. title: 'title',
  131. trigger: 'manual'
  132. });
  133. if (show) {
  134. AJS.$(popupSelectorID).tooltip('show');
  135. setTimeout(
  136. () => {
  137. // hide the tooltip
  138. AJS.$(popupSelectorID).tooltip('hide');
  139. },
  140. timeout);
  141. } else {
  142. AJS.$(popupSelectorID).tooltip('hide');
  143. }
  144. }