// Global variables var postindex = 0; var postcount = 0; var maxposts = 20; var cache = new Array(); var list_id = 'asideslist'; var base_url = 'http://gossip.elliottback.com/wp-content/plugins/wp-asides-get.php'; var asideInterval = false; // for Mozilla browsers if (document.addEventListener) { document.addEventListener("DOMContentLoaded", asidesStart, false); } // for other browsers addLoadEvent(asidesStart); // A Load Event Adder function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { oldonload(); func(); } } } // Repeating Snippets function asidesStart(){ if (arguments.callee.done){ return; } else { arguments.callee.done = true; } loadCache(); } // Create a new Ajax object function createXMLHttp() { if (typeof XMLHttpRequest != "undefined") return new XMLHttpRequest(); var xhrVersion = [ "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp","Microsoft.XMLHttp" ]; for (var i = 0; i < xhrVersion.length; i++) { try { var xhrObj = new ActiveXObject(xhrVersion[i]); return xhrObj; } catch (e) { } } return null; } function loadCache(){ var xmlhttp = createXMLHttp(); xmlhttp.open("GET", base_url + "?postoffset=" + postindex + "&postcount=" + maxposts); xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { // someting went wrong if(xmlhttp.responseText.length == 0){ return; } // store the posts in the cache cache = eval(xmlhttp.responseText); // close xmlhttp object xmlhttp.close; // chain the rest of the code retrievePost(function(){ asideInterval = setInterval('retrievePost()', 5 * 1000); }); } }; xmlhttp.send(null); } // Retrieve a post function retrievePost(after_action) { // get the element var element = document.getElementById(list_id); // get the index postindex = postindex % maxposts; // get the post var post = cache[postindex]; // remove the element and add a new one if(postcount > 0){ new Effect.Fade(element.firstChild, { duration:0.5, afterFinish:function(){ element.removeChild(element.firstChild); addNew(post, element); } }); } else { addNew(post, element); } // perform the after action if(after_action != null) after_action(); } // Adds a `post` to an `element` function addNew(post, element){ // append the new element var li = document.createElement("li"); li.innerHTML = post; li.style.display = "none"; element.appendChild(li); new Effect.Appear(li, {duration:0.5}); // increment the post index postindex++; postcount++; }