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

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