Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

etherpad.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. // TODO FIX large video and prezi toggling. Too many calls from different places.
  30. var largeVideo = null;
  31. if (isPresentationVisible())
  32. largeVideo = $('#presentation>iframe');
  33. else
  34. largeVideo = $('#largeVideo');
  35. if ($('#etherpad>iframe').css('visibility') === 'hidden') {
  36. largeVideo.fadeOut(300, function () {
  37. if (isPresentationVisible())
  38. largeVideo.css({opacity:'0'});
  39. else
  40. largeVideo.css({visibility:'hidden'});
  41. $('#etherpad>iframe').fadeIn(300, function() {
  42. $('#etherpad>iframe').css({visibility:'visible'});
  43. $('#etherpad').css({zIndex:2});
  44. });
  45. });
  46. }
  47. else if ($('#etherpad>iframe')) {
  48. $('#etherpad>iframe').fadeOut(300, function () {
  49. $('#etherpad>iframe').css({visibility:'hidden'});
  50. $('#etherpad').css({zIndex:0});
  51. if (!isPresentation) {
  52. $('#largeVideo').fadeIn(300, function() {
  53. $('#largeVideo').css({visibility:'visible'});
  54. });
  55. }
  56. });
  57. }
  58. };
  59. /**
  60. * Shares the Etherpad name with other participants.
  61. */
  62. function shareEtherpad() {
  63. connection.emuc.addEtherpadToPresence(etherpadName);
  64. connection.emuc.sendPresence();
  65. }
  66. /**
  67. * Creates the Etherpad button and adds it to the toolbar.
  68. */
  69. function enableEtherpadButton() {
  70. if (!$('#etherpadButton').is(":visible"))
  71. $('#etherpadButton').css({display:'inline-block'});
  72. }
  73. /**
  74. * Creates the IFrame for the etherpad.
  75. */
  76. function createIFrame() {
  77. etherpadIFrame = document.createElement('iframe');
  78. etherpadIFrame.src = domain + etherpadName + options;
  79. etherpadIFrame.frameBorder = 0;
  80. etherpadIFrame.scrolling = "no";
  81. etherpadIFrame.width = $('#largeVideoContainer').width() || 640;
  82. etherpadIFrame.height = $('#largeVideoContainer').height() || 480;
  83. etherpadIFrame.setAttribute('style', 'visibility: hidden;');
  84. document.getElementById('etherpad').appendChild(etherpadIFrame);
  85. }
  86. /**
  87. * On Etherpad added to muc.
  88. */
  89. $(document).bind('etherpadadded.muc', function (event, jid, etherpadName) {
  90. console.log("Etherpad added", etherpadName);
  91. if (config.etherpad_base && !focus) {
  92. Etherpad.init(etherpadName);
  93. }
  94. });
  95. /**
  96. * On focus changed event.
  97. */
  98. $(document).bind('focusechanged.muc', function (event, focus) {
  99. console.log("Focus changed");
  100. if (config.etherpad_base)
  101. shareEtherpad();
  102. });
  103. /**
  104. * On video selected event.
  105. */
  106. $(document).bind('video.selected', function (event, isPresentation) {
  107. if (!config.etherpad_base)
  108. return;
  109. if (etherpadIFrame && etherpadIFrame.style.visibility !== 'hidden')
  110. Etherpad.toggleEtherpad(isPresentation);
  111. });
  112. return my;
  113. }(Etherpad || {}));