| author | cavaliet |
| Wed, 18 Apr 2012 13:37:00 +0200 | |
| changeset 869 | faae5df935de |
| parent 862 | 71d80cda96de |
| child 871 | a5607fa1ef0b |
| 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 |
|
|
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 |
|
|
869
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
24 |
this.lastSSFullUrl = ""; |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
25 |
this.lastSSUrl = ""; |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
26 |
this.lastSSId = ""; |
| 861 | 27 |
this.containerDiv = this.selector.find('.SlideShareContainer'); |
28 |
|
|
29 |
// Update the slide from timeupdate event |
|
30 |
this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.slideShareUpdater)); |
|
31 |
|
|
32 |
this._Popcorn.listen("IriSP.SlideShareWidget.show", IriSP.wrap(this, this.show)); |
|
33 |
this._Popcorn.listen("IriSP.SlideShareWidget.hide", IriSP.wrap(this, this.hide)); |
|
34 |
|
|
35 |
// Get data from "slideshare" cutting/annotation-type |
|
36 |
var annotations = this._serializer._data.annotations; |
|
37 |
var view_type = this._serializer.getSlideShareType(); |
|
38 |
if(typeof(view_type) === "undefined") { |
|
39 |
return; |
|
40 |
} |
|
41 |
var i = 0; |
|
42 |
this.segments_slides = []; |
|
43 |
var nb_annot = annotations.length; |
|
44 |
for (i = 0; i < nb_annot; i++) { |
|
45 |
var annotation = annotations[i]; |
|
46 |
/* filter the annotations whose type is not the one we want */ |
|
47 |
if (view_type != "" && typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined" |
|
48 |
&& annotation.meta["id-ref"] != view_type) { |
|
49 |
continue; |
|
50 |
} |
|
51 |
this.segments_slides.push(annotation); |
|
52 |
} |
|
53 |
}; |
|
54 |
||
55 |
/* update the slider and the position marker as time passes */ |
|
56 |
IriSP.SlideShareWidget.prototype.slideShareUpdater = function() { |
|
57 |
// If it is asked not to synchronize, we do nothing |
|
58 |
if(this._disableUpdate) |
|
59 |
return; |
|
60 |
|
|
61 |
var self = this; |
|
62 |
|
|
63 |
// We search if a segments_slides is in the current timecode |
|
64 |
var time = this._Popcorn.currentTime() * 1000; |
|
65 |
var nb_slides = this.segments_slides.length; |
|
66 |
var found = false; |
|
67 |
for (i = 0; i < nb_slides; i++) { |
|
68 |
var segment_slide = this.segments_slides[i]; |
|
69 |
if(segment_slide.begin<time && time<segment_slide.end){ |
|
70 |
found = true; |
|
|
869
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
71 |
if(segment_slide.content.description!=this.lastSSFullUrl){ |
| 861 | 72 |
// 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
|
73 |
this.lastSSFullUrl = segment_slide.content.description; |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
74 |
var description_ar = this.lastSSFullUrl.split("#id="); |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
75 |
var slideNb = 1; |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
76 |
if(description_ar[1]){ |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
77 |
slideNb = description_ar[1]; |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
78 |
} |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
79 |
if(description_ar[0]!=this.lastSSUrl){ |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
80 |
this.lastSSUrl = description_ar[0]; |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
81 |
// We have the slideshare oembed url. |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
82 |
var url = "http://www.slideshare.net/api/oembed/1?format=jsonp&url=" + this.lastSSUrl; |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
83 |
|
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
84 |
IriSP.jQuery.ajax({ |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
85 |
url: url, |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
86 |
dataType: "jsonp", |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
87 |
success: function(data) { |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
88 |
self.lastSSId = data["slideshow_id"]; |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
89 |
embed_code = data["html"]; |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
90 |
// If slideNb exist, we hack the embed code to add ?startSlide=X |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
91 |
if(slideNb){ |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
92 |
embed_code = embed_code.replace(new RegExp("ssplayer2.swf\\?","g"), "ssplayer2.swf?startSlide=" + slideNb + "&"); |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
93 |
} |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
94 |
self.containerDiv.html(embed_code); |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
95 |
}, |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
96 |
error: function(jqXHR, textStatus, errorThrown){ |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
97 |
self.containerDiv.html("Error while downloading the slideshow. jqXHR = " + jqXHR + ", textStatus = " + textStatus + ", errorThrown = " + errorThrown); |
| 861 | 98 |
} |
|
869
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
99 |
}); |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
100 |
} |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
101 |
else{ |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
102 |
// If the presentation was already loaded, we only use the ss js api to load the wanted slide number |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
103 |
if(this.lastSSId!=""){ |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
104 |
// We get the embed flash element |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
105 |
var embed = document.getElementsByName("__sse" + this.lastSSId)[0]; |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
106 |
if(embed){ |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
107 |
embed.jumpTo(parseInt(slideNb)); |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
108 |
} |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
109 |
} |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
110 |
} |
| 861 | 111 |
return; |
112 |
} |
|
113 |
} |
|
114 |
} |
|
115 |
if(found==false){ |
|
|
869
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
116 |
this.lastSSFullUrl = ""; |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
117 |
this.lastSSUrl = ""; |
|
faae5df935de
update slide share widget with flash embed and js slide number control.
cavaliet
parents:
862
diff
changeset
|
118 |
this.lastSSId = ""; |
| 861 | 119 |
this.containerDiv.html(""); |
120 |
} |
|
121 |
||
122 |
}; |
|
123 |
||
124 |
// Functions to stop or trigger sync between timeupdate event and slides |
|
125 |
IriSP.SlideShareWidget.prototype.unSyncHandler = function(params) { |
|
126 |
//console.log("slideShare NO SYNC !"); |
|
127 |
this._disableUpdate = true; |
|
128 |
}; |
|
129 |
IriSP.SlideShareWidget.prototype.syncHandler = function(params) { |
|
130 |
//console.log("slideShare SYNC PLEASE !"); |
|
131 |
this._disableUpdate = false; |
|
132 |
}; |
|
133 |
||
134 |
||
135 |
/** responds to an "IriSP.SlideShareWidget.position" message |
|
136 |
@param params an array with the first element being the left distance in |
|
137 |
percents and the second element the width of the slice in pixels |
|
138 |
*/ |
|
139 |
IriSP.SlideShareWidget.prototype.positionSlideShareHandler = function(params) { |
|
140 |
//console.log("positionSlideShareHandler"); |
|
141 |
}; |
|
142 |
||
143 |
||
144 |
IriSP.SlideShareWidget.prototype.show = function() { |
|
145 |
this.selector.show(); |
|
146 |
}; |
|
147 |
||
148 |
IriSP.SlideShareWidget.prototype.hide = function() { |
|
149 |
this.selector.hide(); |
|
150 |
}; |