PDA

View Full Version : Resolved SD menu, mark a href link selected, while using ajaxpage calls for links



dragon_sa
02-25-2012, 03:03 PM
1) Script Title: Slashdot Menu

2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex1/slashdot.htm

3) Describe problem:
I cant get the markCurrent feature to work when I am using the ajaxpage calls to load content into another div from the menu

ajaxpage script ur
http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.html

I find the markContent works when I reload the whole page with a normal url but when I use this javascript call in the href the markCurrent feature no longer works.

the ajax link I use

<a href="javascript:ajaxpage('t.php', 'rightContent');">Current or not</a>

how can I make it so that the markCurrent feature works when I click on this ajaxpage link without reloading the entire page?

jscheuer1
02-25-2012, 04:54 PM
First thing I would try is:


<a href="#" onclick="ajaxpage('t.php', 'rightContent');">Current or not</a>

If that's no good, then:


<a href="#" onclick="ajaxpage('t.php', 'rightContent'); return true;">Current or not</a>

If either of these works, it may also reposition the page in an undesirable way. If so, that can be dealt with.

If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.

dragon_sa
02-25-2012, 05:38 PM
Thanks tried both options neither work, here is a link to the page

-- link removed no longer valid --

jscheuer1
02-25-2012, 11:36 PM
OK, make the links like so:


<a href="#" onclick="ajaxpage('t.php', 'rightContent');">Current or not</a>

Do not use the javascript: prefix. That wasn't the problem, it's just unnecessary. And be sure to change all of the ajaxpage links to the above format.

The problem is that the SD Menu isn't designed for this. So we'll add some code to the onload function to make it work like we want it to. Replace this:


<script type="text/javascript">
// <![CDATA[
var myMenu;
window.onload = function() {
myMenu = new SDMenu("my_menu");
myMenu.init();
};
// ]]>
</script>

with:


<script type="text/javascript">
// <![CDATA[
var myMenu;
window.onload = function() {
myMenu = new SDMenu("my_menu");
myMenu.init();
var m = myMenu.menu.getElementsByTagName('a');
for (var i = m.length - 1; i > -1; --i){
if(/ajaxpage/.test(m[i].onclick)){
(function(old){
m[i].onclick = function(){
old();
myMenu.mark(this);
return false;
};
})(m[i].onclick);
}
}
myMenu.mark = function(link){
for (var i = m.length - 1; i > -1; --i){
if(m[i].className){
m[i].className = m[i].className.replace(/\bcurrent/, '');
}
}
link.className += link.className? ' current' : 'current';
};
};
// ]]>
</script>

dragon_sa
02-26-2012, 03:38 AM
Thank you very much John, that works very well, your help in the matter is very much appreciated, this site is excellent and the forums here are fantastic for the support :)