Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

middleware.web.ts 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { AnyAction } from 'redux';
  2. import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
  3. import {
  4. CLEAR_TOOLBOX_TIMEOUT,
  5. SET_FULL_SCREEN,
  6. SET_TOOLBOX_TIMEOUT
  7. } from './actionTypes';
  8. import './subscriber';
  9. /**
  10. * Middleware which intercepts Toolbox actions to handle changes to the
  11. * visibility timeout of the Toolbox.
  12. *
  13. * @param {Store} store - The redux store.
  14. * @returns {Function}
  15. */
  16. MiddlewareRegistry.register(store => next => action => {
  17. switch (action.type) {
  18. case CLEAR_TOOLBOX_TIMEOUT: {
  19. const { timeoutID } = store.getState()['features/toolbox'];
  20. clearTimeout(timeoutID ?? undefined);
  21. break;
  22. }
  23. case SET_FULL_SCREEN:
  24. return _setFullScreen(next, action);
  25. case SET_TOOLBOX_TIMEOUT: {
  26. const { timeoutID } = store.getState()['features/toolbox'];
  27. const { handler, timeoutMS }: { handler: Function; timeoutMS: number; } = action;
  28. clearTimeout(timeoutID ?? undefined);
  29. action.timeoutID = setTimeout(handler, timeoutMS);
  30. break;
  31. }
  32. }
  33. return next(action);
  34. });
  35. type DocumentElement = {
  36. mozRequestFullScreen?: Function;
  37. requestFullscreen?: Function;
  38. webkitRequestFullscreen?: Function;
  39. };
  40. /**
  41. * Makes an external request to enter or exit full screen mode.
  42. *
  43. * @param {Dispatch} next - The redux dispatch function to dispatch the
  44. * specified action to the specified store.
  45. * @param {Action} action - The redux action SET_FULL_SCREEN which is being
  46. * dispatched in the specified store.
  47. * @private
  48. * @returns {Object} The value returned by {@code next(action)}.
  49. */
  50. function _setFullScreen(next: Function, action: AnyAction) {
  51. const result = next(action);
  52. if (typeof APP === 'object') {
  53. const { fullScreen } = action;
  54. if (fullScreen) {
  55. const documentElement: DocumentElement
  56. = document.documentElement || {};
  57. if (typeof documentElement.requestFullscreen === 'function') {
  58. documentElement.requestFullscreen();
  59. } else if (
  60. typeof documentElement.mozRequestFullScreen === 'function') {
  61. documentElement.mozRequestFullScreen();
  62. } else if (
  63. typeof documentElement.webkitRequestFullscreen === 'function') {
  64. documentElement.webkitRequestFullscreen();
  65. }
  66. return result;
  67. }
  68. if (typeof document.exitFullscreen === 'function') {
  69. document.exitFullscreen();
  70. } else if (typeof document.mozCancelFullScreen === 'function') {
  71. document.mozCancelFullScreen();
  72. } else if (typeof document.webkitExitFullscreen === 'function') {
  73. document.webkitExitFullscreen();
  74. }
  75. }
  76. return result;
  77. }