Skip to content

Instantly share code, notes, and snippets.

@acbilimoria
Last active October 6, 2015 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acbilimoria/a1df0dd3329d9638b6e3 to your computer and use it in GitHub Desktop.
Save acbilimoria/a1df0dd3329d9638b6e3 to your computer and use it in GitHub Desktop.
tabbing
show_tab = () ->
if location.hash.match(/^#tab-/)
$(".nav-tabs a[href=##{location.hash.replace('#tab-', '')}]").tab('show')
return
show_tab()
$(window).on 'popstate', ->
show_tab()
$('a[data-toggle="tab"]').on 'shown.bs.tab', (e) ->
window.location.hash = e.target.hash.replace('#', '#tab-')
if errored_pane = $('.tab-pane .field_with_errors:eq(1)').parents('.tab-pane').attr('id')
$(".nav-tabs a[href=##{errored_pane}]").tab('show')
====================
or
====================
if location.hash.match(/^#tab-/)
$(".nav-tabs a[href=##{location.hash.replace('#tab-', '')}]").tab('show')
$(window).on 'popstate', ->
if location.hash.match(/^#tab-/)
$(".nav-tabs a[href=##{location.hash.replace('#tab-', '')}]").tab('show')
return
$('a[data-toggle="tab"]').on 'shown.bs.tab', (e) ->
window.location.hash = e.target.hash.replace('#', '#tab-')
if errored_pane = $('.tab-pane .field_with_errors:eq(1)').parents('.tab-pane').attr('id')
$(".nav-tabs a[href=##{errored_pane}]").tab('show')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment