(function () { //Version 1.1 // Localize jQuery variable var jQuery; var localOrServerURL = "https://api.barnensbibliotek.se/Api_v1"; var widgetbaseurl = "https://www.barnensbibliotek.se/desktopmodules/barnensboktips/api/widget"; var TipID = new Array(); var title = new Array(); var bookid = new Array(); var author = new Array(); var HighAge = new Array(); var LowAge = new Array(); var Review = new Array(); var UserName = new Array(); var Userid = new Array(); var Userage = new Array(); var Tiptype = new Array(); var Category = new Array(); var ImgSrc = new Array(); //*** vald jquerycontainer för bokpuffen *** var _boktipContDiv = "#bb_barnensboktipsContainer"; /******** Load jQuery if not present *********/ if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.7.2') { var script_tag = document.createElement('script'); script_tag.setAttribute("type", "text/javascript"); script_tag.setAttribute("src", "https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"); if (script_tag.readyState) { script_tag.onreadystatechange = function () { // For old versions of IE if (this.readyState == 'complete' || this.readyState == 'loaded') { scriptLoadHandler(); } }; } else { script_tag.onload = scriptLoadHandler; } // Try to find the head, otherwise default to the documentElement (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag); } else { // The jQuery version on the window is the one we want to use jQuery = window.jQuery; main(); } //addDependentsource("http://dev.bokpuffen.se/wp-content/themes/twentyten/jwplayer/swfobject.js"); //function addDependentsource(url) { // var mediaplayer = document.createElement('script'); // mediaplayer.setAttribute("type", "text/javascript"); // mediaplayer.setAttribute("src", url); // (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(mediaplayer); //} /******** Called once jQuery has loaded ******/ function scriptLoadHandler() { // Restore $ and window.jQuery to their previous values and store the // new jQuery in our local jQuery variable jQuery = window.jQuery.noConflict(true); // Call our main function main(); } /******** Our main function ********/ function main() { jQuery(document).ready(function ($) { /**** Init widget ****/ var init = $("#bb_barnensboktipsContainer").attr("rel"); //required var _incval = $("#bb_barnensboktipsContainer").attr("rev"); //required if (init) { var _typval = ""; var triminit = init.replace(/[\s]/g, ""); var initvals = triminit.split(","); var _devkey = initvals[0] var _searchtyp = initvals[1]; var _visaCss = initvals[2]; var _visalogo = initvals[3]; var _visashortvers = initvals[4]; switch (_searchtyp) { case 'byrandom': _searchtyp = 'byrandom'; break; case 'byuser': _searchtyp = 'byuser'; break; case 'byauthor': _searchtyp = 'byauthor'; break; case 'byrandomincategory': _searchtyp = 'BookTipsByRandomInCategory'; break; default: _searchtyp = 'bylatest'; break; }; } else { _searchtyp = "bylatest"; }; /******* Load CSS *******/ if (_visaCss != "nocss") { var css_link = $("", { rel: "stylesheet", type: "text/css", href: widgetbaseurl + "/barnensboktipswidget.css" }); css_link.appendTo('head'); } /******* Load HTML *******/ getboktipsJsonData(); function getboktipsJsonData() { $.ajax({ type: "GET", url: localOrServerURL + "/boktips/" + _searchtyp + "/" + _incval + "/devkey/" + _devkey + "?callback=?", dataType: "jsonp", success: function (data) { var i = 1; $.each(data.Booktiplist, function (item, val) { TipID[i] = val.TipID; title[i] = val.title; bookid[i] = val.Bookid; author[i] = val.Author; Review[i] = val.Review; UserName[i] = val.UserName; Userid[i] = val.Userid; ImgSrc[i] = val.ImgSrc; mainhtmloutput(TipID[i], title[i], bookid[i], author[i], Review[i], UserName[i], Userid[i], ImgSrc[i]); //mainhtmloutput(bookid[1], present[1], pageurl[1], forfattare[1], title[1], forlag[1], isbn[1], ljudfil[1], upplasare[1], imgsrc[1]); i++; //return false; }); }, error: function (xhr, ajaxOptions, thrownError) { alert("Nått blev fel!"); } }); } var htmlblock = ""; if (_visalogo == "nologo") { htmlblock = "