I'm trying to attach simple event to the <canvas> element but only
Safari seems to work right with the following code (it's all condesed
in one html page):

--- start
<html>
    <link rel="stylesheet" href="test.css" type="text/css"
media="screen" title="no title" charset="utf-8" />
    <head>
        <title>Canvas test page</title>
        <script type="text/javascript" src="MochiKit.js" />
        <!--<script type="text/javascript" src="test_canvas.js" />-->
        <script type="text/javascript">
        function draw() {
            var canvas = getElement("test-canvas");
            console.log(canvas)

            connect(canvas, "onmousedown",
                function(e) {
                    var canvas = e.src();
                    var ctx = canvas.getContext("2d");

                    ctx.beginPath();
                    var x = e.mouse().client.x;
                    var y = e.mouse().client.y;
                    var offset = MochiKit.Style.getElementPosition(
                        'test-canvas', e.page);
                    ctx.moveTo(x - offset.x, y - offset.y);
                    e.stopPropagation();
                }
            );

            connect(canvas, "onmouseup",
                function(e) {
                    var canvas = e.src();
                    var ctx = canvas.getContext("2d");

                    var x = e.mouse().client.x;
                    var y = e.mouse().client.y;
                    var offset = MochiKit.Style.getElementPosition(
                        'test-canvas', e.page);
                    ctx.lineTo(x - offset.x, y - offset.y);
                    ctx.closePath();
                    ctx.stroke();
                    e.stopPropagation();
                }
            );
        }
        </script>
    </head>
    <body onload="draw();">
        <canvas id="test-canvas"></canvas>
    </body>
</html>
--- end

I think I'm missing something but neither Firefox nor Opera eat that code :-)


-- 
Lawrence
http://www.oluyede.org/blog

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/mochikit
-~----------~----~----~----~------~----~------~--~---

Reply via email to