'
);
}
$('ul.nav-namespaces li a, ul.nav-packages li a').click(function(){
// Google Chrome does not do Ajax locally
if ($.browser.chrome && (window.location.protocol == 'file:'))
{
return true;
}
$(this).parents('.side-nav').find('.active').removeClass('active');
$(this).parent().addClass('active');
$('div.namespace-contents').load(
this.href + ' div.namespace-contents', function(){
initializeContents();
$(window).scrollTop($('div.namespace-contents').position().top);
}
);
$('div.package-contents').load(
this.href + ' div.package-contents', function(){
initializeContents();
$(window).scrollTop($('div.package-contents').position().top);
}
);
return false;
});
function filterPath(string)
{
return string
.replace(/^\//, '')
.replace(/(index|default).[a-zA-Z]{3,4}$/, '')
.replace(/\/$/, '');
}
var locationPath = filterPath(location.pathname);
// the ipad already smoothly scrolls and does not detect the scrollable
// element if top=0; as such we disable this behaviour for the iPad
if (!$.browser.ipad) {
$('a[href*=#]').each(function ()
{
var thisPath = filterPath(this.pathname) || locationPath;
if (locationPath == thisPath && (location.hostname == this.hostname || !this.hostname) && this.hash.replace(/#/, ''))
{
var target = decodeURIComponent(this.hash.replace(/#/,''));
// note: I'm using attribute selector, because id selector can't match elements with '$'
var $target = $('[id="'+target+'"]');
if ($target.length > 0)
{
$(this).click(function (event)
{
var scrollElem = scrollableElement('html', 'body');
var targetOffset = $target.offset().top;
event.preventDefault();
$(scrollElem).animate({scrollTop:targetOffset}, 400, function ()
{
location.hash = target;
});
});
}
}
});
}
// use the first element that is "scrollable"
function scrollableElement(els)
{
for (var i = 0, argLength = arguments.length; i < argLength; i++)
{
var el = arguments[i], $scrollElement = $(el);
if ($scrollElement.scrollTop() > 0)
{
return el;
}
else
{
$scrollElement.scrollTop(1);
var isScrollable = $scrollElement.scrollTop() > 0;
$scrollElement.scrollTop(0);
if (isScrollable)
{
return el;
}
}
}
return [];
}
// Hide API Documentation menu if it's empty
$('.nav .dropdown a[href=#api]').next().filter(function(i, el) {
if ($(el).children().length == 0) {
return true;
}
}).parent().hide();
});