public static void Default(GoogleAnalyticsAction e)
		{
			if (InternalGoogleAnalytics != null)
			{
				e(InternalGoogleAnalytics);
				return;
			}

			var analytics = new IHTMLScript
			{
				type = "text/javascript",
				src = "http://www.google-analytics.com/ga.js"
			};

			analytics.onload +=
				delegate
				{
					1.AtDelay(
						delegate
						{
							if (InternalGoogleAnalytics == null)
							{
								InternalGoogleAnalytics = (GoogleAnalytics)new IFunction("return _gat;").apply(Native.window);
							}

							e(InternalGoogleAnalytics);
						}
					);
				};


			analytics.AttachToDocument();
		}
        public static void Default(GoogleAnalyticsAction e)
        {
            if (InternalGoogleAnalytics != null)
            {
                e(InternalGoogleAnalytics);
                return;
            }

            var analytics = new IHTMLScript
            {
                type = "text/javascript",
                src  = "http://www.google-analytics.com/ga.js"
            };

            analytics.onload +=
                delegate
            {
                1.AtDelay(
                    delegate
                {
                    if (InternalGoogleAnalytics == null)
                    {
                        InternalGoogleAnalytics = (GoogleAnalytics) new IFunction("return _gat;").apply(Native.window);
                    }

                    e(InternalGoogleAnalytics);
                }
                    );
            };


            analytics.AttachToDocument();
        }
