src/js/widgets/slideShareWidget.js
changeset 877 2e9467422f64
parent 871 a5607fa1ef0b
child 878 c983360f0e7a
equal deleted inserted replaced
873:a6602ce57aca 877:2e9467422f64
    67   var self = this;
    67   var self = this;
    68   
    68   
    69   // We search if a segments_slides is in the current timecode
    69   // We search if a segments_slides is in the current timecode
    70   var time = this._Popcorn.currentTime() * 1000;
    70   var time = this._Popcorn.currentTime() * 1000;
    71   var nb_slides = this.segments_slides.length;
    71   var nb_slides = this.segments_slides.length;
    72   var found = false;
    72   var forceEmpty = false;
    73   for (i = 0; i < nb_slides; i++) {
    73   for (i = 0; i < nb_slides; i++) {
    74     var segment_slide = this.segments_slides[i];
    74     var segment_slide = this.segments_slides[i];
    75     if(segment_slide.begin<time && time<segment_slide.end){
    75     if(segment_slide.begin<time && time<segment_slide.end){
    76     	found = true;
       
    77     	if(segment_slide.content.description!=this.lastSSFullUrl){
    76     	if(segment_slide.content.description!=this.lastSSFullUrl){
    78 			// The url is like http://stuf.com#X and X is the slide number. So we split and save it.
    77 			// The url is like http://stuf.com#X and X is the slide number. So we split and save it.
    79     		this.lastSSFullUrl = segment_slide.content.description;
    78     		this.lastSSFullUrl = segment_slide.content.description;
    80     		var description_ar = this.lastSSFullUrl.split("#id=");
    79     		if(this.lastSSFullUrl==""){
    81     		var slideNb = 1;
    80     			// We force unload
    82     		if(description_ar[1]){
    81     			forceEmpty = true;
    83     			slideNb = description_ar[1];
       
    84     		}
       
    85     		if(description_ar[0]!=this.lastSSUrl){
       
    86     			this.lastSSUrl = description_ar[0];
       
    87 	    		// We have the slideshare oembed url.
       
    88 	    		var url = "http://www.slideshare.net/api/oembed/1?format=jsonp&url=" + this.lastSSUrl;
       
    89 	    		
       
    90 	    		IriSP.jQuery.ajax({
       
    91 					url: url,
       
    92 					dataType: "jsonp",
       
    93 					success: function(data) {
       
    94 						self.lastSSId = data["slideshow_id"];
       
    95 						embed_code = data["html"];
       
    96 						// If slideNb exist, we hack the embed code to add ?startSlide=X
       
    97 						if(slideNb){
       
    98 							embed_code = embed_code.replace(new RegExp("ssplayer2.swf\\?","g"), "ssplayer2.swf?startSlide=" + slideNb + "&");
       
    99 						}
       
   100 						self.containerDiv.html(embed_code);
       
   101 					},
       
   102 					error: function(jqXHR, textStatus, errorThrown){
       
   103 						self.containerDiv.html("Error while downloading the slideshow. jqXHR = " + jqXHR + ", textStatus = " + textStatus + ", errorThrown = " + errorThrown);
       
   104 					}
       
   105 	    		});
       
   106     		}
    82     		}
   107     		else{
    83     		else{
   108     			// If the presentation was already loaded, we only use the ss js api to load the wanted slide number
    84 	    		var description_ar = this.lastSSFullUrl.split("#id=");
   109     			if(this.lastSSId!=""){
    85 	    		var slideNb = 1;
   110     				// We get the embed flash element
    86 	    		if(description_ar[1]){
   111     				var embed = document.getElementsByName("__sse" + this.lastSSId)[0];
    87 	    			slideNb = description_ar[1];
   112     				if(embed){
    88 	    		}
   113     					embed.jumpTo(parseInt(slideNb));
    89 	    		if(description_ar[0]!=this.lastSSUrl && description_ar[0].substring(0,7)=="http://"){
   114     				}
    90 	    			this.lastSSUrl = description_ar[0];
   115     			}
    91 		    		// We have the slideshare oembed url (version 1 because we want the flash embed).
       
    92 		    		var url = "http://www.slideshare.net/api/oembed/1?format=jsonp&url=" + this.lastSSUrl;
       
    93 		    		
       
    94 		    		IriSP.jQuery.ajax({
       
    95 						url: url,
       
    96 						dataType: "jsonp",
       
    97 						success: function(data) {
       
    98 							self.lastSSId = data["slideshow_id"];
       
    99 							embed_code = data["html"];
       
   100 							// If slideNb exist, we hack the embed code to add ?startSlide=X
       
   101 							if(slideNb){
       
   102 								embed_code = embed_code.replace(new RegExp("ssplayer2.swf\\?","g"), "ssplayer2.swf?startSlide=" + slideNb + "&");
       
   103 							}
       
   104 							self.containerDiv.html(embed_code);
       
   105 						},
       
   106 						error: function(jqXHR, textStatus, errorThrown){
       
   107 							self.containerDiv.html("Error while downloading the slideshow. jqXHR = " + jqXHR + ", textStatus = " + textStatus + ", errorThrown = " + errorThrown);
       
   108 						}
       
   109 		    		});
       
   110 	    		}
       
   111 	    		else if(description_ar[0]!=this.lastSSUrl){
       
   112 	    			this.lastSSUrl = description_ar[0];
       
   113 	    			this.lastSSId = "";
       
   114 		    		// In this case, we only have an id that is meant to build the flash embed
       
   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>';
       
   116 					self.containerDiv.html(embed_code);
       
   117 	    		}
       
   118 	    		else{
       
   119 	    			// If the presentation was already loaded, we only use the ss js api to load the wanted slide number
       
   120 	    			var embed = null;
       
   121 	    			if(this.lastSSId!=""){
       
   122 	    				// If the presentation was loaded from a public url, we get the div from its id.
       
   123 						embed = document.getElementsByName("__sse" + this.lastSSId)[0];
       
   124 	    			}
       
   125 	    			else if(this.lastSSUrl.substring(0,7)!="http://"){
       
   126 	    				// If the presentation was loaded from a private id, we get the div from dom tree.
       
   127 	    				embed = this.containerDiv.children()[0].children[0];
       
   128 	    			}
       
   129 					if(embed){
       
   130 						embed.jumpTo(parseInt(slideNb));
       
   131 					}
       
   132 	    		}
       
   133 	    		return;
   116     		}
   134     		}
   117     		return;
       
   118     	}
   135     	}
   119     }
   136     }
   120   }
   137   }
   121   if(found==false){
   138   if(forceEmpty==true){
   122 	this.lastSSFullUrl = "";
   139 	this.lastSSFullUrl = "";
   123 	this.lastSSUrl = "";
   140 	this.lastSSUrl = "";
   124 	this.lastSSId = "";
   141 	this.lastSSId = "";
   125   	this.containerDiv.html("");
   142   	this.containerDiv.html("");
   126   }
   143   }