選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Etherpad.js 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /* global $, config, connection, dockToolbar, Moderator,
  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. * Shares the Etherpad name with other participants.
  25. */
  26. function shareEtherpad() {
  27. connection.emuc.addEtherpadToPresence(etherpadName);
  28. connection.emuc.sendPresence();
  29. }
  30. /**
  31. * Creates the Etherpad button and adds it to the toolbar.
  32. */
  33. function enableEtherpadButton() {
  34. if (!$('#etherpadButton').is(":visible"))
  35. $('#etherpadButton').css({display: 'inline-block'});
  36. }
  37. /**
  38. * Creates the IFrame for the etherpad.
  39. */
  40. function createIFrame() {
  41. etherpadIFrame = document.createElement('iframe');
  42. etherpadIFrame.src = domain + etherpadName + options;
  43. etherpadIFrame.frameBorder = 0;
  44. etherpadIFrame.scrolling = "no";
  45. etherpadIFrame.width = $('#largeVideoContainer').width() || 640;
  46. etherpadIFrame.height = $('#largeVideoContainer').height() || 480;
  47. etherpadIFrame.setAttribute('style', 'visibility: hidden;');
  48. document.getElementById('etherpad').appendChild(etherpadIFrame);
  49. etherpadIFrame.onload = function() {
  50. document.domain = document.domain;
  51. bubbleIframeMouseMove(etherpadIFrame);
  52. setTimeout(function() {
  53. // the iframes inside of the etherpad are
  54. // not yet loaded when the etherpad iframe is loaded
  55. var outer = etherpadIFrame.
  56. contentDocument.getElementsByName("ace_outer")[0];
  57. bubbleIframeMouseMove(outer);
  58. var inner = outer.
  59. contentDocument.getElementsByName("ace_inner")[0];
  60. bubbleIframeMouseMove(inner);
  61. }, 2000);
  62. };
  63. }
  64. function bubbleIframeMouseMove(iframe){
  65. var existingOnMouseMove = iframe.contentWindow.onmousemove;
  66. iframe.contentWindow.onmousemove = function(e){
  67. if(existingOnMouseMove) existingOnMouseMove(e);
  68. var evt = document.createEvent("MouseEvents");
  69. var boundingClientRect = iframe.getBoundingClientRect();
  70. evt.initMouseEvent(
  71. "mousemove",
  72. true, // bubbles
  73. false, // not cancelable
  74. window,
  75. e.detail,
  76. e.screenX,
  77. e.screenY,
  78. e.clientX + boundingClientRect.left,
  79. e.clientY + boundingClientRect.top,
  80. e.ctrlKey,
  81. e.altKey,
  82. e.shiftKey,
  83. e.metaKey,
  84. e.button,
  85. null // no related element
  86. );
  87. iframe.dispatchEvent(evt);
  88. };
  89. }
  90. /**
  91. * On video selected event.
  92. */
  93. $(document).bind('video.selected', function (event, isPresentation) {
  94. if (config.etherpad_base && etherpadIFrame && etherpadIFrame.style.visibility !== 'hidden')
  95. Etherpad.toggleEtherpad(isPresentation);
  96. });
  97. var Etherpad = {
  98. /**
  99. * Initializes the etherpad.
  100. */
  101. init: function (name) {
  102. if (config.etherpad_base && !etherpadName) {
  103. domain = config.etherpad_base;
  104. if (!name) {
  105. // In case we're the focus we generate the name.
  106. etherpadName = Math.random().toString(36).substring(7) +
  107. '_' + (new Date().getTime()).toString();
  108. shareEtherpad();
  109. }
  110. else
  111. etherpadName = name;
  112. enableEtherpadButton();
  113. /**
  114. * Resizes the etherpad, when the window is resized.
  115. */
  116. $(window).resize(function () {
  117. resize();
  118. });
  119. }
  120. },
  121. /**
  122. * Opens/hides the Etherpad.
  123. */
  124. toggleEtherpad: function (isPresentation) {
  125. if (!etherpadIFrame)
  126. createIFrame();
  127. var largeVideo = null;
  128. if (Prezi.isPresentationVisible())
  129. largeVideo = $('#presentation>iframe');
  130. else
  131. largeVideo = $('#largeVideo');
  132. if ($('#etherpad>iframe').css('visibility') === 'hidden') {
  133. $('#activeSpeaker').css('visibility', 'hidden');
  134. largeVideo.fadeOut(300, function () {
  135. if (Prezi.isPresentationVisible()) {
  136. largeVideo.css({opacity: '0'});
  137. } else {
  138. VideoLayout.setLargeVideoVisible(false);
  139. }
  140. });
  141. $('#etherpad>iframe').fadeIn(300, function () {
  142. document.body.style.background = '#eeeeee';
  143. $('#etherpad>iframe').css({visibility: 'visible'});
  144. $('#etherpad').css({zIndex: 2});
  145. });
  146. }
  147. else if ($('#etherpad>iframe')) {
  148. $('#etherpad>iframe').fadeOut(300, function () {
  149. $('#etherpad>iframe').css({visibility: 'hidden'});
  150. $('#etherpad').css({zIndex: 0});
  151. document.body.style.background = 'black';
  152. });
  153. if (!isPresentation) {
  154. $('#largeVideo').fadeIn(300, function () {
  155. VideoLayout.setLargeVideoVisible(true);
  156. });
  157. }
  158. }
  159. resize();
  160. },
  161. isVisible: function() {
  162. var etherpadIframe = $('#etherpad>iframe');
  163. return etherpadIframe && etherpadIframe.is(':visible');
  164. }
  165. };
  166. module.exports = Etherpad;