|
861
|
1 |
|
|
|
2 |
/** A widget to display slide show from embed slide share */ |
|
|
3 |
IriSP.SlideShareWidget = function(Popcorn, config, Serializer) { |
|
|
4 |
IriSP.Widget.call(this, Popcorn, config, Serializer); |
|
|
5 |
}; |
|
|
6 |
|
|
|
7 |
IriSP.SlideShareWidget.prototype = new IriSP.Widget(); |
|
|
8 |
|
|
|
9 |
IriSP.SlideShareWidget.prototype.draw = function() { |
|
|
10 |
var self = this; |
|
|
11 |
|
|
|
12 |
var templ = Mustache.to_html(IriSP.slideShareWidget_template); |
|
|
13 |
this.selector.append(templ); |
|
|
14 |
|
|
|
15 |
// Synchro management |
|
|
16 |
this._disableUpdate = false; |
|
|
17 |
this.selector.find('.sync_on').click(function(event) { self.syncHandler.call(self, event); }); |
|
|
18 |
this.selector.find('.sync_off').click(function(event) { self.unSyncHandler.call(self, event); }); |
|
|
19 |
|
|
|
20 |
// global variables used to keep the position and width of the zone. |
|
|
21 |
this.zoneLeft = 0; |
|
|
22 |
this.zoneWidth = 0; |
|
|
23 |
// global variable to save the last slide url |
|
|
24 |
this.lastSlide = ""; |
|
|
25 |
this.containerDiv = this.selector.find('.SlideShareContainer'); |
|
|
26 |
|
|
|
27 |
// Update the slide from timeupdate event |
|
|
28 |
this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.slideShareUpdater)); |
|
|
29 |
|
|
|
30 |
this._Popcorn.listen("IriSP.SlideShareWidget.show", IriSP.wrap(this, this.show)); |
|
|
31 |
this._Popcorn.listen("IriSP.SlideShareWidget.hide", IriSP.wrap(this, this.hide)); |
|
|
32 |
|
|
|
33 |
// Get data from "slideshare" cutting/annotation-type |
|
|
34 |
var annotations = this._serializer._data.annotations; |
|
|
35 |
var view_type = this._serializer.getSlideShareType(); |
|
|
36 |
if(typeof(view_type) === "undefined") { |
|
|
37 |
return; |
|
|
38 |
} |
|
|
39 |
var i = 0; |
|
|
40 |
this.segments_slides = []; |
|
|
41 |
var nb_annot = annotations.length; |
|
|
42 |
for (i = 0; i < nb_annot; i++) { |
|
|
43 |
var annotation = annotations[i]; |
|
|
44 |
/* filter the annotations whose type is not the one we want */ |
|
|
45 |
if (view_type != "" && typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined" |
|
|
46 |
&& annotation.meta["id-ref"] != view_type) { |
|
|
47 |
continue; |
|
|
48 |
} |
|
|
49 |
this.segments_slides.push(annotation); |
|
|
50 |
} |
|
|
51 |
}; |
|
|
52 |
|
|
|
53 |
/* update the slider and the position marker as time passes */ |
|
|
54 |
IriSP.SlideShareWidget.prototype.slideShareUpdater = function() { |
|
|
55 |
// If it is asked not to synchronize, we do nothing |
|
|
56 |
if(this._disableUpdate) |
|
|
57 |
return; |
|
|
58 |
|
|
|
59 |
var self = this; |
|
|
60 |
|
|
|
61 |
// We search if a segments_slides is in the current timecode |
|
|
62 |
var time = this._Popcorn.currentTime() * 1000; |
|
|
63 |
var nb_slides = this.segments_slides.length; |
|
|
64 |
var found = false; |
|
|
65 |
for (i = 0; i < nb_slides; i++) { |
|
|
66 |
var segment_slide = this.segments_slides[i]; |
|
|
67 |
if(segment_slide.begin<time && time<segment_slide.end){ |
|
|
68 |
found = true; |
|
|
69 |
if(segment_slide.content.description!=this.lastSlide){ |
|
|
70 |
// The url is like http://stuf.com#X and X is the slide number. So we split and save it. |
|
|
71 |
this.lastSlide = segment_slide.content.description; |
|
|
72 |
var description_ar = this.lastSlide.split("#"); |
|
|
73 |
console.log("description_ar = " + description_ar); |
|
|
74 |
var slideUrl = description_ar[0]; |
|
|
75 |
var slideNb = description_ar[1]; |
|
|
76 |
// We have the slideshare oembed url. |
|
|
77 |
var url = "http://www.slideshare.net/api/oembed/2?format=jsonp&url=" + slideUrl; |
|
|
78 |
|
|
|
79 |
IriSP.jQuery.ajax({ |
|
|
80 |
url: url, |
|
|
81 |
dataType: "jsonp", |
|
|
82 |
success: function(data) { |
|
|
83 |
ss_id = data["slideshow_id"]; |
|
|
84 |
embed_code = data["html"]; |
|
|
85 |
// If slideNb exist, we hack the embed code to add ?startSlide=X |
|
|
86 |
if(slideNb){ |
|
|
87 |
embed_code = embed_code.replace(new RegExp("embed_code/"+ss_id), "embed_code/" + ss_id + "?startSlide=" + slideNb); |
|
|
88 |
} |
|
|
89 |
self.containerDiv.html(embed_code); |
|
|
90 |
}, |
|
|
91 |
error: function(jqXHR, textStatus, errorThrown){ |
|
|
92 |
self.containerDiv.html("Error while downloading the slideshow. jqXHR = " + jqXHR + ", textStatus = " + textStatus + ", errorThrown = " + errorThrown); |
|
|
93 |
} |
|
|
94 |
}); |
|
|
95 |
return; |
|
|
96 |
} |
|
|
97 |
} |
|
|
98 |
} |
|
|
99 |
if(found==false){ |
|
|
100 |
this.lastSlide = ""; |
|
|
101 |
this.containerDiv.html(""); |
|
|
102 |
} |
|
|
103 |
|
|
|
104 |
}; |
|
|
105 |
|
|
|
106 |
// Functions to stop or trigger sync between timeupdate event and slides |
|
|
107 |
IriSP.SlideShareWidget.prototype.unSyncHandler = function(params) { |
|
|
108 |
//console.log("slideShare NO SYNC !"); |
|
|
109 |
this._disableUpdate = true; |
|
|
110 |
}; |
|
|
111 |
IriSP.SlideShareWidget.prototype.syncHandler = function(params) { |
|
|
112 |
//console.log("slideShare SYNC PLEASE !"); |
|
|
113 |
this._disableUpdate = false; |
|
|
114 |
}; |
|
|
115 |
|
|
|
116 |
|
|
|
117 |
/** responds to an "IriSP.SlideShareWidget.position" message |
|
|
118 |
@param params an array with the first element being the left distance in |
|
|
119 |
percents and the second element the width of the slice in pixels |
|
|
120 |
*/ |
|
|
121 |
IriSP.SlideShareWidget.prototype.positionSlideShareHandler = function(params) { |
|
|
122 |
//console.log("positionSlideShareHandler"); |
|
|
123 |
}; |
|
|
124 |
|
|
|
125 |
|
|
|
126 |
IriSP.SlideShareWidget.prototype.show = function() { |
|
|
127 |
this.selector.show(); |
|
|
128 |
}; |
|
|
129 |
|
|
|
130 |
IriSP.SlideShareWidget.prototype.hide = function() { |
|
|
131 |
this.selector.hide(); |
|
|
132 |
}; |