| author | cavaliet |
| Tue, 24 Apr 2012 12:08:47 +0200 | |
| changeset 877 | 2e9467422f64 |
| parent 871 | a5607fa1ef0b |
| child 878 | c983360f0e7a |
| permissions | -rw-r--r-- |
| 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 |
|
|
|
871
a5607fa1ef0b
Enhance SlideShare widget for it to point the a specified div (like annotationListWidget).
cavaliet
parents:
869
diff
changeset
|
12 |
// If the div supposed to host the slides does not exist, we cancel |
|
a5607fa1ef0b
Enhance SlideShare widget for it to point the a specified div (like annotationListWidget).
cavaliet
parents:
869
diff
changeset
|
13 |
if(this.selector.length==0){ |
|
a5607fa1ef0b
Enhance SlideShare widget for it to point the a specified div (like annotationListWidget).
cavaliet
parents:
869
diff
changeset
|
14 |
if(console){ if(console.log){ console.log("No div for slideshare widget, this widget is canceled. id = " + this._id); } } |
|
a5607fa1ef0b
Enhance SlideShare widget for it to point the a specified div (like annotationListWidget).
cavaliet
parents:
869
diff
changeset
|
15 |
return; |
|
a5607fa1ef0b
Enhance SlideShare widget for it to point the a specified div (like annotationListWidget).
cavaliet
parents:
869
diff
changeset
|
16 |
} |
| 861 | 17 |
var templ = Mustache.to_html(IriSP.slideShareWidget_template); |
|
871
a5607fa1ef0b
Enhance SlideShare widget for it to point the a specified div (like annotationListWidget).
cavaliet
parents:
869
diff
changeset
|
18 |
this.selector.html(templ); |
| 861 | 19 |
|
20 |
// Synchro management |
|
21 |
this._disableUpdate = false; |
|
22 |
this.selector.find('.sync_on').click(function(event) { self.syncHandler.call(self, event); }); |
|
23 |
this.selector.find('.sync_off').click(function(event) { self.unSyncHandler.call(self, event); }); |
|
24 |
|
|
25 |
// global variables used to keep the position and width of the zone. |
|
26 |
this.zoneLeft = 0; |
|
27 |
this.zoneWidth = 0; |
|
28 |
// global variable to save the last slide url |
|
|
869
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
29 |
this.lastSSFullUrl = ""; |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
30 |
this.lastSSUrl = ""; |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
31 |
this.lastSSId = ""; |
| 861 | 32 |
this.containerDiv = this.selector.find('.SlideShareContainer'); |
33 |
|
|
34 |
// Update the slide from timeupdate event |
|
35 |
this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.slideShareUpdater)); |
|
36 |
|
|
37 |
this._Popcorn.listen("IriSP.SlideShareWidget.show", IriSP.wrap(this, this.show)); |
|
38 |
this._Popcorn.listen("IriSP.SlideShareWidget.hide", IriSP.wrap(this, this.hide)); |
|
39 |
|
|
40 |
// Get data from "slideshare" cutting/annotation-type |
|
41 |
var annotations = this._serializer._data.annotations; |
|
42 |
var view_type = this._serializer.getSlideShareType(); |
|
43 |
if(typeof(view_type) === "undefined") { |
|
|
871
a5607fa1ef0b
Enhance SlideShare widget for it to point the a specified div (like annotationListWidget).
cavaliet
parents:
869
diff
changeset
|
44 |
if(console){ if(console.log){ console.log("No annotation-type for slideshare widget, this widget is canceled."); } } |
|
a5607fa1ef0b
Enhance SlideShare widget for it to point the a specified div (like annotationListWidget).
cavaliet
parents:
869
diff
changeset
|
45 |
return; |
| 861 | 46 |
} |
47 |
var i = 0; |
|
48 |
this.segments_slides = []; |
|
49 |
var nb_annot = annotations.length; |
|
50 |
for (i = 0; i < nb_annot; i++) { |
|
51 |
var annotation = annotations[i]; |
|
52 |
/* filter the annotations whose type is not the one we want */ |
|
53 |
if (view_type != "" && typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined" |
|
54 |
&& annotation.meta["id-ref"] != view_type) { |
|
55 |
continue; |
|
56 |
} |
|
57 |
this.segments_slides.push(annotation); |
|
58 |
} |
|
59 |
}; |
|
60 |
||
61 |
/* update the slider and the position marker as time passes */ |
|
62 |
IriSP.SlideShareWidget.prototype.slideShareUpdater = function() { |
|
63 |
// If it is asked not to synchronize, we do nothing |
|
64 |
if(this._disableUpdate) |
|
65 |
return; |
|
66 |
|
|
67 |
var self = this; |
|
68 |
|
|
69 |
// We search if a segments_slides is in the current timecode |
|
70 |
var time = this._Popcorn.currentTime() * 1000; |
|
71 |
var nb_slides = this.segments_slides.length; |
|
|
877
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
72 |
var forceEmpty = false; |
| 861 | 73 |
for (i = 0; i < nb_slides; i++) { |
74 |
var segment_slide = this.segments_slides[i]; |
|
75 |
if(segment_slide.begin<time && time<segment_slide.end){ |
|
|
869
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
76 |
if(segment_slide.content.description!=this.lastSSFullUrl){ |
| 861 | 77 |
// The url is like http://stuf.com#X and X is the slide number. So we split and save it. |
|
869
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
78 |
this.lastSSFullUrl = segment_slide.content.description; |
|
877
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
79 |
if(this.lastSSFullUrl==""){ |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
80 |
// We force unload |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
81 |
forceEmpty = true; |
|
869
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
82 |
} |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
83 |
else{ |
|
877
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
84 |
var description_ar = this.lastSSFullUrl.split("#id="); |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
85 |
var slideNb = 1; |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
86 |
if(description_ar[1]){ |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
87 |
slideNb = description_ar[1]; |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
88 |
} |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
89 |
if(description_ar[0]!=this.lastSSUrl && description_ar[0].substring(0,7)=="http://"){ |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
90 |
this.lastSSUrl = description_ar[0]; |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
91 |
// We have the slideshare oembed url (version 1 because we want the flash embed). |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
92 |
var url = "http://www.slideshare.net/api/oembed/1?format=jsonp&url=" + this.lastSSUrl; |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
93 |
|
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
94 |
IriSP.jQuery.ajax({ |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
95 |
url: url, |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
96 |
dataType: "jsonp", |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
97 |
success: function(data) { |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
98 |
self.lastSSId = data["slideshow_id"]; |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
99 |
embed_code = data["html"]; |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
100 |
// If slideNb exist, we hack the embed code to add ?startSlide=X |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
101 |
if(slideNb){ |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
102 |
embed_code = embed_code.replace(new RegExp("ssplayer2.swf\\?","g"), "ssplayer2.swf?startSlide=" + slideNb + "&"); |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
103 |
} |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
104 |
self.containerDiv.html(embed_code); |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
105 |
}, |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
106 |
error: function(jqXHR, textStatus, errorThrown){ |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
107 |
self.containerDiv.html("Error while downloading the slideshow. jqXHR = " + jqXHR + ", textStatus = " + textStatus + ", errorThrown = " + errorThrown); |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
108 |
} |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
109 |
}); |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
110 |
} |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
111 |
else if(description_ar[0]!=this.lastSSUrl){ |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
112 |
this.lastSSUrl = description_ar[0]; |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
113 |
this.lastSSId = ""; |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
114 |
// In this case, we only have an id that is meant to build the flash embed |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
115 |
embed_code = '<div style="width:425px"><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=' + this.lastSSUrl + '&startSlide=' + slideNb + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" width="425" height="355"></embed></div>'; |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
116 |
self.containerDiv.html(embed_code); |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
117 |
} |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
118 |
else{ |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
119 |
// If the presentation was already loaded, we only use the ss js api to load the wanted slide number |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
120 |
var embed = null; |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
121 |
if(this.lastSSId!=""){ |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
122 |
// If the presentation was loaded from a public url, we get the div from its id. |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
123 |
embed = document.getElementsByName("__sse" + this.lastSSId)[0]; |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
124 |
} |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
125 |
else if(this.lastSSUrl.substring(0,7)!="http://"){ |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
126 |
// If the presentation was loaded from a private id, we get the div from dom tree. |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
127 |
embed = this.containerDiv.children()[0].children[0]; |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
128 |
} |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
129 |
if(embed){ |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
130 |
embed.jumpTo(parseInt(slideNb)); |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
131 |
} |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
132 |
} |
|
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
133 |
return; |
|
869
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
134 |
} |
| 861 | 135 |
} |
136 |
} |
|
137 |
} |
|
|
877
2e9467422f64
update SlideShareWidget with the new private embed.
cavaliet
parents:
871
diff
changeset
|
138 |
if(forceEmpty==true){ |
|
869
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
139 |
this.lastSSFullUrl = ""; |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
140 |
this.lastSSUrl = ""; |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
141 |
this.lastSSId = ""; |
| 861 | 142 |
this.containerDiv.html(""); |
143 |
} |
|
144 |
||
145 |
}; |
|
146 |
||
147 |
// Functions to stop or trigger sync between timeupdate event and slides |
|
148 |
IriSP.SlideShareWidget.prototype.unSyncHandler = function(params) { |
|
149 |
//console.log("slideShare NO SYNC !"); |
|
150 |
this._disableUpdate = true; |
|
151 |
}; |
|
152 |
IriSP.SlideShareWidget.prototype.syncHandler = function(params) { |
|
153 |
//console.log("slideShare SYNC PLEASE !"); |
|
154 |
this._disableUpdate = false; |
|
155 |
}; |
|
156 |
||
157 |
||
158 |
/** responds to an "IriSP.SlideShareWidget.position" message |
|
159 |
@param params an array with the first element being the left distance in |
|
160 |
percents and the second element the width of the slice in pixels |
|
161 |
*/ |
|
162 |
IriSP.SlideShareWidget.prototype.positionSlideShareHandler = function(params) { |
|
163 |
//console.log("positionSlideShareHandler"); |
|
164 |
}; |
|
165 |
||
166 |
||
167 |
IriSP.SlideShareWidget.prototype.show = function() { |
|
168 |
this.selector.show(); |
|
169 |
}; |
|
170 |
||
171 |
IriSP.SlideShareWidget.prototype.hide = function() { |
|
172 |
this.selector.hide(); |
|
173 |
}; |