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

etherpad.js 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. var Etherpad = (function (my) {
  2. var etherpadName = null;
  3. var etherpadIFrame = null;
  4. var domain = null;
  5. var options = "?showControls=true&showChat=false&showLineNumbers=true&useMonospaceFont=false";
  6. /**
  7. * Initializes the etherpad.
  8. */
  9. my.init = function (name) {
  10. if (config.etherpad_base && !etherpadName) {
  11. domain = config.etherpad_base;
  12. if (!name) {
  13. // In case we're the focus we generate the name.
  14. etherpadName = Math.random().toString(36).substring(7)
  15. + '_' + (new Date().getTime()).toString();
  16. shareEtherpad();
  17. }
  18. else
  19. etherpadName = name;
  20. enableEtherpadButton();
  21. }
  22. };
  23. /**
  24. * Opens/hides the Etherpad.
  25. */
  26. my.toggleEtherpad = function (isPresentation) {
  27. if (!etherpadIFrame)
  28. createIFrame();
  29. var largeVideo = null;
  30. if (Prezi.isPresentationVisible())
  31. largeVideo = $('#presentation>iframe');
  32. else
  33. largeVideo = $('#largeVideo');
  34. if ($('#etherpad>iframe').css('visibility') === 'hidden') {
  35. largeVideo.fadeOut(300, function () {
  36. if (Prezi.isPresentationVisible())
  37. largeVideo.css({opacity:'0'});
  38. else {
  39. setLargeVideoVisible(false);
  40. dockToolbar(true);
  41. }
  42. $('#etherpad>iframe').fadeIn(300, function() {
  43. document.body.style.background = '#eeeeee';
  44. $('#etherpad>iframe').css({visibility:'visible'});
  45. $('#etherpad').css({zIndex:2});
  46. });
  47. });
  48. }
  49. else if ($('#etherpad>iframe')) {
  50. $('#etherpad>iframe').fadeOut(300, function () {
  51. $('#etherpad>iframe').css({visibility:'hidden'});
  52. $('#etherpad').css({zIndex:0});
  53. document.body.style.background = 'black';
  54. if (!isPresentation) {
  55. $('#largeVideo').fadeIn(300, function() {
  56. setLargeVideoVisible(true);
  57. dockToolbar(false);
  58. });
  59. }
  60. });
  61. }
  62. resize();
  63. };
  64. /**
  65. * Resizes the etherpad.
  66. */
  67. function resize() {
  68. if ($('#etherpad>iframe').length) {
  69. var remoteVideos = $('#remoteVideos');
  70. var availableHeight
  71. = window.innerHeight - remoteVideos.outerHeight();
  72. var availableWidth = Util.getAvailableVideoWidth();
  73. $('#etherpad>iframe').width(availableWidth);
  74. $('#etherpad>iframe').height(availableHeight);
  75. }
  76. }
  77. /**
  78. * Shares the Etherpad name with other participants.
  79. */
  80. function shareEtherpad() {
  81. connection.emuc.addEtherpadToPresence(etherpadName);
  82. connection.emuc.sendPresence();
  83. }
  84. /**
  85. * Creates the Etherpad button and adds it to the toolbar.
  86. */
  87. function enableEtherpadButton() {
  88. if (!$('#etherpadButton').is(":visible"))
  89. $('#etherpadButton').css({display:'inline-block'});
  90. }
  91. /**
  92. * Creates the IFrame for the etherpad.
  93. */
  94. function createIFrame() {
  95. etherpadIFrame = document.createElement('iframe');
  96. etherpadIFrame.src = domain + etherpadName + options;
  97. etherpadIFrame.frameBorder = 0;
  98. etherpadIFrame.scrolling = "no";
  99. etherpadIFrame.width = $('#largeVideoContainer').width() || 640;
  100. etherpadIFrame.height = $('#largeVideoContainer').height() || 480;
  101. etherpadIFrame.setAttribute('style', 'visibility: hidden;');
  102. document.getElementById('etherpad').appendChild(etherpadIFrame);
  103. }
  104. /**
  105. * On Etherpad added to muc.
  106. */
  107. $(document).bind('etherpadadded.muc', function (event, jid, etherpadName) {
  108. console.log("Etherpad added", etherpadName);
  109. if (config.etherpad_base && !focus) {
  110. Etherpad.init(etherpadName);
  111. }
  112. });
  113. /**
  114. * On focus changed event.
  115. */
  116. $(document).bind('focusechanged.muc', function (event, focus) {
  117. console.log("Focus changed");
  118. if (config.etherpad_base)
  119. shareEtherpad();
  120. });
  121. /**
  122. * On video selected event.
  123. */
  124. $(document).bind('video.selected', function (event, isPresentation) {
  125. if (!config.etherpad_base)
  126. return;
  127. if (etherpadIFrame && etherpadIFrame.style.visibility !== 'hidden')
  128. Etherpad.toggleEtherpad(isPresentation);
  129. });
  130. /**
  131. * Resizes the etherpad, when the window is resized.
  132. */
  133. $(window).resize(function () {
  134. resize();
  135. });
  136. return my;
  137. }(Etherpad || {}));