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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* global $ */
  2. /**
  3. * Created by hristo on 12/22/14.
  4. */
  5. module.exports = {
  6. /**
  7. * Returns the available video width.
  8. */
  9. getAvailableVideoWidth: function (isVisible) {
  10. var PanelToggler = require("../side_pannels/SidePanelToggler");
  11. if(typeof isVisible === "undefined" || isVisible === null)
  12. isVisible = PanelToggler.isVisible();
  13. var rightPanelWidth
  14. = isVisible ? PanelToggler.getPanelSize()[0] : 0;
  15. return window.innerWidth - rightPanelWidth;
  16. },
  17. /**
  18. * Changes the style class of the element given by id.
  19. */
  20. buttonClick: function(id, classname) {
  21. $(id).toggleClass(classname); // add the class to the clicked element
  22. },
  23. /**
  24. * Returns the text width for the given element.
  25. *
  26. * @param el the element
  27. */
  28. getTextWidth: function (el) {
  29. return (el.clientWidth + 1);
  30. },
  31. /**
  32. * Returns the text height for the given element.
  33. *
  34. * @param el the element
  35. */
  36. getTextHeight: function (el) {
  37. return (el.clientHeight + 1);
  38. },
  39. /**
  40. * Plays the sound given by id.
  41. *
  42. * @param id the identifier of the audio element.
  43. */
  44. playSoundNotification: function (id) {
  45. document.getElementById(id).play();
  46. },
  47. /**
  48. * Escapes the given text.
  49. */
  50. escapeHtml: function (unsafeText) {
  51. return $('<div/>').text(unsafeText).html();
  52. },
  53. imageToGrayScale: function (canvas) {
  54. var context = canvas.getContext('2d');
  55. var imgData = context.getImageData(0, 0, canvas.width, canvas.height);
  56. var pixels = imgData.data;
  57. for (var i = 0, n = pixels.length; i < n; i += 4) {
  58. var grayscale
  59. = pixels[i] * 0.3 + pixels[i+1] * 0.59 + pixels[i+2] * 0.11;
  60. pixels[i ] = grayscale; // red
  61. pixels[i+1] = grayscale; // green
  62. pixels[i+2] = grayscale; // blue
  63. // pixels[i+3] is alpha
  64. }
  65. // redraw the image in black & white
  66. context.putImageData(imgData, 0, 0);
  67. },
  68. setTooltip: function (element, key, position) {
  69. element.setAttribute("data-i18n", "[data-content]" + key);
  70. element.setAttribute("data-toggle", "popover");
  71. element.setAttribute("data-placement", position);
  72. element.setAttribute("data-html", true);
  73. element.setAttribute("data-container", "body");
  74. }
  75. };