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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. * Indicates if the given string is an alphanumeric string.
  45. * Note that some special characters are also allowed (-, _ , /) for the
  46. * purpose of checking URIs. (FIXME: This should maybe moved to another not
  47. * so generic method in the future.)
  48. */
  49. my.isAlphanumeric = function(unsafeText) {
  50. var regex = /^[a-z0-9-_\/]+$/i;
  51. return regex.test(unsafeText);
  52. };
  53. /**
  54. * Returns the available video width.
  55. */
  56. my.getAvailableVideoWidth = function() {
  57. var chatspaceWidth = $('#chatspace').is(":visible")
  58. ? $('#chatspace').width()
  59. : 0;
  60. return window.innerWidth - chatspaceWidth;
  61. };
  62. return my;
  63. }(Util || {}));