From 85e9e1109e4ac543046de3e1e1811e8b2f48ee20 Mon Sep 17 00:00:00 2001 From: Michael Hellein Date: Thu, 23 Jun 2011 18:08:10 -0400 Subject: [PATCH] corrected up/down detection for navigating site tree --- jquery.bbq.pjax.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/jquery.bbq.pjax.js b/jquery.bbq.pjax.js index fbba750..cb07284 100644 --- a/jquery.bbq.pjax.js +++ b/jquery.bbq.pjax.js @@ -31,10 +31,11 @@ // Set up the initial pjax-page content. var $pjaxPage = $pjaxWrapTemplate.clone() $pjaxPage.append($container.children()).appendTo($container) + $pjaxPage.data('pjax-title', document.title) $currentPage = cache[lastURL] = $pjaxPage $(options.linkSelector).live('click', function(event){ - $link = $(event.srcElement) + $link = $(this) // Get the url from the link's href attribute, stripping any leading #. $.bbq.pushState( $link.attr( 'href' ).replace( /^#/, '' ), 2 ) @@ -58,7 +59,8 @@ } else { $container.addClass('pjax-loading') cache[rel_url] = $pjaxWrapTemplate.clone().data('pjax-url', rel_url) - cache[rel_url].load(url, function(){ + var delim = url.indexOf('?') == -1 ? '?' : '&' + cache[rel_url].load(url+delim+'_pjax=true', function(){ $(this).find('meta').remove() $(this).data('pjax-title', $.trim( $(this).find('title').remove().text() )) $(this).hide().appendTo($container) @@ -71,8 +73,10 @@ var transition = function($to){ // Make some guesses about the direction we're navigating by inspecting the URLs. var dir = 'same' - var fromDepth = $currentPage.data('pjax-url') ? $currentPage.data('pjax-url').replace(/\/&/, '').split('/').length : 0 - var toDepth = $to.data('pjax-url') ? $to.data('pjax-url').replace(/\/&/, '').split('/').length : 0 + var initialDepth = initialUrl.replace(/\/$/, '').split('/').length + var fromDepth = $currentPage.data('pjax-url') ? $currentPage.data('pjax-url').replace(/\/$/, '').split('/').length : initialDepth + var toDepth = $to.data('pjax-url') ? $to.data('pjax-url').replace(/\/$/, '').split('/').length : initialDepth + if (fromDepth > toDepth) { dir = 'up' } else if (fromDepth < toDepth) { @@ -112,4 +116,6 @@ return url != '' ? url : rootUrlPlaceholder } + var initialUrl = rootRelativeUrl(window.location.href) + })(jQuery)