2014-04-13 12:30:47 +00:00
|
|
|
/* global $, config, Prezi, Util, connection, setLargeVideoVisible, dockToolbar */
|
2014-02-12 22:24:26 +00:00
|
|
|
var Etherpad = (function (my) {
|
|
|
|
var etherpadName = null;
|
2014-02-13 12:08:56 +00:00
|
|
|
var etherpadIFrame = null;
|
|
|
|
var domain = null;
|
|
|
|
var options = "?showControls=true&showChat=false&showLineNumbers=true&useMonospaceFont=false";
|
2014-02-12 22:24:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the etherpad.
|
|
|
|
*/
|
|
|
|
my.init = function (name) {
|
|
|
|
|
|
|
|
if (config.etherpad_base && !etherpadName) {
|
|
|
|
|
2014-02-13 12:08:56 +00:00
|
|
|
domain = config.etherpad_base;
|
|
|
|
|
2014-02-12 22:24:26 +00:00
|
|
|
if (!name) {
|
|
|
|
// In case we're the focus we generate the name.
|
2014-04-13 12:30:47 +00:00
|
|
|
etherpadName = Math.random().toString(36).substring(7) +
|
|
|
|
'_' + (new Date().getTime()).toString();
|
2014-02-12 22:24:26 +00:00
|
|
|
shareEtherpad();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
etherpadName = name;
|
|
|
|
|
2014-02-19 14:32:22 +00:00
|
|
|
enableEtherpadButton();
|
2014-02-12 22:24:26 +00:00
|
|
|
}
|
2014-02-19 14:32:22 +00:00
|
|
|
};
|
2014-02-12 22:24:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens/hides the Etherpad.
|
|
|
|
*/
|
|
|
|
my.toggleEtherpad = function (isPresentation) {
|
2014-02-13 12:08:56 +00:00
|
|
|
if (!etherpadIFrame)
|
|
|
|
createIFrame();
|
|
|
|
|
2014-02-12 22:24:26 +00:00
|
|
|
var largeVideo = null;
|
2014-03-26 10:33:46 +00:00
|
|
|
if (Prezi.isPresentationVisible())
|
2014-02-12 22:24:26 +00:00
|
|
|
largeVideo = $('#presentation>iframe');
|
|
|
|
else
|
|
|
|
largeVideo = $('#largeVideo');
|
|
|
|
|
2014-03-01 07:39:39 +00:00
|
|
|
if ($('#etherpad>iframe').css('visibility') === 'hidden') {
|
2014-02-12 22:24:26 +00:00
|
|
|
largeVideo.fadeOut(300, function () {
|
2014-04-13 12:30:47 +00:00
|
|
|
if (Prezi.isPresentationVisible()) {
|
|
|
|
largeVideo.css({opacity: '0'});
|
|
|
|
} else {
|
2014-06-12 18:35:42 +00:00
|
|
|
VideoLayout.setLargeVideoVisible(false);
|
2014-09-04 13:18:28 +00:00
|
|
|
ToolbarToggler.dockToolbar(true);
|
2014-03-26 10:33:46 +00:00
|
|
|
}
|
2014-02-12 22:24:26 +00:00
|
|
|
|
2014-04-13 12:30:47 +00:00
|
|
|
$('#etherpad>iframe').fadeIn(300, function () {
|
2014-03-26 10:33:46 +00:00
|
|
|
document.body.style.background = '#eeeeee';
|
2014-04-13 12:30:47 +00:00
|
|
|
$('#etherpad>iframe').css({visibility: 'visible'});
|
|
|
|
$('#etherpad').css({zIndex: 2});
|
2014-02-12 22:24:26 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else if ($('#etherpad>iframe')) {
|
|
|
|
$('#etherpad>iframe').fadeOut(300, function () {
|
2014-04-13 12:30:47 +00:00
|
|
|
$('#etherpad>iframe').css({visibility: 'hidden'});
|
|
|
|
$('#etherpad').css({zIndex: 0});
|
2014-03-26 10:33:46 +00:00
|
|
|
document.body.style.background = 'black';
|
2014-02-12 22:24:26 +00:00
|
|
|
if (!isPresentation) {
|
2014-04-13 12:30:47 +00:00
|
|
|
$('#largeVideo').fadeIn(300, function () {
|
2014-06-12 18:35:42 +00:00
|
|
|
VideoLayout.setLargeVideoVisible(true);
|
2014-09-04 13:18:28 +00:00
|
|
|
ToolbarToggler.dockToolbar(false);
|
2014-02-12 22:24:26 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-03-26 10:33:46 +00:00
|
|
|
resize();
|
2014-02-12 22:24:26 +00:00
|
|
|
};
|
|
|
|
|
2014-03-26 10:33:46 +00:00
|
|
|
/**
|
|
|
|
* Resizes the etherpad.
|
|
|
|
*/
|
|
|
|
function resize() {
|
|
|
|
if ($('#etherpad>iframe').length) {
|
|
|
|
var remoteVideos = $('#remoteVideos');
|
|
|
|
var availableHeight
|
|
|
|
= window.innerHeight - remoteVideos.outerHeight();
|
|
|
|
var availableWidth = Util.getAvailableVideoWidth();
|
|
|
|
|
|
|
|
$('#etherpad>iframe').width(availableWidth);
|
|
|
|
$('#etherpad>iframe').height(availableHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-12 22:24:26 +00:00
|
|
|
/**
|
|
|
|
* Shares the Etherpad name with other participants.
|
|
|
|
*/
|
|
|
|
function shareEtherpad() {
|
|
|
|
connection.emuc.addEtherpadToPresence(etherpadName);
|
|
|
|
connection.emuc.sendPresence();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the Etherpad button and adds it to the toolbar.
|
|
|
|
*/
|
2014-02-19 14:32:22 +00:00
|
|
|
function enableEtherpadButton() {
|
|
|
|
if (!$('#etherpadButton').is(":visible"))
|
2014-04-13 12:30:47 +00:00
|
|
|
$('#etherpadButton').css({display: 'inline-block'});
|
2014-02-12 22:24:26 +00:00
|
|
|
}
|
|
|
|
|
2014-02-13 12:08:56 +00:00
|
|
|
/**
|
|
|
|
* Creates the IFrame for the etherpad.
|
|
|
|
*/
|
|
|
|
function createIFrame() {
|
|
|
|
etherpadIFrame = document.createElement('iframe');
|
|
|
|
etherpadIFrame.src = domain + etherpadName + options;
|
|
|
|
etherpadIFrame.frameBorder = 0;
|
|
|
|
etherpadIFrame.scrolling = "no";
|
|
|
|
etherpadIFrame.width = $('#largeVideoContainer').width() || 640;
|
|
|
|
etherpadIFrame.height = $('#largeVideoContainer').height() || 480;
|
|
|
|
etherpadIFrame.setAttribute('style', 'visibility: hidden;');
|
|
|
|
|
|
|
|
document.getElementById('etherpad').appendChild(etherpadIFrame);
|
|
|
|
}
|
|
|
|
|
2014-02-12 22:24:26 +00:00
|
|
|
/**
|
|
|
|
* On Etherpad added to muc.
|
|
|
|
*/
|
|
|
|
$(document).bind('etherpadadded.muc', function (event, jid, etherpadName) {
|
|
|
|
console.log("Etherpad added", etherpadName);
|
|
|
|
if (config.etherpad_base && !focus) {
|
|
|
|
Etherpad.init(etherpadName);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On focus changed event.
|
|
|
|
*/
|
|
|
|
$(document).bind('focusechanged.muc', function (event, focus) {
|
|
|
|
console.log("Focus changed");
|
|
|
|
if (config.etherpad_base)
|
|
|
|
shareEtherpad();
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On video selected event.
|
|
|
|
*/
|
|
|
|
$(document).bind('video.selected', function (event, isPresentation) {
|
|
|
|
if (!config.etherpad_base)
|
|
|
|
return;
|
|
|
|
|
2014-03-01 07:39:39 +00:00
|
|
|
if (etherpadIFrame && etherpadIFrame.style.visibility !== 'hidden')
|
2014-02-12 22:24:26 +00:00
|
|
|
Etherpad.toggleEtherpad(isPresentation);
|
|
|
|
});
|
|
|
|
|
2014-03-26 10:33:46 +00:00
|
|
|
/**
|
|
|
|
* Resizes the etherpad, when the window is resized.
|
|
|
|
*/
|
|
|
|
$(window).resize(function () {
|
|
|
|
resize();
|
|
|
|
});
|
|
|
|
|
2014-02-12 22:24:26 +00:00
|
|
|
return my;
|
2014-03-01 07:39:39 +00:00
|
|
|
}(Etherpad || {}));
|