getViewportDimensions.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. "use strict";
  2. /**
  3. * Copyright (c) 2013-present, Facebook, Inc.
  4. *
  5. * This source code is licensed under the MIT license found in the
  6. * LICENSE file in the root directory of this source tree.
  7. *
  8. *
  9. * @typechecks
  10. */
  11. function getViewportWidth() {
  12. var width;
  13. if (document.documentElement) {
  14. width = document.documentElement.clientWidth;
  15. }
  16. if (!width && document.body) {
  17. width = document.body.clientWidth;
  18. }
  19. return width || 0;
  20. }
  21. function getViewportHeight() {
  22. var height;
  23. if (document.documentElement) {
  24. height = document.documentElement.clientHeight;
  25. }
  26. if (!height && document.body) {
  27. height = document.body.clientHeight;
  28. }
  29. return height || 0;
  30. }
  31. /**
  32. * Gets the viewport dimensions including any scrollbars.
  33. */
  34. function getViewportDimensions() {
  35. return {
  36. width: window.innerWidth || getViewportWidth(),
  37. height: window.innerHeight || getViewportHeight()
  38. };
  39. }
  40. /**
  41. * Gets the viewport dimensions excluding any scrollbars.
  42. */
  43. getViewportDimensions.withoutScrollbars = function () {
  44. return {
  45. width: getViewportWidth(),
  46. height: getViewportHeight()
  47. };
  48. };
  49. module.exports = getViewportDimensions;