.NET to Javascript compiler

C# code   Html page   Start
public class TreeViewApp
{
    readonly static ImageTextRenderer<Node> renderer = CreateRenderer();
    internal readonly static Func<IRenderer, IEnumerator<Func<HtmlElement, object, object>>> Render = renderer.Render;

    public static void Start()
    {
        HtmlElement elem = HtmlDocument.Current.GetElementById("tree");
        TreeView treeView = CreateTree(elem);
        new ClassSwitcher(treeView);
        GridApp.ResizeMainElement(elem);
        AdviseContextMenu(treeView);
        AdviseDragDrop(treeView);
    }

    internal static TreeView<Node> CreateTree(HtmlElement elem)
    {
        TreeView<Node> treeView = new TreeView<Node>() { Element = elem };
        treeView.NodeClassName = "treeNodeWin7-20";
        treeView.NodeSource = new NodeSource(); ;
        treeView.Renderer = Render;
        return treeView;
    }

    internal static void AdviseContextMenu(TreeView treeView)
    {
        treeView.AdviseContextMenu(delegate(IHierarchyLevel treeViewLevel, long treeItemIndex)
        {
            long value = -1;
            if (treeItemIndex >= 0)
            {
                Node node = (Node)treeViewLevel.List[treeItemIndex];
                value = node.Start + node.Count;
            }

            return new ContextMenu()
            {
                Skin = MenuApp.Menu.Value.Skin,
                List = MenuApp.Menu.Value.List,
                Renderer = MenuApp.Menu.Value.Renderer,
                Execute = delegate(IHierarchyLevel menuLevel, long menuItemIndex)
                {
                    HtmlWindow.Current.Alert("Menu: " + MenuApp.Text(menuLevel, menuItemIndex) + " Node: " + value);
                }
            };
        });
    }

    internal static void AdviseDragDrop(DataTreeView treeView)
    {
        treeView.AdviseDrag(delegate(HtmlMouseEvent e)
        {
            return new TreeViewDragSource(treeView, e);
        });

        treeView.AdviseDrop(delegate(object dataObject)
        {
            Node node = dataObject as Node;
            return node != null ? new TreeViewDragDropTarget(treeView, node) : null;
        });

        if(SupportedHtml5Features.File)
        {
            TreeViewDropTarget dropTarget = new TreeViewDropTarget(treeView);
            treeView.AdviseDrop(
                delegate (HtmlMouseEvent e)
                {
                    dropTarget.DragOver(e);
                    dropTarget.ShowFeedback();
                },
                delegate (HtmlDropEvent e)
                {
                    dropTarget.Drop(e);
                    MessageBox.Show(string.Format("Dropped {0} files", e.Files.Length));
                });


            HtmlDocument.Current.Body.AdviseDrop(null, null);
        }
    }

    static ImageTextRenderer<Node> CreateRenderer()
    {
        ImageTextRenderer<Node> renderer = new ImageTextRenderer<Node>();
        renderer.Image.Image = delegate(Node node)
        {
            return "images/folderWin7.gif";
        };

        renderer.Text.Text = delegate(Node node)
        {
            return "<" + (node.Start + node.Count).ToString("N0"); 
        };

        return renderer;
    }

    class ClassSwitcher
    {
        readonly static string[] ids = new string[] { "xp", "win7" };

        readonly TreeView tree;

        internal ClassSwitcher(TreeView tree)
        {
            this.tree = tree;
            foreach (string id in ids)
            {
                HtmlRadioButton radioButton = (HtmlRadioButton)HtmlDocument.Current.GetElementById(id);
                radioButton.AdviseClick(treeStyle_Click);
                if (radioButton.Checked)
                {
                    SwitchClass(radioButton);
                }
            }
        }

        void SwitchClass(HtmlRadioButton elem)
        {
            tree.NodeClassName = elem.GetAttribute("value");
        }

        void treeStyle_Click(HtmlEvent e)
        {
            SwitchClass((HtmlRadioButton)e.Target);
        }
    }
}

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" style="overflow:hidden;width:100%;height:100%">
<head>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type" />
    <meta http-equiv="x-ua-compatible" content="IE=11;IE=10;IE=9;IE=8;IE=7" />
    <link rel="stylesheet" href="styles/jscriptsuite.css" type="text/css" />
    <link rel="stylesheet" href="styles/summary.css" type="text/css" />
    <script language="javascript" type="text/javascript" src="js/treeview.js"></script>
</head>
<body onload="StartScript()" scroll="no" style="overflow:hidden;width:100%;height:100%;margin:0 0 0 0">
    TreeView control. Virtual scrolling, node selection, keyboard navigation
    <div>
        <input type="radio" value="treeNodeXP20" id="xp" name="treeNodeStyle" checked="checked" />
        <label for="xp">XP</label>
        <input type="radio" value="treeNodeWin7-20" id="win7" name="treeNodeStyle" />
        <label for="win7">Win 7</label>
    </div>
    <div id="tree" style="border:solid 1px black; width:100%"></div>
</body>
</html>

© 2009 JScriptSuite. All rights reserved.