Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

UIUtil.js 2.4KB

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