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 optional history.pushState behaviour to Tab.show. #12101

Closed
wants to merge 2 commits into from
Closed

Added optional history.pushState behaviour to Tab.show. #12101

wants to merge 2 commits into from

Conversation

Robadob
Copy link

@Robadob Robadob commented Jan 5, 2014

history.pushState updates the browser history and address bar.

I found it unusual that the functionality of pressing tabs updating the address bar to this url was unavailable, so that tabs could be more easily treated as a single page nav. I understand this behaviour isn't always necessary, hence the optional usage by adding follow-url as an attribute to the anchor which is used to show the tab.

Loading the correct tab then works something like this where all tab anchors have .my_tabs

$(document).ready(function(){
    $address=document.URL;
    if($address.replace(/^[^#]*/, "").length==0)
       $address=$address+$(".my_tabs.active").attr("href");
    $selector = $address.replace(/^[^#]*/, "");
    $(".phase_link").each(
        function( index ) {
            if ($selector == $(this).attr("href"))
                $(this).tab("show");
        }
    );
});

history.pushState is HTML5 so wont work in older browsers, however this functionality is implemented at the end of the show method so any javascript error caused by it would't break the primary functionality of tabs. If it were desired for this to implemented for older browsers this stackoverflow post suggests a method which I haven't tested; http://stackoverflow.com/a/136506/1646387

@Robadob
Copy link
Author

Robadob commented Jan 5, 2014

I fixed the only reported Travis issue, I won't try and rebase the change because I tried to do it on an earlier version and just ended up creating 2 more commits.

@cvrebert
Copy link
Collaborator

cvrebert commented Jan 5, 2014

Given the outcome of #581, I'm doubtful that this will be merged.

@Robadob
Copy link
Author

Robadob commented Jan 5, 2014

Ah thanks, given heruan's comment on that pull request towards ie7 support being dropped in BS3 there's always a change that this functionality will be looked at in future, so a possible implementation is here if it is.

@fat
Copy link
Member

fat commented Mar 14, 2014

don't really think this is worth adding. it's super easy to add for people that want it: listen to shown.bs.tab – and my hunch is it would mean a lots of support down the line. If you really want this behavior… you're probably better off building ontop of a framework that manages url structure for you

@fat fat closed this Mar 14, 2014
@mdo mdo removed this from the v3.2.0 milestone Mar 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants