Template:Evry/TestPageJS
// Testing external JS for test page (new layout) $(function () {
$('.navbar-toggle').click(function () { $('.navbar-nav').toggleClass('slide-in'); $('.side-body').toggleClass('body-slide-in'); $('#search').removeClass('in').addClass('collapse').slideUp(200);
/// uncomment code for absolute positioning tweek see top comment in css //$('.absolute-wrapper').toggleClass('slide-in'); }); // Remove menu for searching $('#search-trigger').click(function () { $('.navbar-nav').removeClass('slide-in'); $('.side-body').removeClass('body-slide-in');
/// uncomment code for absolute positioning tweek see top comment in css //$('.absolute-wrapper').removeClass('slide-in');
});
});
$("li.panel > a").click( function () { $(this).parent().toggleClass('current-panel'); $("li.panel").not($(this).parent()).each(function(){
$('.panel-collapse.in').collapse('hide');
$(this).removeClass('current-panel'); }) });
/*$(document).ready(
function() { $("#side-navigation").niceScroll({cursorcolor:"#00F"});
} );*/
// Cache selectors var lastId,
topMenu = $("#top-menu"), topMenuHeight = topMenu.outerHeight()+15, // All list items menuItems = topMenu.find("a"), // Anchors corresponding to menu items scrollItems = menuItems.map(function(){ var item = $($(this).attr("href")); if (item.length) { return item; } });
// Bind click handler to menu items // so we can get a fancy scroll animation menuItems.click(function(e){
var href = $(this).attr("href"), offsetTop = href === "#" ? 0 : $(href).offset().top-topMenuHeight+1; $('html, body').stop().animate({ scrollTop: offsetTop-35 }, 300); e.preventDefault();
});
// Bind to scroll $(window).scroll(function(){
// Get container scroll position var fromTop = $(this).scrollTop()+topMenuHeight; // Get id of current scroll item var cur = scrollItems.map(function(){ if ($(this).offset().top < fromTop) return this; }); // Get the id of the current element cur = cur[cur.length-1]; var id = cur && cur.length ? cur[0].id : ""; if (lastId !== id) { lastId = id; // Set/remove active class menuItems .parent().removeClass("active") .end().filter("[href=#"+id+"]").parent().addClass("active"); }
});
// Sticky div relocation function to let the page navigation stay on top function sticky_nav_relocate() { var window_top = $(window).scrollTop(); // Position of 'top of window' var top_menu_top = $('#top-menu-anchor').offset().top; // Position of top of div // If the div top position is lower than the window top position (which means that the div is visually 'higher'), stick it! if (window_top > top_menu_top) { $('#top-menu').addClass('stick'); // Quick fix to make the div-width equal to the content width $("#top-menu").css("width", $("#content-body").width()); } else { $('#top-menu').removeClass('stick'); } } // Triggers barcharts legend div relocation function on scroll event $(function() { $(window).scroll(sticky_nav_relocate); sticky_nav_relocate(); });