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.

middleware.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // @flow
  2. import { MiddlewareRegistry } from '../base/redux';
  3. import {
  4. CLEAR_TOOLBOX_TIMEOUT,
  5. SET_TOOLBOX_TIMEOUT,
  6. SET_FULL_SCREEN
  7. } from './actionTypes';
  8. declare var APP: Object;
  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);
  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 } = action;
  28. clearTimeout(timeoutID);
  29. action.timeoutID = setTimeout(handler, timeoutMS);
  30. break;
  31. }
  32. }
  33. return next(action);
  34. });
  35. /**
  36. * Makes an external request to enter or exit full screen mode.
  37. *
  38. * @param {Dispatch} next - The redux dispatch function to dispatch the
  39. * specified action to the specified store.
  40. * @param {Action} action - The redux action SET_FULL_SCREEN which is being
  41. * dispatched in the specified store.
  42. * @private
  43. * @returns {Object} The value returned by {@code next(action)}.
  44. */
  45. function _setFullScreen(next, action) {
  46. if (typeof APP === 'object') {
  47. const { fullScreen } = action;
  48. if (fullScreen) {
  49. const documentElement = document.documentElement || {};
  50. if (typeof documentElement.requestFullscreen === 'function') {
  51. documentElement.requestFullscreen();
  52. } else if (
  53. typeof documentElement.msRequestFullscreen === 'function') {
  54. documentElement.msRequestFullscreen();
  55. } else if (
  56. typeof documentElement.mozRequestFullScreen === 'function') {
  57. documentElement.mozRequestFullScreen();
  58. } else if (
  59. typeof documentElement.webkitRequestFullscreen === 'function') {
  60. documentElement.webkitRequestFullscreen();
  61. }
  62. } else if (typeof document.exitFullscreen === 'function') {
  63. document.exitFullscreen();
  64. } else if (typeof document.msExitFullscreen === 'function') {
  65. document.msExitFullscreen();
  66. } else if (typeof document.mozCancelFullScreen === 'function') {
  67. document.mozCancelFullScreen();
  68. } else if (typeof document.webkitExitFullscreen === 'function') {
  69. document.webkitExitFullscreen();
  70. }
  71. }
  72. return next(action);
  73. }