Sha256: 7f2f2e88dcc6d2fa1929d738de94f13f764fcd1eebc10d6ec725e31070fd1ea3

Contents?: true

Size: 838 Bytes

Versions: 4

Compression:

Stored size: 838 Bytes

Contents

Trestle.init(function(e, root) {
  $(root).find("a[data-toggle='tab']").on('shown.bs.tab', function(e) {
    var hash = $(this).attr("href");
    var withinModal = $(this).closest('.modal').length > 0;

    if (hash.substr(0, 1) == "#" && !withinModal) {
      history.replaceState({ turbolinks: {} }, "", "#!" + hash.substr(1));
    }
  });
});

Trestle.focusActiveTab = function() {
  if (location.hash.substr(0, 2) == "#!") {
    // Focus on active tab from URL
    $("a[data-toggle='tab'][href='#" + location.hash.substr(2) + "']").tab("show");
  } else if ($(".tab-pane:has(.has-error)").length) {
    // Focus on first tab with errors
    var pane = $(".tab-pane:has(.has-error)").first();
    $("a[data-toggle='tab'][href='#" + pane.attr("id") + "']").tab("show");
  }
};

Trestle.init(function() {
  Trestle.focusActiveTab();
});

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
trestle-0.8.13 app/assets/javascripts/trestle/components/_tabs.js
trestle-0.8.12 app/assets/javascripts/trestle/components/_tabs.js
trestle-0.8.11 app/assets/javascripts/trestle/components/_tabs.js
trestle-0.8.10 app/assets/javascripts/trestle/components/_tabs.js