Посмотрим теперь ...
- Обработчики двух кликов присваивают элементам
a
, оба отправляют запросы ajax на разные URL.
$('#content').load(attr);
не использует #content
для фильтрации результатов ..
также
function loadContent() {
$('#content').load(toLoad,'',showNewContent())
}
function showNewContent() {
$('#content').show('normal',hideLoader());
}
действительно должно быть
function loadContent() {
$('#content').load(toLoad,'',showNewContent /*no parenthesis here, just passing a callback */)
}
function showNewContent() {
$('#content').show('normal',hideLoader /*no parenthesis here, just passing a callback */);
}
Исправьте эти проблемы для начала и вернитесь, если проблемы не исчезнут.
Объединенные детали
jQuery.fn.center = function(centerCallback) {
this.css("position", "absolute");
this.css("top", ($(window).height() - this.height()) / 2 + $(window).scrollTop() + "px");
this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");
if (centerCallback != undefined) {
centerCallback(this);
return this;
}
}
var navi_switch = true;
var content_container = 'test';
$(document).ready(function() {
loadInitialContent(); // call our function to load the initial content based on url hash
$('#wrapper').center(function() {
$('#main_navigation').css("top", (parseInt($('#main_navigation').parent().height()) - parseInt($('#main_navigation').height())) / 2 + "px");
});
$('#main_navigation a').click(function() {
var href = $(this).attr('href'); // get the href
window.location.hash = href.substr(0, href.length - 5); // change the hash of the url
href += ' #content'; // add the #content filter to the href
if (navi_switch) {
$('#main_navigation').animate({
top: '0'
}, 500, function() {
navi_switch = false;
$('#content').hide('fast', function(){
$(this).load(href, function(){
$(this).show('normal', function(){
$('#load').fadeOut('normal');
});
});
});
});
} else {
$('#content').hide('fast', function(){
$(this).load(href, function(){
$(this).show('normal', function(){
$('#load').fadeOut('normal');
});
});
});
}
return false;
});
});
function loadInitialContent() {
var hash = window.location.hash.substr(1);
var href = $('#main_navigation a[href^="' + hash + '."]').attr('href') + ' #content';
$('#content').load(href);
}