<commit_before># Get alias for the global scope
globals = @

# All will be in the "RW" namespace
RW = globals.RW ? {}
globals.RW = RW

RW.io = {}

# Define keyboard input io
RW.io.keyboard = 
  meta:
    visual: false
  factory: (options) ->
    eventNamespace = _.uniqueId('keyboard')

    keysDown = {}

    $(options.elementSelector).on "keydown.#{eventNamespace} keyup.#{eventNamespace} focusout.#{eventNamespace}", "#captureSpace", (event) ->
      event.preventDefault()   

      # jQuery standardizes the keycode into http://api.jquery.com/event.which/
      switch event.type 
        when 'keydown' then keysDown[event.which] = true
        when 'keyup' then delete keysDown[event.which]
        when 'focusout' then keysDown = {} # Lost focus, so will not receive keyup events
        else throw new Error('Unexpected event type')

    return {
      provideData: -> 
        global: 
          keysDown: keysDown

      establishData: -> # NOOP. Input io does not take data

      # Remove all event handlers
      destroy: -> $(options.elementSelector).off(".#{eventNamespace}")
    }

# Define mouse input/output io
RW.io.mouse = 
  meta:
    visual: false
  factory: (options) ->
    eventNamespace = _.uniqueId('mouse')

    mouse =
      down: false
      position: [0, 0]
      cursor: null
    lastMouse = RW.cloneData(mouse)

    # This disables selection, which allows the cursor to change in Chrome
    $(options.elementSelector).on("selectstart.#{eventNamespace}", -> false)

    $(options.elementSelector).on "mousedown.#{eventNamespace} mouseup.#{eventNamespace} mousemove.#{eventNamespace} mouseleave.#{eventNamespace}", "#captureSpace", (event) ->
      switch event.type 
        when 'mousedown' then mouse.down = true
        when 'mouseup' then mouse.down = false
        when 'mousemove'
          # Get position relative to canvas.
          # Based on http://www.html5canvastutorials.com/advanced/html5-canvas-mouse-coordinates/
          rect = event.target.getBoundingClientRect()
          target = $(event.target)
          mouse.position = [
            Math.floor((event.clientX - rect.left) * target.attr("width") / rect.width)
            Math.floor((event.clientY - rect.top) * target.attr("height") / rect.height)<commit_msg>fixed mouse capture for FF, but not for Chrome<commit_after># Get alias for the global scope
globals = @

# All will be in the "RW" namespace
RW = globals.RW ? {}
globals.RW = RW

RW.io = {}

# Define keyboard input io
RW.io.keyboard = 
  meta:
    visual: false
  factory: (options) ->
    eventNamespace = _.uniqueId('keyboard')

    keysDown = {}

    $(options.elementSelector).on "keydown.#{eventNamespace} keyup.#{eventNamespace} focusout.#{eventNamespace}", "#captureSpace", (event) ->
      event.preventDefault()   

      # jQuery standardizes the keycode into http://api.jquery.com/event.which/
      switch event.type 
        when 'keydown' then keysDown[event.which] = true
        when 'keyup' then delete keysDown[event.which]
        when 'focusout' then keysDown = {} # Lost focus, so will not receive keyup events
        else throw new Error('Unexpected event type')

    return {
      provideData: -> 
        global: 
          keysDown: keysDown

      establishData: -> # NOOP. Input io does not take data

      # Remove all event handlers
      destroy: -> $(options.elementSelector).off(".#{eventNamespace}")
    }

# Define mouse input/output io
RW.io.mouse = 
  meta:
    visual: false
  factory: (options) ->
    eventNamespace = _.uniqueId('mouse')

    mouse =
      down: false
      position: [0, 0]
      cursor: null
    lastMouse = RW.cloneData(mouse)

    # This disables selection, which allows the cursor to change in Chrome
    $(options.elementSelector).on("selectstart.#{eventNamespace}", -> false)

    $(options.elementSelector).on "mousedown.#{eventNamespace} mouseup.#{eventNamespace} mousemove.#{eventNamespace} mouseleave.#{eventNamespace}", "#captureSpace", (event) ->
      switch event.type 
        when 'mousedown' then mouse.down = true
        when 'mouseup' then mouse.down = false
        when 'mousemove'
          # Get position relative to canvas.
          # Based on http://www.html5canvastutorials.com/advanced/html5-canvas-mouse-coordinates/
          rect = event.target.getBoundingClientRect()
          target = $(event.target)
          mouse.position = [
            Math.floor((event.clientX - rect.left) * options.size[0] / rect.width)
            Math.floor((event.clientY - rect.top) * options.size[1] / rect.height)
{'fraction_non_alphanumeric': 0.12258771929824562, 'fraction_numerical': 0.0021929824561403508, 'mean_word_length': 2.7850622406639003, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4704916', 'n_tokens_mistral': 1329, 'n_tokens_neox': 1304, 'n_words': 351}