2013-05-22 12:43:49 +00:00
|
|
|
SyntaxHighlighter.defaults['gutter'] = false;
|
|
|
|
SyntaxHighlighter.all();
|
2010-12-21 02:00:33 +00:00
|
|
|
|
2013-05-22 12:43:49 +00:00
|
|
|
// hackity hack
|
|
|
|
$(window).load(function() {
|
2012-02-08 19:27:20 +00:00
|
|
|
var ft = $("#floating-toc");
|
|
|
|
var ul = ft.find('ul');
|
|
|
|
var lis = ft.find('li');
|
2013-05-22 12:43:49 +00:00
|
|
|
var liHeight = $(lis.first()).height();
|
2010-12-21 02:00:33 +00:00
|
|
|
|
2013-05-22 12:43:49 +00:00
|
|
|
ul.css('margin', '0px');
|
|
|
|
ft.css('height', liHeight + 'px');
|
2010-12-21 03:48:43 +00:00
|
|
|
|
2010-12-21 02:00:33 +00:00
|
|
|
showNs = function(ns) {
|
2012-02-08 19:27:20 +00:00
|
|
|
var index = 0;
|
2010-12-21 03:48:43 +00:00
|
|
|
|
|
|
|
for(i in nsPositions.nss) {
|
2013-05-22 12:43:49 +00:00
|
|
|
if(ns == nsPositions.nss[i]) index = i;
|
2010-12-21 03:48:43 +00:00
|
|
|
}
|
|
|
|
|
2013-05-22 12:43:49 +00:00
|
|
|
if(index != lastNsIndex) {
|
|
|
|
lastNsIndex = index;
|
|
|
|
ul.animate({marginTop: (-1 * liHeight * index) + 'px'},
|
|
|
|
300);
|
|
|
|
}
|
2010-12-21 02:00:33 +00:00
|
|
|
|
2013-05-22 12:43:49 +00:00
|
|
|
}
|
2010-12-21 02:00:33 +00:00
|
|
|
|
|
|
|
var calcNsPositions = function() {
|
2013-05-22 12:43:49 +00:00
|
|
|
var hheight = $('.docs-header').first().height();
|
2012-02-08 19:27:20 +00:00
|
|
|
var nss = [];
|
|
|
|
var anchors = [];
|
|
|
|
var positions = [];
|
2010-12-21 02:00:33 +00:00
|
|
|
$.each(lis, function(i, el) {
|
2012-02-08 19:27:20 +00:00
|
|
|
var ns = $(el).attr('id').split('_')[1];
|
|
|
|
nss.push(ns);
|
|
|
|
var a = $("a[name='"+ns+"']");
|
|
|
|
anchors.push(a);
|
2013-05-22 12:43:49 +00:00
|
|
|
positions.push(a.offset().top - hheight);
|
|
|
|
// console.log(a.offset().top)
|
2010-12-21 02:00:33 +00:00
|
|
|
});
|
|
|
|
|
2012-02-08 19:27:20 +00:00
|
|
|
return {nss: nss, positions: positions};
|
2013-05-22 12:43:49 +00:00
|
|
|
}
|
2010-12-21 02:00:33 +00:00
|
|
|
|
2012-02-08 19:27:20 +00:00
|
|
|
var nsPositions = calcNsPositions();
|
2013-05-22 12:43:49 +00:00
|
|
|
// console.log(nsPositions)
|
2012-02-08 19:27:20 +00:00
|
|
|
var lastNsIndex = -1;
|
|
|
|
var $window = $(window);
|
2010-12-21 03:48:43 +00:00
|
|
|
|
2010-12-21 02:00:33 +00:00
|
|
|
var currentSection = function(nsp) {
|
2012-02-08 19:27:20 +00:00
|
|
|
var ps = nsp.positions;
|
2013-05-22 12:43:49 +00:00
|
|
|
var scroll = $window.scrollTop();
|
2012-02-08 19:27:20 +00:00
|
|
|
var nsIndex = -1;
|
2010-12-21 02:00:33 +00:00
|
|
|
|
2013-05-22 12:43:49 +00:00
|
|
|
for(var i = 0, length = ps.length; i < length; i++) {
|
|
|
|
if(ps[i] >= scroll) {
|
2012-02-08 19:27:20 +00:00
|
|
|
nsIndex = i-1;
|
2010-12-21 02:00:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-22 12:43:49 +00:00
|
|
|
if(nsIndex == -1) {
|
|
|
|
if(scroll >= ps[0]) {
|
|
|
|
nsIndex = ps.length - 1;
|
|
|
|
} else {
|
|
|
|
nsIndex = 0;
|
|
|
|
}
|
2010-12-21 02:00:33 +00:00
|
|
|
}
|
|
|
|
|
2013-05-22 12:43:49 +00:00
|
|
|
return nsp.nss[nsIndex];
|
|
|
|
}
|
2010-12-21 02:00:33 +00:00
|
|
|
|
|
|
|
$(window).scroll(function(e) {
|
2012-02-08 19:27:20 +00:00
|
|
|
showNs(currentSection(nsPositions));
|
|
|
|
});
|
|
|
|
});
|