Skip to content

Commit

Permalink
corrected up/down detection for navigating site tree
Browse files Browse the repository at this point in the history
  • Loading branch information
michaek committed Jun 23, 2011
1 parent 5467a18 commit 85e9e11
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions jquery.bbq.pjax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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)
Expand All @@ -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) {
Expand Down Expand Up @@ -112,4 +116,6 @@
return url != '' ? url : rootUrlPlaceholder
}

var initialUrl = rootRelativeUrl(window.location.href)

})(jQuery)

0 comments on commit 85e9e11

Please sign in to comment.