You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. createEtherpadButton();
  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 createEtherpadButton() {
  70. //<div class="header_button_separator"></div>
  71. //<a class="button" onclick='Etherpad.openEtherpad("teeest");'>
  72. //<i title="Open shared document" class="fa fa-file-text fa-lg"></i></a>
  73. var separator = document.createElement('div');
  74. separator.className = 'header_button_separator';
  75. var button = document.createElement('a');
  76. button.className = 'button';
  77. button.setAttribute('onclick', 'Etherpad.toggleEtherpad(0);');
  78. var buttonImage = document.createElement('i');
  79. buttonImage.setAttribute('title', 'Open shared document');
  80. buttonImage.className = 'fa fa-file-text fa-lg';
  81. button.appendChild(buttonImage);
  82. var toolbar = document.getElementById('toolbar');
  83. toolbar.insertBefore(button,
  84. toolbar.childNodes[toolbar.childNodes.length - 4]);
  85. toolbar.insertBefore(separator, button);
  86. }
  87. /**
  88. * Creates the IFrame for the etherpad.
  89. */
  90. function createIFrame() {
  91. etherpadIFrame = document.createElement('iframe');
  92. etherpadIFrame.src = domain + etherpadName + options;
  93. etherpadIFrame.frameBorder = 0;
  94. etherpadIFrame.scrolling = "no";
  95. etherpadIFrame.width = $('#largeVideoContainer').width() || 640;
  96. etherpadIFrame.height = $('#largeVideoContainer').height() || 480;
  97. etherpadIFrame.setAttribute('style', 'visibility: hidden;');
  98. document.getElementById('etherpad').appendChild(etherpadIFrame);
  99. }
  100. /**
  101. * On Etherpad added to muc.
  102. */
  103. $(document).bind('etherpadadded.muc', function (event, jid, etherpadName) {
  104. console.log("Etherpad added", etherpadName);
  105. if (config.etherpad_base && !focus) {
  106. Etherpad.init(etherpadName);
  107. }
  108. });
  109. /**
  110. * On focus changed event.
  111. */
  112. $(document).bind('focusechanged.muc', function (event, focus) {
  113. console.log("Focus changed");
  114. if (config.etherpad_base)
  115. shareEtherpad();
  116. });
  117. /**
  118. * On video selected event.
  119. */
  120. $(document).bind('video.selected', function (event, isPresentation) {
  121. if (!config.etherpad_base)
  122. return;
  123. if (etherpadIFrame && etherpadIFrame.style.visibility != 'hidden')
  124. Etherpad.toggleEtherpad(isPresentation);
  125. });
  126. return my;
  127. }(Etherpad || {}));