|
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 |
|
|
|
96 |
/* |
|
|
97 |
var url = this.url_proxy; |
|
|
98 |
if(url.search(/\?/)<0){ |
|
|
99 |
url += "?"; |
|
|
100 |
} |
|
|
101 |
url += "&" + this.parameter_name + "=" + this.lastSlide; |
|
|
102 |
|
|
|
103 |
IriSP.jQuery.ajax({ |
|
|
104 |
url: url, |
|
|
105 |
success: function(xml) { |
|
|
106 |
xml = IriSP.jQuery.parseXML(xml); |
|
|
107 |
self.containerDiv.html(xml); |
|
|
108 |
}, |
|
|
109 |
error: function(jqXHR, textStatus, errorThrown){ |
|
|
110 |
self.containerDiv.html("Error while downloading the slideshow. jqXHR = " + jqXHR + ", textStatus = " + textStatus + ", errorThrown = " + errorThrown); |
|
|
111 |
} |
|
|
112 |
}); |
|
|
113 |
|
|
|
114 |
*/ |
|
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
return; |
|
|
119 |
} |
|
|
120 |
} |
|
|
121 |
} |
|
|
122 |
if(found==false){ |
|
|
123 |
this.lastSlide = ""; |
|
|
124 |
this.containerDiv.html(""); |
|
|
125 |
} |
|
|
126 |
|
|
|
127 |
}; |
|
|
128 |
|
|
|
129 |
// Functions to stop or trigger sync between timeupdate event and slides |
|
|
130 |
IriSP.SlideShareWidget.prototype.unSyncHandler = function(params) { |
|
|
131 |
//console.log("slideShare NO SYNC !"); |
|
|
132 |
this._disableUpdate = true; |
|
|
133 |
}; |
|
|
134 |
IriSP.SlideShareWidget.prototype.syncHandler = function(params) { |
|
|
135 |
//console.log("slideShare SYNC PLEASE !"); |
|
|
136 |
this._disableUpdate = false; |
|
|
137 |
}; |
|
|
138 |
|
|
|
139 |
|
|
|
140 |
/** responds to an "IriSP.SlideShareWidget.position" message |
|
|
141 |
@param params an array with the first element being the left distance in |
|
|
142 |
percents and the second element the width of the slice in pixels |
|
|
143 |
*/ |
|
|
144 |
IriSP.SlideShareWidget.prototype.positionSlideShareHandler = function(params) { |
|
|
145 |
//console.log("positionSlideShareHandler"); |
|
|
146 |
}; |
|
|
147 |
|
|
|
148 |
|
|
|
149 |
IriSP.SlideShareWidget.prototype.show = function() { |
|
|
150 |
this.selector.show(); |
|
|
151 |
}; |
|
|
152 |
|
|
|
153 |
IriSP.SlideShareWidget.prototype.hide = function() { |
|
|
154 |
this.selector.hide(); |
|
|
155 |
}; |
|
|
156 |
|
|
|
157 |
|
|
|
158 |
// SHA1ise function |
|
|
159 |
IriSP.SlideShareWidget.prototype.sha1 = function(msg) { |
|
|
160 |
|
|
|
161 |
function rotate_left(n,s) { |
|
|
162 |
var t4 = ( n<<s ) | (n>>>(32-s)); |
|
|
163 |
return t4; |
|
|
164 |
}; |
|
|
165 |
|
|
|
166 |
function lsb_hex(val) { |
|
|
167 |
var str=""; |
|
|
168 |
var i; |
|
|
169 |
var vh; |
|
|
170 |
var vl; |
|
|
171 |
|
|
|
172 |
for( i=0; i<=6; i+=2 ) { |
|
|
173 |
vh = (val>>>(i*4+4))&0x0f; |
|
|
174 |
vl = (val>>>(i*4))&0x0f; |
|
|
175 |
str += vh.toString(16) + vl.toString(16); |
|
|
176 |
} |
|
|
177 |
return str; |
|
|
178 |
}; |
|
|
179 |
|
|
|
180 |
function cvt_hex(val) { |
|
|
181 |
var str=""; |
|
|
182 |
var i; |
|
|
183 |
var v; |
|
|
184 |
|
|
|
185 |
for( i=7; i>=0; i-- ) { |
|
|
186 |
v = (val>>>(i*4))&0x0f; |
|
|
187 |
str += v.toString(16); |
|
|
188 |
} |
|
|
189 |
return str; |
|
|
190 |
}; |
|
|
191 |
|
|
|
192 |
|
|
|
193 |
function Utf8Encode(string) { |
|
|
194 |
string = string.replace(/\r\n/g,"\n"); |
|
|
195 |
var utftext = ""; |
|
|
196 |
|
|
|
197 |
for (var n = 0; n < string.length; n++) { |
|
|
198 |
|
|
|
199 |
var c = string.charCodeAt(n); |
|
|
200 |
|
|
|
201 |
if (c < 128) { |
|
|
202 |
utftext += String.fromCharCode(c); |
|
|
203 |
} |
|
|
204 |
else if((c > 127) && (c < 2048)) { |
|
|
205 |
utftext += String.fromCharCode((c >> 6) | 192); |
|
|
206 |
utftext += String.fromCharCode((c & 63) | 128); |
|
|
207 |
} |
|
|
208 |
else { |
|
|
209 |
utftext += String.fromCharCode((c >> 12) | 224); |
|
|
210 |
utftext += String.fromCharCode(((c >> 6) & 63) | 128); |
|
|
211 |
utftext += String.fromCharCode((c & 63) | 128); |
|
|
212 |
} |
|
|
213 |
|
|
|
214 |
} |
|
|
215 |
|
|
|
216 |
return utftext; |
|
|
217 |
}; |
|
|
218 |
|
|
|
219 |
var blockstart; |
|
|
220 |
var i, j; |
|
|
221 |
var W = new Array(80); |
|
|
222 |
var H0 = 0x67452301; |
|
|
223 |
var H1 = 0xEFCDAB89; |
|
|
224 |
var H2 = 0x98BADCFE; |
|
|
225 |
var H3 = 0x10325476; |
|
|
226 |
var H4 = 0xC3D2E1F0; |
|
|
227 |
var A, B, C, D, E; |
|
|
228 |
var temp; |
|
|
229 |
|
|
|
230 |
msg = Utf8Encode(msg); |
|
|
231 |
|
|
|
232 |
var msg_len = msg.length; |
|
|
233 |
|
|
|
234 |
var word_array = new Array(); |
|
|
235 |
for( i=0; i<msg_len-3; i+=4 ) { |
|
|
236 |
j = msg.charCodeAt(i)<<24 | msg.charCodeAt(i+1)<<16 | |
|
|
237 |
msg.charCodeAt(i+2)<<8 | msg.charCodeAt(i+3); |
|
|
238 |
word_array.push( j ); |
|
|
239 |
} |
|
|
240 |
|
|
|
241 |
switch( msg_len % 4 ) { |
|
|
242 |
case 0: |
|
|
243 |
i = 0x080000000; |
|
|
244 |
break; |
|
|
245 |
case 1: |
|
|
246 |
i = msg.charCodeAt(msg_len-1)<<24 | 0x0800000; |
|
|
247 |
break; |
|
|
248 |
|
|
|
249 |
case 2: |
|
|
250 |
i = msg.charCodeAt(msg_len-2)<<24 | msg.charCodeAt(msg_len-1)<<16 | 0x08000; |
|
|
251 |
break; |
|
|
252 |
|
|
|
253 |
case 3: |
|
|
254 |
i = msg.charCodeAt(msg_len-3)<<24 | msg.charCodeAt(msg_len-2)<<16 | msg.charCodeAt(msg_len-1)<<8 | 0x80; |
|
|
255 |
break; |
|
|
256 |
} |
|
|
257 |
|
|
|
258 |
word_array.push( i ); |
|
|
259 |
|
|
|
260 |
while( (word_array.length % 16) != 14 ) word_array.push( 0 ); |
|
|
261 |
|
|
|
262 |
word_array.push( msg_len>>>29 ); |
|
|
263 |
word_array.push( (msg_len<<3)&0x0ffffffff ); |
|
|
264 |
|
|
|
265 |
|
|
|
266 |
for ( blockstart=0; blockstart<word_array.length; blockstart+=16 ) { |
|
|
267 |
|
|
|
268 |
for( i=0; i<16; i++ ) W[i] = word_array[blockstart+i]; |
|
|
269 |
for( i=16; i<=79; i++ ) W[i] = rotate_left(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1); |
|
|
270 |
|
|
|
271 |
A = H0; |
|
|
272 |
B = H1; |
|
|
273 |
C = H2; |
|
|
274 |
D = H3; |
|
|
275 |
E = H4; |
|
|
276 |
|
|
|
277 |
for( i= 0; i<=19; i++ ) { |
|
|
278 |
temp = (rotate_left(A,5) + ((B&C) | (~B&D)) + E + W[i] + 0x5A827999) & 0x0ffffffff; |
|
|
279 |
E = D; |
|
|
280 |
D = C; |
|
|
281 |
C = rotate_left(B,30); |
|
|
282 |
B = A; |
|
|
283 |
A = temp; |
|
|
284 |
} |
|
|
285 |
|
|
|
286 |
for( i=20; i<=39; i++ ) { |
|
|
287 |
temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff; |
|
|
288 |
E = D; |
|
|
289 |
D = C; |
|
|
290 |
C = rotate_left(B,30); |
|
|
291 |
B = A; |
|
|
292 |
A = temp; |
|
|
293 |
} |
|
|
294 |
|
|
|
295 |
for( i=40; i<=59; i++ ) { |
|
|
296 |
temp = (rotate_left(A,5) + ((B&C) | (B&D) | (C&D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff; |
|
|
297 |
E = D; |
|
|
298 |
D = C; |
|
|
299 |
C = rotate_left(B,30); |
|
|
300 |
B = A; |
|
|
301 |
A = temp; |
|
|
302 |
} |
|
|
303 |
|
|
|
304 |
for( i=60; i<=79; i++ ) { |
|
|
305 |
temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff; |
|
|
306 |
E = D; |
|
|
307 |
D = C; |
|
|
308 |
C = rotate_left(B,30); |
|
|
309 |
B = A; |
|
|
310 |
A = temp; |
|
|
311 |
} |
|
|
312 |
|
|
|
313 |
H0 = (H0 + A) & 0x0ffffffff; |
|
|
314 |
H1 = (H1 + B) & 0x0ffffffff; |
|
|
315 |
H2 = (H2 + C) & 0x0ffffffff; |
|
|
316 |
H3 = (H3 + D) & 0x0ffffffff; |
|
|
317 |
H4 = (H4 + E) & 0x0ffffffff; |
|
|
318 |
|
|
|
319 |
} |
|
|
320 |
|
|
|
321 |
var temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4); |
|
|
322 |
|
|
|
323 |
return temp.toLowerCase(); |
|
|
324 |
|
|
|
325 |
}; |