joshuagatcke / HTML-KickStart

Ultra–Lean HTML Building Blocks for Rapid Website Production
http://www.99lime.com
MIT License
1.22k stars 244 forks source link

Added ability to mix url tabs and hash tabs without generating an error on load #65

Open abstractlabs opened 9 years ago

abstractlabs commented 9 years ago

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.

tekreme73 commented 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;
});