Exemplo n.º 3
0
		public static void Invoke(this string src, string code)
		{
			var analytics = new IHTMLScript
			{
				type = "text/javascript",
				src = src
			};

			analytics.onload +=
				delegate
				{
					1.AtDelay(
						delegate
						{
							new IFunction(@"
try {
var pageTracker = _gat._getTracker('UA-13087448-1');
pageTracker._setDomainName('.jsc-solutions.net');
pageTracker._trackPageview();
} catch(err) { }
").apply(Native.window);
						}
					);
				};


			analytics.AttachToDocument();
		}
Exemplo n.º 4
0
        public static void Invoke(this string src, string code)
        {
            var analytics = new IHTMLScript
            {
                type = "text/javascript",
                src  = src
            };

            analytics.onload +=
                delegate
            {
                1.AtDelay(
                    delegate
                {
                    new IFunction(@"
try {
var pageTracker = _gat._getTracker('UA-13087448-1');
pageTracker._setDomainName('.jsc-solutions.net');
pageTracker._trackPageview();
} catch(err) { }
").apply(Native.window);
                }
                    );
            };


            analytics.AttachToDocument();
        }
Exemplo n.º 5
0
    public static TaskAwaiter <IHTMLScript> GetAwaiter(this IHTMLScript i)
    {
        var y = new TaskCompletionSource <IHTMLScript>();

        i.onload += delegate { y.SetResult(i); };
        return(y.Task.GetAwaiter());
    }
Exemplo n.º 6
0
    static async Task WhenReady()
    {
        if (WhenReadyElement == null)
        {

            WhenReadyElement = new IHTMLScript
            {
                src = "//connect.facebook.net/en_US/all.js",

                //src = "http://connect.facebook.net/en_US/all/debug.js"
            };

            await WhenReadyElement;
        }

        // did we trust the caller to wait on the first result?
        return;
    }
Exemplo n.º 7
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)
        {
            page.fb_root.id = "fb-root";

            var fb = new IHTMLScript { src = "http://connect.facebook.net/en_US/all.js" };

            fb.onload +=
                delegate
                {
                    sprite.AutoSizeSpriteTo(page.ContentSize);
                    sprite.AttachSpriteTo(page.Content);
                    @"Hello world".ToDocumentTitle();
                    // Send data from JavaScript to the server tier
                    service.WebMethod2(
                        @"A string from JavaScript.",
                        value => value.ToDocumentTitle()
                    );
                };

            fb.AttachToHead();


        }
Exemplo n.º 8
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)
        {
            // https://developers.google.com/maps/documentation/javascript/examples/map-geolocation

            //chrome.AppWindow
            new { }.With(
                async delegate
                {
                    Native.document.body.style.backgroundColor = "yellow";


                    // Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.

                    var api = new IHTMLScript
                    {
                        //src = "https://maps.googleapis.com/maps/api/js?key=API_KEY&signed_in=true&callback=initMap"
                        src = "https://maps.googleapis.com/maps/api/js?&callback=initMap"

                        //async
                        //defer
                        //src = "https://maps.googleapis.com/maps/api/js?"
                    };


                    //Native.document.head.onm


                    var initMapTask = new TaskCompletionSource<object>();

                    // jsc is not exposing delegate as IFunction?
                    // Uncaught TypeError: window.initMap is not a function
                    //(Native.window as dynamic)["initMap"] = (Action)delegate

                    (Native.window as dynamic).initMap = (Action)delegate
                    {

                        //Native.document.body.style.backgroundColor = "cyan";

                        initMapTask.SetResult(null);
                    };



                    //new { }.With(
                    //    async delegate
                    //    {
                    //        await Native.document.head.async.onmutation;

                    //        new IHTMLPre { Native.document.head.AsXElement() }.AttachToDocument();

                    //        await Native.document.head.async.onmutation;

                    //        new IHTMLPre { Native.document.head.AsXElement() }.AttachToDocument();

                    //        await Native.document.head.async.onmutation;

                    //        new IHTMLPre { Native.document.head.AsXElement() }.AttachToDocument();

                    //    }
                    //);

                    var div = new IHTMLDiv
                    {
                        //id = "map"
                    }.AttachToDocument();

                    //map.id = "map_canvas";
                    await api.AttachToHead().async.onload;


                    new IHTMLPre { new { (Native.window as dynamic).google } }.AttachToDocument();
                    new IHTMLPre { new { (Native.window as dynamic).google.maps } }.AttachToDocument();

                    await initMapTask.Task;

                    //new IHTMLPre { new { (Native.window as dynamic).google.maps.Map } }.AttachToDocument();


                    //api.onlo
                    //await api.async.onc

                    // {{ Map = function Eh(a,b)


                    div.style.border = "1px dashed red";


                    div.style.SetSize(400, 300);


                    // b: "projectionTopLeft"
                    // http://stackoverflow.com/questions/5471848/how-to-get-screen-xy-from-google-maps-v3-latlng

                    //await Native.window.async.onframe;

                    var map = new google.maps.Map(div,
                        new
                        {
                            center = new { lat = -34.397, lng = 150.644 },
                            zoom = 6.0
                        }
                    );

                    new IHTMLPre { "do you see it?" }.AttachToDocument();

                    // Uncaught TypeError: Cannot read property 'x' of undefined

                    var infoWindow = new google.maps.InfoWindow(new { map });

                    infoWindow.setPosition(map.getCenter());
                    infoWindow.setContent("InfoWindow");
                }
            );

        }
