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.

prezi.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. var Prezi = (function (my) {
  2. var preziPlayer = null;
  3. /**
  4. * Reloads the current presentation.
  5. */
  6. my.reloadPresentation = function() {
  7. var iframe = document.getElementById(preziPlayer.options.preziId);
  8. iframe.src = iframe.src;
  9. };
  10. /**
  11. * Shows/hides a presentation.
  12. */
  13. my.setPresentationVisible = function (visible) {
  14. var prezi = $('#presentation>iframe');
  15. if (visible) {
  16. // Trigger the video.selected event to indicate a change in the
  17. // large video.
  18. $(document).trigger("video.selected", [true]);
  19. $('#largeVideo').fadeOut(300);
  20. prezi.fadeIn(300, function() {
  21. prezi.css({opacity:'1'});
  22. ToolbarToggler.dockToolbar(true);
  23. VideoLayout.setLargeVideoVisible(false);
  24. });
  25. $('#activeSpeaker').css('visibility', 'hidden');
  26. }
  27. else {
  28. if (prezi.css('opacity') == '1') {
  29. prezi.fadeOut(300, function () {
  30. prezi.css({opacity:'0'});
  31. $('#reloadPresentation').css({display:'none'});
  32. $('#largeVideo').fadeIn(300, function() {
  33. VideoLayout.setLargeVideoVisible(true);
  34. ToolbarToggler.dockToolbar(false);
  35. });
  36. });
  37. }
  38. }
  39. };
  40. /**
  41. * Returns <tt>true</tt> if the presentation is visible, <tt>false</tt> -
  42. * otherwise.
  43. */
  44. my.isPresentationVisible = function () {
  45. return ($('#presentation>iframe') != null
  46. && $('#presentation>iframe').css('opacity') == 1);
  47. };
  48. /**
  49. * Opens the Prezi dialog, from which the user could choose a presentation
  50. * to load.
  51. */
  52. my.openPreziDialog = function() {
  53. var myprezi = connection.emuc.getPrezi(connection.emuc.myroomjid);
  54. if (myprezi) {
  55. messageHandler.openTwoButtonDialog("Remove Prezi",
  56. "Are you sure you would like to remove your Prezi?",
  57. false,
  58. "Remove",
  59. function(e,v,m,f) {
  60. if(v) {
  61. connection.emuc.removePreziFromPresence();
  62. connection.emuc.sendPresence();
  63. }
  64. }
  65. );
  66. }
  67. else if (preziPlayer != null) {
  68. messageHandler.openTwoButtonDialog("Share a Prezi",
  69. "Another participant is already sharing a Prezi." +
  70. "This conference allows only one Prezi at a time.",
  71. false,
  72. "Ok",
  73. function(e,v,m,f) {
  74. $.prompt.close();
  75. }
  76. );
  77. }
  78. else {
  79. var openPreziState = {
  80. state0: {
  81. html: '<h2>Share a Prezi</h2>' +
  82. '<input id="preziUrl" type="text" ' +
  83. 'placeholder="e.g. ' +
  84. 'http://prezi.com/wz7vhjycl7e6/my-prezi" autofocus>',
  85. persistent: false,
  86. buttons: { "Share": true , "Cancel": false},
  87. defaultButton: 1,
  88. submit: function(e,v,m,f){
  89. e.preventDefault();
  90. if(v)
  91. {
  92. var preziUrl = document.getElementById('preziUrl');
  93. if (preziUrl.value)
  94. {
  95. var urlValue
  96. = encodeURI(Util.escapeHtml(preziUrl.value));
  97. if (urlValue.indexOf('http://prezi.com/') != 0
  98. && urlValue.indexOf('https://prezi.com/') != 0)
  99. {
  100. $.prompt.goToState('state1');
  101. return false;
  102. }
  103. else {
  104. var presIdTmp = urlValue.substring(
  105. urlValue.indexOf("prezi.com/") + 10);
  106. if (!isAlphanumeric(presIdTmp)
  107. || presIdTmp.indexOf('/') < 2) {
  108. $.prompt.goToState('state1');
  109. return false;
  110. }
  111. else {
  112. connection.emuc
  113. .addPreziToPresence(urlValue, 0);
  114. connection.emuc.sendPresence();
  115. $.prompt.close();
  116. }
  117. }
  118. }
  119. }
  120. else
  121. $.prompt.close();
  122. }
  123. },
  124. state1: {
  125. html: '<h2>Share a Prezi</h2>' +
  126. 'Please provide a correct prezi link.',
  127. persistent: false,
  128. buttons: { "Back": true, "Cancel": false },
  129. defaultButton: 1,
  130. submit:function(e,v,m,f) {
  131. e.preventDefault();
  132. if(v==0)
  133. $.prompt.close();
  134. else
  135. $.prompt.goToState('state0');
  136. }
  137. }
  138. };
  139. var focusPreziUrl = function(e) {
  140. document.getElementById('preziUrl').focus();
  141. };
  142. messageHandler.openDialogWithStates(openPreziState, focusPreziUrl, focusPreziUrl);
  143. }
  144. };
  145. /**
  146. * A new presentation has been added.
  147. *
  148. * @param event the event indicating the add of a presentation
  149. * @param jid the jid from which the presentation was added
  150. * @param presUrl url of the presentation
  151. * @param currentSlide the current slide to which we should move
  152. */
  153. var presentationAdded = function(event, jid, presUrl, currentSlide) {
  154. console.log("presentation added", presUrl);
  155. var presId = getPresentationId(presUrl);
  156. var elementId = 'participant_'
  157. + Strophe.getResourceFromJid(jid)
  158. + '_' + presId;
  159. // We explicitly don't specify the peer jid here, because we don't want
  160. // this video to be dealt with as a peer related one (for example we
  161. // don't want to show a mute/kick menu for this one, etc.).
  162. VideoLayout.addRemoteVideoContainer(null, elementId);
  163. VideoLayout.resizeThumbnails();
  164. var controlsEnabled = false;
  165. if (jid === connection.emuc.myroomjid)
  166. controlsEnabled = true;
  167. Prezi.setPresentationVisible(true);
  168. $('#largeVideoContainer').hover(
  169. function (event) {
  170. if (Prezi.isPresentationVisible()) {
  171. var reloadButtonRight = window.innerWidth
  172. - $('#presentation>iframe').offset().left
  173. - $('#presentation>iframe').width();
  174. $('#reloadPresentation').css({ right: reloadButtonRight,
  175. display:'inline-block'});
  176. }
  177. },
  178. function (event) {
  179. if (!Prezi.isPresentationVisible())
  180. $('#reloadPresentation').css({display:'none'});
  181. else {
  182. var e = event.toElement || event.relatedTarget;
  183. if (e && e.id != 'reloadPresentation' && e.id != 'header')
  184. $('#reloadPresentation').css({display:'none'});
  185. }
  186. });
  187. preziPlayer = new PreziPlayer(
  188. 'presentation',
  189. {preziId: presId,
  190. width: getPresentationWidth(),
  191. height: getPresentationHeihgt(),
  192. controls: controlsEnabled,
  193. debug: true
  194. });
  195. $('#presentation>iframe').attr('id', preziPlayer.options.preziId);
  196. preziPlayer.on(PreziPlayer.EVENT_STATUS, function(event) {
  197. console.log("prezi status", event.value);
  198. if (event.value == PreziPlayer.STATUS_CONTENT_READY) {
  199. if (jid != connection.emuc.myroomjid)
  200. preziPlayer.flyToStep(currentSlide);
  201. }
  202. });
  203. preziPlayer.on(PreziPlayer.EVENT_CURRENT_STEP, function(event) {
  204. console.log("event value", event.value);
  205. connection.emuc.addCurrentSlideToPresence(event.value);
  206. connection.emuc.sendPresence();
  207. });
  208. $("#" + elementId).css( 'background-image',
  209. 'url(../images/avatarprezi.png)');
  210. $("#" + elementId).click(
  211. function () {
  212. Prezi.setPresentationVisible(true);
  213. }
  214. );
  215. };
  216. /**
  217. * A presentation has been removed.
  218. *
  219. * @param event the event indicating the remove of a presentation
  220. * @param jid the jid for which the presentation was removed
  221. * @param the url of the presentation
  222. */
  223. var presentationRemoved = function (event, jid, presUrl) {
  224. console.log('presentation removed', presUrl);
  225. var presId = getPresentationId(presUrl);
  226. Prezi.setPresentationVisible(false);
  227. $('#participant_'
  228. + Strophe.getResourceFromJid(jid)
  229. + '_' + presId).remove();
  230. $('#presentation>iframe').remove();
  231. if (preziPlayer != null) {
  232. preziPlayer.destroy();
  233. preziPlayer = null;
  234. }
  235. };
  236. /**
  237. * Indicates if the given string is an alphanumeric string.
  238. * Note that some special characters are also allowed (-, _ , /, &, ?, =, ;) for the
  239. * purpose of checking URIs.
  240. */
  241. function isAlphanumeric(unsafeText) {
  242. var regex = /^[a-z0-9-_\/&\?=;]+$/i;
  243. return regex.test(unsafeText);
  244. }
  245. /**
  246. * Returns the presentation id from the given url.
  247. */
  248. function getPresentationId (presUrl) {
  249. var presIdTmp = presUrl.substring(presUrl.indexOf("prezi.com/") + 10);
  250. return presIdTmp.substring(0, presIdTmp.indexOf('/'));
  251. }
  252. /**
  253. * Returns the presentation width.
  254. */
  255. function getPresentationWidth() {
  256. var availableWidth = Util.getAvailableVideoWidth();
  257. var availableHeight = getPresentationHeihgt();
  258. var aspectRatio = 16.0 / 9.0;
  259. if (availableHeight < availableWidth / aspectRatio) {
  260. availableWidth = Math.floor(availableHeight * aspectRatio);
  261. }
  262. return availableWidth;
  263. }
  264. /**
  265. * Returns the presentation height.
  266. */
  267. function getPresentationHeihgt() {
  268. var remoteVideos = $('#remoteVideos');
  269. return window.innerHeight - remoteVideos.outerHeight();
  270. }
  271. /**
  272. * Resizes the presentation iframe.
  273. */
  274. function resize() {
  275. if ($('#presentation>iframe')) {
  276. $('#presentation>iframe').width(getPresentationWidth());
  277. $('#presentation>iframe').height(getPresentationHeihgt());
  278. }
  279. }
  280. /**
  281. * Presentation has been removed.
  282. */
  283. $(document).bind('presentationremoved.muc', presentationRemoved);
  284. /**
  285. * Presentation has been added.
  286. */
  287. $(document).bind('presentationadded.muc', presentationAdded);
  288. /*
  289. * Indicates presentation slide change.
  290. */
  291. $(document).bind('gotoslide.muc', function (event, jid, presUrl, current) {
  292. if (preziPlayer && preziPlayer.getCurrentStep() != current) {
  293. preziPlayer.flyToStep(current);
  294. var animationStepsArray = preziPlayer.getAnimationCountOnSteps();
  295. for (var i = 0; i < parseInt(animationStepsArray[current]); i++) {
  296. preziPlayer.flyToStep(current, i);
  297. }
  298. }
  299. });
  300. /**
  301. * On video selected event.
  302. */
  303. $(document).bind('video.selected', function (event, isPresentation) {
  304. if (!isPresentation && $('#presentation>iframe')) {
  305. Prezi.setPresentationVisible(false);
  306. }
  307. });
  308. $(window).resize(function () {
  309. resize();
  310. });
  311. return my;
  312. }(Prezi || {}));