Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

etherpad.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. var aspectRatio = 16.0 / 9.0;
  74. if (availableHeight < availableWidth / aspectRatio) {
  75. availableWidth = Math.floor(availableHeight * aspectRatio);
  76. }
  77. $('#etherpad>iframe').width(availableWidth);
  78. $('#etherpad>iframe').height(availableHeight);
  79. }
  80. }
  81. /**
  82. * Shares the Etherpad name with other participants.
  83. */
  84. function shareEtherpad() {
  85. connection.emuc.addEtherpadToPresence(etherpadName);
  86. connection.emuc.sendPresence();
  87. }
  88. /**
  89. * Creates the Etherpad button and adds it to the toolbar.
  90. */
  91. function enableEtherpadButton() {
  92. if (!$('#etherpadButton').is(":visible"))
  93. $('#etherpadButton').css({display:'inline-block'});
  94. }
  95. /**
  96. * Creates the IFrame for the etherpad.
  97. */
  98. function createIFrame() {
  99. etherpadIFrame = document.createElement('iframe');
  100. etherpadIFrame.src = domain + etherpadName + options;
  101. etherpadIFrame.frameBorder = 0;
  102. etherpadIFrame.scrolling = "no";
  103. etherpadIFrame.width = $('#largeVideoContainer').width() || 640;
  104. etherpadIFrame.height = $('#largeVideoContainer').height() || 480;
  105. etherpadIFrame.setAttribute('style', 'visibility: hidden;');
  106. document.getElementById('etherpad').appendChild(etherpadIFrame);
  107. }
  108. /**
  109. * On Etherpad added to muc.
  110. */
  111. $(document).bind('etherpadadded.muc', function (event, jid, etherpadName) {
  112. console.log("Etherpad added", etherpadName);
  113. if (config.etherpad_base && !focus) {
  114. Etherpad.init(etherpadName);
  115. }
  116. });
  117. /**
  118. * On focus changed event.
  119. */
  120. $(document).bind('focusechanged.muc', function (event, focus) {
  121. console.log("Focus changed");
  122. if (config.etherpad_base)
  123. shareEtherpad();
  124. });
  125. /**
  126. * On video selected event.
  127. */
  128. $(document).bind('video.selected', function (event, isPresentation) {
  129. if (!config.etherpad_base)
  130. return;
  131. if (etherpadIFrame && etherpadIFrame.style.visibility !== 'hidden')
  132. Etherpad.toggleEtherpad(isPresentation);
  133. });
  134. /**
  135. * Resizes the etherpad, when the window is resized.
  136. */
  137. $(window).resize(function () {
  138. resize();
  139. });
  140. return my;
  141. }(Etherpad || {}));