getViewportDimensions.js 1.2 KB

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