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

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