function decode_utf8( s ) { return decodeURIComponent( escape( s ) ); } cb = {}; (function() { function getScript(src,cb) { var head = document.getElementsByTagName("head")[0]; var script = document.createElement("script"); script.type = "text/javascript"; script.language = "javascript"; script.charset = "utf-8"; script.src = src; script.onload = script.onreadystatechange = function () { script.onload = script.onreadystatechange = null; setTimeout(cb,2000); } head.appendChild(script); } /**************/ /* RUN BANNER */ /**************/ function run($) { // set to false when committing var dev = false; var meta = $('head meta'); var charset = 'utf-8'; $.each(meta, function(i) { var metac = meta[i].content.split('charset=')[1]; if (metac != undefined) { charset = metac; } }); /*******************/ /* BANNER SETTINGS */ /*******************/ var groupId = 136; var widgetId = '00000000000000880002247e'; var widgetSize = '468x400'; var widgetLang = 'fi'; var siteType = ''; if (siteType == undefined || siteType == "") { siteType = "sb"; } // remove borderwidth from banner width var widgetWidth = parseInt(widgetSize.split("x")[0])-2; var widgetHeight = parseInt(widgetSize.split("x")[1])-2; var contentWidth = 100; var contentHeight = 80; /*******************/ /* WIDGET LANGUAGE */ /*******************/ if (widgetLang == "en") { lang_sent_by = "Sent by: "; } else if (widgetLang == "fi") { lang_sent_by = "Lähettänyt: "; } // set banner properties var pageSize = 4; switch (widgetSize) { case "980x120": pageSize = 4; attSize = "55x55"; fromPrefix = lang_sent_by; break; case "300x250": pageSize = 4; attSize = "42x42"; fromPrefix = "- "; break; case "468x400": pageSize = 10; attSize = "50x50"; fromPrefix = "- "; break; case "140x350": pageSize = 5; attSize = "0x0"; fromPrefix = "- "; break; } if (dev == true) { var site = 'http://192.168.1.36:8080/SparkBox'; var csssite = 'http://192.168.1.36:8080/SparkBox'; //var site = 'http://192.168.1.33:8080/SparkBox'; //var csssite = 'http://192.168.1.33:8080/SparkBox'; foo = function(data) { //alert(data.response["@result"] + ': site is set'); } if (siteType == 'as') { $.getScript('http://192.168.1.36:8080/SparkBox/api/site/switch?site=teppo&callback=foo'); } else { $.getScript('http://192.168.1.36:8080/SparkBox/api/site/switch?site=kissa&callback=foo'); } //$.getScript('http://192.168.1.36:8080/SparkBox/api/site/switch?site=kissa&callback=foo'); } else { if (siteType == 'as') { var site = $('script[src*='+widgetId+']').attr('src').split('.adspark.biz')[0]; site += ".adspark.biz"; var csssite = site; } else { var site = $('script[src*='+widgetId+']').attr('src').split('.sparkboxes.com')[0]; site += ".sparkboxes.com"; var csssite = site; } } /***********************/ /* INJECT DATA TO SITE */ /***********************/ $('script[src*='+widgetId+']').replaceWith('' + '
'); /*****************/ /* COLOR SETTERS */ /*****************/ var colorSetters = { bBgColor : [ '#_'+widgetId+'.gspark.banner', 'background-color'], bTitlebarBgColor : [ '#_'+widgetId+'.gspark.banner .titlebar h2', 'background-color'], bTitlebarTextColor : [ '#_'+widgetId+'.gspark.banner .titlebar h2', 'color'], bSparkBgColor : [ '#_'+widgetId+'.gspark.banner .sparkBanner', 'background-color'], bSparkTextColor : [ '#_'+widgetId+'.gspark.banner .sparkBanner .cont td', 'color'] }; var colors = new Array(); var xcolors = new Array(); /**************************************/ /* GET WIDGET COLORS AND SET LANGUAGE */ /**************************************/ function getWidgetColors(widgetColors) { $.each(widgetColors, function() { k = $(this)[0]; v = $(this)[1]; colors[k] = v; }); /************************/ /* COLORIZE WIDGET HERE */ /************************/ //console.log(colors.wBgColor); $.each(colorSetters, function (k, v) { var css = {}; try { //alert(k+ " " +v[1] + " "+ colors[k]); css[v[1]] = ( (k.indexOf('Color') != -1) ? '#' : '') + colors[k]; $(v[0]).css(css); } catch (error) {} }); // set widget width and height var wid = widgetWidth+"px"; var hei = widgetHeight+"px"; $('#_'+widgetId).css('width', wid).css('height', hei); var showAttachment = false; if (colors.bImg == "attachment") { $('#_'+widgetId+' .sparks .banU').hide(); $('#_'+widgetId+' .sparks .banI').show(); } else { $('#_'+widgetId+' .sparks .banI').hide(); $('#_'+widgetId+' .sparks .banU').show(); } if (attSize == "0x0") { $('#_'+widgetId+' .sparks .banI').hide(); $('#_'+widgetId+' .sparks .banU').hide(); } // set links var sparks = $('#_'+widgetId+' .sparks .sparkBanner'); $.each(sparks, function() { var sid = parseInt( $(this).find('.sparkId').html() ); if (colors.bRedurl.split('?')[1] == "" || colors.bRedurl.split('?')[1] == undefined) { var link = colors.bRedurl + '?openSpark=' + sid; } else { var link = colors.bRedurl + '&openSpark=' + sid; } $(this).find('.bannerLink').attr('href', link).attr('target', '_blank'); }); /*******************/ /* BANNER TITLEBAR */ /*******************/ var titlebar = ""; titlebar += ''; $('#_'+widgetId+'.gspark > .titleBar').html(titlebar); return colors; } // banner link ie $('#_'+widgetId+' .sparkBanner').live('click', function() { if ($.browser.msie) { var link = $(this).find('.bannerLink').attr('href'); window.open(link); } }); /***********************/ /* GET WIDGET CALLBACK */ /***********************/ cb.getWidget = function(data) { var colorData = data.response.list[0].colors[0]; getWidgetColors(colorData); return colors; } /************************/ /* LIST MEDIAS CALLBACK */ /************************/ cb.listMedias = function (data) { nocache = Math.random(); var page = document.location.href.split("?page=")[1]; if (page == undefined) var page = 0; if (pageSize == undefined) var pageSize = 15; sparks = data.response.list; var html = ""; $.each(sparks, function(i) { html += printSpark(data.response.list[i], contentWidth, contentHeight); }); html += ''; $('.gspark .sparks').html(html); var wurl = site+'/api/widget/get?widget='+widgetId+'&callback=cb.getWidget'; $.getScript(wurl); showVisualContent(); } function listMedias(groupId, pageSize) { nocache = Math.random(); var page = document.location.href.split("?page=")[1]; if (page == undefined) var page = 0; if (pageSize == undefined) var pageSize = 15; var url = site+'/api/media/list?sparkbox='+groupId+'&page='+page+'&pageSize='+pageSize+'&nocache='+nocache+'&callback=cb.listMedias'; $.getScript(url); } cb.showMedia = function (data) { //console.log(data); nocache = Math.random(); var page = document.location.href.split("?page=")[1]; if (page == undefined) var page = 0; if (pageSize == undefined) var pageSize = 15; sparks = data.response.list; var html = ""; $.each(sparks, function(i) { html += printSpark(data.response.list[i], contentWidth, contentHeight); }); html += ''; $('.gspark .sparks').html(html); var wurl = site+'/api/widget/get?widget='+widgetId+'&callback=cb.getWidget'; $.getScript(wurl); showVisualContent(); } function showMedia(mediaId) { nocache = Math.random(); var page = document.location.href.split("?page=")[1]; if (page == undefined) var page = 0; if (pageSize == undefined) var pageSize = 15; var url = site+'/api/media/get?media='+mediaId+'&page='+page+'&pageSize='+pageSize+'&nocache='+nocache+'&callback=cb.showMedia'; $.getScript(url); } /********************************************************/ /* SHOW IMAGES AND EMBEDS PAGED AT THE TOP OF THE SPARK */ /********************************************************/ function showVisualContent() { var sparks = $('#_'+widgetId+' .spark'); $.each(sparks, function() { var sparkId = $(this).find('.sparkId').html(); var visuCount = parseInt( $(this).find('.imageWindow > div').length ); if (visuCount == 0) return; visPager = ""; for (i=0;i