I have a coffeescript file called shapes.coffee:
jQuery ->
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) ->
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 ->
mouse_down_selected = false
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.
Thanks.