var configCustom = {"width":"400px","height":"340px","v":"158438","displayTitle":"0","backgroundColor":"FFFF00","textFont":"Arial","textColor":"000000","linkColor":"000000","hrColor":"000000","linkFont":"Arial","timeColor":"FFFFFF"}; var venyoo = { /* defaults for config (can not be overridden by configCustom) */ config: { targetId: 'venyooTargetDiv', targetTestString: 'href="https://venyoo.de', frameSrc: 'https://venyoo.de/embed/page', ajaxSrc: 'https://venyoo.de/embed/events' }, /* defaults for custom config (may be overridden by venyooConfigCustom) */ configCustomDefaults: {"width":"600","height":"600","v":"0","u":"0","d":"","q":"","ut":"","uc":"","c":"","lat":"","lng":"","r":"","t":"","et":"","h":"","source":"","itemsPerPage":"10","title":"Veranstaltungen bei venyoo","displayTitle":"1","backgroundColor":"FFFFFF","titleColor":"888888","titleFont":"Georgia","textFont":"Trebuchet MS","textColor":"555555","linkColor":"476600","hrColor":"EEEEEE","f":"","displayVenue":"1","displayDescription":"1","displayPics":"1","linkFont":"Trebuchet MS","timeColor":"555555"}, setSrcParams: function(){ var urlParams = new Array(); for(i in this.configCustomDefaults) { if(this.config[i] != this.configCustomDefaults[i]) { urlParams.push(encodeURIComponent(i)+'='+encodeURIComponent(this.config[i])); } } if(urlParams.length > 0){ var urlParamString = urlParams.join('&'); this.config.frameSrc += '?'+urlParamString; this.config.ajaxSrc += '?'+urlParamString; } }, mergeCustomConfig: function(cConfig){ for(i in this.configCustomDefaults) { if(typeof(cConfig[i]) == 'undefined') { this.config[i] = this.configCustomDefaults[i]; } else { this.config[i] = cConfig[i]; } } }, setItemsPerPage: function(){ /* wenn defaultwert benutzt: automatisch anpassen */ if(this.config.itemsPerPage == this.configCustomDefaults.itemsPerPage) { var height = this.config.height.replace(/px/, ''); height = height-50; if(this.config.displayTitle == 1) { height = height-25; } var itemHeight = 75; this.config.itemsPerPage = Math.floor(height/itemHeight); } }, /* inits, creates and writes the widget */ createWidget: function(){ if(typeof(configCustom) != 'undefined') { this.mergeCustomConfig(configCustom); } /* legacy (parameters from old widget) */ if(typeof(venyooConfigCustom) != 'undefined') { this.mergeCustomConfig(venyooConfigCustom); } this.setItemsPerPage(); this.setSrcParams(); var targetDiv = document.getElementById(this.config.targetId); if(targetDiv && this.checkBacklink(targetDiv)){ if (window.XMLHttpRequest) { this.loadByAjax(targetDiv); } else { this.loadByIframe(targetDiv); } } }, /* inits, creates and writes the widget */ checkBacklink: function(targetDiv){ /* checks for targetTestString (backlink) */ var stringSuccess = targetDiv.innerHTML.toLowerCase().indexOf(this.config.targetTestString); /* toLowerCase: IE returns tags in upper case */ if(stringSuccess == -1){ var stringSuccess = targetDiv.innerHTML.toLowerCase().indexOf('href="http://venyoo.de'); } if (stringSuccess != -1) { return true; } }, /* creates HTML for the widget */ loadByIframe: function(targetDiv) { html = ''; html += '<iframe frameborder="0" marginheight="0" marginwidth="0"'; html += ' style="height:'+this.config.height+' !important; width:'+this.config.width+' !important; background-color:#'+this.config.backgroundColor+' !important;"'; html += ' src="'+this.config.frameSrc+'"'; html += '/>'; targetDiv.innerHTML = html; }, loadByAjax: function(targetDiv) { req = new XMLHttpRequest(); var width = this.config.width; var height = this.config.height; req.onreadystatechange = function() { if (req.readyState==4 && req.status==200) { targetDiv.innerHTML = req.responseText; targetDiv.style.width = width; targetDiv.style.height = height; targetDiv.setAttribute("style", targetDiv.getAttribute("style")+" width:"+width+"; height:"+height+";"); } }; req.open("GET", this.config.ajaxSrc, true); req.send(); } }; venyoo.createWidget(); 