1 
  2 /**
  3  * @private
  4  * @description Engine to render an abstract data to pure HTML
  5  * @constructor
  6  * @class
  7  * @version 0.1a
  8  */ 
  9 function SntPureHtmlEmbed(){
 10 	this.classid = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
 11 	this.type = 'application/x-shockwave-flash';
 12 	this.codebase = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0'
 13 	this.bf = new browserInfo().process();
 14 	this.browser = null;
 15 	// error status, default is fine
 16 	this.status = true;
 17 	this.callback = null;
 18 	return this;
 19 };
 20 
 21 SntPureHtmlEmbed.prototype = {	
 22 	/**
 23 	 * @function
 24 	 * @description Add one param element to object
 25 	 * @param o object instance
 26 	 * @param name name of attribute
 27 	 * @param value value of the attribute
 28 	 */
 29 	createParam : function(o, name, value){
 30 		var p = document.createElement('param');
 31 		p.setAttribute('name', name);
 32 		p.setAttribute('value', value);
 33 		o.appendChild(p);
 34 	},
 35 	/**
 36 	 * @function
 37 	 * @description Set callback function
 38 	 * @param fn callback function or null
 39 	 * @return void
 40 	 */
 41 	setCallback : function(fn){
 42 		this.callback = fn;
 43 	},
 44 	/**
 45 	 * @function
 46 	 * @description Create and object element
 47 	 * @param swf path to swf movie
 48 	 * @param attrs array with attributes for the object element
 49 	 * @param params list of params for the object element such as AllowFullScreen etc.
 50 	 * @return HTML DOM element
 51 	 */
 52 	createObject : function(swf, size, attrs, params){
 53 		var o = document.createElement("object");
 54 		
 55 		// set class id, required attribute for IE		
 56 		o.setAttribute('classid', this.classid);
 57 		o.setAttribute('type', this.type);
 58 		o.setAttribute('codebase', this.codebase);
 59 		
 60 		o.setAttribute('width', size.width);
 61 		o.setAttribute('height', size.height);
 62 		
 63 		// set path to swf
 64 		params['movie'] = swf;
 65 		
 66 		// set attributes
 67 		for(var a in attrs){
 68 			if(a == 'name')continue;
 69 			if(a == 'styleclass'){
 70 				o.setAttribute('class', attrs[a]);
 71 				continue;
 72 			}
 73 			o.setAttribute(a, attrs[a]);			
 74 		}
 75 		
 76 		// set params
 77 		for(var p in params){
 78 			this.createParam(o, p, params[p]);
 79 		}
 80 	
 81 
 82 		
 83 		var embed = this.createEmbed(swf, size, attrs, params);
 84 		// if browser is IE7 just return embed	
 85 		if(this.bf.isBrowser('IE_7') == true){				
 86 			// fix name attribute for IE7
 87 			return [o, embed.outerHTML.replace('<EMBED ', '<EMBED name="' + attrs['name'] + '" ')];	
 88 		}else{
 89 			o.appendChild(embed);
 90 		}
 91 		
 92 		return o;
 93 	},
 94 	
 95 	/**
 96 	 * @functions
 97 	 * @description create an embed element into object
 98 	 * @param swf path to flash movie
 99 	 * @param size array with size of the flash object (associate array with keys <b>width</b> and <b>height</b>)
100 	 * @param attrs array with attributes for the embed element	 
101 	 * @param params array with params (for embed it's attributes too) for the embed element
102 	 * @return void
103 	 */
104 	createEmbed : function(swf, size, attrs, params){
105 
106 	 	// set path to swf
107 		attrs['src'] = swf;
108 		embed = document.createElement('embed');
109 		embed.setAttribute('type', this.type);
110 		
111 		embed.setAttribute('width', size.width);
112 		embed.setAttribute('height', size.height);
113 		
114 		if(attrs['id'])delete attrs['id'];			
115 				
116 		// set all params as embed's attributes
117 		for(var p in params){
118 			embed.setAttribute(p, params[p]);
119 		}
120 
121 		// set all of attributes
122 		for(var a in attrs){
123 			embed.setAttribute(a, attrs[a]);
124 		}
125 		return embed;
126 	},
127 	/**
128 	 * @function
129 	 * @private
130 	 * @description render flashvars array to GET-like request string
131 	 * @param fv an array with flashvars
132 	 * @return string
133 	 */
134 	renderFlashvars : function(fv){
135 		var tmp = [];
136 		for(var n in fv){ tmp[tmp.length] = escape(n) + '=' + escape(fv[n]); }
137 		return tmp.join('&');
138 	},
139 	
140 	/** 
141 	 * @function
142 	 * @description Render all received data to object element with required params.
143 	 *				This function used in SntEmbed#render 
144 	 * @param id Id of the holder
145 	 * @param swfMovie path to the swf 
146 	 * @param size an array with two elements `width` and `height` with video holder size
147 	 * @param flashvars array with flashvars
148 	 * @param params array with parameters
149 	 * @param attributes an array with attributes
150 	 * @render status of the rendering
151 	 */
152 	render : function(id, swfMovie, size, flashvars, params, attributes){	
153 		var holder = $$(id);
154 		if(holder == null){
155 			return false;			
156 		}
157 				
158 		this.browser = new browserInfo().process();
159 		// change holder id to temporary id
160 		holder.setAttribute('id', id + 'Temp');
161 
162 		// render flashvars to one string		
163 		params['flashvars'] = this.renderFlashvars(flashvars);
164 		
165 		// replace object with id temporary id to flash object element
166 		var parent = holder.parentNode;
167 		var embed = this.createObject(swfMovie, size, attributes, params);
168 		if(this.bf.isBrowser('IE_7') == true){	
169 			parent.innerHTML(embed[1]);		
170 			parent.appendChild(embed[0]);
171 
172 			//parent.innerHTML = embed;
173 		}else{
174 			parent.appendChild(embed);
175 			parent.removeChild(holder);	
176 		}
177 		alert(parent.outerHTML);
178 
179 		if(this.callback != null)this.callback($$(id));
180 		return this.status;
181 	}	
182 };
183 
184