views:

31

answers:

2

Hi,

This isn't a specific code question, but more of a conceptual question. I'm trying to figure out which direction I should go in solving this problem.

Here is the site testsite

Right now when you hover over interior and click Mastersuite, it takes you to a page for the master suite, which includes the navbar through SSI, but when the page loads the navigation menu is reset just like when you first load the index. I want to have the menu load in the state it was in when the link was clicked. I also want to have only one HTML file for the navbar on ALL pages.

What would be the most universal, clean, and update-able way of doing this?

My ideas

  • use query string to tell navbar script which section the viewer is in
  • use some kind of JavaScript within the subsection page (ie:mastersuite.html or bathrooms.html) to tell the navbar script what page the user is on
+1  A: 

One option is for each of the links that takes you to another page, set the hash to the section ID to which it belongs.

<a href="mastersuite.shtml#section1">Master Suite</a>

Then on each page, when the page loads, get the hash value, and use it as a selector to fire the event that shows that category.

if(window.location.hash)
    $(window.location.hash).mouseover();  // Or mouseenter if that's the event
patrick dw
@Gert - If you mean that the page wouldn't change, but the content would be dynamically loaded, that's a good idea. Only problem may be if you want your pages to be crawlable by search engines. Any dynamically loaded content wouldn't be seen.
patrick dw
@patrick - +1, good solution.
Gert G
@patrick - Very good point about web crawlers. I guess a one page solution is probably only good for an application, not a site. :) I've deleted my suggestion.
Gert G
@Gert - All depends. May not be a big deal for a particular site. There's a document from Google on making AJAX sites crawlable that someone posted here. I haven't gotten around to reading it yet. I'll have to get on that. :o) http://code.google.com/web/ajaxcrawling/
patrick dw
@patrick - It would be a good idea, but since Google is just one of many search engines, it's probably for the best to keep on multiplying those pages. ;)
Gert G
@Gert - There's other search engines? ;o)
patrick dw
oh thats a cool idea ill try it!
Black Magic
whenever i write if(window.location.hash = 'section1'){document.write('section1')}it just adds the anchor section1 to the url even if i tyoed it in w/o the anchor
Black Magic
@Black Magic - If you're using the `=` operator, then yes, it will write that value to the URL, because `=` is an assignment operator. Since you're in an `if()` statement, you need the "equal to" comparison operator `==`.
patrick dw
@patrick oh ok, that makes sense, thanks for the tip
Black Magic
A: 

Ok so this is what i did and seems like a nice solution.

on the section page (ie: bathrooms.shtml or mastersuite.shtml) i used this

<script type="text/javascript">

var section='1';

</script>

the value of "section" is the section that that the page is under.

and then on my navbar script i used this

$(window).load(function() {//functionality
$('#section1').hoverIntent(navSelect('.interior','0px'));
$('#section2').hoverIntent(navSelect('.exterior','100px'));
$('#section3').hoverIntent(navSelect('.view','200px'));

function navSelect(section,selectorPosition){
    var func = function(evt){
        if ( $(section).is(':hidden')){
        $('.subSection').fadeOut(250);
        $(section).delay(250).fadeIn(250);
        $('#selector').animate({"left":selectorPosition},250);
        }
    }
    return { over: func, out: func };
}
});
//----------------------------------------------------------
if(section==0){//index page
$(window).load(function() {

$('.section').mouseover(function(){
$('#nav2').fadeOut(0).animate({"height":"30px"}, 250);      
});
});
}

//----------------------------------------------------------
if(section==1){//section1
$(window).load(function() {

$('#nav2').animate({"height":"30px"}, 0);
$('.subSection').fadeOut(250);
$('.interior').fadeIn(0);
$('#selector').animate({"left":"0px"},0);
});
}
//----------------------------------------------------------
if(section==2){//section2
$(window).load(function() {

$('#nav2').animate({"height":"30px"}, 0);
$('.subSection').fadeOut(250);
$('.exterior').fadeIn(0);
$('#selector').animate({"left":"100px"},0);
});
}
//----------------------------------------------------------
if(section==3){//section3
$(window).load(function() {

$('#nav2').animate({"height":"30px"}, 0);
$('.subSection').fadeOut(250);
$('.view').fadeIn(0);
$('#selector').animate({"left":"200px"},0);
});
}

I like this because it requires no querystring or anchors, and it is ridiculously simple

Black Magic