I was just about to tell you to get rid of this when I noticed it was working:
Code:
<script type="text/javascript">
$(function(){
// Bind an event to window.onhashchange that, when the hash changes, gets the
// hash and adds the class "selected" to any matching nav link.
$(window).bind('hashchange', function(){
var hash = location.hash;
// Set the page title based on the hash.
document.title = 'The hash is ' + ( hash.replace( /^#/, '' ) || 'blank' ) + '.';
// Iterate over all nav links, setting the "selected" class as-appropriate.
$('#nav a').each(function(){
var that = $(this);
that[ that.attr( 'href' ) === hash ? 'addClass' : 'removeClass' ]( 'selected' );
});
})
// Since the event is only triggered when the hash changes, we need to trigger
// the event now, to handle the hash the page may have loaded with.
$(window).trigger('hashchange');
});
</script>
Now, I'm a little out of my depth here only because there's so much going on on the page that I'm not sure why that's working or if it's cross browser enough to rely upon. But let's not worry about that just yet. If it will work for what we want it to in most browsers, we can try to make adjustments later.
Here's what we should try. First back up what you have, as it's not so bad.
Next, get rid of:
Code:
<script type="text/javascript">
jQuery(function($){
var hashlinks = $('.jqloadlink').click(function(e){
e.preventDefault();
hashlinks.removeClass('selected');
$(this).addClass('selected');
var hash = this.hash, page = this.getAttribute('data-page');
$('#content').load(page, function(){location.hash = hash;});
document.title = 'The hash is ' + hash.replace(/#?!\//, '');
});
hashlinks.each(function(){
var page, hash;
if((hash = this.hash) === location.hash && (page = this.getAttribute('data-page'))){
hashlinks.removeClass('selected');
$('#content').load(page);
$(this).addClass('selected');
document.title = 'The hash is ' + hash.replace(/#?!\//, '');
return false;
}
});
});
</script>
Then change this:
Code:
<script type="text/javascript">
$(function(){
// Bind an event to window.onhashchange that, when the hash changes, gets the
// hash and adds the class "selected" to any matching nav link.
$(window).bind('hashchange', function(){
var hash = location.hash;
// Set the page title based on the hash.
document.title = 'The hash is ' + ( hash.replace( /^#/, '' ) || 'blank' ) + '.';
// Iterate over all nav links, setting the "selected" class as-appropriate.
$('#nav a').each(function(){
var that = $(this);
that[ that.attr( 'href' ) === hash ? 'addClass' : 'removeClass' ]( 'selected' );
});
})
// Since the event is only triggered when the hash changes, we need to trigger
// the event now, to handle the hash the page may have loaded with.
$(window).trigger('hashchange');
});
</script>
to this:
Code:
<script type="text/javascript">
$(function(){
var hashlinks = $('.jqloadlink');
// Bind an event to window.onhashchange
$(window).bind('hashchange', function(){
var hash = location.hash;
// Set the page title based on the hash.
//document.title = 'The hash is ' + ( hash.replace( /^#/, '' ) || 'blank' ) + '.';
// Iterate over all class="jqloadlink" links, setting the "selected" class and executing their AJAX code as appropriate.
hashlinks.each(function(){
var page;
if(this.hash === hash && (page = this.getAttribute('data-page'))){
hashlinks.removeClass('selected');
$('#content').load(page);
$(this).addClass('selected');
return false;
}
});
});
// Since the event is only triggered when the hash changes, we need to trigger
// the event now, to handle the hash the page may have loaded with.
$(window).trigger('hashchange');
});
</script>
Then bring back:
Code:
<script type='text/javascript' src='js/jquery.ba-hashchange.min.js'></script>
It should go just before the hashchange code we just modified. And if you can, upgrade to version 1.3:
https://raw.github.com/cowboy/jquery...hchange.min.js
Even if it doesn't work, let me see it before you get rid of it. We may be able to fix it.
Oh, and now the title will remain whatever the title tag on the page says it is. That currently is:
Code:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>HabFab V1</title>
<link href="css/global.css" rel="st . . .
Change it to:
Code:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>HabFab » V1</title>
<link href="css/global.css" rel="st . . .
or HabFab » V2 - This is version 2, right?
We could have the hash come after, like:
HabFab » V2 » eventstoday
The browser cache may need to be cleared and/or the page refreshed to see changes.
Bookmarks