You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UIUtil.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* global $ */
  2. /**
  3. * Created by hristo on 12/22/14.
  4. */
  5. const UIUtil = {
  6. /**
  7. * Returns the available video width.
  8. */
  9. getAvailableVideoWidth() {
  10. return window.innerWidth;
  11. },
  12. /**
  13. * Escapes the given text.
  14. */
  15. escapeHtml(unsafeText) {
  16. return $('<div/>').text(unsafeText)
  17. .html();
  18. },
  19. /**
  20. * Inserts given child element as the first one into the container.
  21. * @param container the container to which new child element will be added
  22. * @param newChild the new element that will be inserted into the container
  23. */
  24. prependChild(container, newChild) {
  25. const firstChild = container.childNodes[0];
  26. if (firstChild) {
  27. container.insertBefore(newChild, firstChild);
  28. } else {
  29. container.appendChild(newChild);
  30. }
  31. },
  32. /**
  33. * Redirects to a given URL.
  34. *
  35. * @param {string} url - The redirect URL.
  36. * NOTE: Currently used to redirect to 3rd party location for
  37. * authentication. In most cases redirectWithStoredParams action must be
  38. * used instead of this method in order to preserve curent URL params.
  39. */
  40. redirect(url) {
  41. window.location.href = url;
  42. },
  43. /**
  44. * Indicates if we're currently in full screen mode.
  45. *
  46. * @return {boolean} {true} to indicate that we're currently in full screen
  47. * mode, {false} otherwise
  48. */
  49. isFullScreen() {
  50. return Boolean(document.fullscreenElement
  51. || document.mozFullScreenElement
  52. || document.webkitFullscreenElement
  53. || document.msFullscreenElement);
  54. },
  55. /**
  56. * Checks if the given DOM element is currently visible. The offsetParent
  57. * will be null if the "display" property of the element or any of its
  58. * parent containers is set to "none". This method will NOT check the
  59. * visibility property though.
  60. * @param {el} The DOM element we'd like to check for visibility
  61. */
  62. isVisible(el) {
  63. return el.offsetParent !== null;
  64. }
  65. };
  66. export default UIUtil;