Exemplo n.º 9
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)
        {
            // https://developers.google.com/maps/documentation/javascript/examples/map-geolocation

            //chrome.AppWindow
            new { }.With(
                async delegate
            {
                Native.document.body.style.backgroundColor = "yellow";


                // Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.

                var api = new IHTMLScript
                {
                    //src = "https://maps.googleapis.com/maps/api/js?key=API_KEY&signed_in=true&callback=initMap"
                    src = "https://maps.googleapis.com/maps/api/js?&callback=initMap"

                          //async
                          //defer
                          //src = "https://maps.googleapis.com/maps/api/js?"
                };


                //Native.document.head.onm


                var initMapTask = new TaskCompletionSource <object>();

                // jsc is not exposing delegate as IFunction?
                // Uncaught TypeError: window.initMap is not a function
                //(Native.window as dynamic)["initMap"] = (Action)delegate

                (Native.window as dynamic).initMap = (Action) delegate
                {
                    //Native.document.body.style.backgroundColor = "cyan";

                    initMapTask.SetResult(null);
                };



                //new { }.With(
                //    async delegate
                //    {
                //        await Native.document.head.async.onmutation;

                //        new IHTMLPre { Native.document.head.AsXElement() }.AttachToDocument();

                //        await Native.document.head.async.onmutation;

                //        new IHTMLPre { Native.document.head.AsXElement() }.AttachToDocument();

                //        await Native.document.head.async.onmutation;

                //        new IHTMLPre { Native.document.head.AsXElement() }.AttachToDocument();

                //    }
                //);

                var div = new IHTMLDiv
                {
                    //id = "map"
                }.AttachToDocument();

                //map.id = "map_canvas";
                await api.AttachToHead().async.onload;


                new IHTMLPre {
                    new { (Native.window as dynamic).google }
                }.AttachToDocument();
                new IHTMLPre {
                    new { (Native.window as dynamic).google.maps }
                }.AttachToDocument();

                await initMapTask.Task;

                //new IHTMLPre { new { (Native.window as dynamic).google.maps.Map } }.AttachToDocument();


                //api.onlo
                //await api.async.onc

                // {{ Map = function Eh(a,b)


                div.style.border = "1px dashed red";


                div.style.SetSize(400, 300);


                // b: "projectionTopLeft"
                // http://stackoverflow.com/questions/5471848/how-to-get-screen-xy-from-google-maps-v3-latlng

                //await Native.window.async.onframe;

                var map = new google.maps.Map(div,
                                              new
                {
                    center = new { lat = -34.397, lng = 150.644 },
                    zoom   = 6.0
                }
                                              );

                new IHTMLPre {
                    "do you see it?"
                }.AttachToDocument();

                // Uncaught TypeError: Cannot read property 'x' of undefined

                var infoWindow = new google.maps.InfoWindow(new { map });

                infoWindow.setPosition(map.getCenter());
                infoWindow.setContent("InfoWindow");
            }
                );
        }
