示例#1
0
        /// <summary>
        /// This is a javascript application.
        /// </summary>
        /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
        public Application(IApp page)
        {
            var t = new ScriptCoreLib.JavaScript.Controls.TextEditor(
                page.body
                );


            new IHTMLButton {
                "InnerHTML"
            }.AttachToDocument().onclick += delegate
            {
                new IHTMLPre {
                    t.InnerHTML
                }.AttachToDocument();

                // <p>x</p><p><br /></p><p><img src="https://192.168.1.12:21279/assets/TestTextEditorImage/createlink.png">&nbsp;<br /></p><p>x</p>
                // x<div><img src="https://192.168.1.12:30903/assets/TestTextEditorImage/createlink.png"></div><div>x</div>
            };

            new IHTMLButton {
                "xml"
            }.AttachToDocument().onclick += delegate
            {
                var xml = t.Document.body.AsXElement();

                // <body xmlns="http://www.w3.org/1999/xhtml" style="height: auto; border: 0; overflow: auto; background-color:transparent;">x<div><br /></div><div><img src="https://192.168.1.12:21279/assets/TestTextEditorImage/createlink.png" /><br /></div><div>x</div></body>
                //new IHTMLPre { xml }.AttachToDocument();

                new IHTMLPre {
                    innerText = "" + xml
                }.AttachToDocument();

                // x<div><img src="https://192.168.1.12:30903/assets/TestTextEditorImage/createlink.png"></div><div>x</div>
            };

            new IHTMLButton {
                "p"
            }.AttachToDocument().onclick += delegate
            {
                var xml = t.Document.body.AsXElement();

                // <body xmlns="http://www.w3.org/1999/xhtml" style="height: auto; border: 0; overflow: auto; background-color:transparent;">x<div><br /></div><div><img src="https://192.168.1.12:21279/assets/TestTextEditorImage/createlink.png" /><br /></div><div>x</div></body>
                //new IHTMLPre { xml }.AttachToDocument();

                var p = new XElement("p", xml.Nodes());

                // <p>xxx<DIV><BR/></DIV><DIV><IMG src="https://192.168.1.12:24526/assets/TestTextEditorImage/createlink.png"/><BR/></DIV><DIV>x</DIV></p>

                //view-source:54860 41388ms XContainer Add xIEnumerable
                //2016-01-04 20:48:00.746 view-source:54860 41388ms XContainer Add xIEnumerable Add { item = xxx }
                //2016-01-04 20:48:00.748 view-source:54860 41388ms XContainer Add xIEnumerable Add { item = <div xmlns="http://www.w3.org/1999/xhtml"><br /></div> }
                //2016-01-04 20:48:00.750 view-source:54860 41398ms XContainer Add xIEnumerable Add { item = <div xmlns="http://www.w3.org/1999/xhtml">xxxx</div> }

                new IHTMLPre {
                    innerText = "" + p
                }.AttachToDocument();

                // x<div><img src="https://192.168.1.12:30903/assets/TestTextEditorImage/createlink.png"></div><div>x</div>
            };
        }
        /// <summary>
        /// This is a javascript application.
        /// </summary>
        /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
        public Application(IApp page)
        {
            var t = new ScriptCoreLib.JavaScript.Controls.TextEditor(
                page.body
            );


            new IHTMLButton { "InnerHTML" }.AttachToDocument().onclick += delegate
            {

                new IHTMLPre { t.InnerHTML }.AttachToDocument();

                // <p>x</p><p><br /></p><p><img src="https://192.168.1.12:21279/assets/TestTextEditorImage/createlink.png">&nbsp;<br /></p><p>x</p>
                // x<div><img src="https://192.168.1.12:30903/assets/TestTextEditorImage/createlink.png"></div><div>x</div>


            };

            new IHTMLButton { "xml" }.AttachToDocument().onclick += delegate
            {

                var xml = t.Document.body.AsXElement();

                // <body xmlns="http://www.w3.org/1999/xhtml" style="height: auto; border: 0; overflow: auto; background-color:transparent;">x<div><br /></div><div><img src="https://192.168.1.12:21279/assets/TestTextEditorImage/createlink.png" /><br /></div><div>x</div></body>
                //new IHTMLPre { xml }.AttachToDocument();

                new IHTMLPre { innerText = "" + xml }.AttachToDocument();

                // x<div><img src="https://192.168.1.12:30903/assets/TestTextEditorImage/createlink.png"></div><div>x</div>
            };

            new IHTMLButton { "p" }.AttachToDocument().onclick += delegate
            {

                var xml = t.Document.body.AsXElement();

                // <body xmlns="http://www.w3.org/1999/xhtml" style="height: auto; border: 0; overflow: auto; background-color:transparent;">x<div><br /></div><div><img src="https://192.168.1.12:21279/assets/TestTextEditorImage/createlink.png" /><br /></div><div>x</div></body>
                //new IHTMLPre { xml }.AttachToDocument();

                var p = new XElement("p", xml.Nodes());

                // <p>xxx<DIV><BR/></DIV><DIV><IMG src="https://192.168.1.12:24526/assets/TestTextEditorImage/createlink.png"/><BR/></DIV><DIV>x</DIV></p>

                //view-source:54860 41388ms XContainer Add xIEnumerable
                //2016-01-04 20:48:00.746 view-source:54860 41388ms XContainer Add xIEnumerable Add { item = xxx }
                //2016-01-04 20:48:00.748 view-source:54860 41388ms XContainer Add xIEnumerable Add { item = <div xmlns="http://www.w3.org/1999/xhtml"><br /></div> }
                //2016-01-04 20:48:00.750 view-source:54860 41398ms XContainer Add xIEnumerable Add { item = <div xmlns="http://www.w3.org/1999/xhtml">xxxx</div> }

                new IHTMLPre { innerText = "" + p }.AttachToDocument();

                // x<div><img src="https://192.168.1.12:30903/assets/TestTextEditorImage/createlink.png"></div><div>x</div>
            };
        }
        // Z:\jsc.svn\examples\javascript\android\com.abstractatech.wiki\com.abstractatech.wiki\Application.cs


        /// <summary>
        /// This is a javascript application.
        /// </summary>
        /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
        public Application(IApp page)
        {

            var t = new ScriptCoreLib.JavaScript.Controls.TextEditor(
                page.body,

                fonts:
                    new[] {
                        new Fonts.BLOKKRegular().rule,
                        new Fonts.redacted_script_regular().rule,
                    }
            );

            Console.WriteLine("adding the button");

            // <font color="#0000fc">s</font>


            new IHTMLButton
            {
                "make svg friendly"
            }.AttachToDocument().WhenClicked(
                x =>
                {
                    Console.WriteLine(
                        new { body = t.Document.body.AsXElement() }
                    );

                //7990ms { body = <body style="height: auto; border: 0; overflow: auto; background-color:transparent;">ss<font color="#ff0000">dfsdf</font>sd</body> } view-source:35444
                //7993ms { f = <font color="#ff0000">dfsdf</font> } 

                t.Document.body.AsXElement().Elements().WithEach(
                zf =>
                {
                            Console.WriteLine(new { zf, zf.Name.LocalName });

                        // 10797ms { zf = <font color="#ff0000">dfs</font>, LocalName = FONT } 

                        if (zf.Name.LocalName.ToLower() == "div")
                            {

                                var ff = new IHTMLSpan { innerText = zf.Value };

                                var color = zf.Attribute("color").Value;

                                ff.style.color = color;

                                Console.WriteLine("ReplaceWith" + new { ff.innerText, color });

                                zf.ReplaceWith(ff.AsXElement());
                            }

                            if (zf.Name.LocalName.ToLower() == "font")
                            {

                                var ff = new IHTMLSpan { innerText = zf.Value };

                                var color = zf.Attribute("color").Value;

                                ff.style.color = color;

                                Console.WriteLine("ReplaceWith" + new { ff.innerText, color });

                                zf.ReplaceWith(ff.AsXElement());
                            }
                        }
            );

                // we inline images, should look for fonts inside svg too?
                t.Document.body.AsXElement().Elements("font").ToArray().WithEach(
                f =>
                {
                            Console.WriteLine(new { f });


                            var ff = new IHTMLSpan { innerText = f.Value };

                            ff.style.color = f.Attribute("color").Value;

                            f.ReplaceWith(ff.AsXElement());

                        //f.Nodes().att
                    }
            );
                }
            );

            new IHTMLButton
            {
                "getframe"
            }.AttachToDocument().WhenClicked(
                delegate
                {
                    var snapshot = new IHTMLDiv
                    {
                        innerHTML = t.InnerHTML
                    };

                    Console.WriteLine(t.InnerHTML);

                    IHTMLImage i = snapshot;

                    i.AttachToDocument();
                }
            );

            //@"Hello world".ToDocumentTitle();
            //// Send data from JavaScript to the server tier
            //service.WebMethod2(
            //    @"A string from JavaScript.",
            //    value => value.ToDocumentTitle()
            //);
        }