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.

Etherpad.js 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* global $, config,
  2. setLargeVideoVisible, Util */
  3. var VideoLayout = require("../videolayout/VideoLayout");
  4. var Prezi = require("../prezi/Prezi");
  5. var UIUtil = require("../util/UIUtil");
  6. var etherpadName = null;
  7. var etherpadIFrame = null;
  8. var domain = null;
  9. var options = "?showControls=true&showChat=false&showLineNumbers=true&useMonospaceFont=false";
  10. /**
  11. * Resizes the etherpad.
  12. */
  13. function resize() {
  14. if ($('#etherpad>iframe').length) {
  15. var remoteVideos = $('#remoteVideos');
  16. var availableHeight
  17. = window.innerHeight - remoteVideos.outerHeight();
  18. var availableWidth = UIUtil.getAvailableVideoWidth();
  19. $('#etherpad>iframe').width(availableWidth);
  20. $('#etherpad>iframe').height(availableHeight);
  21. }
  22. }
  23. /**
  24. * Creates the Etherpad button and adds it to the toolbar.
  25. */
  26. function enableEtherpadButton() {
  27. if (!$('#etherpadButton').is(":visible"))
  28. $('#etherpadButton').css({display: 'inline-block'});
  29. }
  30. /**
  31. * Creates the IFrame for the etherpad.
  32. */
  33. function createIFrame() {
  34. etherpadIFrame = document.createElement('iframe');
  35. etherpadIFrame.src = domain + etherpadName + options;
  36. etherpadIFrame.frameBorder = 0;
  37. etherpadIFrame.scrolling = "no";
  38. etherpadIFrame.width = $('#largeVideoContainer').width() || 640;
  39. etherpadIFrame.height = $('#largeVideoContainer').height() || 480;
  40. etherpadIFrame.setAttribute('style', 'visibility: hidden;');
  41. document.getElementById('etherpad').appendChild(etherpadIFrame);
  42. etherpadIFrame.onload = function() {
  43. document.domain = document.domain;
  44. bubbleIframeMouseMove(etherpadIFrame);
  45. setTimeout(function() {
  46. // the iframes inside of the etherpad are
  47. // not yet loaded when the etherpad iframe is loaded
  48. var outer = etherpadIFrame.
  49. contentDocument.getElementsByName("ace_outer")[0];
  50. bubbleIframeMouseMove(outer);
  51. var inner = outer.
  52. contentDocument.getElementsByName("ace_inner")[0];
  53. bubbleIframeMouseMove(inner);
  54. }, 2000);
  55. };
  56. }
  57. function bubbleIframeMouseMove(iframe){
  58. var existingOnMouseMove = iframe.contentWindow.onmousemove;
  59. iframe.contentWindow.onmousemove = function(e){
  60. if(existingOnMouseMove) existingOnMouseMove(e);
  61. var evt = document.createEvent("MouseEvents");
  62. var boundingClientRect = iframe.getBoundingClientRect();
  63. evt.initMouseEvent(
  64. "mousemove",
  65. true, // bubbles
  66. false, // not cancelable
  67. window,
  68. e.detail,
  69. e.screenX,
  70. e.screenY,
  71. e.clientX + boundingClientRect.left,
  72. e.clientY + boundingClientRect.top,
  73. e.ctrlKey,
  74. e.altKey,
  75. e.shiftKey,
  76. e.metaKey,
  77. e.button,
  78. null // no related element
  79. );
  80. iframe.dispatchEvent(evt);
  81. };
  82. }
  83. /**
  84. * On video selected event.
  85. */
  86. $(document).bind('video.selected', function (event, isPresentation) {
  87. if (config.etherpad_base && etherpadIFrame && etherpadIFrame.style.visibility !== 'hidden')
  88. Etherpad.toggleEtherpad(isPresentation);
  89. });
  90. var Etherpad = {
  91. /**
  92. * Initializes the etherpad.
  93. */
  94. init: function (name) {
  95. if (config.etherpad_base && !etherpadName && name) {
  96. domain = config.etherpad_base;
  97. etherpadName = name;
  98. enableEtherpadButton();
  99. /**
  100. * Resizes the etherpad, when the window is resized.
  101. */
  102. $(window).resize(function () {
  103. resize();
  104. });
  105. }
  106. },
  107. /**
  108. * Opens/hides the Etherpad.
  109. */
  110. toggleEtherpad: function (isPresentation) {
  111. if (!etherpadIFrame)
  112. createIFrame();
  113. var largeVideo = null;
  114. if (Prezi.isPresentationVisible())
  115. largeVideo = $('#presentation>iframe');
  116. else
  117. largeVideo = $('#largeVideo');
  118. if ($('#etherpad>iframe').css('visibility') === 'hidden') {
  119. $('#activeSpeaker').css('visibility', 'hidden');
  120. largeVideo.fadeOut(300, function () {
  121. if (Prezi.isPresentationVisible()) {
  122. largeVideo.css({opacity: '0'});
  123. } else {
  124. VideoLayout.setLargeVideoVisible(false);
  125. }
  126. });
  127. $('#etherpad>iframe').fadeIn(300, function () {
  128. document.body.style.background = '#eeeeee';
  129. $('#etherpad>iframe').css({visibility: 'visible'});
  130. $('#etherpad').css({zIndex: 2});
  131. });
  132. }
  133. else if ($('#etherpad>iframe')) {
  134. $('#etherpad>iframe').fadeOut(300, function () {
  135. $('#etherpad>iframe').css({visibility: 'hidden'});
  136. $('#etherpad').css({zIndex: 0});
  137. document.body.style.background = 'black';
  138. });
  139. if (!isPresentation) {
  140. $('#largeVideo').fadeIn(300, function () {
  141. VideoLayout.setLargeVideoVisible(true);
  142. });
  143. }
  144. }
  145. resize();
  146. },
  147. isVisible: function() {
  148. var etherpadIframe = $('#etherpad>iframe');
  149. return etherpadIframe && etherpadIframe.is(':visible');
  150. }
  151. };
  152. module.exports = Etherpad;