if(!vp_widget){ var vp_lastarticles = { url : 'http://www.bioaddict.fr/widget/lastarticles', params:{ records_per_page:4, format:'full', title:'Toute l\'info pour un monde plus bio', showTabHeader:true, logotype:'large' }, style:{ width:'100%', height:'440px', frame_color:'CCCCCC', link_color:'335599', tvp_color:'474747', background_color:'FFFFFF' }, func:{ init:function(widget){ widget.config.func.setConfig(widget, widget.user_config); }, setConfig:function(widget, config){ if(config.style){ widget.objectReplace(widget.config.style, config.style); } if(config.params){ widget.objectReplace(widget.config.params, config.params); } }, getConfig:function(widget){ var params = widget.serializeConfig(widget.config.params); var styles = widget.serializeConfig(widget.config.style); var p = '{params:'+params+', style:'+styles+'}'; return p; } } }; var vp_widget = function(widget, config){ this.user_config = arguments.length > 1 ? config : {}; this.apikey = arguments.length > 0 ? widget[0] : 0; this.w_name = arguments.length > 0 ? widget[1] : ''; this.version = arguments.length > 0 ? widget[2] : ''; this.widget_id = arguments.length > 0 ? widget[3] : 0; this.init = function(callBack){ this.script_key = ''; if(this.w_name){ this.config = this.clone(eval('vp_'+this.w_name)); this.config.func.init(this); this.createContainer(); this.createLoading(); this.createTabHeader(); this.createIframe(); this.createFooter(); if(arguments.length && typeof arguments[0] == 'function'){ callBack(this); } return this; } }; this.getConfig = function(){ return this.config.func.getConfig(this); }; this.setConfig = function(config){ return this.config.func.setConfig(this, config); }; this.clone = function (srcInstance){ if(typeof(srcInstance) != 'object' || srcInstance == null){ return srcInstance; } var newInstance = srcInstance.constructor(); for(var i in srcInstance){ newInstance[i] = this.clone(srcInstance[i]); } return newInstance; }; this.observe = function(obj, event, handler) { if (obj.addEventListener) { obj.addEventListener(event, handler, false); } else if (obj.attachEvent) { obj.attachEvent('on'+event, handler); } }; this.objectReplace=function(obj1,obj2){ for(var key in obj2){ if(obj1[key] != "undefined"){ obj1[key] = obj2[key]; } } }; this.createFooter = function(){ a = document.createElement('a'); a.href='http://www.bioaddict.fr'; a.id = 'vd_widget_footer'; cssText=this.config.params.showTabHeader ? 'display:none;' : 'display:block;'; cssText+='font-size:10px;text-shadow:#FFF;'; a.style.cssText=cssText; a.target='_blank'; a.title = 'le journal du bio et du développement durable'; a.innerHTML = 'par bioaddict.fr'; this.container.appendChild(document.createElement('br')); this.container.appendChild(a); } this.createTabHeader = function(){ link = document.createElement('a'); link.id = 'vp_tabHeader'; link.target = '_blank'; link.href = 'http://www.bioaddict.fr'; link.title = 'le journal du bio et du développement durable'; if(this.config.params.showTabHeader == false){ link.style.cssText='display:none;'; } img = document.createElement('img'); if(this.config.params.logotype == 'small'){ img.src= 'http://www.bioaddict.fr/images/logowidget-small.png'; img.width = 100; img.height = 18; img.style.cssText = 'margin:1px 0 0 0;position:absolute;'; } else{ img.src= 'http://www.bioaddict.fr/images/logowidget.png'; img.width = 187; img.height = 56; img.style.cssText = 'margin:1px 0 0 -4px;position:absolute;'; } img.alt = 'le journal du bio et du développement durable'; img.border = 0; link.appendChild(img); this.container.appendChild(link); }; this.createContainer = function(){ this.container = document.createElement('div'); //this.container.style.cssText = 'width:'+this.config.style.width+';text-align:left;'; this.container.style.cssText = 'text-align:left;position:relative;'; document.getElementById('vp_script').parentNode.insertBefore(this.container, document.getElementById('vp_script')); }; this.createLoading = function(){ this.lng = document.createElement('div'); var regx = new RegExp("px","g"); var width = this.config.style.width.match(regx) ? this.config.style.width : 'inherit' ; var cssText = 'background:#FFF url(http://www.bioaddict.fr/images/ajax-loader-widget.gif) no-repeat scroll center center;'; cssText+= 'position:absolute;'; cssText+= 'width:'+width+';'; cssText+= 'height:'+this.config.style.height+';'; cssText+= 'opacity:0.5;-moz-opacity:0.5;filter:alpha(opacity=50);'; cssText+= 'display:none'; this.lng.style.cssText = cssText; this.lng.id = 'loading'; this.container.appendChild(this.lng); }; this.loading = function(activate){ if(!arguments.length || typeof activate != 'boolean'){ activate = false; } if(document.getElementById('loading') && activate === true){ document.getElementById('loading').style.display = 'block'; document.getElementById('loading').style.marginTop = document.getElementById('vp_widget_iframe').style.marginTop; document.getElementById('loading').style.height = document.getElementById('vp_widget_iframe').style.height; } else if(document.getElementById('loading') && activate === false){ document.getElementById('loading').style.display = 'none'; } }; this.createIframe = function(){ this.frame = document.createElement('iframe'); this.frame.id = 'vp_widget_iframe'; this.frame.name = 'vp_widget_iframe'; this.observe(this.frame,'load',this.loading) this.frame.marginWidth = 0; this.frame.marginHeight = 0; this.frame.frameBorder = 0; var cssText = ''; if(this.config.params.showTabHeader){ if(this.config.params.logotype == 'small'){ cssText+='margin-top:18px;'; } else{ cssText+='margin-top:56px;'; } } cssText+= 'zoom:1;border:1px solid #'+this.config.style.frame_color+';'; cssText+= 'width:'+(isNaN(this.config.style.width) ? this.config.style.width : this.config.style.width+'px')+';'; cssText+= 'height:'+(isNaN(this.config.style.height) ? this.config.style.height : this.config.style.height+'px')+';'; this.frame.style.cssText = cssText; this.container.appendChild(this.frame); this.load(this.config); }; this.getHeight = function(){ var d= document.documentElement; var b= document.body; var who= d.offsetHeight? d: b ; return Math.max(who.scrollHeight,who.offsetHeight); }; this.reload = function(){ this.load(this.config); } this.load = function(new_config){ this.loading(true); var src = this.config.url+'?'; src+='api_key='+this.apikey+'&page=1'; src+='&widget_id='+this.widget_id; src+='&format='+new_config.params.format; src+='&records_per_page='+new_config.params.records_per_page; src+='&title='+new_config.params.title; src+='&tvp_color='+escape(new_config.style.tvp_color.replace(/%/g, '%25').replace(/\+/g, '%2B')).replace(/%25/g, '%'); src+='&link_color='+new_config.style.link_color; src+='&frame_color='+new_config.style.frame_color; src+='&version='+this.version; src+='&background_color='+new_config.style.background_color; this.frame.src=src; }; this.serializeConfig = function(data){ var _thisObject = this; var f = function(data){ var str_data; if (data == null || (typeof(data) == 'string' && data == '')){ str_data = "''"; } else switch(typeof(data)){ case 'object': var arrayCount = 0; str_data = ''; for (i in data){ if (i == 'length'){ continue; } arrayCount++; str_data += i+':'+f(data[i]); str_data +=','; } str_data='{'+str_data.substring(0,str_data.length-1)+'}'; break; case 'string': str_data = '\'' + data.replace(/\'/g,"\\\'") + '\''; break; case 'number': str_data = data; break; case 'boolean': str_data = data ? '1' : '0'; break; default: return null; } return str_data; } return f(data); }; } }