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

Etherpad.js 4.3KB

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