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 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* global $, config, interfaceConfig */
  2. /**
  3. * Created by hristo on 12/22/14.
  4. */
  5. var UIUtil = 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. /**
  76. * Inserts given child element as the first one into the container.
  77. * @param container the container to which new child element will be added
  78. * @param newChild the new element that will be inserted into the container
  79. */
  80. prependChild: function (container, newChild) {
  81. var firstChild = container.childNodes[0];
  82. if (firstChild) {
  83. container.insertBefore(newChild, firstChild);
  84. } else {
  85. container.appendChild(newChild);
  86. }
  87. },
  88. isButtonEnabled: function (name) {
  89. var isEnabled = interfaceConfig.TOOLBAR_BUTTONS.indexOf(name) !== -1;
  90. if (name === 'prezi') {
  91. return isEnabled && !config.disablePrezi;
  92. } else if (name === 'recording') {
  93. return isEnabled && config.enableRecording;
  94. }
  95. return isEnabled;
  96. },
  97. hideDisabledButtons: function (mappings) {
  98. var selector = Object.keys(mappings)
  99. .map(function (buttonName) {
  100. return UIUtil.isButtonEnabled(buttonName)
  101. ? null : mappings[buttonName]; })
  102. .filter(function (item) { return item; })
  103. .join(',');
  104. $(selector).hide();
  105. }
  106. };