X-Git-Url: https://jasonwoof.com/gitweb/?p=crayon_mockup.git;a=blobdiff_plain;f=auto.coffee;fp=auto.coffee;h=7a55b2acd8975fb03fdd541bf869eaaeced48842;hp=0000000000000000000000000000000000000000;hb=c8077c7a5c9ce3610d8f926b7fdf8969974728c8;hpb=591650afff9fefa9c5e5e71419559e0bffe82cc4 diff --git a/auto.coffee b/auto.coffee new file mode 100644 index 0000000..7a55b2a --- /dev/null +++ b/auto.coffee @@ -0,0 +1,36 @@ +# globals +$svg = null #jquery object for svg element +selected = null + +stop_drawing = -> + selected = null +click = (x, y) -> + unless selected? + selected = [] + if selected.length > 0 + last = selected[selected.length - 1] + obj = document.createElementNS("http://www.w3.org/2000/svg", "path") + obj.setAttributeNS(null, "d", "M #{last[0]} #{last[1]} L #{x} #{y}") + $svg[0].appendChild(obj) + selected.push [x, y] + console.log selected + +# called automatically on domcontentloaded +init = -> + $container = $ '.crayon_mockup' + $stop_button = $ '
[end current polyline]
' + $tools = $ '
' + $tools.append $stop_button + $stop_button.click stop_drawing + $container.append $tools + $svg = $ '' + #$test_path = $ '' + #$svg.append $test_path + $container.append $svg + console.log 'hi' + $svg.mousedown (e) -> + console.log 'hi' + offset = $svg.offset() + click e.pageX - offset.left, e.pageY - offset.top + +$ init