2015-01-07 14:54:03 +00:00
|
|
|
var ToolbarToggler = require("../toolbars/ToolbarToggler");
|
|
|
|
var UIUtil = require("../util/UIUtil");
|
|
|
|
var VideoLayout = require("../videolayout/VideoLayout");
|
|
|
|
var messageHandler = require("../util/MessageHandler");
|
2015-01-23 12:01:44 +00:00
|
|
|
var PreziPlayer = require("./PreziPlayer");
|
2015-01-07 14:54:03 +00:00
|
|
|
|
|
|
|
var preziPlayer = null;
|
|
|
|
|
2015-07-29 19:39:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows/hides a presentation.
|
|
|
|
*/
|
|
|
|
function setPresentationVisible(visible) {
|
|
|
|
|
|
|
|
if (visible) {
|
|
|
|
VideoLayout.setLargeVideoState("prezi");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
VideoLayout.setLargeVideoState("video");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-07 14:54:03 +00:00
|
|
|
var Prezi = {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reloads the current presentation.
|
|
|
|
*/
|
|
|
|
reloadPresentation: function() {
|
|
|
|
var iframe = document.getElementById(preziPlayer.options.preziId);
|
|
|
|
iframe.src = iframe.src;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns <tt>true</tt> if the presentation is visible, <tt>false</tt> -
|
|
|
|
* otherwise.
|
|
|
|
*/
|
|
|
|
isPresentationVisible: function () {
|
|
|
|
return ($('#presentation>iframe') != null
|
|
|
|
&& $('#presentation>iframe').css('opacity') == 1);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens the Prezi dialog, from which the user could choose a presentation
|
|
|
|
* to load.
|
|
|
|
*/
|
|
|
|
openPreziDialog: function() {
|
2015-01-28 14:35:22 +00:00
|
|
|
var myprezi = APP.xmpp.getPrezi();
|
2015-01-07 14:54:03 +00:00
|
|
|
if (myprezi) {
|
2015-02-20 16:17:46 +00:00
|
|
|
messageHandler.openTwoButtonDialog("dialog.removePreziTitle",
|
2015-02-26 15:35:35 +00:00
|
|
|
null,
|
|
|
|
"dialog.removePreziMsg",
|
|
|
|
null,
|
2015-01-07 14:54:03 +00:00
|
|
|
false,
|
2015-02-20 16:17:46 +00:00
|
|
|
"dialog.Remove",
|
2015-01-07 14:54:03 +00:00
|
|
|
function(e,v,m,f) {
|
|
|
|
if(v) {
|
2015-02-06 12:54:19 +00:00
|
|
|
APP.xmpp.removePreziFromPresence();
|
2015-01-07 14:54:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else if (preziPlayer != null) {
|
2015-02-20 16:17:46 +00:00
|
|
|
messageHandler.openTwoButtonDialog("dialog.sharePreziTitle",
|
2015-02-26 15:35:35 +00:00
|
|
|
null, "dialog.sharePreziMsg",
|
|
|
|
null,
|
2015-01-07 14:54:03 +00:00
|
|
|
false,
|
2015-02-20 16:17:46 +00:00
|
|
|
"dialog.Ok",
|
2015-01-07 14:54:03 +00:00
|
|
|
function(e,v,m,f) {
|
|
|
|
$.prompt.close();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
2015-07-03 09:34:05 +00:00
|
|
|
var html = APP.translation.generateTranslationHTML(
|
2015-02-26 15:35:35 +00:00
|
|
|
"dialog.sharePreziTitle");
|
2015-07-03 09:34:05 +00:00
|
|
|
var cancelButton = APP.translation.generateTranslationHTML(
|
2015-02-26 15:35:35 +00:00
|
|
|
"dialog.Cancel");
|
2015-07-03 09:34:05 +00:00
|
|
|
var shareButton = APP.translation.generateTranslationHTML(
|
2015-02-26 15:35:35 +00:00
|
|
|
"dialog.Share");
|
2015-07-03 09:34:05 +00:00
|
|
|
var backButton = APP.translation.generateTranslationHTML(
|
2015-02-26 15:35:35 +00:00
|
|
|
"dialog.Back");
|
2015-03-10 12:47:47 +00:00
|
|
|
var buttons = [];
|
|
|
|
var buttons1 = [];
|
|
|
|
// Cancel button to both states
|
|
|
|
buttons.push({title: cancelButton, value: false});
|
|
|
|
buttons1.push({title: cancelButton, value: false});
|
|
|
|
// Share button
|
|
|
|
buttons.push({title: shareButton, value: true});
|
|
|
|
// Back button
|
|
|
|
buttons1.push({title: backButton, value: true});
|
2015-07-03 09:34:05 +00:00
|
|
|
var linkError = APP.translation.generateTranslationHTML(
|
2015-02-26 15:35:35 +00:00
|
|
|
"dialog.preziLinkError");
|
2015-03-09 15:50:13 +00:00
|
|
|
var defaultUrl = APP.translation.translateString("defaultPreziLink",
|
|
|
|
{url: "http://prezi.com/wz7vhjycl7e6/my-prezi"});
|
2015-01-07 14:54:03 +00:00
|
|
|
var openPreziState = {
|
|
|
|
state0: {
|
2015-02-20 16:17:46 +00:00
|
|
|
html: '<h2>' + html + '</h2>' +
|
2015-03-11 09:03:32 +00:00
|
|
|
'<input name="preziUrl" type="text" ' +
|
2015-03-09 15:50:13 +00:00
|
|
|
'data-i18n="[placeholder]defaultPreziLink" data-i18n-options=\'' +
|
|
|
|
JSON.stringify({"url": "http://prezi.com/wz7vhjycl7e6/my-prezi"}) +
|
|
|
|
'\' placeholder="' + defaultUrl + '" autofocus>',
|
2015-01-07 14:54:03 +00:00
|
|
|
persistent: false,
|
2015-02-20 16:17:46 +00:00
|
|
|
buttons: buttons,
|
2015-03-11 09:03:32 +00:00
|
|
|
focus: ':input:first',
|
|
|
|
defaultButton: 0,
|
|
|
|
submit: function (e, v, m, f) {
|
2015-01-07 14:54:03 +00:00
|
|
|
e.preventDefault();
|
|
|
|
if(v)
|
|
|
|
{
|
2015-03-11 09:03:32 +00:00
|
|
|
var preziUrl = f.preziUrl;
|
2015-01-07 14:54:03 +00:00
|
|
|
|
2015-03-11 09:03:32 +00:00
|
|
|
if (preziUrl)
|
2015-01-07 14:54:03 +00:00
|
|
|
{
|
|
|
|
var urlValue
|
2015-03-11 09:03:32 +00:00
|
|
|
= encodeURI(UIUtil.escapeHtml(preziUrl));
|
2015-01-07 14:54:03 +00:00
|
|
|
|
|
|
|
if (urlValue.indexOf('http://prezi.com/') != 0
|
|
|
|
&& urlValue.indexOf('https://prezi.com/') != 0)
|
|
|
|
{
|
|
|
|
$.prompt.goToState('state1');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var presIdTmp = urlValue.substring(
|
|
|
|
urlValue.indexOf("prezi.com/") + 10);
|
|
|
|
if (!isAlphanumeric(presIdTmp)
|
|
|
|
|| presIdTmp.indexOf('/') < 2) {
|
|
|
|
$.prompt.goToState('state1');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
2015-02-06 12:54:19 +00:00
|
|
|
APP.xmpp.addToPresence("prezi", urlValue);
|
2015-01-07 14:54:03 +00:00
|
|
|
$.prompt.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
$.prompt.close();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
state1: {
|
2015-02-20 16:17:46 +00:00
|
|
|
html: '<h2>' + html + '</h2>' +
|
|
|
|
linkError,
|
2015-01-07 14:54:03 +00:00
|
|
|
persistent: false,
|
2015-02-20 16:17:46 +00:00
|
|
|
buttons: buttons1,
|
2015-03-11 09:03:32 +00:00
|
|
|
focus: ':input:first',
|
2015-01-07 14:54:03 +00:00
|
|
|
defaultButton: 1,
|
2015-03-11 09:03:32 +00:00
|
|
|
submit: function (e, v, m, f) {
|
2015-01-07 14:54:03 +00:00
|
|
|
e.preventDefault();
|
2015-03-11 09:03:32 +00:00
|
|
|
if (v === 0)
|
2015-01-07 14:54:03 +00:00
|
|
|
$.prompt.close();
|
|
|
|
else
|
|
|
|
$.prompt.goToState('state0');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2015-03-13 12:35:11 +00:00
|
|
|
messageHandler.openDialogWithStates(openPreziState);
|
2015-01-07 14:54:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A new presentation has been added.
|
|
|
|
*
|
|
|
|
* @param event the event indicating the add of a presentation
|
|
|
|
* @param jid the jid from which the presentation was added
|
|
|
|
* @param presUrl url of the presentation
|
|
|
|
* @param currentSlide the current slide to which we should move
|
|
|
|
*/
|
|
|
|
function presentationAdded(event, jid, presUrl, currentSlide) {
|
|
|
|
console.log("presentation added", presUrl);
|
|
|
|
|
|
|
|
var presId = getPresentationId(presUrl);
|
|
|
|
|
|
|
|
var elementId = 'participant_'
|
|
|
|
+ Strophe.getResourceFromJid(jid)
|
|
|
|
+ '_' + presId;
|
|
|
|
|
2015-06-23 08:00:46 +00:00
|
|
|
VideoLayout.addPreziContainer(elementId);
|
2015-01-07 14:54:03 +00:00
|
|
|
|
|
|
|
var controlsEnabled = false;
|
2015-02-06 12:54:19 +00:00
|
|
|
if (jid === APP.xmpp.myJid())
|
2015-01-07 14:54:03 +00:00
|
|
|
controlsEnabled = true;
|
|
|
|
|
|
|
|
setPresentationVisible(true);
|
2015-07-29 19:39:09 +00:00
|
|
|
VideoLayout.setLargeVideoHover(
|
2015-01-07 14:54:03 +00:00
|
|
|
function (event) {
|
|
|
|
if (Prezi.isPresentationVisible()) {
|
|
|
|
var reloadButtonRight = window.innerWidth
|
|
|
|
- $('#presentation>iframe').offset().left
|
|
|
|
- $('#presentation>iframe').width();
|
|
|
|
|
|
|
|
$('#reloadPresentation').css({ right: reloadButtonRight,
|
|
|
|
display:'inline-block'});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function (event) {
|
|
|
|
if (!Prezi.isPresentationVisible())
|
|
|
|
$('#reloadPresentation').css({display:'none'});
|
|
|
|
else {
|
|
|
|
var e = event.toElement || event.relatedTarget;
|
|
|
|
|
|
|
|
if (e && e.id != 'reloadPresentation' && e.id != 'header')
|
|
|
|
$('#reloadPresentation').css({display:'none'});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
preziPlayer = new PreziPlayer(
|
|
|
|
'presentation',
|
|
|
|
{preziId: presId,
|
|
|
|
width: getPresentationWidth(),
|
|
|
|
height: getPresentationHeihgt(),
|
|
|
|
controls: controlsEnabled,
|
|
|
|
debug: true
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#presentation>iframe').attr('id', preziPlayer.options.preziId);
|
|
|
|
|
|
|
|
preziPlayer.on(PreziPlayer.EVENT_STATUS, function(event) {
|
|
|
|
console.log("prezi status", event.value);
|
|
|
|
if (event.value == PreziPlayer.STATUS_CONTENT_READY) {
|
2015-02-06 12:54:19 +00:00
|
|
|
if (jid != APP.xmpp.myJid())
|
2015-01-07 14:54:03 +00:00
|
|
|
preziPlayer.flyToStep(currentSlide);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
preziPlayer.on(PreziPlayer.EVENT_CURRENT_STEP, function(event) {
|
|
|
|
console.log("event value", event.value);
|
2015-01-28 14:35:22 +00:00
|
|
|
APP.xmpp.addToPresence("preziSlide", event.value);
|
2015-01-07 14:54:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$("#" + elementId).css( 'background-image',
|
|
|
|
'url(../images/avatarprezi.png)');
|
|
|
|
$("#" + elementId).click(
|
|
|
|
function () {
|
|
|
|
setPresentationVisible(true);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A presentation has been removed.
|
|
|
|
*
|
|
|
|
* @param event the event indicating the remove of a presentation
|
|
|
|
* @param jid the jid for which the presentation was removed
|
|
|
|
* @param the url of the presentation
|
|
|
|
*/
|
|
|
|
function presentationRemoved(event, jid, presUrl) {
|
|
|
|
console.log('presentation removed', presUrl);
|
|
|
|
var presId = getPresentationId(presUrl);
|
|
|
|
setPresentationVisible(false);
|
|
|
|
$('#participant_'
|
|
|
|
+ Strophe.getResourceFromJid(jid)
|
|
|
|
+ '_' + presId).remove();
|
|
|
|
$('#presentation>iframe').remove();
|
|
|
|
if (preziPlayer != null) {
|
|
|
|
preziPlayer.destroy();
|
|
|
|
preziPlayer = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates if the given string is an alphanumeric string.
|
|
|
|
* Note that some special characters are also allowed (-, _ , /, &, ?, =, ;) for the
|
|
|
|
* purpose of checking URIs.
|
|
|
|
*/
|
|
|
|
function isAlphanumeric(unsafeText) {
|
|
|
|
var regex = /^[a-z0-9-_\/&\?=;]+$/i;
|
|
|
|
return regex.test(unsafeText);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the presentation id from the given url.
|
|
|
|
*/
|
|
|
|
function getPresentationId (presUrl) {
|
|
|
|
var presIdTmp = presUrl.substring(presUrl.indexOf("prezi.com/") + 10);
|
|
|
|
return presIdTmp.substring(0, presIdTmp.indexOf('/'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the presentation width.
|
|
|
|
*/
|
|
|
|
function getPresentationWidth() {
|
|
|
|
var availableWidth = UIUtil.getAvailableVideoWidth();
|
|
|
|
var availableHeight = getPresentationHeihgt();
|
|
|
|
|
|
|
|
var aspectRatio = 16.0 / 9.0;
|
|
|
|
if (availableHeight < availableWidth / aspectRatio) {
|
|
|
|
availableWidth = Math.floor(availableHeight * aspectRatio);
|
|
|
|
}
|
|
|
|
return availableWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the presentation height.
|
|
|
|
*/
|
|
|
|
function getPresentationHeihgt() {
|
|
|
|
var remoteVideos = $('#remoteVideos');
|
|
|
|
return window.innerHeight - remoteVideos.outerHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resizes the presentation iframe.
|
|
|
|
*/
|
|
|
|
function resize() {
|
|
|
|
if ($('#presentation>iframe')) {
|
|
|
|
$('#presentation>iframe').width(getPresentationWidth());
|
|
|
|
$('#presentation>iframe').height(getPresentationHeihgt());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Presentation has been removed.
|
|
|
|
*/
|
|
|
|
$(document).bind('presentationremoved.muc', presentationRemoved);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Presentation has been added.
|
|
|
|
*/
|
|
|
|
$(document).bind('presentationadded.muc', presentationAdded);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Indicates presentation slide change.
|
|
|
|
*/
|
|
|
|
$(document).bind('gotoslide.muc', function (event, jid, presUrl, current) {
|
|
|
|
if (preziPlayer && preziPlayer.getCurrentStep() != current) {
|
|
|
|
preziPlayer.flyToStep(current);
|
|
|
|
|
|
|
|
var animationStepsArray = preziPlayer.getAnimationCountOnSteps();
|
|
|
|
for (var i = 0; i < parseInt(animationStepsArray[current]); i++) {
|
|
|
|
preziPlayer.flyToStep(current, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$(window).resize(function () {
|
|
|
|
resize();
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Prezi;
|