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

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