domManagement.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* eslint-disable @typescript-eslint/naming-convention */
  2. /**
  3. * Checks if the window object exists
  4. * @returns true if the window object exists
  5. */
  6. export function IsWindowObjectExist() {
  7. return typeof window !== "undefined";
  8. }
  9. /**
  10. * Checks if the navigator object exists
  11. * @returns true if the navigator object exists
  12. */
  13. export function IsNavigatorAvailable() {
  14. return typeof navigator !== "undefined";
  15. }
  16. /**
  17. * Check if the document object exists
  18. * @returns true if the document object exists
  19. */
  20. export function IsDocumentAvailable() {
  21. return typeof document !== "undefined";
  22. }
  23. /**
  24. * Extracts text content from a DOM element hierarchy
  25. * @param element defines the root element
  26. * @returns a string
  27. */
  28. export function GetDOMTextContent(element) {
  29. let result = "";
  30. let child = element.firstChild;
  31. while (child) {
  32. if (child.nodeType === 3) {
  33. result += child.textContent;
  34. }
  35. child = child.nextSibling;
  36. }
  37. return result;
  38. }
  39. /**
  40. * Sets of helpers dealing with the DOM and some of the recurrent functions needed in
  41. * Babylon.js
  42. */
  43. export const DomManagement = {
  44. /**
  45. * Checks if the window object exists
  46. * @returns true if the window object exists
  47. */
  48. IsWindowObjectExist,
  49. /**
  50. * Checks if the navigator object exists
  51. * @returns true if the navigator object exists
  52. */
  53. IsNavigatorAvailable,
  54. /**
  55. * Check if the document object exists
  56. * @returns true if the document object exists
  57. */
  58. IsDocumentAvailable,
  59. /**
  60. * Extracts text content from a DOM element hierarchy
  61. * @param element defines the root element
  62. * @returns a string
  63. */
  64. GetDOMTextContent,
  65. };
  66. //# sourceMappingURL=domManagement.js.map