您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Etherpad.js 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /* global $ */
  2. import VideoLayout from "../videolayout/VideoLayout";
  3. import LargeContainer from '../videolayout/LargeContainer';
  4. import UIUtil from "../util/UIUtil";
  5. import SidePanelToggler from "../side_pannels/SidePanelToggler";
  6. import BottomToolbar from '../toolbars/BottomToolbar';
  7. /**
  8. * Etherpad options.
  9. */
  10. const options = $.param({
  11. showControns: true,
  12. showChat: false,
  13. showLineNumbers: true,
  14. useMonospaceFont: false
  15. });
  16. function bubbleIframeMouseMove(iframe){
  17. var existingOnMouseMove = iframe.contentWindow.onmousemove;
  18. iframe.contentWindow.onmousemove = function(e){
  19. if(existingOnMouseMove) existingOnMouseMove(e);
  20. var evt = document.createEvent("MouseEvents");
  21. var boundingClientRect = iframe.getBoundingClientRect();
  22. evt.initMouseEvent(
  23. "mousemove",
  24. true, // bubbles
  25. false, // not cancelable
  26. window,
  27. e.detail,
  28. e.screenX,
  29. e.screenY,
  30. e.clientX + boundingClientRect.left,
  31. e.clientY + boundingClientRect.top,
  32. e.ctrlKey,
  33. e.altKey,
  34. e.shiftKey,
  35. e.metaKey,
  36. e.button,
  37. null // no related element
  38. );
  39. iframe.dispatchEvent(evt);
  40. };
  41. }
  42. /**
  43. * Default Etherpad frame width.
  44. */
  45. const DEFAULT_WIDTH = 640;
  46. /**
  47. * Default Etherpad frame height.
  48. */
  49. const DEFAULT_HEIGHT = 480;
  50. const EtherpadContainerType = "etherpad";
  51. /**
  52. * Container for Etherpad iframe.
  53. */
  54. class Etherpad extends LargeContainer {
  55. constructor (domain, name) {
  56. super();
  57. const iframe = document.createElement('iframe');
  58. iframe.src = domain + name + '?' + options;
  59. iframe.frameBorder = 0;
  60. iframe.scrolling = "no";
  61. iframe.width = DEFAULT_WIDTH;
  62. iframe.height = DEFAULT_HEIGHT;
  63. iframe.setAttribute('style', 'visibility: hidden;');
  64. this.container.appendChild(iframe);
  65. iframe.onload = function() {
  66. document.domain = document.domain;
  67. bubbleIframeMouseMove(iframe);
  68. setTimeout(function() {
  69. const doc = iframe.contentDocument;
  70. // the iframes inside of the etherpad are
  71. // not yet loaded when the etherpad iframe is loaded
  72. const outer = doc.getElementsByName("ace_outer")[0];
  73. bubbleIframeMouseMove(outer);
  74. const inner = doc.getElementsByName("ace_inner")[0];
  75. bubbleIframeMouseMove(inner);
  76. }, 2000);
  77. };
  78. this.iframe = iframe;
  79. }
  80. get isOpen () {
  81. return !!this.iframe;
  82. }
  83. get container () {
  84. return document.getElementById('etherpad');
  85. }
  86. resize (containerWidth, containerHeight, animate) {
  87. let height = containerHeight - BottomToolbar.getFilmStripHeight();
  88. let width = containerWidth;
  89. $(this.iframe).width(width).height(height);
  90. }
  91. show () {
  92. const $iframe = $(this.iframe);
  93. const $container = $(this.container);
  94. return new Promise(resolve => {
  95. $iframe.fadeIn(300, function () {
  96. document.body.style.background = '#eeeeee';
  97. $iframe.css({visibility: 'visible'});
  98. $container.css({zIndex: 2});
  99. resolve();
  100. });
  101. });
  102. }
  103. hide () {
  104. const $iframe = $(this.iframe);
  105. const $container = $(this.container);
  106. return new Promise(resolve => {
  107. $iframe.fadeOut(300, function () {
  108. $iframe.css({visibility: 'hidden'});
  109. $container.css({zIndex: 0});
  110. resolve();
  111. });
  112. });
  113. }
  114. }
  115. /**
  116. * Manager of the Etherpad frame.
  117. */
  118. export default class EtherpadManager {
  119. constructor (domain, name) {
  120. if (!domain || !name) {
  121. throw new Error("missing domain or name");
  122. }
  123. this.domain = domain;
  124. this.name = name;
  125. this.etherpad = null;
  126. }
  127. get isOpen () {
  128. return !!this.etherpad;
  129. }
  130. /**
  131. * Create new Etherpad frame.
  132. */
  133. openEtherpad () {
  134. this.etherpad = new Etherpad(this.domain, this.name);
  135. VideoLayout.addLargeVideoContainer(
  136. EtherpadContainerType,
  137. this.etherpad
  138. );
  139. }
  140. /**
  141. * Toggle Etherpad frame visibility.
  142. * Open new Etherpad frame if there is no Etherpad frame yet.
  143. */
  144. toggleEtherpad () {
  145. if (!this.isOpen) {
  146. this.openEtherpad();
  147. }
  148. let isVisible = VideoLayout.isLargeContainerTypeVisible(
  149. EtherpadContainerType
  150. );
  151. VideoLayout.showLargeVideoContainer(EtherpadContainerType, !isVisible);
  152. }
  153. }