Я относительно новичок в JavaScript и jQuery.
Я использую плагин jQuery BBQ для обеспечения функциональности задней страницы. У меня есть следующая реализация:
// Be sure to bind to the "hashchange" event on document.ready, not
// before, or else it may fail in IE6/7. This limitation may be
// removed in a future revision.
$(function(){
// Override the default behavior of all `a` elements so that, when
// clicked, their `href` value is pushed onto the history hash
// instead of being navigated to directly.
$(".content a").click(function(){
var href = $(this).attr( "href" );
// Push this URL "state" onto the history hash.
$.bbq.pushState({ url: href });
// Prevent the default click behavior.
return false;
});
// Bind a callback that executes when document.location.hash changes.
$(window).bind( "hashchange", function(e) {
// In jQuery 1.4, use e.getState( "url" );
var url = $.bbq.getState( "url" );
// In this example, whenever the event is triggered, iterate over
// all `a` elements, setting the class to "current" if the
// href matches (and removing it otherwise).
$("a").each(function(){
var href = $(this).attr( "href" );
if ( href === url ) {
$(this).addClass( "current" );
} else {
$(this).removeClass( "current" );
}
});
console.log(url)
$.getScript(url)
});
// 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" );
});
Теперь это прекрасно работает, если я сразу перехожу на mysite.com/brands, URL-адрес загружается нормально, и когда я нажимаю на вкладку, URL-адрес отображается следующим образом http://localhost:3000/trends#url=/trends/latest, что нормально, кнопка «Назад» работает, когда Я перехожу на другие вкладки на странице.
$. GetScript вызывает JavaScript, который в настоящее время загружает мои компоненты в шаблоны.
Проблема в том, что он работает только на однослойной основе. Если я щелкну родительский элемент навигации Trends и выберу вкладку, плагин не будет работать. Как будто он отказывается это видеть.
Я вижу, что плагин BBQ имеет расширенные функции, но я не уверен, что то, что я хочу, даже продвинуто.
Кто-нибудь может подсказать из jQuery или предыдущего опыта работы с плагином, что я мог сделать?
Очень ценится.
Спасибо
Geoff