Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

PreziPlayer.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. (function() {
  2. "use strict";
  3. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  4. window.PreziPlayer = (function() {
  5. PreziPlayer.API_VERSION = 1;
  6. PreziPlayer.CURRENT_STEP = 'currentStep';
  7. PreziPlayer.CURRENT_ANIMATION_STEP = 'currentAnimationStep';
  8. PreziPlayer.CURRENT_OBJECT = 'currentObject';
  9. PreziPlayer.STATUS_LOADING = 'loading';
  10. PreziPlayer.STATUS_READY = 'ready';
  11. PreziPlayer.STATUS_CONTENT_READY = 'contentready';
  12. PreziPlayer.EVENT_CURRENT_STEP = "currentStepChange";
  13. PreziPlayer.EVENT_CURRENT_ANIMATION_STEP = "currentAnimationStepChange";
  14. PreziPlayer.EVENT_CURRENT_OBJECT = "currentObjectChange";
  15. PreziPlayer.EVENT_STATUS = "statusChange";
  16. PreziPlayer.EVENT_PLAYING = "isAutoPlayingChange";
  17. PreziPlayer.EVENT_IS_MOVING = "isMovingChange";
  18. PreziPlayer.domain = "https://prezi.com";
  19. PreziPlayer.path = "/player/";
  20. PreziPlayer.players = {};
  21. PreziPlayer.binded_methods = ['changesHandler'];
  22. PreziPlayer.createMultiplePlayers = function(optionArray){
  23. for(var i=0; i<optionArray.length; i++) {
  24. var optionSet = optionArray[i];
  25. new PreziPlayer(optionSet.id, optionSet);
  26. };
  27. };
  28. PreziPlayer.messageReceived = function(event){
  29. var message, item, player;
  30. try {
  31. message = JSON.parse(event.data);
  32. if (message.id && (player = PreziPlayer.players[message.id])) {
  33. if (player.options.debug === true) {
  34. if (console && console.log)
  35. console.log('received', message);
  36. }
  37. if (message.type === "changes") {
  38. player.changesHandler(message);
  39. }
  40. for (var i = 0; i < player.callbacks.length; i++) {
  41. item = player.callbacks[i];
  42. if (item && message.type === item.event) {
  43. item.callback(message);
  44. }
  45. }
  46. }
  47. } catch (e) { }
  48. };
  49. function PreziPlayer(id, options) {
  50. var params, paramString = "", _this = this;
  51. if (PreziPlayer.players[id]){
  52. PreziPlayer.players[id].destroy();
  53. }
  54. for(var i=0; i<PreziPlayer.binded_methods.length; i++) {
  55. var method_name = PreziPlayer.binded_methods[i];
  56. _this[method_name] = __bind(_this[method_name], _this);
  57. };
  58. options = options || {};
  59. this.options = options;
  60. this.values = {'status': PreziPlayer.STATUS_LOADING};
  61. this.values[PreziPlayer.CURRENT_STEP] = 0;
  62. this.values[PreziPlayer.CURRENT_ANIMATION_STEP] = 0;
  63. this.values[PreziPlayer.CURRENT_OBJECT] = null;
  64. this.callbacks = [];
  65. this.id = id;
  66. this.embedTo = document.getElementById(id);
  67. if (!this.embedTo) {
  68. throw "The element id is not available.";
  69. }
  70. this.iframe = document.createElement('iframe');
  71. params = [
  72. { name: 'oid', value: options.preziId },
  73. { name: 'explorable', value: options.explorable ? 1 : 0 },
  74. { name: 'controls', value: options.controls ? 1 : 0 }
  75. ];
  76. for(var i=0; i<params.length; i++) {
  77. var param = params[i];
  78. paramString += (i===0 ? "?" : "&") + param.name + "=" + param.value;
  79. };
  80. this.iframe.src = PreziPlayer.domain + PreziPlayer.path + paramString;
  81. this.iframe.frameBorder = 0;
  82. this.iframe.scrolling = "no";
  83. this.iframe.width = options.width || 640;
  84. this.iframe.height = options.height || 480;
  85. this.embedTo.innerHTML = '';
  86. // JITSI: IN CASE SOMETHING GOES WRONG.
  87. try {
  88. this.embedTo.appendChild(this.iframe);
  89. }
  90. catch (err) {
  91. console.log("CATCH ERROR");
  92. }
  93. // JITSI: Increase interval from 200 to 500, which fixes prezi
  94. // crashes for us.
  95. this.initPollInterval = setInterval(function(){
  96. _this.sendMessage({'action': 'init'});
  97. }, 500);
  98. PreziPlayer.players[id] = this;
  99. }
  100. PreziPlayer.prototype.changesHandler = function(message) {
  101. var key, value, j, item;
  102. if (this.initPollInterval) {
  103. clearInterval(this.initPollInterval);
  104. this.initPollInterval = false;
  105. }
  106. for (key in message.data) {
  107. if (message.data.hasOwnProperty(key)){
  108. value = message.data[key];
  109. this.values[key] = value;
  110. for (j=0; j<this.callbacks.length; j++) {
  111. item = this.callbacks[j];
  112. if (item && item.event === key + "Change"){
  113. item.callback({type: item.event, value: value});
  114. }
  115. }
  116. }
  117. }
  118. };
  119. PreziPlayer.prototype.destroy = function() {
  120. if (this.initPollInterval) {
  121. clearInterval(this.initPollInterval);
  122. this.initPollInterval = false;
  123. }
  124. this.embedTo.innerHTML = '';
  125. };
  126. PreziPlayer.prototype.sendMessage = function(message) {
  127. if (this.options.debug === true) {
  128. if (console && console.log) console.log('sent', message);
  129. }
  130. message.version = PreziPlayer.API_VERSION;
  131. message.id = this.id;
  132. return this.iframe.contentWindow.postMessage(JSON.stringify(message), '*');
  133. };
  134. PreziPlayer.prototype.nextStep = /* nextStep is DEPRECATED */
  135. PreziPlayer.prototype.flyToNextStep = function() {
  136. return this.sendMessage({
  137. 'action': 'present',
  138. 'data': ['moveToNextStep']
  139. });
  140. };
  141. PreziPlayer.prototype.previousStep = /* previousStep is DEPRECATED */
  142. PreziPlayer.prototype.flyToPreviousStep = function() {
  143. return this.sendMessage({
  144. 'action': 'present',
  145. 'data': ['moveToPrevStep']
  146. });
  147. };
  148. PreziPlayer.prototype.toStep = /* toStep is DEPRECATED */
  149. PreziPlayer.prototype.flyToStep = function(step, animation_step) {
  150. var obj = this;
  151. // check animation_step
  152. if (animation_step > 0 &&
  153. obj.values.animationCountOnSteps &&
  154. obj.values.animationCountOnSteps[step] <= animation_step) {
  155. animation_step = obj.values.animationCountOnSteps[step];
  156. }
  157. // jump to animation steps by calling flyToNextStep()
  158. function doAnimationSteps() {
  159. if (obj.values.isMoving == true) {
  160. setTimeout(doAnimationSteps, 100); // wait until the flight ends
  161. return;
  162. }
  163. while (animation_step-- > 0) {
  164. obj.flyToNextStep(); // do the animation steps
  165. }
  166. }
  167. setTimeout(doAnimationSteps, 200); // 200ms is the internal "reporting" time
  168. // jump to the step
  169. return this.sendMessage({
  170. 'action': 'present',
  171. 'data': ['moveToStep', step]
  172. });
  173. };
  174. PreziPlayer.prototype.toObject = /* toObject is DEPRECATED */
  175. PreziPlayer.prototype.flyToObject = function(objectId) {
  176. return this.sendMessage({
  177. 'action': 'present',
  178. 'data': ['moveToObject', objectId]
  179. });
  180. };
  181. PreziPlayer.prototype.play = function(defaultDelay) {
  182. return this.sendMessage({
  183. 'action': 'present',
  184. 'data': ['startAutoPlay', defaultDelay]
  185. });
  186. };
  187. PreziPlayer.prototype.stop = function() {
  188. return this.sendMessage({
  189. 'action': 'present',
  190. 'data': ['stopAutoPlay']
  191. });
  192. };
  193. PreziPlayer.prototype.pause = function(defaultDelay) {
  194. return this.sendMessage({
  195. 'action': 'present',
  196. 'data': ['pauseAutoPlay', defaultDelay]
  197. });
  198. };
  199. PreziPlayer.prototype.getCurrentStep = function() {
  200. return this.values.currentStep;
  201. };
  202. PreziPlayer.prototype.getCurrentAnimationStep = function() {
  203. return this.values.currentAnimationStep;
  204. };
  205. PreziPlayer.prototype.getCurrentObject = function() {
  206. return this.values.currentObject;
  207. };
  208. PreziPlayer.prototype.getStatus = function() {
  209. return this.values.status;
  210. };
  211. PreziPlayer.prototype.isPlaying = function() {
  212. return this.values.isAutoPlaying;
  213. };
  214. PreziPlayer.prototype.getStepCount = function() {
  215. return this.values.stepCount;
  216. };
  217. PreziPlayer.prototype.getAnimationCountOnSteps = function() {
  218. return this.values.animationCountOnSteps;
  219. };
  220. PreziPlayer.prototype.getTitle = function() {
  221. return this.values.title;
  222. };
  223. PreziPlayer.prototype.setDimensions = function(dims) {
  224. for (var parameter in dims) {
  225. this.iframe[parameter] = dims[parameter];
  226. }
  227. }
  228. PreziPlayer.prototype.getDimensions = function() {
  229. return {
  230. width: parseInt(this.iframe.width, 10),
  231. height: parseInt(this.iframe.height, 10)
  232. }
  233. }
  234. PreziPlayer.prototype.on = function(event, callback) {
  235. this.callbacks.push({
  236. event: event,
  237. callback: callback
  238. });
  239. };
  240. PreziPlayer.prototype.off = function(event, callback) {
  241. var j, item;
  242. if (event === undefined) {
  243. this.callbacks = [];
  244. }
  245. j = this.callbacks.length;
  246. while (j--) {
  247. item = this.callbacks[j];
  248. if (item && item.event === event && (callback === undefined || item.callback === callback)){
  249. this.callbacks.splice(j, 1);
  250. }
  251. }
  252. };
  253. if (window.addEventListener) {
  254. window.addEventListener('message', PreziPlayer.messageReceived, false);
  255. } else {
  256. window.attachEvent('onmessage', PreziPlayer.messageReceived);
  257. }
  258. return PreziPlayer;
  259. })();
  260. })();
  261. module.exports = PreziPlayer;