JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
improve instructions
[crayon_mockup.git] / auto.coffee
1 # globals
2 $svg = null #jquery object for svg element
3 selected = null
4
5 stop_drawing = ->
6         selected = null
7 click = (x, y) ->
8         unless selected?
9                 selected = []
10         if selected.length > 0
11                 last = selected[selected.length - 1]
12                 obj = document.createElementNS("http://www.w3.org/2000/svg", "path")
13                 obj.setAttributeNS(null, "d", "M #{last[0]} #{last[1]} L #{x} #{y}")
14                 $svg[0].appendChild(obj)
15         selected.push [x, y]
16         console.log selected
17
18 # called automatically on domcontentloaded
19 init = ->
20         $container = $ '.crayon_mockup'
21         $stop_button = $ '<div class="button">[end current polyline]</div>'
22         $tools = $ '<div class="toolbar"></div>'
23         $tools.append $stop_button
24         $stop_button.click stop_drawing
25         $container.append $tools
26         $svg = $ '<svg height="500" width="500" viewBox="0 0 500 500" style="border: 1px dotted #aaa" xmlns="http://www.w3.org/2000/svg"></svg>'
27         #$test_path = $ '<line id="line" x1="5" y1="50" x2="105" y2="150" style="stroke: rgb(0,127,127); stroke-width: 5;"></line>'
28         #$svg.append $test_path
29         $container.append $svg
30         console.log 'hi'
31         $svg.mousedown (e) ->
32                 console.log 'hi'
33                 offset = $svg.offset()
34                 click e.pageX - offset.left, e.pageY - offset.top
35
36 $ init