<commit_before>/**
 * MIT License
 * @author <NAME><http://barretlee.com/about/>
 * @datetime 2015-11-16 20:21:27
 */

~function(window, undefined) {

  // exports to global
  umd("Lazyload", Lazyload);

  Lazyload.TAG = "data-src";
  Lazyload.DISTANCE = 0;

  // Lazyload Component
  function Lazyload(elements) {
    this.elements = typeof elements === "string" ? $(elements) : elements;
    this.init();
  };

  // init, bind event
  Lazyload.prototype.init = function() {
    var self = this;
    self._detectElementIfInScreen();

    var timer;
    addEventListener("scroll", function() {
      timer = setTimeout(function() {
        timer && clearTimeout(timer);
        self._detectElementIfInScreen();
      }, 50);
    });
    addEventListener("resize", function(){
      self._detectElementIfInScreen();
    });
  };

  // detect if in screen
  Lazyload.prototype._detectElementIfInScreen = function() {
    if(!this.elements.length) return;
    for (var i = 0; i < this.elements.length; i++) {
      var ele = this.elements[i];
      var rect = ele.getBoundingClientRect();
      if(rect.top >= Lazyload.DISTANCE && rect.left >= Lazyload.DISTANCE
        && rect.top <= (window.innerHeight || document.documentElement.clientHeight)
        && rect.left <= (window.innerWidth || document.documentElement.clientWidth)) {
        this.loadItem(ele, i);
        this.elements.splice(i, 1);
        i--;
      }
    }
  };

  // lazyload img or script
  Lazyload.prototype.loadItem = function(ele, i) {
    var imgs = ele.getElementsByTagName("img");
    for(var i = 0; i < imgs.length; i++) {
      var img = imgs[i];
      var src = img.getAttribute(Lazyload.TAG);
      if(src) {
        img.setAttribute("src", src);
      }
    }

    var textareas = ele.getElementsByTagName("textarea");
    for(var j = 0; j < textareas.length; j++){
      var script = textareas[j].value;
      if(window.execScript) {
        window.execScript(script);
      } else {
        new Function(script)();
      }
    }
  };

  // mini Query
  function $(query) {
    var res = [];
    if (document.querySelectorAll) {
      res = document.querySelectorAll(query);
    } else {
      var firstStyleSheet = document.styleSheets[0] || document.createStyleSheet();
      firstStyleSheet.addRule(query, 'Barret:Lee');
      for (var i = 0, len = document.all.length; i < len; i++) {
        var item = document.all[i];
        item.currentStyle.Barret && res.push(item);
      }
      firstStyleSheet.removeRule(0);
    }
    if(res.item) { /* Fuck IE8 */
      var ret = [];
      for(var i = 0; i < res.length; i++){
        ret.push(res.item(i));
      }
      res = ret;
    }
    return res;
  };

  function addEventListener(evt, fn){
    window.addEventListener ? this.addEventListener(evt, fn, false) : (window.attachEvent)
        ? this.attachEvent('on' + evt, fn) : this['on' + evt] = fn;
  }

  // UMD
  function umd(name, component) {
    switch (true) {
      case typeof module === 'object' && !!module.exports:
        module.exports = component;
        break;
      case String(typeof define) === 'function' && !!define.amd:
        define(name, function() {
          return component;
        });
        break;
      default:
        try { /* Fuck IE8- */<commit_msg>modify<commit_after>/**
 * MIT License
 * @author <NAME><http://barretlee.com/about/>
 * @datetime 2015-11-16 20:21:27
 */

~function(window, undefined) {

  // exports to global
  umd("Lazyload", Lazyload);

  Lazyload.TAG = "data-src";
  Lazyload.DISTANCE = 0;

  // Lazyload Component
  function Lazyload(elements) {
    this.elements = typeof elements === "string" ? $(elements) : elements;
    this.init();
  };

  // init, bind event
  Lazyload.prototype.init = function() {
    var self = this;
    self._detectElementIfInScreen();

    var timer;
    addEventListener("scroll", function() {
      timer && clearTimeout(timer);
      timer = setTimeout(function() {
        self._detectElementIfInScreen();
      }, 50);
    });
    addEventListener("resize", function(){
      self._detectElementIfInScreen();
    });
  };

  // detect if in screen
  Lazyload.prototype._detectElementIfInScreen = function() {
    if(!this.elements.length) return;
    for (var i = 0; i < this.elements.length; i++) {
      var ele = this.elements[i];
      var rect = ele.getBoundingClientRect();
      if(rect.top >= Lazyload.DISTANCE && rect.left >= Lazyload.DISTANCE
        && rect.top <= (window.innerHeight || document.documentElement.clientHeight)
        && rect.left <= (window.innerWidth || document.documentElement.clientWidth)) {
        this.loadItem(ele, i);
        this.elements.splice(i, 1);
        i--;
      }
    }
  };

  // lazyload img or script
  Lazyload.prototype.loadItem = function(ele, i) {
    var imgs = ele.getElementsByTagName("img");
    for(var i = 0; i < imgs.length; i++) {
      var img = imgs[i];
      var src = img.getAttribute(Lazyload.TAG);
      if(src) {
        img.setAttribute("src", src);
      }
    }

    var textareas = ele.getElementsByTagName("textarea");
    for(var j = 0; j < textareas.length; j++){
      var script = textareas[j].value;
      if(window.execScript) {
        window.execScript(script);
      } else {
        new Function(script)();
      }
    }
  };

  // mini Query
  function $(query) {
    var res = [];
    if (document.querySelectorAll) {
      res = document.querySelectorAll(query);
    } else {
      var firstStyleSheet = document.styleSheets[0] || document.createStyleSheet();
      firstStyleSheet.addRule(query, 'Barret:Lee');
      for (var i = 0, len = document.all.length; i < len; i++) {
        var item = document.all[i];
        item.currentStyle.Barret && res.push(item);
      }
      firstStyleSheet.removeRule(0);
    }
    if(res.item) { /* Fuck IE8 */
      var ret = [];
      for(var i = 0; i < res.length; i++){
        ret.push(res.item(i));
      }
      res = ret;
    }
    return res;
  };

  function addEventListener(evt, fn){
    window.addEventListener ? this.addEventListener(evt, fn, false) : (window.attachEvent)
        ? this.attachEvent('on' + evt, fn) : this['on' + evt] = fn;
  }

  // UMD
  function umd(name, component) {
    switch (true) {
      case typeof module === 'object' && !!module.exports:
        module.exports = component;
        break;
      case typeof define === 'function' && !!define.amd:
        define(name, function() {
          return component;
        });
        break;
      default:
        try { /* Fuck IE8- */
{'fraction_non_alphanumeric': 0.15419917393299679, 'fraction_numerical': 0.008260670032124828, 'mean_word_length': 2.4610905240868184, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 11, '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': '2570686', 'n_tokens_mistral': 2121, 'n_tokens_neox': 2092, 'n_words': 440}