Open abstractlabs opened 9 years ago
My response :
Example in kickstart.js :
// tab click
$(document).on('click', 'ul.tabs a[href*="#"]', function(e){
e.preventDefault();
var tabs = $(this).parents('ul.tabs').find('li');
var tab_next = $(this).attr('href');
var tab_current = tabs.filter('.current').find('a').attr('href');
var aCur = tab_current.split("#");
var idCur = aCur.length > 0 ? aCur[ aCur.length - 1 ] : '';
$("#" + idCur).hide();
tabs.removeClass('current');
$(this).parent().addClass('current');
var aNext = tab_next.split("#");
var idNext = aNext.length > 0 ? aNext[ aNext.length - 1 ] : '';
$("#" + idNext).show();
history.pushState( null, null, window.location.search + $(this).attr('href') );
return false;
});
In one project I am working on I found the need to mix hash and url anchors using the .tabs class. When using a URL anchor they would display correctly but would generate console errors. The one liner simply checks to see of the href starts with a hash tag before triggering the show() method on document ready.