src/js/widgets/slideShareWidget.js
changeset 879 85da59ccbdf8
parent 878 c983360f0e7a
equal deleted inserted replaced
878:c983360f0e7a 879:85da59ccbdf8
     1 
     1 
     2 /** A widget to display slide show from embed slide share */
     2 /** A widget to display slide show from embed slide share */
     3 IriSP.SlideShareWidget = function(Popcorn, config, Serializer) {
     3 IriSP.SlideShareWidget = function(Popcorn, config, Serializer) {
     4   IriSP.Widget.call(this, Popcorn, config, Serializer);
     4   IriSP.Widget.call(this, Popcorn, config, Serializer);
       
     5   // Default flash embed size
       
     6   this.embed_width = 425;
       
     7   this.embed_height = 355;
       
     8   if(this._config.embed_width){
       
     9 	  this.embed_width = this._config.embed_width;
       
    10   }
       
    11   if(this._config.embed_height){
       
    12 	  this.embed_height = this._config.embed_height;
       
    13   }
     5 };
    14 };
     6 
    15 
     7 IriSP.SlideShareWidget.prototype = new IriSP.Widget();
    16 IriSP.SlideShareWidget.prototype = new IriSP.Widget();
     8 
    17 
     9 IriSP.SlideShareWidget.prototype.draw = function() {
    18 IriSP.SlideShareWidget.prototype.draw = function() {
    15 	  return;
    24 	  return;
    16   }
    25   }
    17   var templ = Mustache.to_html(IriSP.slideShareWidget_template);
    26   var templ = Mustache.to_html(IriSP.slideShareWidget_template);
    18   this.selector.append(templ);
    27   this.selector.append(templ);
    19   
    28   
    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.  
    29   // global variables used to keep the position and width of the zone.  
    26   this.zoneLeft = 0;
    30   this.zoneLeft = 0;
    27   this.zoneWidth = 0;
    31   this.zoneWidth = 0;
    28   // global variable to save the last slide url
    32   // global variable to save the last slide url
    29   this.lastSSFullUrl = "";
    33   this.lastSSFullUrl = "";
    30   this.lastSSUrl = "";
    34   this.lastSSUrl = "";
    31   this.lastSSId = "";
    35   this.lastSSId = "";
    32   this.containerDiv = this.selector.find('.SlideShareContainer');
    36   this.containerDiv = this.selector.find('.SlideShareContainer');
       
    37   
       
    38   // Synchro management
       
    39   this._disableUpdate = false;
       
    40   this.buttonsDiv = this.selector.find('.SlideShareButtons');
       
    41   this.buttonsDiv.width(this.embed_width - 2); // -2 because of css borders 328 -> 235px
       
    42   this.buttonsDiv.find('.left_icon').css("margin-left",(this.embed_width-96)+"px");
       
    43   this.buttonsDiv.find('.ss_sync_on').click(function(event) { self.unSyncHandler.call(self, event); });
       
    44   this.buttonsDiv.find('.ss_sync_off').click(function(event) { self.syncHandler.call(self, event); });
       
    45   this.buttonsDiv.find('.ss_sync_off').hide();
       
    46   this.buttonsDiv.hide();
    33   
    47   
    34   // Update the slide from timeupdate event
    48   // Update the slide from timeupdate event
    35   this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.slideShareUpdater));
    49   this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.slideShareUpdater));
    36   
    50   
    37   this._Popcorn.listen("IriSP.SlideShareWidget.show", IriSP.wrap(this, this.show));
    51   this._Popcorn.listen("IriSP.SlideShareWidget.show", IriSP.wrap(this, this.show));
    80     		if(this.lastSSFullUrl==""){
    94     		if(this.lastSSFullUrl==""){
    81     			// We force unload
    95     			// We force unload
    82     			forceEmpty = true;
    96     			forceEmpty = true;
    83     		}
    97     		}
    84     		else{
    98     		else{
       
    99     			this.buttonsDiv.show();
    85 	    		var description_ar = this.lastSSFullUrl.split("#id=");
   100 	    		var description_ar = this.lastSSFullUrl.split("#id=");
    86 	    		var slideNb = 1;
   101 	    		var slideNb = 1;
    87 	    		if(description_ar[1]){
   102 	    		if(description_ar[1]){
    88 	    			slideNb = description_ar[1];
   103 	    			slideNb = description_ar[1];
    89 	    		}
   104 	    		}
   100 							embed_code = data["html"];
   115 							embed_code = data["html"];
   101 							// If slideNb exist, we hack the embed code to add ?startSlide=X
   116 							// If slideNb exist, we hack the embed code to add ?startSlide=X
   102 							if(slideNb){
   117 							if(slideNb){
   103 								embed_code = embed_code.replace(new RegExp("ssplayer2.swf\\?","g"), "ssplayer2.swf?startSlide=" + slideNb + "&");
   118 								embed_code = embed_code.replace(new RegExp("ssplayer2.swf\\?","g"), "ssplayer2.swf?startSlide=" + slideNb + "&");
   104 							}
   119 							}
       
   120 							// The embed always send the default width and height, so we can easily change them.
       
   121 							embed_code = embed_code.replace(new RegExp("425","g"), self.embed_width);
       
   122 							embed_code = embed_code.replace(new RegExp("355","g"), self.embed_height);
       
   123 							// We hide the title upon the slides.
       
   124 							embed_code = embed_code.replace(new RegExp("block"), "none");
   105 							self.containerDiv.html(embed_code);
   125 							self.containerDiv.html(embed_code);
   106 						},
   126 						},
   107 						error: function(jqXHR, textStatus, errorThrown){
   127 						error: function(jqXHR, textStatus, errorThrown){
   108 							self.containerDiv.html("Error while downloading the slideshow. jqXHR = " + jqXHR + ", textStatus = " + textStatus + ", errorThrown = " + errorThrown);
   128 							self.containerDiv.html("Error while downloading the slideshow. jqXHR = " + jqXHR + ", textStatus = " + textStatus + ", errorThrown = " + errorThrown);
   109 						}
   129 						}
   111 	    		}
   131 	    		}
   112 	    		else if(description_ar[0]!=this.lastSSUrl){
   132 	    		else if(description_ar[0]!=this.lastSSUrl){
   113 	    			this.lastSSUrl = description_ar[0];
   133 	    			this.lastSSUrl = description_ar[0];
   114 	    			this.lastSSId = "";
   134 	    			this.lastSSId = "";
   115 		    		// In this case, we only have an id that is meant to build the flash embed
   135 		    		// In this case, we only have an id that is meant to build the flash embed
   116 					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>';
   136 					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="'+this.embed_width+'" height="'+this.embed_height+'"></embed></div>';
   117 					self.containerDiv.html(embed_code);
   137 					this.containerDiv.html(embed_code);
   118 	    		}
   138 	    		}
   119 	    		else{
   139 	    		else{
   120 	    			// If the presentation was already loaded, we only use the ss js api to load the wanted slide number
   140 	    			// If the presentation was already loaded, we only use the ss js api to load the wanted slide number
   121 	    			var embed = null;
   141 	    			var embed = null;
   122 	    			if(this.lastSSId!=""){
   142 	    			if(this.lastSSId!=""){
   139   if(forceEmpty==true){
   159   if(forceEmpty==true){
   140 	this.lastSSFullUrl = "";
   160 	this.lastSSFullUrl = "";
   141 	this.lastSSUrl = "";
   161 	this.lastSSUrl = "";
   142 	this.lastSSId = "";
   162 	this.lastSSId = "";
   143   	this.containerDiv.html("");
   163   	this.containerDiv.html("");
       
   164   	this.buttonsDiv.hide();
   144   }
   165   }
   145 
   166 
   146 };
   167 };
   147 
   168 
   148 // Functions to stop or trigger sync between timeupdate event and slides        
   169 // Functions to stop or trigger sync between timeupdate event and slides        
   149 IriSP.SlideShareWidget.prototype.unSyncHandler = function(params) {
   170 IriSP.SlideShareWidget.prototype.unSyncHandler = function() {
   150 	//console.log("slideShare NO SYNC !");
   171 	//console.log("slideShare NO SYNC !");
   151 	this._disableUpdate = true;
   172 	this._disableUpdate = true;
       
   173 	this.buttonsDiv.find('.ss_sync_on').hide();
       
   174 	this.buttonsDiv.find('.ss_sync_off').show();
   152 };
   175 };
   153 IriSP.SlideShareWidget.prototype.syncHandler = function(params) {
   176 IriSP.SlideShareWidget.prototype.syncHandler = function() {
   154 	//console.log("slideShare SYNC PLEASE !");
   177 	//console.log("slideShare SYNC PLEASE !");
   155 	this._disableUpdate = false;
   178 	this._disableUpdate = false;
       
   179 	this.buttonsDiv.find('.ss_sync_on').show();
       
   180 	this.buttonsDiv.find('.ss_sync_off').hide();
   156 };
   181 };
   157 
   182 
   158 
   183 
   159 /** responds to an "IriSP.SlideShareWidget.position" message
   184 /** responds to an "IriSP.SlideShareWidget.position" message
   160     @param params an array with the first element being the left distance in
   185     @param params an array with the first element being the left distance in