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.

util.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* global $ */
  2. /**
  3. * Utility functions.
  4. */
  5. var Util = (function (my) {
  6. /**
  7. * Returns the text width for the given element.
  8. *
  9. * @param el the element
  10. */
  11. my.getTextWidth = function (el) {
  12. return (el.clientWidth + 1);
  13. };
  14. /**
  15. * Returns the text height for the given element.
  16. *
  17. * @param el the element
  18. */
  19. my.getTextHeight = function (el) {
  20. return (el.clientHeight + 1);
  21. };
  22. /**
  23. * Casts the given number to integer.
  24. *
  25. * @param number the number to cast
  26. */
  27. my.toInteger = function (number) {
  28. return Math.round(Number(number));
  29. };
  30. /**
  31. * Plays the sound given by id.
  32. *
  33. * @param id the identifier of the audio element.
  34. */
  35. my.playSoundNotification = function (id) {
  36. document.getElementById(id).play();
  37. };
  38. /**
  39. * Escapes the given text.
  40. */
  41. my.escapeHtml = function (unsafeText) {
  42. return $('<div/>').text(unsafeText).html();
  43. };
  44. /**
  45. * Returns the available video width.
  46. */
  47. my.getAvailableVideoWidth = function () {
  48. var chatspaceWidth = $('#chatspace').is(":visible") ? $('#chatspace').width() : 0;
  49. return window.innerWidth - chatspaceWidth;
  50. };
  51. return my;
  52. }(Util || {}));