Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

abstractlabs
Copy link

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
Copy link

My response :

  • a[href+="#"] => a[href*="#"]
  • split href to get the element id

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants