<commit_before>(function (global, factory) {
  if (typeof define === 'function' && define.amd) {
    // AMD. Register as an anonymous module unless amdModuleId is set
    define([], function () {
      return (global['lrStickyHeader'] = factory(global));
    });
  } else if (typeof exports === 'object') {
    // Node. Does not work with strict CommonJS, but
    // only CommonJS-like environments that support module.exports,
    // like Node.
    module.exports = factory(global);
  } else {
    global['lrStickyHeader'] = factory(global);
  }
})(window, function factory (window) {
  'use strict';
  function getOffset (element, property) {
    var offset = element[property];
    var parent = element;
    while ((parent = parent.offsetParent) !== null) {
      offset += parent[property];
    }
    return offset;
  }

  var sticky = {
    //todo some memoize stuff
    setWidth: function setWidth () {
      var firstRow = this.tbody.getElementsByTagName('TR')[0];
      var trh = this.thead.getElementsByTagName('TR')[0];
      var firstTds;
      var firstThs;

      function setCellWidth (cell) {
        cell.style.width = cell.offsetWidth + 'px';
      }

      if (firstRow && trh) {
        firstTds = firstRow.getElementsByTagName('TD');
        firstThs = trh.getElementsByTagName('TH');

        [].forEach.call(firstTds, setCellWidth);
        [].forEach.call(firstThs, setCellWidth);
      }
    },
    eventListener: function eventListener () {
      var offsetTop = this.offsetTopOverride ? this.offsetTopOverride : getOffset(this.thead, 'offsetTop');
      var offsetLeft = getOffset(this.thead, 'offsetLeft');
      var classes = this.thead.className.split(' ');

      if (this.stick !== true) {
        var scrollPosition = this.isWindowScroll ? this.scrollContainer.scrollY : this.scrollContainer.scrollTop;
        if (offsetTop - scrollPosition < 0) {
          this.stick = true;
          this.treshold = offsetTop;
          this.setWidth();
          this.thead.style.left = offsetLeft + 'px';
          this.thead.style.top = this.isWindowScroll ? 0 : this.scrollContainer.getBoundingClientRect().top + 'px';
          setTimeout(function () {
            classes.push('lr-sticky-header');
            this.thead.style.position = 'fixed';
            this.thead.className = classes.join(' ');
          }.bind(this), 0);
        }
      }

      if (this.stick === true) {
        var scrollPosition = this.isWindowScroll ? this.scrollContainer.scrollY : this.scrollContainer.scrollTop;
        if (this.treshold - scrollPosition > 0) {
          this.stick = false;
          this.thead.style.position = 'initial';
          classes.splice(classes.indexOf('lr-sticky-header'), 1);
          this.thead.className = (classes).join(' ');
        }
      }
    }
  };

  return function lrStickyHeader (tableElement, options) {
    options                   = options || {};
    options.scrollContainer   = options.scrollContainer || window;
    options.offsetTopOverride = options.offsetTopOverride || null;

    var isWindowScroll = options.scrollContainer === window;

    var thead;
    var tbody;

    if (tableElement.tagName !== 'TABLE') {
      throw new Error('lrStickyHeader only works on table element');
    }

    tbody = tableElement.getElementsByTagName('TBODY');
    thead = tableElement.getElementsByTagName('THEAD');
    if (!thead.length) {
      throw new Error('could not find the thead group element');<commit_msg>streamlined code to be more in line with master instead of latest bower release<commit_after>(function (global, factory) {
  if (typeof define === 'function' && define.amd) {
    // AMD. Register as an anonymous module unless amdModuleId is set
    define([], function () {
      return (global['lrStickyHeader'] = factory(global));
    });
  } else if (typeof exports === 'object') {
    // Node. Does not work with strict CommonJS, but
    // only CommonJS-like environments that support module.exports,
    // like Node.
    module.exports = factory(global);
  } else {
    global['lrStickyHeader'] = factory(global);
  }
})(window, function factory (window) {
  'use strict';
  function getOffset (element, property) {
    var offset = element[property];
    var parent = element;
    while ((parent = parent.offsetParent) !== null) {
      offset += parent[property];
    }
    return offset;
  }

  var sticky = {
    //todo some memoize stuff
    setWidth: function setWidth () {
      var firstRow = this.tbody.getElementsByTagName('TR')[0];
      var trh = this.thead.getElementsByTagName('TR')[0];
      var firstTds;
      var firstThs;

      function setCellWidth (cell) {
        cell.style.width = cell.offsetWidth + 'px';
      }

      if (firstRow && trh) {
        firstTds = firstRow.getElementsByTagName('TD');
        firstThs = trh.getElementsByTagName('TH');

        [].forEach.call(firstTds, setCellWidth);
        [].forEach.call(firstThs, setCellWidth);
      }
    },
    eventListener: function eventListener () {
      var offsetTop      = this.offsetTopOverride ? this.offsetTopOverride : getOffset(this.thead, 'offsetTop');
      var offsetLeft     = getOffset(this.thead, 'offsetLeft');
      var classes        = this.thead.className.split(' ');
      var scrollPosition = this.isWindowScroll ? this.scrollContainer.scrollY : this.scrollContainer.scrollTop;

      if (this.stick !== true && (offsetTop - scrollPosition < 0)) {
        if (offsetTop - scrollPosition < 0) {
          this.stick = true;
          this.treshold = offsetTop;
          this.setWidth();
          this.thead.style.left = offsetLeft + 'px';
          this.thead.style.top = this.isWindowScroll ? 0 : this.scrollContainer.getBoundingClientRect().top + 'px';
          setTimeout(function () {
            classes.push('lr-sticky-header');
            this.thead.style.position = 'fixed';
            this.thead.className = classes.join(' ');
          }.bind(this), 0);
        }
      }

      if (this.stick === true && (this.treshold - scrollPosition > 0)) {
        if (this.treshold - scrollPosition > 0) {
          this.stick = false;
          this.thead.style.position = 'initial';
          classes.splice(classes.indexOf('lr-sticky-header'), 1);
          this.thead.className = (classes).join(' ');
        }
      }
    }
  };

  return function lrStickyHeader (tableElement, options) {
    options                   = options || {};
    options.scrollContainer   = options.scrollContainer || window;
    options.offsetTopOverride = options.offsetTopOverride || null;

    var isWindowScroll = options.scrollContainer === window;

    var thead;
    var tbody;

    if (tableElement.tagName !== 'TABLE') {
      throw new Error('lrStickyHeader only works on table element');
    }

    tbody = tableElement.getElementsByTagName('TBODY');
    thead = tableElement.getElementsByTagName('THEAD');
    if (!thead.length) {
      throw new Error('could not find the thead group element');
{'fraction_non_alphanumeric': 0.12987385321100917, 'fraction_numerical': 0.0022935779816513763, 'mean_word_length': 2.6528795811518324, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '6391299', 'n_tokens_mistral': 2037, 'n_tokens_neox': 1966, 'n_words': 463}