Frankey 0 Light Poster

Hi there,

I am busy with a ajax driven application in combination with Wordpress and now i found a great script that will convert every link into a ajaxlink that will call its content to a div. great, and it works! sometimes :(

when it outputs urls like

www.domain.com/#/information or www.domain.com/#/2010/genetics/story-about-dna/

will work fine, only it seems that sometimes it isn't rewriting the url with REGEX correctly so the it will like normally to the next page www.domain.com/information.

Someone i capable of seeing the problem through? when that this will work it is a great script for us all!

you can find the website i am working on on www.flance.be

var oldsearch, sort, URLHash="", data, preload, render, loadid, loader, navfix;

if (!location.href.match(baseurl)) location = baseurl;

sessid=(document.cookie.match("PHPSESSID="+sessid) ? "" : "&PHPSESSID="+sessid);


function WPACF_Init() {
	loader = document.getElementById("ACFLoader");

	Navigate(false);
	AjaxLinks();

	if (window.createPopup) {
		navfix = document.frames("navfix");
		navfix.document.write(GetUrl());
		navfix.document.close();
	}

	setInterval("Navigate(true)",250);
}

function AjaxLinks() {
	if (!document.getElementsByTagName("a")) return;
	
	tags = document.getElementsByTagName("a");
	for (i = 0; i < tags.length; i++) {
		tag = tags[i];
		if (tag.href) {
		    if (tag.href.indexOf(baseurl) == 0) { 
			tag.onmouseover=function(){loadid = setTimeout("Prefetch(\""+this.href+"\")", 250);};
			tag.onmouseout=function(){clearTimeout(loadid);};
			tag.onclick=ClickLink;
		    } else if (tag.protocol.match("http")) {
			tag.onclick=function(){if (window.urchinTracker) urchinTracker("/outgoing/"+this.hostname+"/"+FixUrl(this.pathname));};
			tag.target="_blank";
		    }
		}
	}
}
function Req(param, query) {
	try { xhr = (window.XMLHttpRequest ? new XMLHttpRequest : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP"): 0)); }
	catch(e) {xhr = 0; }

	if(!xhr) return false;

	xhr.onreadystatechange = ReqData;
	xhr.open((query ? "POST" : "GET"), themeurl+"acf.php?"+param+sessid, true);
	if (query) xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(query);
	return true;
}
function ReqData(){
	if(xhr.readyState==4){
		data = (xhr.responseXML.documentElement ? xhr.responseXML.documentElement : 0);

		if ((data) && (render == null)) {
			tags = data.getElementsByTagName("element");
			img = new Array();
			regexp = /<img [^>]*src\s*=\s*["']?([^"'\t\r\n>]+)/gi;
			j = 0;

			for( i = 0; i < tags.length; i++ ) {
				while (image = regexp.exec(tags[i].firstChild.data)) {
					img[j] = new Image();
					img[j].src = image[1];
					j++;
				}
			}
		} else if (render != null) RenderData();
	}
}
function RenderData(){
    if (!data) {
	location=baseurl+(render.match("=") ? "?" : "/")+render;
	return;
    }

    render = null;
    tags = data.getElementsByTagName("element");
    for( i = 0; i < tags.length; i++ ) {
	    document.getElementById(tags[i].getAttribute("id")).innerHTML = tags[i].firstChild.data;
    }
    AjaxLinks();
    if(data.getElementsByTagName("title").length) document.title=data.getElementsByTagName("title")[0].firstChild.data;
    if(data.getElementsByTagName("redir").length) location=data.getElementsByTagName("redir")[0].firstChild.data;
    if(data.getElementsByTagName("sort").length) sort=data.getElementsByTagName("sort")[0].firstChild.data;
    if(data.getElementsByTagName("refresh").length) location.reload(true);

    document.body.style.cursor = "";
    if (loader) loader.style.display = "none";
}
function Load(url) {
	render = url;
	document.body.style.cursor = "progress";
	if (loader) loader.style.display = "block";
}
function ClickLink() {
	path = FixUrl(this.href);
	if (render == path) return false;

	Load(path);
	if (preload == path){
		 if (data != null) RenderData();
	} else if (!Req("g="+path+"&sort="+sort, null)) {
		data = null;
		render = null;
		return true;
	}
	location.hash = "/"+path;
	URLHash = location.hash;
	if (navfix) {
		navfix.document.write(path);
		navfix.document.close();
	}
	scroll(0,0);
	if (window.urchinTracker) urchinTracker("/"+path);
	return false;
}
function Prefetch(url) {
	path = FixUrl(url);
	if (preload == path || render == path) return;
	data = null;
	
	preload = path;
	if (!Req("g="+path+"&sort="+sort, null)) {
	    preload = null;
	    data = null;
	}
}
function Navigate(timer) {
    nfdd=(navfix ? navfix.document.documentElement : 0);
    if ((nfdd) && (timer) && (GetUrl() != nfdd.innerText)) location.hash = "/"+nfdd.innerText;

    if ((location.hash != URLHash) && ((location.hash.match("#/")) || (!location.hash))) {
	URLHash = location.hash;
	if(render != location.hash.substring(2)) {
	    Load(location.hash.substring(2));
	    if (!Req("g="+render+"&sort="+sort, null)){
    		data = null;
		render = null;
	    } else
	        if (window.urchinTracker) urchinTracker("/"+FixUrl(this.pathname));
        }
    }
}
function SendSearch(keys) {
	if (oldsearch == keys.replace(/^\s*|\s*$/g,"")) return;

	Load(GetUrl());

	Req("s="+keys, null);
	oldsearch = keys.replace(/^\s*|\s*$/g,"");
}
function SendComment() {
	frm = document.forms['commentform'].elements;
	pairs = new Array();

	Load(GetUrl());
	frm.submit.disabled = true;

	for (i = 0; i < frm.length; i++) {
	if ((name = frm[i].name) && (value = frm[i].value))
		pairs.push(name + "=" + encodeURIComponent(value));
	}

	return (!Req("", pairs.join("&")));
}
function FixUrl(url) {
	if (url) return url.replace(baseurl,"").replace(/^\/?(index\.php)?\??|\/?(#.*)?$/g,"");
}
function GetUrl() {
	return (location.hash.match("#/") ? location.hash.substring(2) : FixUrl(location.href));
}
}