<commit_before>#= require_self

html = document.documentElement
match = html.matchesSelector ? html.webkitMatchesSelector ? html.msMatchesSelector ? html.mozMatchesSelector

Trix.extend
  handleEvent: (eventName, {onElement, matchingSelector, withCallback, inPhase, preventDefault, times} = {}) ->
    element = onElement ? html
    selector = matchingSelector
    callback = withCallback
    useCapture = inPhase is "capturing"

    handler = (event) ->
      handler.destroy() if times? and --times is 0
      target = Trix.findClosestElementFromNode(event.target, matchingSelector: selector)
      withCallback?.call(target, event, target) if target?
      event.preventDefault() if preventDefault

    handler.destroy = ->
      element.removeEventListener(eventName, handler, useCapture)

    element.addEventListener(eventName, handler, useCapture)
    handler

  handleEventOnce: (eventName, options = {}) ->
    options.times = 1
    Trix.handleEvent(eventName, options)

  triggerEvent: (eventName, {onElement, bubbles, cancelable, attributes} = {}) ->
    element = onElement ? html
    bubbles = bubbles isnt false
    cancelable = cancelable isnt false

    event = document.createEvent("Events")
    event.initEvent(eventName, bubbles, cancelable)
    Trix.extend.call(event, attributes) if attributes?
    element.dispatchEvent(event)

  elementMatchesSelector: (element, selector) ->
    if element?.nodeType is 1
      match.call(element, selector)

  findClosestElementFromNode: (node, {matchingSelector} = {}) ->
    node = node.parentNode until not node? or node.nodeType is Node.ELEMENT_NODE

    if matchingSelector?<commit_msg>Move event.preventDefault() to under if target?<commit_after>#= require_self

html = document.documentElement
match = html.matchesSelector ? html.webkitMatchesSelector ? html.msMatchesSelector ? html.mozMatchesSelector

Trix.extend
  handleEvent: (eventName, {onElement, matchingSelector, withCallback, inPhase, preventDefault, times} = {}) ->
    element = onElement ? html
    selector = matchingSelector
    callback = withCallback
    useCapture = inPhase is "capturing"

    handler = (event) ->
      handler.destroy() if times? and --times is 0
      target = Trix.findClosestElementFromNode(event.target, matchingSelector: selector)
      if target?
        withCallback?.call(target, event, target)
        event.preventDefault() if preventDefault

    handler.destroy = ->
      element.removeEventListener(eventName, handler, useCapture)

    element.addEventListener(eventName, handler, useCapture)
    handler

  handleEventOnce: (eventName, options = {}) ->
    options.times = 1
    Trix.handleEvent(eventName, options)

  triggerEvent: (eventName, {onElement, bubbles, cancelable, attributes} = {}) ->
    element = onElement ? html
    bubbles = bubbles isnt false
    cancelable = cancelable isnt false

    event = document.createEvent("Events")
    event.initEvent(eventName, bubbles, cancelable)
    Trix.extend.call(event, attributes) if attributes?
    element.dispatchEvent(event)

  elementMatchesSelector: (element, selector) ->
    if element?.nodeType is 1
      match.call(element, selector)

  findClosestElementFromNode: (node, {matchingSelector} = {}) ->
    node = node.parentNode until not node? or node.nodeType is Node.ELEMENT_NODE

    if matchingSelector?
{'fraction_non_alphanumeric': 0.09874326750448834, 'fraction_numerical': 0.0017953321364452424, 'mean_word_length': 4.072837632776935, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '5428361', 'n_tokens_mistral': 934, 'n_tokens_neox': 912, 'n_words': 234}