window.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * DevExtreme (core/utils/window.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. var domAdapter = require("../dom_adapter");
  11. var _hasWindow = "undefined" !== typeof window;
  12. var windowObject = _hasWindow && window;
  13. if (!windowObject) {
  14. windowObject = {};
  15. windowObject.window = windowObject
  16. }
  17. module.exports = {
  18. hasWindow: function() {
  19. return _hasWindow
  20. },
  21. getWindow: function() {
  22. return windowObject
  23. },
  24. hasProperty: function(prop) {
  25. return this.hasWindow() && prop in windowObject
  26. },
  27. defaultScreenFactorFunc: function(width) {
  28. if (width < 768) {
  29. return "xs"
  30. } else {
  31. if (width < 992) {
  32. return "sm"
  33. } else {
  34. if (width < 1200) {
  35. return "md"
  36. } else {
  37. return "lg"
  38. }
  39. }
  40. }
  41. },
  42. getCurrentScreenFactor: function(screenFactorCallback) {
  43. var screenFactorFunc = screenFactorCallback || this.defaultScreenFactorFunc;
  44. var windowWidth = domAdapter.getDocumentElement().clientWidth;
  45. return screenFactorFunc(windowWidth)
  46. },
  47. getNavigator: function() {
  48. return this.hasWindow() ? windowObject.navigator : {
  49. userAgent: ""
  50. }
  51. }
  52. };