PDA

View Full Version : Dynamic Ajax and PollC oddness



vtbaritone
03-29-2007, 02:04 AM
1) Script Title: Dynamic Ajax Content

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

3) Describe problem: Here's what I'm trying to do: I have a menu on the index page, and all the content loaded with the Dynamic Ajax Content script. I've added a script to write the javascript part of the links so the html is clean, and linked that to the PollC function for initializing scripts with the DAC, as below:


function pollC(id, load){
if (!load&&document.getElementById(id)){
document.getElementById(id).id='';
return;
}
else if (load&&document.getElementById(id)){
//if (id=='unique_1') //optional, and IE doesn't like it
loadLinks(); //required
return;
}
else if (load&&!document.getElementById(id))
setTimeout("pollC('"+id+"', 'load')", 60);
}

function loadLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
var target = anchor.getAttribute("href");
if (!anchor.getAttribute("href") || anchor.getAttribute("href").match("javascript") != null) continue;
if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "pages") {
anchor.href = "javascript:ajaxpage('" + target + "', 'content');"
anchor.onMouseDown=pollC('unique_1');
anchor.onMouseUp=pollC('unique_1', 'load');
}
else if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
anchor.target = "_blank";
anchor.title = "External Link: " + anchor.getAttribute("href");
}
}
}

If a loaded page doesn't have a link that's rel="pages" the call to PollC is lost in the menu, though the link remembers the "javascript" call. You can see what I'm talking about here: http://www.souris.us/temp/ Open "Musicking" and click on "Biography" - which has no links. Then open "Living-->Essays" and click on "Souris..." The link at the bottom has not been hit by the loadLinks function. If I add a link to the Bio page, I can follow the exact same sequence, and lo, it all works as intended.

I'm sure I could just add links to every page, but that feels like a hack, not a solution. Any ideas? And thanks in advance!!