domManagement.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * Sets of helpers dealing with the DOM and some of the recurrent functions needed in
  3. * Babylon.js
  4. */
  5. export class DomManagement {
  6. /**
  7. * Checks if the window object exists
  8. * @returns true if the window object exists
  9. */
  10. public static IsWindowObjectExist(): boolean {
  11. return (typeof window) !== "undefined";
  12. }
  13. /**
  14. * Checks if the navigator object exists
  15. * @returns true if the navigator object exists
  16. */
  17. public static IsNavigatorAvailable(): boolean {
  18. return (typeof navigator) !== "undefined";
  19. }
  20. /**
  21. * Extracts text content from a DOM element hierarchy
  22. * @param element defines the root element
  23. * @returns a string
  24. */
  25. public static GetDOMTextContent(element: HTMLElement): string {
  26. var result = "";
  27. var child = element.firstChild;
  28. while (child) {
  29. if (child.nodeType === 3) {
  30. result += child.textContent;
  31. }
  32. child = <any>(child.nextSibling);
  33. }
  34. return result;
  35. }
  36. }