Jump to content

[jquery] Breadcrumb Coding


ehime

Recommended Posts

I wrote a few functions in Javascript but would like to migrate them to JQuery and consolidate the code if at all possible, anybody up to the task?All three of these are pretty much part of one major function. Call a page to a specified DIV, then allow track back functionality to restoremy lost back buttons. If these can be meshed, smashed together, recoded for space savings, whatever I would be immensely appreciative.XHR for DIV's

/* Swap XMLRequest to Declared DIV Tag */function getHttpRequest() {	var i = 0;	var end = httpRequestFns.length;	var req = null;			  	while (i < end) {	try {		req = httpRequestFns[i]();		getHttpRequest = httpRequestFns[i];		httpRequestFns = null;		break;	} catch (e) {		continue;	}	i++;	}	return req;}var httpRequestFns = [function() { return new XMLHttpRequest(); },			  function() {			  return new ActiveXObject("Msxml3.XMLHTTP");			  },			  function() {			  return new ActiveXObject("Msxml2.XMLHTTP");			  },			  function() {			  return new ActiveXObject("Microsoft.XMLHTTP");			  },			  function() {return null}];function loadDiv(url, div) {	var req = getHttpRequest();	if (req) {	req.onreadystatechange = getProcessReqChangeFn(req, div);	req.open("GET", url, true);	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	req.setRequestHeader("Content-Type", "text/xml; charset=iso-8859-9");	req.send(null);	}	return req;}function getProcessReqChangeFn(req, div) {	return function() {	// only if req shows "complete"	if (req.readyState == 4) {		// only if "OK"		if (req.status == 200) {		if (document.getElementById) {			if (typeof div == "string") {			div = document.getElementById(div);			}			div.innerHTML = req.responseText;			initLytebox(); // Lytebox loves being initiated here for god knows what reason?			div = null;		}		} else {		req.onreadystatechange = getProcessReqChangeFn(req, div);		// if document doesn't exist....		req.open("GET", "error.html", true);		req.send(null);		}		return req;	}	};}

Breadcrumb Trackback Maincode

/*Breadcrumbing for fun and profit */function PathWatch(path_change_cb, interval) {		// Store initial path		this.path = document.location.href;				// Store the function to call when the path changes		this.path_change_cb = path_change_cb;			// Default interval is 400 miliseconds	if (!interval) interval = 400;		this.check_new_path = function() {			// If the location has changed, store the new location	// and call the callback function	if (document.location.href != this.path) {		this.path = document.location.href;		this.path_change_cb();}}// Check for a new path every interval milisecondsthis.oInterval = setInterval(this.check_new_path, interval);}

Breadcrumbing Page CodeFormed by: <a href="#some/bread/crumb.php" rel="divtogoto">Click Me</a>

function path_changed() {	var relationship = element.getAttribute("rel");	request_path = document.location.hash.substr(1);	loadDiv(request_path, relationship);}

Thanks for your time and patience! It is much MUCH appreciated.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...