( function(){
var uniqclass = "id-"+Date.now();
// create root div
var me = document.currentScript;
var div = document.createElement("div");
div.className = 'idposts';
div.innerHTML = "
Suosittelemme
";
me.parentNode.insertBefore(div, me);
// append styles
jQuery("head").append("");
jQuery.ajax({
dataType: "json",
url: "https://api.indiedays.com/posts/posts.json",
success: function( json ){
var items = [];
for(var i=0; i< json.posts.length; i++){
var post = json.posts[i];
var idpost = document.createElement("div");
idpost.className = "idpost";
var idpostimagea = document.createElement("a");
idpostimagea.href = post.posturl;
idpostimagea.target = "_blank";
var idpostimage = document.createElement("div");
idpostimage.className = "idpostimage";
idpostimage.setAttribute("data-href", post.posturl);
idpostimage.style.backgroundImage = "url("+post.original_image_url+")";
var idpostcontent = document.createElement("div");
idpostcontent.classList.add("idpostcontent");
var h3 = document.createElement("h3");
var h3a = document.createElement("a");
h3a.href = post.posturl;
h3a.target = "_blank";
h3a.innerHTML = post.blogtitle;
var h2 = document.createElement("h2");
var h2a = document.createElement("a");
h2a.href = post.posturl;
h2a.target = "_blank";
h2a.innerHTML = post.posttitle;
idpost.appendChild(idpostimagea);
idpostimagea.appendChild(idpostimage);
idpost.appendChild(idpostcontent);
idpostcontent.appendChild(h3);
h3.appendChild(h3a);
idpostcontent.appendChild(h2);
h2.appendChild(h2a);
items.push(idpost);
}
items = shuffle(items);
jQuery("."+uniqclass).append(items);
},
error: function( xhr, status, error){
console.log(error);
},
method: "GET"
});
})();
function shuffle(a) {
var j, x, i;
for (i = a.length - 1; i > 0; i--) {
j = Math.floor(Math.random() * (i + 1));
x = a[i];
a[i] = a[j];
a[j] = x;
}
return a;
}