domManagement.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. * Check if the document object exists
  22. * @returns true if the document object exists
  23. */
  24. public static IsDocumentAvailable(): boolean {
  25. return (typeof document) !== "undefined";
  26. }
  27. /**
  28. * Extracts text content from a DOM element hierarchy
  29. * @param element defines the root element
  30. * @returns a string
  31. */
  32. public static GetDOMTextContent(element: HTMLElement): string {
  33. var result = "";
  34. var child = element.firstChild;
  35. while (child) {
  36. if (child.nodeType === 3) {
  37. result += child.textContent;
  38. }
  39. child = <any>(child.nextSibling);
  40. }
  41. return result;
  42. }
  43. }