update SlideShareWidget with the new private embed.
authorcavaliet
Tue, 24 Apr 2012 12:08:47 +0200
changeset 877 2e9467422f64
parent 873 a6602ce57aca
child 878 c983360f0e7a
update SlideShareWidget with the new private embed.
src/js/widgets/slideShareWidget.js
--- a/src/js/widgets/slideShareWidget.js	Fri Apr 20 14:04:52 2012 +0200
+++ b/src/js/widgets/slideShareWidget.js	Tue Apr 24 12:08:47 2012 +0200
@@ -69,56 +69,73 @@
   // We search if a segments_slides is in the current timecode
   var time = this._Popcorn.currentTime() * 1000;
   var nb_slides = this.segments_slides.length;
-  var found = false;
+  var forceEmpty = false;
   for (i = 0; i < nb_slides; i++) {
     var segment_slide = this.segments_slides[i];
     if(segment_slide.begin<time && time<segment_slide.end){
-    	found = true;
     	if(segment_slide.content.description!=this.lastSSFullUrl){
 			// The url is like http://stuf.com#X and X is the slide number. So we split and save it.
     		this.lastSSFullUrl = segment_slide.content.description;
-    		var description_ar = this.lastSSFullUrl.split("#id=");
-    		var slideNb = 1;
-    		if(description_ar[1]){
-    			slideNb = description_ar[1];
-    		}
-    		if(description_ar[0]!=this.lastSSUrl){
-    			this.lastSSUrl = description_ar[0];
-	    		// We have the slideshare oembed url.
-	    		var url = "http://www.slideshare.net/api/oembed/1?format=jsonp&url=" + this.lastSSUrl;
-	    		
-	    		IriSP.jQuery.ajax({
-					url: url,
-					dataType: "jsonp",
-					success: function(data) {
-						self.lastSSId = data["slideshow_id"];
-						embed_code = data["html"];
-						// If slideNb exist, we hack the embed code to add ?startSlide=X
-						if(slideNb){
-							embed_code = embed_code.replace(new RegExp("ssplayer2.swf\\?","g"), "ssplayer2.swf?startSlide=" + slideNb + "&");
-						}
-						self.containerDiv.html(embed_code);
-					},
-					error: function(jqXHR, textStatus, errorThrown){
-						self.containerDiv.html("Error while downloading the slideshow. jqXHR = " + jqXHR + ", textStatus = " + textStatus + ", errorThrown = " + errorThrown);
-					}
-	    		});
+    		if(this.lastSSFullUrl==""){
+    			// We force unload
+    			forceEmpty = true;
     		}
     		else{
-    			// If the presentation was already loaded, we only use the ss js api to load the wanted slide number
-    			if(this.lastSSId!=""){
-    				// We get the embed flash element
-    				var embed = document.getElementsByName("__sse" + this.lastSSId)[0];
-    				if(embed){
-    					embed.jumpTo(parseInt(slideNb));
-    				}
-    			}
+	    		var description_ar = this.lastSSFullUrl.split("#id=");
+	    		var slideNb = 1;
+	    		if(description_ar[1]){
+	    			slideNb = description_ar[1];
+	    		}
+	    		if(description_ar[0]!=this.lastSSUrl && description_ar[0].substring(0,7)=="http://"){
+	    			this.lastSSUrl = description_ar[0];
+		    		// We have the slideshare oembed url (version 1 because we want the flash embed).
+		    		var url = "http://www.slideshare.net/api/oembed/1?format=jsonp&url=" + this.lastSSUrl;
+		    		
+		    		IriSP.jQuery.ajax({
+						url: url,
+						dataType: "jsonp",
+						success: function(data) {
+							self.lastSSId = data["slideshow_id"];
+							embed_code = data["html"];
+							// If slideNb exist, we hack the embed code to add ?startSlide=X
+							if(slideNb){
+								embed_code = embed_code.replace(new RegExp("ssplayer2.swf\\?","g"), "ssplayer2.swf?startSlide=" + slideNb + "&");
+							}
+							self.containerDiv.html(embed_code);
+						},
+						error: function(jqXHR, textStatus, errorThrown){
+							self.containerDiv.html("Error while downloading the slideshow. jqXHR = " + jqXHR + ", textStatus = " + textStatus + ", errorThrown = " + errorThrown);
+						}
+		    		});
+	    		}
+	    		else if(description_ar[0]!=this.lastSSUrl){
+	    			this.lastSSUrl = description_ar[0];
+	    			this.lastSSId = "";
+		    		// In this case, we only have an id that is meant to build the flash embed
+					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>';
+					self.containerDiv.html(embed_code);
+	    		}
+	    		else{
+	    			// If the presentation was already loaded, we only use the ss js api to load the wanted slide number
+	    			var embed = null;
+	    			if(this.lastSSId!=""){
+	    				// If the presentation was loaded from a public url, we get the div from its id.
+						embed = document.getElementsByName("__sse" + this.lastSSId)[0];
+	    			}
+	    			else if(this.lastSSUrl.substring(0,7)!="http://"){
+	    				// If the presentation was loaded from a private id, we get the div from dom tree.
+	    				embed = this.containerDiv.children()[0].children[0];
+	    			}
+					if(embed){
+						embed.jumpTo(parseInt(slideNb));
+					}
+	    		}
+	    		return;
     		}
-    		return;
     	}
     }
   }
-  if(found==false){
+  if(forceEmpty==true){
 	this.lastSSFullUrl = "";
 	this.lastSSUrl = "";
 	this.lastSSId = "";