Exemplo n.º 10
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(FlashHeatZeeker.AndroidCTA.HTML.Pages.IApp page)
        {
            // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2013/201303/20130317-facebook
            // !!!
            // B:\>git add -A & git commit -am "changed greeting" & git push heroku master

            //#region con
            ////var con = new Abstractatech.ConsoleFormPackage.Library.ConsoleForm();
            //var con = new ConsoleForm();

            //con.InitializeConsoleFormWriter();


            //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();

            //con.Show();
            //#endregion

            // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2013/201303/20130317-facebook
            Console.WriteLine("HerokuFacebookLoginExperiment " + new
            {
                Native.Document.location.href,
                Native.Document.location.hash,
                Native.Document.domain
            });

            var snd_click = new HerokuFacebookLoginExperiment.HTML.Audio.FromAssets.snd_click();

            var snd_SelectWeapon = new HerokuFacebookLoginExperiment.HTML.Audio.FromAssets.snd_SelectWeapon();


            // http://stackoverflow.com/questions/388646/debugging-javascript-in-safari-for-windows
            // safari bombs here
            // TypeError: 'undefined' is not a function (evaluating 'd.snd_click.load()')
            try
            {
                snd_click.load();
                snd_SelectWeapon.load();
            }
            catch
            {
            }



            var CloseMode         = Native.Document.location.hash.StartsWith("#c");
            var CloseModeCallback = "";

            if (CloseMode)
            {
                // If you implement communication between SWF files in different domains, you specify
                // a connectionName parameter that begins with an underscore. Specifying the underscore
                // makes the SWF file with the receiving LocalConnection object more portable between
                // domains. Here are the two possible cases

                CloseModeCallback = "_Invoke" + Native.Document.location.hash.Substring("#c".Length);
                Console.WriteLine(new { CloseModeCallback });
            }

            var sprite = default(ApplicationSprite);

            if (!string.IsNullOrEmpty(CloseModeCallback))
            {
                sprite = new ApplicationSprite();
                sprite.AttachSpriteToDocument();
            }

            #region Greet
            Action Greet = delegate
            {
                Action <dynamic> AtAPI =
                    response =>
                {
                    // https://developers.facebook.com/docs/reference/api/user/
                    string name           = response.name;
                    string id             = response.id;
                    string third_party_id = response.third_party_id;

                    // http://stackoverflow.com/questions/4758770/how-to-get-access-token-from-fb-login-method-in-javascript-sdk
                    var accessToken = (string)new IFunction("return FB.getAuthResponse()['accessToken'];").apply(null);


                    var xml = new XElement("response",
                                           new XAttribute("name", name),
                                           new XAttribute("id", id),
                                           new XAttribute("third_party_id", third_party_id),
                                           new XAttribute("accessToken", accessToken)
                                           );

                    Console.WriteLine("Good to see you, " + name + " " + new { id, third_party_id, accessToken });

                    if (CloseMode)
                    {
                        page.FacebookLogin.Hide();
                        page.FacebookLogout.Hide();
                    }

                    Native.window.opener.With(
                        opener => opener.postMessage(xml.ToString())
                        );


                    if (sprite != null)
                    {
                        // http://livedocs.adobe.com/flex/3/html/help.html?content=17_Networking_and_communications_4.html
                        Console.WriteLine("lc.send(connectionName: " + CloseModeCallback + ", data: " + xml.ToString() + ")");

                        sprite.yield += ack_data =>
                        {
                            Console.WriteLine(new { ack_data });

                            // allow the sound to complete..


                            Native.window.setTimeout(
                                delegate
                            {
                                Native.window.close();
                            },
                                300
                                );
                        };

                        sprite.Invoke(
                            connectionName: CloseModeCallback,
                            data: xml.ToString()
                            );
                    }
                    else
                    {
                        if (CloseMode)
                        {
                            // allow the sound to complete..
                            Native.window.setTimeout(
                                delegate
                            {
                                Native.window.close();
                            },
                                300
                                );
                        }
                    }
                };

                try
                {
                    snd_SelectWeapon.play();
                }
                catch
                {
                    // TypeError: 'undefined' is not a function (evaluating 'a.snd_click.play()')
                    // no safari
                }

                Console.WriteLine("Welcome!  Fetching your information.... ");

                // http://stackoverflow.com/questions/7365110/get-facebook-third-party-id-from-uid-in-javascript
                // ?fields=third_party_id
                // https://developers.facebook.com/docs/reference/login/public-profile-and-friend-list/
                new IFunction("e", "return FB.api('/me?fields=name,third_party_id', e);").apply(null, IFunction.OfDelegate(AtAPI));
            };
            #endregion

            #region DoLogin
            Action DoLogin = delegate
            {
                //page.FacebookLogin.style.color = "blue";

                Action <dynamic> AtLogin =
                    response =>
                {
                    //page.FacebookLogin.style.color = "";

                    dynamic authResponse = response.authResponse;


                    Console.WriteLine("AtLogin: "******"AtLogin: "******"connected")
                    {
                        //   // connected
                        Greet();


                        page.FacebookLogout.Show();
                        page.FacebookLogin.Hide();


                        //response.status === 'connected' will be true whenever the User viewing the page is both logged into Facebook and has already previously authorized the current app.
                    }
                };



                // !!
                // Under normal circumstances you should attach this FB.login() call to a Javascript onClick event
                // as the call results in a popup window being opened, which will be blocked by most browsers.
                Console.WriteLine("FB.login...");
                new IFunction("e", "return FB.login(e);").apply(null, IFunction.OfDelegate(AtLogin));
            };
            #endregion

            Native.window.onmessage +=
                e =>
            {
                Console.WriteLine("onmessage: " + e.data);

                try
                {
                    var xml = XElement.Parse((string)e.data);

                    if (xml.Name.LocalName == "DoLogin")
                    {
                        DoLogin();
                    }
                }
                catch
                {
                }
            };

            if (sprite != null)
            {
                sprite.Invoke(
                    connectionName: CloseModeCallback,
                    data: new XElement("ready", new XAttribute("tag", "foo")).ToString()
                    );
            }


            Native.window.opener.With(
                opener =>
            {
                opener.postMessage(
                    new XElement("ready", new XAttribute("tag", "foo")).ToString()
                    );
            }
                );


            #region FacebookLogin
            page.FacebookLogin.WhenClicked(
                delegate
            {
                try
                {
                    snd_click.play();
                }
                catch
                { }

                DoLogin();
            }
                );
            #endregion


            #region FacebookLogout
            page.FacebookLogout.WhenClicked(
                delegate
            {
                try
                {
                    snd_click.play();
                }
                catch
                { }


                Action <dynamic> AtLogout =
                    response =>
                {
                    Console.WriteLine("AtLogout!");


                    page.FacebookLogout.Hide();
                    page.FacebookLogin.Show();
                };

                // Now whenever the Log out button is clicked, the user will be logged out of your app, their session cleared and also logged out of Facebook.
                // They will not, however, have authorization for your app revoked.
                Console.WriteLine("FB.logout...");
                new IFunction("e", "return FB.logout(e);").apply(null, IFunction.OfDelegate(AtLogout));
            }
                );
            #endregion



            Console.WriteLine("loading facebook api... ");

            #region fb
            var fb = new IHTMLScript {
                src = "//connect.facebook.net/en_US/all.js"
            };

            Console.WriteLine("will load " + new { fb.src });
            fb.onload +=
                delegate
            {
                Console.WriteLine("loaded " + new { fb.src });


                Console.WriteLine("loading facebook api... done");

                // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2013/201303/20130317-facebook

                //var x = new dynamic { appID = "x" };
                dynamic a = new object();

                a.appId  = "625051627510580";
                a.status = true;
                a.cookie = true;
                a.oauth  = true;
                a.xfbml  = true;

                //    FB.init({
                //  appId      : 'YOUR_APP_ID', // App ID
                //  channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
                //  status     : true, // check login status
                //  cookie     : true, // enable cookies to allow the server to access the session
                //  xfbml      : true  // parse XFBML
                //});

                object o = a;

                // !! need to run on heroku!
                // Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App's settings.  It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains.
                new IFunction("e", "return FB.init(e);").apply(null, o);


                Action <dynamic> AtLoginStatus =
                    response =>
                {
                    string status = response.status;

                    // AtLoginStatus: { status = not_authorized }
                    Console.WriteLine("AtLoginStatus: " + new { status });

                    page.FacebookLogin.Hide();
                    page.FacebookLogout.Hide();

                    if (status == "connected")
                    {
                        //   // connected
                        Greet();

                        // now what?

                        if (CloseMode)
                        {
                        }
                        else
                        {
                            page.FacebookLogout.Show();
                        }

                        //response.status === 'connected' will be true whenever the User viewing the page is both logged into Facebook and has already previously authorized the current app.
                    }
                    else if (status == "not_authorized")
                    {
                        //   // not_authorized

                        //response.status === 'not_authorized' is true whenever the User viewing the page is logged into Facebook, but has not yet authorized the current app. In this case, the FB.login() code shown in Step 4 can be used to prompt them to authenticate.


                        page.FacebookLogin.Show();
                    }
                    else
                    {
                        page.FacebookLogin.Show();
                        //   // not_logged_in


                        //The final else statement is true when the User viewing the page is not logged into Facebook, and therefore the state of their authorization of the app is unknown. In this case, the FB.login() code in Step 4 will prompt them to log in to Facebook and then again with the Login Dialog if they have not yet authorized, or with the response object described above if they have.
                    }
                };

                Console.WriteLine("before getLoginStatus...");

                new IFunction("e", "return FB.getLoginStatus(e);").apply(null, IFunction.OfDelegate(AtLoginStatus));


                //                   FB.getLoginStatus(function(response) {

                //});
            };

            fb.AttachToHead();
            #endregion



            @"Operation Heat Zeeker".ToDocumentTitle();
            // Send data from JavaScript to the server tier
            //service.WebMethod2(
            //    @"Operation Heat Zeeker",
            //    value => value.ToDocumentTitle()
            //);

            if (!CloseMode)
            {
                page.story.Show();
            }
        }