Sha256: 65894621f7cbec1f6157f1d73a49b936038edce1bbefcad7562ef80a64d865eb

Contents?: true

Size: 1.25 KB

Versions: 62

Compression:

Stored size: 1.25 KB

Contents

// Set the document hash to the tab href
$(document).on('show.bs.tab', function (e) {
  history.replaceState(null, null, '#' + e.target.getAttribute('id'));
});

// Display the tab based on form errors, the document hash, or ?tab= params
$(document).ready(function() {
  var href = '';

  var $tab_with_error = $(".form-control.is-invalid").first().closest('.tab-pane')

  if ($tab_with_error.length > 0) {
    href = $tab_with_error.attr('id')
  } else if (document.location.hash.length > 0) {
    var hash = document.location.hash
    if(hash.startsWith('#tab-')) { href = hash.replace('#tab-', '') }
  } else if (document.location.search.length > 0) {
    var param = new URLSearchParams(document.location.search).get('tab') || ''
    if(param.length > 0) { href = param }
  }

  if (href.length > 0) {
    var $tab = $(".nav.nav-tabs").find("a[href^='#" + href + "']")

    $tab.parents('.tab-pane').each (function() {
      $('.nav.nav-tabs').find("a[href^='#" + $(this).attr('id') + "']").tab('show')
    })

    $tab.tab('show')
  }
});


// Click tab button
$(document).on('click', '[data-click-tab]', function(event) {
  event.preventDefault();

  var href = $(event.currentTarget).attr('href');
  $('.nav.nav-tabs').find("a[href^='" + href + "']").tab('show');
});

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
effective_bootstrap-1.19.10 app/assets/javascripts/effective_bootstrap/tabs.js
effective_bootstrap-1.19.9 app/assets/javascripts/effective_bootstrap/tabs.js
effective_bootstrap-1.19.8 app/assets/javascripts/effective_bootstrap/tabs.js
effective_bootstrap-1.19.7 app/assets/javascripts/effective_bootstrap/tabs.js
effective_bootstrap-1.19.6 app/assets/javascripts/effective_bootstrap/tabs.js
effective_bootstrap-1.19.5 app/assets/javascripts/effective_bootstrap/tabs.js
effective_bootstrap-1.19.4 app/assets/javascripts/effective_bootstrap/tabs.js
effective_bootstrap-1.19.3 app/assets/javascripts/effective_bootstrap/tabs.js
effective_bootstrap-1.19.2 app/assets/javascripts/effective_bootstrap/tabs.js
effective_bootstrap-1.19.1 app/assets/javascripts/effective_bootstrap/tabs.js
effective_bootstrap-1.19.0 app/assets/javascripts/effective_bootstrap/tabs.js
effective_bootstrap-1.18.7 app/assets/javascripts/effective_bootstrap/tabs.js
effective_bootstrap-1.18.4 app/assets/javascripts/effective_bootstrap/tabs.js
effective_bootstrap-1.18.3 app/assets/javascripts/effective_bootstrap/tabs.js
effective_bootstrap-1.18.2 app/assets/javascripts/effective_bootstrap/tabs.js
effective_bootstrap-1.18.1 app/assets/javascripts/effective_bootstrap/tabs.js
effective_bootstrap-1.18.0 app/assets/javascripts/effective_bootstrap/tabs.js
effective_bootstrap-1.17.6 app/assets/javascripts/effective_bootstrap/tabs.js
effective_bootstrap-1.17.5 app/assets/javascripts/effective_bootstrap/tabs.js
effective_bootstrap-1.17.4 app/assets/javascripts/effective_bootstrap/tabs.js