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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright @ 2015 Atlassian Pty Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. * Created by hristo on 12/22/14.
  17. */
  18. module.exports = {
  19. /**
  20. * Returns the available video width.
  21. */
  22. getAvailableVideoWidth: function () {
  23. var PanelToggler = require("../side_pannels/SidePanelToggler");
  24. var rightPanelWidth
  25. = PanelToggler.isVisible() ? PanelToggler.getPanelSize()[0] : 0;
  26. return window.innerWidth - rightPanelWidth;
  27. },
  28. /**
  29. * Changes the style class of the element given by id.
  30. */
  31. buttonClick: function(id, classname) {
  32. $(id).toggleClass(classname); // add the class to the clicked element
  33. },
  34. /**
  35. * Returns the text width for the given element.
  36. *
  37. * @param el the element
  38. */
  39. getTextWidth: function (el) {
  40. return (el.clientWidth + 1);
  41. },
  42. /**
  43. * Returns the text height for the given element.
  44. *
  45. * @param el the element
  46. */
  47. getTextHeight: function (el) {
  48. return (el.clientHeight + 1);
  49. },
  50. /**
  51. * Plays the sound given by id.
  52. *
  53. * @param id the identifier of the audio element.
  54. */
  55. playSoundNotification: function (id) {
  56. document.getElementById(id).play();
  57. },
  58. /**
  59. * Escapes the given text.
  60. */
  61. escapeHtml: function (unsafeText) {
  62. return $('<div/>').text(unsafeText).html();
  63. },
  64. imageToGrayScale: function (canvas) {
  65. var context = canvas.getContext('2d');
  66. var imgData = context.getImageData(0, 0, canvas.width, canvas.height);
  67. var pixels = imgData.data;
  68. for (var i = 0, n = pixels.length; i < n; i += 4) {
  69. var grayscale
  70. = pixels[i] * .3 + pixels[i+1] * .59 + pixels[i+2] * .11;
  71. pixels[i ] = grayscale; // red
  72. pixels[i+1] = grayscale; // green
  73. pixels[i+2] = grayscale; // blue
  74. // pixels[i+3] is alpha
  75. }
  76. // redraw the image in black & white
  77. context.putImageData(imgData, 0, 0);
  78. },
  79. setTooltip: function (element, key, position) {
  80. element.setAttribute("data-i18n", "[data-content]" + key);
  81. element.setAttribute("data-toggle", "popover");
  82. element.setAttribute("data-placement", position);
  83. element.setAttribute("data-html", true);
  84. element.setAttribute("data-container", "body");
  85. }
  86. };