<commit_before>var _eventId = 1
  , c = window.c = {}
  , returnTrue = function () { return true; }
  , returnFalse = function () { return false; }
  , ignoreProperties = /^([A-Z]|layer[XY]$)/
  , sepcialExp = /click|mouse/
  , mouse = {
      mouseenter: 'mouseover',
      mouseleave: 'mouseout'
    }
  , eventMethods = {
      preventDefault: 'isDefaultPrevented',
      stopImmediatePropagation: 'isStopImmediatePropagation',
      stopPropagation: 'isPropagationStopped'
    }
  , opcHandler
  , opcCache = {}
  , createEvent = !!document.createEvent;

/**
 * Get event parts.
 *
 * @param {String} event
 *
 * @return {Object}
 */

function getEventParts (event) {
  var parts = ('' + event).split('.');
  return { ev: parts[0], ns: parts.slice(1).sort().join(' ') };
}

/**
 * Get real event.
 *
 * @param {String} event
 *
 * @return {String}
 */

function realEvent (event) {
  return mouse[event] || event;
}

/**
 * Get tire event id
 *
 * @param {Object} el The element to get tire event id from
 *
 * @return {Number}
 */

function getEventId (el) {
  return el._eventId || (el._eventId = _eventId++);
}

/**
 * Check if ns or event allreday is in the handlers array.
 *
 * @param {Object} parts
 * @param {Array} handlers
 *
 * @return {Boolean}
 */

function inHandlers (parts, handlers) {
  for (var i = 0; i < handlers.length; i++) {
    if (handlers[i].realEvent === realEvent(parts.ev) || handlers[i].ns === parts.ns) {
      return true;
    }
  }
  return false;
}

/**
 * Get event handlers
 *
 * @param {Number} id
 * @param {String} event
 *
 * @return {Array}
 */

function getEventHandlers (id, event) {
  var parts = getEventParts(event)
    , handlers = []
    , tmp
    , ns;

  event = realEvent(parts.ev);
  ns = parts.ns;

  if (!event.length && !parts.ns.length) {
    return handlers;
  }

  c[id] = c[id] || {};

  if (event.length) {
    handlers = c[id][event] = c[id][event] || [];
  }

  if (parts.ns.length) {
    for (event in c[id]) {
      tmp = c[id][event];
      for (var i = 0, l = tmp.length; i < l; i++) {
        if (tmp[i] && ns.length && tmp[i].ns.length && tire.inArray(ns, tmp[i].ns.split(' ')) !== -1) {
          handlers.push(tmp[i]);
        }
      }
    }
  }

  return handlers;
}

/**
 * Create event handler
 *
 * @param {Object} el
 * @param {String} event
 * @param {Function} callback
 * @param {Function} _callback Orginal callback if delegated event
 */

