<commit_before>(function(window, document, undefined) {
  'use strict';

  var counter = 0,
    headCache = document.getElementsByTagName('head')[0],
    BigIdeasText = {
      DEBUG_MODE: false,
      DEFAULT_MIN_FONT_SIZE_PX: null,
      DEFAULT_MAX_FONT_SIZE_PX: 528,
      GLOBAL_STYLE_ID: 'bigIdeasText-style',
      STYLE_ID: 'bigIdeasText-id',
      LINE_CLASS_PREFIX: 'bigIdeasText-line',
      EXEMPT_CLASS: 'bigIdeasText-exempt',
      test: {
        wholeNumberFontSizeOnly: function() {
          if( !( 'getComputedStyle' in window ) || document.body == null ) {
            return true;
          }
          // Test if whole number font-sizes are supported or not
          var test = document.createElement('div');
          test.style.postion = 'absolute';
          test.style.fontSize = '14.1px';
          document.body.appendChild(test);
          var computedStyle = window.getComputedStyle( test, null );
          document.body.removeChild(test);
          if( computedStyle ) {
            return computedStyle.getPropertyValue( 'font-size' ) === '14px';
          }
          return true;
        }
      },
      supports: {
        wholeNumberFontSizeOnly: undefined
      },
      init: function() {
        if( BigIdeasText.supports.wholeNumberFontSizeOnly === undefined ) {
          BigIdeasText.supports.wholeNumberFontSizeOnly = BigIdeasText.test.wholeNumberFontSizeOnly();
        }

        if(!document.getElementById(BigIdeasText.GLOBAL_STYLE_ID)) {
          headCache.appendChild(BigIdeasText.generateStyleTag(BigIdeasText.GLOBAL_STYLE_ID, [
            '.bigIdeasText * { white-space: nowrap; }',
            '.bigIdeasText > * { display: block; }',
            '.bigIdeasText .' + BigIdeasText.EXEMPT_CLASS + ', .bigIdeasText .' + BigIdeasText.EXEMPT_CLASS + ' * { white-space: normal; }'
          ]));
        }
      },
      bindResize: function(eventName, resizeFunction) {
        window.removeEventListener('rezie', resizeFunction);
        // if(typeof window.Cowboy !== 'undefined' && typeof window.Cowboy.throttle !== 'undefined') {
        //     window.addEventListener('resize', window.Cowboy.throttle(100, resizeFunction), false);
        // } else {
          window.addEventListener('resize', debounce(resizeFunction, 100), false);
        // }
      },
      getStyleId: function(id)
      {
        return BigIdeasText.STYLE_ID + '-' + id;
      },
      generateStyleTag: function(id, css)
      {
        var styleEl = document.createElement('style');
        styleEl.innerHTML = css.join('\n');
        styleEl.setAttribute('id', id);
        return styleEl;
      },
      clearCss: function(id)
      {
        var styleSheets = document.styleSheets;
        forEach(styleSheets, function(sheetCSS) {
          var sheet = sheetCSS.ownerNode;
          if(sheet.id === BigIdeasText.getStyleId(id)) {
            return document.head.removeChild(sheet);
          }
        });
      },
      generateCss: function(id, linesFontSizes, lineWordSpacings, minFontSizes)
      {
        var css = [];

        BigIdeasText.clearCss(id);

        for(var j=0, k=linesFontSizes.length; j<k; j++) {
          css.push('#' + id + ' .' + BigIdeasText.LINE_CLASS_PREFIX + j + ' {' +
            (minFontSizes[j] ? ' white-space: normal;' : '') +
            (linesFontSizes[j] ? ' font-size: ' + linesFontSizes[j] + 'px;' : '') +
            (lineWordSpacings[j] ? ' word-spacing: ' + lineWordSpacings[j] + 'px;' : '') +
            '}');
        }


        return BigIdeasText.generateStyleTag(BigIdeasText.getStyleId(id), css);
      },
      mainMethod: function(options)
      {
        BigIdeasText.init();
        options = extend({
          minfontsize: BigIdeasText.DEFAULT_MIN_FONT_SIZE_PX,
          maxfontsize: BigIdeasText.DEFAULT_MAX_FONT_SIZE_PX,
          childSelector: '',
          resize: true
        }, options || {});

        // FIXME Only works if an array is passed in right now

        forEach(this, function(self)
        {
          var selfStyle = getComputedStyle(self);
          var maxWidth = parseInt(selfStyle.getPropertyValue('width'), 10);
          var id = self.getAttribute('id');
          var children = options.childSelector ? self.querySelectorAll( options.childSelector ) : self.children;
          var minFontSizeAttr = self.getAttribute('bigIdeasText-minfontsize') || false;
          var maxFontSizeAttr = self.getAttribute('bigIdeasText-maxfontsize') || false;
          var minFontSize = options.minfontsize;
          var maxFontSize = options.maxfontsize;

          if(maxFontSizeAttr !== false) {
            maxFontSize = parseInt(maxFontSizeAttr, 10)
          }

          if(minFontSizeAttr !== false) {
            minFontSize = parseInt(minFontSizeAttr, 10)
          }

          addClass(self, 'bigIdeasText');

          if(!id) {
            // KO changed approach here
            id = BigIdeasText.getStyleId(counter++);
            self.setAttribute('id', id);
          }

          if(options.resize) {
            BigIdeasText.bindResize('resize.bigIdeasText-event-' + id, function()
            {
              // TODO only call this if the width has changed.
              BigIdeasText.mainMethod.call(document.getElementById(id), options);
            });
          }

          BigIdeasText.clearCss(id);

          forEach(children, function(child, lineNumber){
            child.className = child.className.replace(new RegExp('\\b' + BigIdeasText.LINE_CLASS_PREFIX + '\\d+\\b'), '');
            addClass(child, BigIdeasText.LINE_CLASS_PREFIX + lineNumber);
          });

          var sizes = calculateSizes(self, children, maxWidth, maxFontSize, minFontSize);
          headCache.appendChild(BigIdeasText.generateCss(id, sizes.fontSizes, sizes.wordSpacings, sizes.minFontSizes));
        });

        // return trigger(this, 'bigIdeasText:complete');
        return this;
      }
    };

  // function trigger(el, name) {
  //   var evt;<commit_msg>Only run if width has actually changed #3<commit_after>(function(window, document, undefined) {
  'use strict';

  var counter = 0,
    headCache = document.getElementsByTagName('head')[0],
    BigIdeasText = {
      DEBUG_MODE: false,
      DEFAULT_MIN_FONT_SIZE_PX: null,
      DEFAULT_MAX_FONT_SIZE_PX: 528,
      GLOBAL_STYLE_ID: 'bigIdeasText-style',
      STYLE_ID: 'bigIdeasText-id',
      LINE_CLASS_PREFIX: 'bigIdeasText-line',
      EXEMPT_CLASS: 'bigIdeasText-exempt',
      test: {
        wholeNumberFontSizeOnly: function() {
          if( !( 'getComputedStyle' in window ) || document.body == null ) {
            return true;
          }
          // Test if whole number font-sizes are supported or not
          var test = document.createElement('div');
          test.style.postion = 'absolute';
          test.style.fontSize = '14.1px';
          document.body.appendChild(test);
          var computedStyle = window.getComputedStyle( test, null );
          document.body.removeChild(test);
          if( computedStyle ) {
            return computedStyle.getPropertyValue( 'font-size' ) === '14px';
          }
          return true;
        }
      },
      supports: {
        wholeNumberFontSizeOnly: undefined
      },
      init: function() {
        if( BigIdeasText.supports.wholeNumberFontSizeOnly === undefined ) {
          BigIdeasText.supports.wholeNumberFontSizeOnly = BigIdeasText.test.wholeNumberFontSizeOnly();
        }

        if(!document.getElementById(BigIdeasText.GLOBAL_STYLE_ID)) {
          headCache.appendChild(BigIdeasText.generateStyleTag(BigIdeasText.GLOBAL_STYLE_ID, [
            '.bigIdeasText * { white-space: nowrap; }',
            '.bigIdeasText > * { display: block; }',
            '.bigIdeasText .' + BigIdeasText.EXEMPT_CLASS + ', .bigIdeasText .' + BigIdeasText.EXEMPT_CLASS + ' * { white-space: normal; }'
          ]));
        }
      },
      bindResize: function(eventName, resizeFunction) {
        window.removeEventListener('resize', resizeFunction);
        window.addEventListener('resize', debounce(resizeFunction, 500), false);
      },
      getStyleId: function(id)
      {
        return BigIdeasText.STYLE_ID + '-' + id;
      },
      generateStyleTag: function(id, css)
      {
        var styleEl = document.createElement('style');
        styleEl.innerHTML = css.join('\n');
        styleEl.setAttribute('id', id);
        return styleEl;
      },
      clearCss: function(id)
      {
        var styleSheets = document.styleSheets;
        forEach(styleSheets, function(sheetCSS) {
          var sheet = sheetCSS.ownerNode;
          if(sheet.id === BigIdeasText.getStyleId(id)) {
            return document.head.removeChild(sheet);
          }
        });
      },
      generateCss: function(id, linesFontSizes, lineWordSpacings, minFontSizes)
      {
        var css = [];

        BigIdeasText.clearCss(id);

        for(var j=0, k=linesFontSizes.length; j<k; j++) {
          css.push('#' + id + ' .' + BigIdeasText.LINE_CLASS_PREFIX + j + ' {' +
            (minFontSizes[j] ? ' white-space: normal;' : '') +
            (linesFontSizes[j] ? ' font-size: ' + linesFontSizes[j] + 'px;' : '') +
            (lineWordSpacings[j] ? ' word-spacing: ' + lineWordSpacings[j] + 'px;' : '') +
            '}');
        }


        return BigIdeasText.generateStyleTag(BigIdeasText.getStyleId(id), css);
      },
      mainMethod: function(options)
      {
        BigIdeasText.init();
        options = extend({
          minfontsize: BigIdeasText.DEFAULT_MIN_FONT_SIZE_PX,
          maxfontsize: BigIdeasText.DEFAULT_MAX_FONT_SIZE_PX,
          childSelector: '',
          resize: true
        }, options || {});

        // FIXME Only works if an array is passed in right now

        forEach(this, function(self)
        {
          var selfStyle = getComputedStyle(self);
          var maxWidth = parseInt(selfStyle.getPropertyValue('width'), 10);
          var id = self.getAttribute('id');
          var children = options.childSelector ? self.querySelectorAll( options.childSelector ) : self.children;
          var minFontSizeAttr = self.getAttribute('bigIdeasText-minfontsize') || false;
          var maxFontSizeAttr = self.getAttribute('bigIdeasText-maxfontsize') || false;
          var selfWidthAttr = self.getAttribute('bigIdeasText-width') || self.offsetWidth;
          var minFontSize = options.minfontsize;
          var maxFontSize = options.maxfontsize;

          if(maxFontSizeAttr !== false) {
            maxFontSize = parseInt(maxFontSizeAttr, 10)
          }

          if(minFontSizeAttr !== false) {
            minFontSize = parseInt(minFontSizeAttr, 10)
          }

          addClass(self, 'bigIdeasText');

          if(!id) {
            // KO changed approach here
            id = BigIdeasText.getStyleId(counter++);
            self.setAttribute('id', id);
          }

          if(options.resize) {
            BigIdeasText.bindResize('resize.bigIdeasText-event-' + id, function()
            {
              if (selfWidthAttr !== self.offsetWidth) {
                self.setAttribute('bigIdeasText-width', self.offsetWidth)
                BigIdeasText.mainMethod.call(document.getElementById(id), options);
              }
            });
          }

          BigIdeasText.clearCss(id);

          forEach(children, function(child, lineNumber){
            child.className = child.className.replace(new RegExp('\\b' + BigIdeasText.LINE_CLASS_PREFIX + '\\d+\\b'), '');
            addClass(child, BigIdeasText.LINE_CLASS_PREFIX + lineNumber);
          });

          var sizes = calculateSizes(self, children, maxWidth, maxFontSize, minFontSize);
          headCache.appendChild(BigIdeasText.generateCss(id, sizes.fontSizes, sizes.wordSpacings, sizes.minFontSizes));
        });

        // return trigger(this, 'bigIdeasText:complete');
        return this;
      }
    };

  // function trigger(el, name) {
  //   var evt;
{'fraction_non_alphanumeric': 0.1242147583549711, 'fraction_numerical': 0.0036854007873356226, 'mean_word_length': 2.262295081967213, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4785059', 'n_tokens_mistral': 3643, 'n_tokens_neox': 3494, 'n_words': 591}