Sha256: 2ae74b08d6b0c17192e8f9c779a0fef1fcc4fdb652a560a7d1579bd66cd59384

Contents?: true

Size: 839 Bytes

Versions: 3

Compression:

Stored size: 839 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.ready(function() {
  Trestle.focusActiveTab();
});

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
trestle-0.8.9 app/assets/javascripts/trestle/components/_tabs.js
trestle-0.8.8 app/assets/javascripts/trestle/components/_tabs.js
trestle-0.8.7 app/assets/javascripts/trestle/components/_tabs.js