<commit_before>module.exports = function() {
  var className = ".tab";

  var Tab = function(element, opts) {
    opts = opts || {};

    this.element = element;
    this.$element = $(element);
    this.tabNav = $(".tabs [href='#" + element.id + "']");
    this.isOpen = false;
    this.siblings = $(className).not(this.$element);
    this.$element.data("tab", this);

    this.init();
  };

  Tab.prototype.init = function() {
    if (this.tabNav.parent("li").hasClass("current")) {
      this.open();
    } else {
      this.close();
    }
  };

  Tab.prototype.open = function() {
    this.$element.removeClass("hidden");
    this.$element.addClass("visible");
    this.isOpen = true;
    $(".tabs .current").removeClass("current");
    this.tabNav.addClass("current");

    $.each(this.siblings, function(idx, el) {
      var tab = $(el).data("tab");
      if (tab) {
        tab.close();
      }
    });
  };

  Tab.prototype.close = function() {
    this.$element.removeClass("visible");
    this.$element.addClass("hidden");
    this.isOpen = false;
  };

  Tab.prototype.toggle = function() {
    if (this.isOpen) {
      this.close();
    } else {
      this.open();
    }
  };

  $(function() {
    $(window)[0].scrollTo(0, 0);


    var tabs = $(className);
    $.each(tabs, function(idx, el) {
      var tab = new Tab(el);

      tab.tabNav.on("click", function(e) {
        e.preventDefault();
        tab.open();
        location.hash = $(this).attr('href');
        $(window)[0].scrollTo(0, 0);
      });
    });

    if ($(".tabs .current").attr("href") !== location.hash) {
      var tab = $(location.hash).data('tab');
      tab.open();
    }

    $(window).on("hashchange", function(e) {
      if ($(".tabs .current").attr("href") !== location.hash) {
        var tab = $(location.hash).data('tab');
        tab.open();
      }
    });
<commit_msg>Make sure tab is defined before trying to open it<commit_after>module.exports = function() {
  var className = ".tab";

  var Tab = function(element, opts) {
    opts = opts || {};

    this.element = element;
    this.$element = $(element);
    this.tabNav = $(".tabs [href='#" + element.id + "']");
    this.isOpen = false;
    this.siblings = $(className).not(this.$element);
    this.$element.data("tab", this);

    this.init();
  };

  Tab.prototype.init = function() {
    if (this.tabNav.parent("li").hasClass("current")) {
      this.open();
    } else {
      this.close();
    }
  };

  Tab.prototype.open = function() {
    this.$element.removeClass("hidden");
    this.$element.addClass("visible");
    this.isOpen = true;
    $(".tabs .current").removeClass("current");
    this.tabNav.addClass("current");

    $.each(this.siblings, function(idx, el) {
      var tab = $(el).data("tab");
      if (tab) {
        tab.close();
      }
    });
  };

  Tab.prototype.close = function() {
    this.$element.removeClass("visible");
    this.$element.addClass("hidden");
    this.isOpen = false;
  };

  Tab.prototype.toggle = function() {
    if (this.isOpen) {
      this.close();
    } else {
      this.open();
    }
  };

  $(function() {
    $(window)[0].scrollTo(0, 0);


    var tabs = $(className);
    $.each(tabs, function(idx, el) {
      var tab = new Tab(el);

      tab.tabNav.on("click", function(e) {
        e.preventDefault();
        tab.open();
        location.hash = $(this).attr('href');
        $(window)[0].scrollTo(0, 0);
      });
    });

    if ($(".tabs .current").attr("href") !== location.hash) {
      var tab = $(location.hash).data('tab');
      tab && tab.open();
    }

    $(window).on("hashchange", function(e) {
      if ($(".tabs .current").attr("href") !== location.hash) {
        var tab = $(location.hash).data('tab');
        tab.open();
      }
    });

{'fraction_non_alphanumeric': 0.213926396611067, 'fraction_numerical': 0.003177124702144559, 'mean_word_length': 2.4345454545454546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5248847', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1219, 'n_words': 216}