src/js/widgets/slideShareWidget.js
changeset 869 faae5df935de
parent 862 71d80cda96de
child 871 a5607fa1ef0b
equal deleted inserted replaced
867:43f615b4dc48 869:faae5df935de
    19   
    19   
    20   // global variables used to keep the position and width of the zone.  
    20   // global variables used to keep the position and width of the zone.  
    21   this.zoneLeft = 0;
    21   this.zoneLeft = 0;
    22   this.zoneWidth = 0;
    22   this.zoneWidth = 0;
    23   // global variable to save the last slide url
    23   // global variable to save the last slide url
    24   this.lastSlide = "";
    24   this.lastSSFullUrl = "";
       
    25   this.lastSSUrl = "";
       
    26   this.lastSSId = "";
    25   this.containerDiv = this.selector.find('.SlideShareContainer');
    27   this.containerDiv = this.selector.find('.SlideShareContainer');
    26   
    28   
    27   // Update the slide from timeupdate event
    29   // Update the slide from timeupdate event
    28   this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.slideShareUpdater));
    30   this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.slideShareUpdater));
    29   
    31   
    64   var found = false;
    66   var found = false;
    65   for (i = 0; i < nb_slides; i++) {
    67   for (i = 0; i < nb_slides; i++) {
    66     var segment_slide = this.segments_slides[i];
    68     var segment_slide = this.segments_slides[i];
    67     if(segment_slide.begin<time && time<segment_slide.end){
    69     if(segment_slide.begin<time && time<segment_slide.end){
    68     	found = true;
    70     	found = true;
    69     	if(segment_slide.content.description!=this.lastSlide){
    71     	if(segment_slide.content.description!=this.lastSSFullUrl){
    70 			// The url is like http://stuf.com#X and X is the slide number. So we split and save it.
    72 			// 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;
    73     		this.lastSSFullUrl = segment_slide.content.description;
    72     		var description_ar = this.lastSlide.split("#");
    74     		var description_ar = this.lastSSFullUrl.split("#id=");
    73     		console.log("description_ar = " + description_ar);
    75     		var slideNb = 1;
    74     		var slideUrl = description_ar[0];
    76     		if(description_ar[1]){
    75     		var slideNb = description_ar[1];
    77     			slideNb = description_ar[1];
    76     		// We have the slideshare oembed url.
    78     		}
    77     		var url = "http://www.slideshare.net/api/oembed/2?format=jsonp&url=" + slideUrl;
    79     		if(description_ar[0]!=this.lastSSUrl){
    78     		
    80     			this.lastSSUrl = description_ar[0];
    79     		IriSP.jQuery.ajax({
    81 	    		// We have the slideshare oembed url.
    80 				url: url,
    82 	    		var url = "http://www.slideshare.net/api/oembed/1?format=jsonp&url=" + this.lastSSUrl;
    81 				dataType: "jsonp",
    83 	    		
    82 				success: function(data) {
    84 	    		IriSP.jQuery.ajax({
    83 					ss_id = data["slideshow_id"];
    85 					url: url,
    84 					embed_code = data["html"];
    86 					dataType: "jsonp",
    85 					// If slideNb exist, we hack the embed code to add ?startSlide=X
    87 					success: function(data) {
    86 					if(slideNb){
    88 						self.lastSSId = data["slideshow_id"];
    87 						embed_code = embed_code.replace(new RegExp("embed_code/"+ss_id), "embed_code/" + ss_id + "?startSlide=" + slideNb);
    89 						embed_code = data["html"];
       
    90 						// If slideNb exist, we hack the embed code to add ?startSlide=X
       
    91 						if(slideNb){
       
    92 							embed_code = embed_code.replace(new RegExp("ssplayer2.swf\\?","g"), "ssplayer2.swf?startSlide=" + slideNb + "&");
       
    93 						}
       
    94 						self.containerDiv.html(embed_code);
       
    95 					},
       
    96 					error: function(jqXHR, textStatus, errorThrown){
       
    97 						self.containerDiv.html("Error while downloading the slideshow. jqXHR = " + jqXHR + ", textStatus = " + textStatus + ", errorThrown = " + errorThrown);
    88 					}
    98 					}
    89 					self.containerDiv.html(embed_code);
    99 	    		});
    90 				},
   100     		}
    91 				error: function(jqXHR, textStatus, errorThrown){
   101     		else{
    92 					self.containerDiv.html("Error while downloading the slideshow. jqXHR = " + jqXHR + ", textStatus = " + textStatus + ", errorThrown = " + errorThrown);
   102     			// If the presentation was already loaded, we only use the ss js api to load the wanted slide number
    93 				}
   103     			if(this.lastSSId!=""){
    94     		});
   104     				// We get the embed flash element
       
   105     				var embed = document.getElementsByName("__sse" + this.lastSSId)[0];
       
   106     				if(embed){
       
   107     					embed.jumpTo(parseInt(slideNb));
       
   108     				}
       
   109     			}
       
   110     		}
    95     		return;
   111     		return;
    96     	}
   112     	}
    97     }
   113     }
    98   }
   114   }
    99   if(found==false){
   115   if(found==false){
   100   	this.lastSlide = "";
   116 	this.lastSSFullUrl = "";
       
   117 	this.lastSSUrl = "";
       
   118 	this.lastSSId = "";
   101   	this.containerDiv.html("");
   119   	this.containerDiv.html("");
   102   }
   120   }
   103 
   121 
   104 };
   122 };
   105 
   123