/// <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) { sprite.wmode(); sprite.AttachSpriteToDocument().With( embed => { embed.style.SetLocation(0, 0); embed.style.SetSize(Native.Window.Width, Native.Window.Height); Native.Window.onresize += delegate { embed.style.SetSize(Native.Window.Width, Native.Window.Height); }; } ); #region con var con = new ConsoleForm(); con.InitializeConsoleFormWriter(); con.Show(); con.Height = 150; con.Left = Native.Window.Width - con.Width; con.Top = 0; Native.Window.onresize += delegate { con.Left = Native.Window.Width - con.Width; con.Top = 0; }; con.Opacity = 0.6; // !! not compatible yet con.HandleFormClosing = false; con.PopupInsteadOfClosing(); #endregion sprite.fps += (fps, nid) => { new { fps, nid }.ToString().ToDocumentTitle(); }; #region context_new_remotegame sprite.context_new_remotegame += remotegame => { var remotegame_con = new ConsoleForm(); remotegame_con.Show(); remotegame_con.Left = 0; remotegame_con.Top = Native.Window.Height - remotegame_con.Height; remotegame_con.Opacity = 0.5; remotegame.AtTitleChange += e => remotegame_con.Text = e; remotegame.AtWriteLine += e => { remotegame_con.textBox1.AppendText(e + Environment.NewLine); remotegame_con.textBox1.ScrollToCaret(); }; remotegame_con.HandleFormClosing = false; remotegame_con.PopupInsteadOfClosing(); }; #endregion var sprites_events = new BindingListWithEvents<ApplicationSprite>(); var sprites = sprites_events.Source; sprites_events.Added += (fsprite, i) => { Console.WriteLine(i + "# Console ready!"); fsprite.InitializeConsoleFormWriter( Console_Write: x => Console.Write(x), Console_WriteLine: x => { var lines = x.Split(Environment.NewLine); foreach (var item in lines) { Console.WriteLine(i + "# " + item); } } ); #region lets do two way binding here. // fsprite -> sprite fsprite.context_onmessage += xml => { // script: error JSC1000: No implementation found for this native method, please implement [static System.Linq.Enumerable.Except(System.Collections.Generic.IEnumerable`1[[FlashHeatZeekerWithStarlingB2.ApplicationSprite, FlashHeatZeekerWithStarlingB2.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Collections.Generic.IEnumerable`1[[FlashHeatZeekerWithStarlingB2.ApplicationSprite, FlashHeatZeekerWithStarlingB2.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]])] sprites.WithEach( x => { // prevent echo if (x == fsprite) return; x.game_postMessage(xml); } ); }; #endregion }; sprites.Add(sprite); #region game_InitializeFrameDiagnostics sprite.game_InitializeFrameDiagnostics( __FrameDiagnostics => { Console.WriteLine("new FrameDiagnostics"); var x = new FrameDiagnostics(); x.Show(); Console.WriteLine("new FrameDiagnostics Show, can you see it?"); Native.Window.onresize += delegate { x.Left = Native.Window.Width - x.Width; x.Top = Native.Window.Height - x.Height; }; x.Initialize(__FrameDiagnostics); // Error 8 'Abstractatech.ConsoleFormPackage.Library.ConsoleForm' does not contain a definition for 'PopupInsteadOfClosing' and no extension method 'PopupInsteadOfClosing' accepting a first argument of type 'Abstractatech.ConsoleFormPackage.Library.ConsoleForm' could be found (are you missing a using directive or an assembly reference?) X:\jsc.svn\examples\actionscript\svg\FlashHeatZeeker\FlashHeatZeekerWithStarlingB2\Application.cs 85 17 FlashHeatZeekerWithStarlingB2 // wtf? x.PopupInsteadOfClosing(); x.Opacity = 0.7; // can we pop it up? x.JoinMultiplayer.Click += delegate { var f = new Form(); // make it small f.Height = 200; var fsprite = new ApplicationSprite(); fsprite.src_fixup(); fsprite.wmode(); var fspriteelement = fsprite.AttachSpriteTo( f.GetHTMLTargetContainer() ); #region ClientSizeChanged / PopupInsteadOfClosing has a bug f.ClientSizeChanged += delegate { var cs = f.ClientSize; fspriteelement.style.SetSize(cs.Width, cs.Height ); }; #endregion f.Show(); f.PopupInsteadOfClosing(); // do events break if popup mode is changed? fsprite.fps += (fps, nid) => { new { fps, nid }.ToString().ToTitle(f); }; sprites.Add(fsprite); // what if we have more of these? }; } ); #endregion }
/// <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) { sprite.wmode(); sprite.AttachSpriteToDocument().With( embed => { embed.style.SetLocation(0, 0); embed.style.SetSize(Native.Window.Width, Native.Window.Height); Native.Window.onresize += delegate { embed.style.SetSize(Native.Window.Width, Native.Window.Height); }; } ); #region con var con = new ConsoleForm(); con.InitializeConsoleFormWriter(); con.Show(); con.Left = Native.Window.Width - con.Width; con.Top = 0; Native.Window.onresize += delegate { con.Left = Native.Window.Width - con.Width; con.Top = 0; }; con.Opacity = 0.6; sprite.InitializeConsoleFormWriter( Console.Write, Console.WriteLine ); // !! not compatible yet con.HandleFormClosing = false; con.PopupInsteadOfClosing(); #endregion sprite.fps += fps => { new { fps }.ToString().ToDocumentTitle(); }; #region context_new_remotegame sprite.context_new_remotegame += remotegame => { var remotegame_con = new ConsoleForm(); remotegame_con.Show(); remotegame_con.Left = 0; remotegame_con.Top = Native.Window.Height - remotegame_con.Height; remotegame_con.Opacity = 0.5; remotegame.AtTitleChange += e => remotegame_con.Text = e; remotegame.AtWriteLine += e => { remotegame_con.textBox1.AppendText(e + Environment.NewLine); remotegame_con.textBox1.ScrollToCaret(); }; remotegame_con.HandleFormClosing = false; remotegame_con.PopupInsteadOfClosing(); }; #endregion #region game_InitializeFrameDiagnostics sprite.game_InitializeFrameDiagnostics( __FrameDiagnostics => { Console.WriteLine("new FrameDiagnostics"); var x = new FrameDiagnostics(); x.Show(); Console.WriteLine("new FrameDiagnostics Show, can you see it?"); Native.Window.onresize += delegate { x.Left = Native.Window.Width - x.Width; x.Top = Native.Window.Height - x.Height; }; x.Initialize(__FrameDiagnostics); x.PopupInsteadOfClosing(); x.Opacity = 0.7; } ); #endregion { int c = 2000; Action<MessageEvent> window_onmessage = e => { var xml = XElement.Parse((string)e.data); c++; //Console.WriteLine(c + " window -> sprite " + xml); sprite.game_postMessage(xml); }; Console.WriteLine("add window_onmessage"); Native.Window.onmessage += window_onmessage; } Action<XElement> sprite_context_onmessage = delegate { }; int ccc = 0; sprite.context_onmessage += e => { ccc++; //Console.WriteLine(ccc + " sprite -> " + e); sprite_context_onmessage(e); }; if (Native.Window.opener != null) { // opener closes, we close. Native.Window.opener.onbeforeunload += delegate { Native.Window.close(); }; sprite_context_onmessage += e => { Native.Window.opener.postMessage(e.ToString()); }; } else { new Button { Text = "Secondary View" }.With( connect => { connect.AttachTo(con); connect.Left = 8; connect.Top = 8; connect.Click += delegate { var w = Native.Window.open(Native.Document.location.href, "_blank", 600, 600, false); w.onload += delegate { Console.WriteLine("loaded: " + w.document.location.href); if (w.document.location.href == "about:blank") { // fck you blank:P 4h of debugging for this. return; } //Native.Window.onmessage += // e => // { // if (e.source == w) // return; // // relay, not echo // w.postMessage(e.data); // }; var w_closed = false; w.onbeforeunload += delegate { w_closed = true; }; var xcc = 0; Action<XElement> __sprite_context_onmessage = e => { if (w_closed) return; xcc++; //Console.WriteLine(xcc + " to child -> " + e); w.postMessage(e.ToString()); }; sprite_context_onmessage += __sprite_context_onmessage; }; }; } ); } }
/// <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 f = new Form(); var fweb = new WebBrowser().AttachTo(f); fweb.Dock = DockStyle.Fill; var fiframe = (IHTMLIFrame)fweb.GetHTMLTargetContainer(); f.Show(); fiframe.onload += delegate { f.Text = "onload"; fiframe.contentWindow.onbeforeunload += delegate { f.Text = "onbeforeunload"; }; }; //sprite.wmode(); sprite.AttachSpriteToDocument().With( embed => { embed.style.SetLocation(0, 0); embed.style.SetSize(Native.window.Width, Native.window.Height); Native.window.onresize += delegate { embed.style.SetSize(Native.window.Width, Native.window.Height); }; } ); #region con var con = new ConsoleForm(); con.InitializeConsoleFormWriter(); con.Show(); con.Left = Native.window.Width - con.Width; con.Top = 0; Native.window.onresize += delegate { con.Left = Native.window.Width - con.Width; con.Top = 0; }; con.Opacity = 0.6; #endregion sprite.InitializeConsoleFormWriter( Console.Write, Console.WriteLine ); fiframe.id = "foo7"; fiframe.name = "foo7"; sprite.SetIFrameName(fiframe.name); con.HandleFormClosing = false; con.PopupInsteadOfClosing(); "Operation «Heat Zeeker»".ToDocumentTitle(); }
//assembly: C:\Users\Arvo\AppData\Local\Temp\ox3kmhez.pak\Abstractatech.JavaScript.FormAsPopup.dll //type: ScriptCoreLib.JavaScript.Extensions.X, Abstractatech.JavaScript.FormAsPopup, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null //offset: 0x004d // method:ScriptCoreLib.JavaScript.DOM.IWindow postMessage(ScriptCoreLib.JavaScript.DOM.IWindow, System.Xml.Linq.XElement, System.Action`1[System.Xml.Linq.XElement]) } /// <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) { #region con var con = new ConsoleForm(); con.InitializeConsoleFormWriter(); con.Show(); con.Left = Native.window.Width - con.Width; con.Top = 0; Native.window.onresize += delegate { con.Left = Native.window.Width - con.Width; con.Top = 0; }; con.Opacity = 0.6; con.HandleFormClosing = false; con.PopupInsteadOfClosing(); #endregion Action<string> __SystemConsoleWrite = Console.Write; IFunction.OfDelegate(__SystemConsoleWrite).Export("__SystemConsoleWrite"); if (page.__marker1 == null) { // the other mode #region let flash know js is ready Console.WriteLine("looking for myself..."); //Native.Window.alert("now what?"); //Action yield = delegate //{ // Console.WriteLine("looking for myself... done!"); //}; new ScriptCoreLib.JavaScript.Runtime.Timer( delegate { Action<IHTMLElement> y = e => { var embed = (IHTMLEmbedFlash)e; try { // this is a hack //var sprite = new ApplicationSprite(); //object sprite_object = sprite; //dynamic a = sprite_object; //a.__InternalElement = embed; //var sprite = (ApplicationSprite)(object)embed; Console.WriteLine("looking for myself... WhenReady?"); embed.CallFunction("WhenReady", new[] { "foo" }); //sprite.WhenReady(yield); } catch { } }; Native.Document.getElementsByTagName("object").WithEach(y); Native.Document.getElementsByTagName("embed").WithEach(y); } ).StartTimeout(500); #endregion return; } var sprite = new ApplicationSprite(); sprite.AutoSizeSpriteTo(page.ContentSize); sprite.AttachSpriteTo(page.Content); //__SystemConsoleWrite //sprite.InitializeConsoleFormWriter(); }
/// <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) { #region con //var con = new Abstractatech.ConsoleFormPackage.Library.ConsoleForm(); var con = new ConsoleForm(); con.InitializeConsoleFormWriter(); con.Show(); con.Left = Native.Window.Width - con.Width; con.Top = 0; Native.Window.onresize += delegate { con.Left = Native.Window.Width - con.Width; con.Top = 0; }; con.Opacity = 0.6; con.HandleFormClosing = false; con.PopupInsteadOfClosing(); #endregion Console.WriteLine("click on InitializeOurFacebookLoginService!"); Native.Window.onmessage += e => { // http://developer.klout.com/blog/read/fb_identity_lookup Console.WriteLine("onmessage: " + e.data); }; // wont work as chrome app! page.InitializeOurFacebookLoginService.WhenClicked( delegate { Console.WriteLine("loading... "); // http://caniuse.com/iframe-sandbox // http://security.stackexchange.com/questions/15146/using-iframes-to-sandbox-untrusted-code var i = new IHTMLIFrame { }; // http://www.w3schools.com/tags/att_iframe_sandbox.asp // The value of the sandbox attribute can either be an empty string (all the restrictions is applied), or a space-separated list of pre-defined values that will REMOVE particular restrictions. // http://www.html5rocks.com/en/tutorials/security/sandboxed-iframes/ // this will break our popups and cookies for facebook! //i.setAttribute("sandbox", "allow-scripts allow-forms allow-popups"); i.src = "http://young-beach-4377.herokuapp.com/"; i.AttachToDocument(); i.onload += delegate { Console.WriteLine("loading... done " + new { i.src }); // can we now talk to it? // }; } ); page.InitializeOurFacebookLoginServiceViaWindow.WhenClicked( delegate { Console.WriteLine("loading... "); //var i = new IWindow { }; //i.document.location.href = "http://young-beach-4377.herokuapp.com/"; var i = Native.Window.open("http://young-beach-4377.herokuapp.com/", "_blank", 400, 225); // doesnt tell us when loaded? i.onload += delegate { Console.WriteLine("loading... done..."); //Console.WriteLine("loading... done " + new { i.document.title }); //Console.WriteLine("loading... done " + new { i.document.location.href }); // can we now talk to it? // }; // popup will be blocked //new IHTMLButton { innerText = "send DoLogin" }.AttachToDocument().WhenClicked( // delegate // { // Console.WriteLine("send DoLogin"); // i.postMessage( // new XElement("DoLogin", new XAttribute("tag", "foo")).ToString() // ); // } //); } ); page.InitializeOurFacebookLoginServiceViaWindowAndClose.WhenClicked( delegate { Console.WriteLine("loading... "); //var i = new IWindow { }; //i.document.location.href = "http://young-beach-4377.herokuapp.com/"; var i = Native.Window.open("http://young-beach-4377.herokuapp.com/#c", "_blank", 400, 225); // doesnt tell us when loaded? i.onload += delegate { Console.WriteLine("InitializeOurFacebookLoginServiceViaWindowAndClose loading... done..."); //Console.WriteLine("loading... done " + new { i.document.title }); //Console.WriteLine("loading... done " + new { i.document.location.href }); // can we now talk to it? // }; i.onbeforeunload += delegate { Console.WriteLine("InitializeOurFacebookLoginServiceViaWindowAndClose onbeforeunload"); }; // popup will be blocked //new IHTMLButton { innerText = "send DoLogin" }.AttachToDocument().WhenClicked( // delegate // { // Console.WriteLine("send DoLogin"); // i.postMessage( // new XElement("DoLogin", new XAttribute("tag", "foo")).ToString() // ); // } //); } ); page.HerokuFacebookLoginAppLoginExperience.WhenClicked( delegate { HerokuFacebookLoginAppLoginExperience.Login( (string id, string name, string third_party_id) => { Console.WriteLine(new { id, name, third_party_id }); } ); } ); @"Hello world".ToDocumentTitle(); // Send data from JavaScript to the server tier //service.WebMethod2( // @"A string from JavaScript.", // value => value.ToDocumentTitle() //); }
private void InitializeConsole() { #region con var con = new ConsoleForm(); con.InitializeConsoleFormWriter(); con.Show(); con.Height = 150; con.Left = Native.window.Width - con.Width; con.Top = 0; Native.window.onresize += delegate { con.Left = Native.window.Width - con.Width; con.Top = 0; }; con.Opacity = 0.6; // !! not compatible yet //FormAsPopupExtensions con.HandleFormClosing = false; con.PopupInsteadOfClosing(); #endregion Action<string> Console_Write = x => { Console.Write(x); }; Action<string> Console_WriteLine = x => { Console.WriteLine(x); }; leftsprite.InitializeConsoleFormWriter( Console_Write, Console_WriteLine ); }