.NET to Javascript compiler

C# code   Html page   Start
public class DragDropApp : HtmlGlobal
{
    readonly HtmlCollection<HtmlTableRow> rows;
    readonly HtmlElement source;
    readonly HtmlElement target;

    IDisposable capture;
    int offsetX, offsetY;

    DragDropApp()
    {
        source = document.GetElementById("source");
        target = document.GetElementById("target");
        source.AdviseMouseDown(OnMouseDown);
        rows = ((HtmlTable)document.GetElementById("table")).Rows;
    }

    public static void Start()
    {
        new DragDropApp();
    }


    void OnMouseDown(HtmlMouseEvent e)
    {
        if (capture == null)
        {
            capture = source.AdviseCapture(OnMouseMove, OnCaptureComplete);
            HtmlRect rc = source.GetBoundingClientRect();
            target.Style.Left = rc.Left + "px";
            target.Style.Top = rc.Left + "px";
            target.Style.Width = rc.Width + "px";
            target.Style.Height = rc.Height + "px";
            target.Style.Display = StyleDisplay.Default;

            offsetX = e.ClientX - rc.Left;
            offsetY = e.ClientY - rc.Top;
            OnEvent(e);
            DisplayAction("started");
            e.PreventDefault();
        }
    }
    void OnMouseMove(HtmlMouseEvent e)
    {
        OnEvent(e);
        DisplayAction("moving");
    }
    void OnCaptureComplete(HtmlMouseEvent e)
    {
        if (e != null)
        {
            OnEvent(e);
            source.Style.Left = (e.ClientX - offsetX) + "px";
            source.Style.Top = (e.ClientY - offsetY) + "px";
            DisplayAction("completed");
        }
        else
        {
            DisplayAction("canceled");
        }
        target.Style.Display = StyleDisplay.None;
        capture.Dispose();
        capture = null;
    }
    void DisplayAction(string text)
    {
        DisplayProperty(0, text);
    }
    void OnEvent(HtmlMouseEvent e)
    {
        target.Style.Left = (e.ClientX - offsetX) + "px";
        target.Style.Top = (e.ClientY - offsetY) + "px";
        int i = 1;
        DisplayProperty(i++, e.ClientX);
        DisplayProperty(i++, e.ClientY);
        DisplayProperty(i++, e.ClientX - offsetX);
        DisplayProperty(i++, e.ClientY - offsetY);

        DisplayProperty(i++, e.AltKey);
        DisplayProperty(i++, e.CtrlKey);
        DisplayProperty(i++, e.ShiftKey);
    }
    void DisplayProperty(int index, object text)
    {
        rows[index].Cells[1].InnerText = text.ToString();
    }
}

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <meta http-equiv="x-ua-compatible" content="IE=11;IE=10;IE=9;IE=8;IE=7" />
	<title>DragDrop.html: mouse event handling</title>
	<script type="text/javascript" language="javascript" src="js/dragdrop.js"></script>
</head>
<body onload="javascript:StartScript()">
	DragDrop.html: mouse event handling
	
	<div id="source" style="position:absolute;left:20px;top:20px;border:solid 1px #cccccc; background-color:blue;cursor:move">
		<table cellpadding="2" cellspacing="0" border="0" id="table">
			<tr>
				<th>Action</th>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<th>clientX</th>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<th>clientY</th>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<th>left</th>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<th>top</th>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<th>altKey</th>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<th>ctrlKey</th>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<th>shiftKey</th>
				<td>&nbsp;</td>
			</tr>
		</table>
	</div>

	<div id="target" style="position:absolute;border:solid 1px black; background-color:transparent;cursor:move;z-index:100;display:none">
		&nbsp;
	</div>

</body>
</html>
© 2009 JScriptSuite. All rights reserved.