Results 1 to 5 of 5

Thread: SD menu, mark a href link selected, while using ajaxpage calls for links

  1. #1
    Join Date
    Apr 2008
    Posts
    28
    Thanks
    8
    Thanked 1 Time in 1 Post

    Question SD menu, mark a href link selected, while using ajaxpage calls for links

    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/dynamici...axcontent.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
    Code:
    <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?
    Last edited by dragon_sa; 02-28-2012 at 01:08 PM. Reason: more descriptive title

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,192 Times in 3,155 Posts
    Blog Entries
    12

    Default

    First thing I would try is:

    Code:
    <a href="#" onclick="ajaxpage('t.php', 'rightContent');">Current or not</a>
    If that's no good, then:

    Code:
    <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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Apr 2008
    Posts
    28
    Thanks
    8
    Thanked 1 Time in 1 Post

    Default

    Thanks tried both options neither work, here is a link to the page

    -- link removed no longer valid --
    Last edited by dragon_sa; 02-26-2012 at 04:01 AM.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,192 Times in 3,155 Posts
    Blog Entries
    12

    Default

    OK, make the links like so:

    Code:
    <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:

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

    Code:
    <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>
    Last edited by jscheuer1; 02-26-2012 at 12:36 AM. Reason: minor code improvements
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. The Following User Says Thank You to jscheuer1 For This Useful Post:

    dragon_sa (02-26-2012)

  6. #5
    Join Date
    Apr 2008
    Posts
    28
    Thanks
    8
    Thanked 1 Time in 1 Post

    Default

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •