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

Etherpad.js 3.5KB

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