您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

UIUtil.js 2.3KB

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