|
1 /* TODO: Add Slide synchronization */ |
|
2 |
|
3 IriSP.Widgets.Slideshare = function(player, config) { |
|
4 IriSP.Widgets.Widget.call(this, player, config); |
|
5 }; |
|
6 |
|
7 IriSP.Widgets.Slideshare.prototype = new IriSP.Widgets.Widget(); |
|
8 |
|
9 IriSP.Widgets.Slideshare.prototype.defaults = { |
|
10 annotation_type: "slide", |
|
11 sync: true, |
|
12 }; |
|
13 |
|
14 IriSP.Widgets.Slideshare.prototype.messages = { |
|
15 fr: { |
|
16 slides_ : "Diapositives" |
|
17 }, |
|
18 en: { |
|
19 slides_ : "Slides" |
|
20 } |
|
21 }; |
|
22 |
|
23 IriSP.Widgets.Slideshare.prototype.template = |
|
24 '<div class="Ldt-SlideShare"><h2>{{l10n.slides_}}</h2><hr /><div class="Ldt-SlideShare-Container"></div></div>'; |
|
25 |
|
26 IriSP.Widgets.Slideshare.prototype.draw = function() { |
|
27 |
|
28 function insertSlideshare(_presentation, _slide) { |
|
29 if (_lastEmbedded === _presentation) { |
|
30 if (_embedObject && typeof _embedObject.jumpTo === "function") { |
|
31 _embedObject.jumpTo(parseInt(_slide)); |
|
32 } |
|
33 } else { |
|
34 _lastEmbedded = _presentation; |
|
35 var _id = IriSP.Model.getUID(), |
|
36 _params = { |
|
37 allowScriptAccess: "always" |
|
38 }, |
|
39 _atts = { |
|
40 id: _id |
|
41 }, |
|
42 _flashvars = { |
|
43 doc : _presentation, |
|
44 startSlide : _slide |
|
45 }; |
|
46 $container.html('<div id="' + _id + '"></div>'); |
|
47 swfobject.embedSWF( |
|
48 "http://static.slidesharecdn.com/swf/ssplayer2.swf", |
|
49 _id, |
|
50 _this.embed_width, |
|
51 _this.embed_height, |
|
52 "8", |
|
53 null, |
|
54 _flashvars, |
|
55 _params, |
|
56 _atts |
|
57 ); |
|
58 _embedObject = document.getElementById(_id); |
|
59 } |
|
60 $container.show(); |
|
61 } |
|
62 |
|
63 var _annotations = this.getWidgetAnnotations(); |
|
64 if (!_annotations.length) { |
|
65 this.$.hide(); |
|
66 } else { |
|
67 this.renderTemplate(); |
|
68 var _lastPres = "", |
|
69 _embedObject = null, |
|
70 _oembedCache = {}, |
|
71 _lastEmbedded = "", |
|
72 _this = this, |
|
73 $container = this.$.find(".Ldt-SlideShare-Container"); |
|
74 |
|
75 this.embed_width = this.embed_width || $container.innerWidth(); |
|
76 this.embed_height = this.embed_height || Math.floor(this.embed_width * 3/4); |
|
77 |
|
78 _annotations.forEach(function(_a) { |
|
79 _a.on("leave", function() { |
|
80 $container.hide(); |
|
81 _lastPres = ""; |
|
82 }); |
|
83 _a.on("enter", function() { |
|
84 var _description = _a.description, |
|
85 _isurl = /^https?:\/\//.test(_description), |
|
86 _presentation = _description.replace(/#.*$/,''), |
|
87 _slidematch = _description.match(/(#|\?|&)id=(\d+)/), |
|
88 _slide = parseInt(_slidematch && _slidematch.length > 2 ? _slidematch[2] : 1); |
|
89 if (_presentation !== _lastPres) { |
|
90 if (_isurl) { |
|
91 if (typeof _oembedCache[_presentation] === "undefined") { |
|
92 var _ajaxUrl = "http://www.slideshare.net/api/oembed/1?url=" |
|
93 + encodeURIComponent(_presentation) |
|
94 + "&format=jsonp&callback=?"; |
|
95 IriSP.jQuery.getJSON(_ajaxUrl, function(_oembedData) { |
|
96 var _presmatch = _oembedData.html.match(/doc=([a-z0-9\-_%]+)/i); |
|
97 if (_presmatch && _presmatch.length > 1) { |
|
98 _oembedCache[_presentation] = _presmatch[1]; |
|
99 insertSlideshare(_presmatch[1], _slide); |
|
100 } |
|
101 }); |
|
102 } else { |
|
103 insertSlideshare(_oembedCache[_presentation], _slide); |
|
104 } |
|
105 } else { |
|
106 insertSlideshare(_presentation, _slide); |
|
107 } |
|
108 } |
|
109 if (_this.sync && _embedObject && typeof _embedObject.jumpTo === "function") { |
|
110 _embedObject.jumpTo(parseInt(_slide)); |
|
111 } |
|
112 _lastPres = _presentation; |
|
113 |
|
114 }); |
|
115 }); |
|
116 } |
|
117 }; |