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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. let result;
  27. if (firstChild) {
  28. result = container.insertBefore(newChild, firstChild);
  29. } else {
  30. result = container.appendChild(newChild);
  31. }
  32. return result;
  33. },
  34. /**
  35. * Redirects to a given URL.
  36. *
  37. * @param {string} url - The redirect URL.
  38. * NOTE: Currently used to redirect to 3rd party location for
  39. * authentication. In most cases redirectWithStoredParams action must be
  40. * used instead of this method in order to preserve curent URL params.
  41. */
  42. redirect(url) {
  43. window.location.href = url;
  44. },
  45. /**
  46. * Indicates if we're currently in full screen mode.
  47. *
  48. * @return {boolean} {true} to indicate that we're currently in full screen
  49. * mode, {false} otherwise
  50. */
  51. isFullScreen() {
  52. return Boolean(document.fullscreenElement
  53. || document.mozFullScreenElement
  54. || document.webkitFullscreenElement
  55. || document.msFullscreenElement);
  56. },
  57. /**
  58. * Checks if the given DOM element is currently visible. The offsetParent
  59. * will be null if the "display" property of the element or any of its
  60. * parent containers is set to "none". This method will NOT check the
  61. * visibility property though.
  62. * @param {el} The DOM element we'd like to check for visibility
  63. */
  64. isVisible(el) {
  65. return el.offsetParent !== null;
  66. }
  67. };
  68. export default UIUtil;