function createEventHandler (el, event, callback, _callback) {
  var id = getEventId(el)
    , handlers = getEventHandlers(id, event)
    , parts = getEventParts(event)
    , cb = callback || _callback;

  var fn = function (event) {
    if (!event.liveTarget) event.liveTarget = event.target || event.srcElement;
    var data = event.data;
    if (tire.isString(data) && /^[\[\{]/.test(data)) data = tire.parseJSON(event.data);
    var result = cb.apply(el, [event].concat(data));
    if (result === false) {
      if (event.stopPropagation) event.stopPropagation();
      if (event.preventDefault) event.preventDefault();
    }
    return result;
  };
  fn._i = cb._i = cb._i || ++_eventId;
  fn.realEvent = realEvent(parts.ev);
  fn.ns = parts.ns;
  handlers.push(fn);
  return fn;
}

/**
 * Create event proxy for delegated events.
 *
 * @param {Object} event
 *
 * @return {Object}
 */

function createProxy (event) {
  var proxy = { originalEvent: event };

  for (var key in event) {
    if (!ignoreProperties.test(key) && event[key] !== undefined) {
      proxy[key] = event[key];
    }
    for (var name in eventMethods) {
      proxy[name] = function () {
        this[eventMethods[name]] = returnTrue;
        return event[name].apply(event, arguments);
      };
      proxy[eventMethods[name]] = returnFalse;
    }
  }

  return proxy;
}

/**
 * Add event to element.
 * Using addEventListener or attachEvent (IE)
 *
 * @param {Object} el
 * @param {String} events
 * @param {Function} callback
 * @param {String} selector
 */

function addEvent (el, events, callback, selector) {
  var fn, _callback;

  if (tire.isString(selector)) {
    _callback = callback;
    fn = function () {
      return (function (el, callback, selector) {
        return function (e) {
          var match = tire(el).find(e.target || e.srcElement);
          
          if (match.is(selector)) {
            var event = tire.extend(createProxy(e), {
              currentTarget: match.get(0)
            });
            console.log('x', el);

            return callback.apply(match, [event].concat(slice.call(arguments, 1)));
          }
        };
      }(el, callback, selector));
    };
  } else {
    callback = selector;
    selector = undefined;
  }

  tire.each(events.split(/\s/), function (index, event) {
    var parts = getEventParts(event);

    if (_callback !== undefined && parts.ev in mouse) {
      var _fn = fn();
      fn = function () {
        return function (e) {
          var related = e.relatedTarget;
          if (!related || (related !== this && !tire.contains(this, related))) {<commit_msg>Fixing so backbone delegated events will works with the last fix.<commit_after>var _eventId = 1
  , c = window.c = {}
  , returnTrue = function () { return true; }
  , returnFalse = function () { return false; }
  , ignoreProperties = /^([A-Z]|layer[XY]$)/
  , sepcialExp = /click|mouse/
  , mouse = {
      mouseenter: 'mouseover',
      mouseleave: 'mouseout'
    }
  , eventMethods = {
      preventDefault: 'isDefaultPrevented',
      stopImmediatePropagation: 'isStopImmediatePropagation',
      stopPropagation: 'isPropagationStopped'
    }
  , opcHandler
  , opcCache = {}
  , createEvent = !!document.createEvent;

/**
 * Get event parts.
 *
 * @param {String} event
 *
 * @return {Object}
 */

function getEventParts (event) {
  var parts = ('' + event).split('.');
  return { ev: parts[0], ns: parts.slice(1).sort().join(' ') };
}

/**
 * Get real event.
 *
 * @param {String} event
 *
 * @return {String}
 */

function realEvent (event) {
  return mouse[event] || event;
}

/**
 * Get tire event id
 *
 * @param {Object} el The element to get tire event id from
 *
 * @return {Number}
 */

function getEventId (el) {
  return el._eventId || (el._eventId = _eventId++);
}

/**
 * Check if ns or event allreday is in the handlers array.
 *
 * @param {Object} parts
 * @param {Array} handlers
 *
 * @return {Boolean}
 */

function inHandlers (parts, handlers) {
  for (var i = 0; i < handlers.length; i++) {
    if (handlers[i].realEvent === realEvent(parts.ev) || handlers[i].ns === parts.ns) {
      return true;
    }
  }
  return false;
}

/**
 * Get event handlers
 *
 * @param {Number} id
 * @param {String} event
 *
 * @return {Array}
 */

function getEventHandlers (id, event) {
  var parts = getEventParts(event)
    , handlers = []
    , tmp
    , ns;

  event = realEvent(parts.ev);
  ns = parts.ns;

  if (!event.length && !parts.ns.length) {
    return handlers;
  }

  c[id] = c[id] || {};

  if (event.length) {
    handlers = c[id][event] = c[id][event] || [];
  }

  if (parts.ns.length) {
    for (event in c[id]) {
      tmp = c[id][event];
      for (var i = 0, l = tmp.length; i < l; i++) {
        if (tmp[i] && ns.length && tmp[i].ns.length && tire.inArray(ns, tmp[i].ns.split(' ')) !== -1) {
          handlers.push(tmp[i]);
        }
      }
    }
  }

  return handlers;
}

/**
 * Create event handler
 *
 * @param {Object} el
 * @param {String} event
 * @param {Function} callback
 * @param {Function} _callback Orginal callback if delegated event
 */

function createEventHandler (el, event, callback, _callback) {
  var id = getEventId(el)
    , handlers = getEventHandlers(id, event)
    , parts = getEventParts(event)
    , cb = callback || _callback;

  var fn = function (event) {
    if (!event.liveTarget) event.liveTarget = event.target || event.srcElement;
    var data = event.data;
    if (tire.isString(data) && /^[\[\{]/.test(data)) data = tire.parseJSON(event.data);
    var result = cb.apply(el, [event].concat(data));
    if (result === false) {
      if (event.stopPropagation) event.stopPropagation();
      if (event.preventDefault) event.preventDefault();
    }
    return result;
  };
  fn._i = cb._i = cb._i || ++_eventId;
  fn.realEvent = realEvent(parts.ev);
  fn.ns = parts.ns;
  handlers.push(fn);
  return fn;
}

/**
 * Create event proxy for delegated events.
 *
 * @param {Object} event
 *
 * @return {Object}
 */

function createProxy (event) {
  var proxy = { originalEvent: event };

  for (var key in event) {
    if (!ignoreProperties.test(key) && event[key] !== undefined) {
      proxy[key] = event[key];
    }
    for (var name in eventMethods) {
      proxy[name] = function () {
        this[eventMethods[name]] = returnTrue;
        return event[name].apply(event, arguments);
      };
      proxy[eventMethods[name]] = returnFalse;
    }
  }

  return proxy;
}

/**
 * Add event to element.
 * Using addEventListener or attachEvent (IE)
 *
 * @param {Object} el
 * @param {String} events
 * @param {Function} callback
 * @param {String} selector
 */

function addEvent (el, events, callback, selector) {
  var fn, _callback;

  if (tire.isString(selector)) {
    _callback = callback;
    fn = function () {
      return (function (el, callback, selector) {
        return function (e) {
          var match = tire(el).find(e.target || e.srcElement);
          match = match.get(0) === el ? match.find(selector) : match;
          if (match.is(selector)) {
            var event = tire.extend(createProxy(e), {
              currentTarget: match.get(0)
            });
            console.log('x', el);

            return callback.apply(match, [event].concat(slice.call(arguments, 1)));
          }
        };
      }(el, callback, selector));
    };
  } else {
    callback = selector;
    selector = undefined;
  }

  tire.each(events.split(/\s/), function (index, event) {
    var parts = getEventParts(event);

    if (_callback !== undefined && parts.ev in mouse) {
      var _fn = fn();
      fn = function () {
        return function (e) {
          var related = e.relatedTarget;
          if (!related || (related !== this && !tire.contains(this, related))) {
{'fraction_non_alphanumeric': 0.16321319846803495, 'fraction_numerical': 0.001669449081803005, 'mean_word_length': 2.695210449927431, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1628847', 'n_tokens_mistral': 3402, 'n_tokens_neox': 3364, 'n_words': 849}