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

Etherpad.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 (!$('#toolbar_button_etherpad').is(":visible"))
  28. $('#toolbar_button_etherpad').css({display: 'inline-block'});
  29. }
  30. /**
  31. * Creates the IFrame for the etherpad.
  32. */
  33. function createIFrame() {
  34. etherpadIFrame = VideoLayout.createEtherpadIframe(
  35. domain + etherpadName + options, function() {
  36. document.domain = document.domain;
  37. bubbleIframeMouseMove(etherpadIFrame);
  38. setTimeout(function() {
  39. // the iframes inside of the etherpad are
  40. // not yet loaded when the etherpad iframe is loaded
  41. var outer = etherpadIFrame.
  42. contentDocument.getElementsByName("ace_outer")[0];
  43. bubbleIframeMouseMove(outer);
  44. var inner = outer.
  45. contentDocument.getElementsByName("ace_inner")[0];
  46. bubbleIframeMouseMove(inner);
  47. }, 2000);
  48. });
  49. }
  50. function bubbleIframeMouseMove(iframe){
  51. var existingOnMouseMove = iframe.contentWindow.onmousemove;
  52. iframe.contentWindow.onmousemove = function(e){
  53. if(existingOnMouseMove) existingOnMouseMove(e);
  54. var evt = document.createEvent("MouseEvents");
  55. var boundingClientRect = iframe.getBoundingClientRect();
  56. evt.initMouseEvent(
  57. "mousemove",
  58. true, // bubbles
  59. false, // not cancelable
  60. window,
  61. e.detail,
  62. e.screenX,
  63. e.screenY,
  64. e.clientX + boundingClientRect.left,
  65. e.clientY + boundingClientRect.top,
  66. e.ctrlKey,
  67. e.altKey,
  68. e.shiftKey,
  69. e.metaKey,
  70. e.button,
  71. null // no related element
  72. );
  73. iframe.dispatchEvent(evt);
  74. };
  75. }
  76. var Etherpad = {
  77. /**
  78. * Initializes the etherpad.
  79. */
  80. init: function (name) {
  81. if (config.etherpad_base && !etherpadName && name) {
  82. domain = config.etherpad_base;
  83. etherpadName = name;
  84. enableEtherpadButton();
  85. /**
  86. * Resizes the etherpad, when the window is resized.
  87. */
  88. $(window).resize(function () {
  89. resize();
  90. });
  91. }
  92. },
  93. /**
  94. * Opens/hides the Etherpad.
  95. */
  96. toggleEtherpad: function (isPresentation) {
  97. if (!etherpadIFrame)
  98. createIFrame();
  99. if(VideoLayout.getLargeVideoState() === "etherpad")
  100. {
  101. VideoLayout.setLargeVideoState("video");
  102. }
  103. else
  104. {
  105. VideoLayout.setLargeVideoState("etherpad");
  106. }
  107. resize();
  108. }
  109. };
  110. module.exports = Etherpad;