title: Refactoring Jquery coffeescript code into separate files
body: <p>I have a coffeescript file called shapes.coffee:</p>
  
  <pre><code>jQuery -&gt;
  
    offset = $('#drawing_canvas').offset()
    mouse_vertical_position = -Number(offset.top)
    mouse_horizontal_position = -Number(offset.left)
  
    canvas = document.getElementById("drawing_canvas")
    context = canvas.getContext("2d")
    container = canvas.parentNode
  
    temporary_canvas = document.createElement("canvas")
    temporary_canvas.id = "temporary_canvas"
    temporary_canvas.height = canvas.height
    temporary_canvas.width = canvas.width
    container.appendChild(temporary_canvas)
    temporary_context = temporary_canvas.getContext("2d")
  
    mouse_down_selected = false
  
    $('#temporary_canvas').mousedown (e) -&gt;
      mouse_down_selected = true
      mouse_horizontal_position = -Number(offset.left)
      mouse_vertical_position = -Number(offset.top)
      mouse_horizontal_position += e.pageX
      mouse_vertical_position += e.pageY
  
    $('body').mouseup -&gt;
     mouse_down_selected = false
  </code></pre>
  
  <p>I would like to refactor some of these lines into their own methods (ideally in separate files).  I have attempted to do this but I get method not defined errors in the console, and I have been unable to find an example involving jquery.  The first group of  code before the temporary canvas function would need to be called on document load.  Any examples or advice is appreciated.</p>
  
  <p>Thanks.</p>