選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Prezi.js 11KB

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