A location chooser for YoWindow widget

No news - good news
User avatar
par
Posts: 8629
Joined: Mon Sep 21, 2009 11:56 am
Name: Pasha
Location: Saint-Petersburg, Russia
Contact:

A location chooser for YoWindow widget

Post by par »

I have made a new location chooser.
The old one was written in Flash.
The new one is written in Java Script.

Why do we need a new one?

1. New location chooser loads super-fast.
Flash chooser: 180 KB
JS chooser: 14 KB

2. You can add new location chooser to your page.
Your visitors will be able choose the location.

You will find the new location chooser on this example page.
The HTML code is so simple you just can copy/paste it to your website and to modify parameters according to your needs.
See the expandable link at the bottom of the page.

http://yowindow.com/example/lc_widget.php

Please drop me a link if you have added new location chooser to your page.
Make me happy :)

The code is very rough.
Please report all the problems you will notice.
Report any Java Script errors you notice while working with the chooser.
If you to see any messages in the Diagnostic Information pane, this is a problem, let me know.
Please include your browser version in the report.


I will replace the old location chooser on yowindow.com with the new one as soon as we are confident enough in the quality.

Pasha
Get YoWindow weather app for your phone or tablet.

Image Image Image
ikarus1969
Posts: 1645
Joined: Wed Nov 18, 2009 9:58 am
Location: Vienna, Austria

Re: A location chooser for YoWindow widget

Post by ikarus1969 »

Hi Pavel!

I played around with the location-chooser a little bit.

The first thing i tryed was to start with my location by calling the "open"-method of the YoLocationChooser with the argument "Austria/Vienna":

Code: Select all

locationChooser.open("Austria/Vienna");
That works as expected.

Then i tried to have the widget reflect this initial setting which did not work.

I tried to make the "place" and "locationChooser a global variable, initialized them in the "onLoad"-method at the beginning and set the "location_id"-property in the "flashvars"-json-object to the id from the location-chooser-variable.
My assumption is that the location-chooser-object also has the properties which are described with the "node"-object.

What i expected was that the widget would show Vienna as the location because the chooser was called with this initial setting. But it showed New York City, the default location.

It seems as if the location id of the location-chooser object only is set when the user changes the selection in the drop-down-box.

Could you please modify the location-chooser object so that the id is (and the other properties are) set when the object is initialized too? Or let the location-chooser object has the same properties as the node-object?
Please! :)

What i want is that the widget can start with the location the location-chooser was initialized with.


My modified javascript-code:

Code: Select all

<html>
<head>
    <title>Location Chooser and YoWindow weather widget</title>
 
<!-- Location Chooser component -->
    <script type="text/javascript" src="http://js.yowindow.com/js/yolc.js"></script>
<!-- YoWindow widget component -->
    <script type="text/javascript" src="http://js.yowindow.com/js/yowidget.js"></script>
 
    <script language="JavaScript">
        var place = null;
        var locationChooser = null;
 
        function onLoad()
        {
            place = document.getElementById('location_chooser_place');
            locationChooser = new YoLocationChooser(place);

            installLocationChooser();
            
            // the following alert displays "undefined" for the id
            alert('locationChooser["@id"]=' + locationChooser["@id"] + "***");

            installYoWidget();
        }
 
        function installLocationChooser()
        {
            var place = document.getElementById('location_chooser_place');
 
//Subscribe to onLocationChange event
            locationChooser.onLocationChange = onLocationChange;
 
/**
lc.open(); - let the user to choose the location, starting on country-level
lc.open("#auto"); - detect location by IP and open it
lc.open("United Kingdom/London"); - open London
*/
            locationChooser.open("Austria/Vienna");
        }
 
/**
Event of YoLocationChooser
It is called every time the location changes.
When location was deselected - node is null
node format
node = {
    @id, // GeoNames id
    @name, // Name from the Geonames data-base
    @p // Population
}
 
Here we reflect selected location in the widget.
*/
        function onLocationChange(node)
        {
 
            //Do not do anything if location was deselected (node is null).
            if (node)
            {
              // the following alert displays the correct id for Vienna!
              alert('locationChooser["@id"]=' + node["@id"] + "***");

              var locationId = node['@id'];
              var yowidget = document.getElementById('yowidget');
   
              //Select location in YoWindow widget
              yowidget.setLocationId(locationId);
            }
        }
 
/**
Creates YoWindow widget and adds it to the place-holder "yowidget_place"
*/
        function installYoWidget()
        {
 /**
flashvars parameters
See http://yowindow.com/widget_parameters.html
 
I have put some examples in the code, uncomment to see them in effect
*/
            var flashvars = {
                // location_id: "auto",
                location_id: locationChooser["@id"],
                landscape: "seaside",
                background: "#FFFFFF",
                lang: "de",
                unit_system: "metric",
                time_format: "24"
            };
 
/**
Flash parameters
*/
            var params = {
                quality: "high",
                bgcolor: "#FFFFFF",
                allowscriptaccess: "always",
                allowfullscreen: "true",
                wmode: "opaque"
            };
 
/**
id and name of YoWindow widget in HTML DOM
*/
            var attributes = {
                id: "yowidget",
                name: "yowidget"
            };
 
            YoWidget.embed(
                "yowidget_place", //place-holder id
                300,              //width
                150,              //height
                flashvars,
                params,
                attributes
            );
        }
 
    </script>
</head>
 
 
<body onLoad="onLoad();">
 
    <div>
        <span id="location_chooser_place" style="display:inline-block; width:250px; vertical-align:top;">
        </span>
 
        <span id="yowidget_place" style="display:inline-block;">
        </span>
    </div>
 
</body>
</html>
»Man is impressive. In a universe full of untold secrets he has invented boredom.«
User avatar
hermanz
Posts: 1892
Joined: Thu Apr 08, 2010 3:21 pm
Name: Herman
Location: Nieuwegein, Netherlands

Re: A location chooser for YoWindow widget

Post by hermanz »

Hi Pasha


well done

I have place hte source on my website
http://hermanz.nl/index.php?option=com_ ... &Itemid=32

http://hermanz.nl/yowindow/locatie.html
ther are no errors
gr.
Herman :D
(Wheather on an I(phone,pad,pod) or Android, YoWindow what else )
User avatar
Don
Posts: 687
Joined: Tue Sep 14, 2010 12:14 am
Name: Don
Location: Roseville, California, United States of America
Contact:

Re: A location chooser for YoWindow widget

Post by Don »

Hi Pavel,
I checked your example page in IE Tester and one of these error messages always pops up with IE 7 or older:
IE_error.jpg
IE_error.jpg (42.39 KiB) Viewed 10922 times
IE_error2.jpg
IE_error2.jpg (39.28 KiB) Viewed 10922 times
IE 8 seems okay.

Don
ikarus1969
Posts: 1645
Joined: Wed Nov 18, 2009 9:58 am
Location: Vienna, Austria

Re: A location chooser for YoWindow widget

Post by ikarus1969 »

Don wrote:IE 8 seems okay.
Not completely. On the one hand the location works well in IE8 on my WinXP-system i get the same errors like you, Don.
After the "doesn't support this property or object"-message i had a look on the included Javascript-file.
The object of the location-chooser only defines (beside others) a method called "setSelectedLocation" but not a method called "setLocationId" which is used in the code of the test-page Pavel provided exactly on the line of the error-message of your post (which is 49).

Why it works anyway: i don't know :?:

my IE8-messages:
Yowin #1.jpg
Yowin #1.jpg (77.32 KiB) Viewed 10912 times
Yowin #2.jpg
Yowin #2.jpg (92.12 KiB) Viewed 10912 times
»Man is impressive. In a universe full of untold secrets he has invented boredom.«
User avatar
par
Posts: 8629
Joined: Mon Sep 21, 2009 11:56 am
Name: Pasha
Location: Saint-Petersburg, Russia
Contact:

Re: A location chooser for YoWindow widget

Post by par »

Hey!

There was a thing that I have overlooked.
There is no way to select location in the widget until it is loaded completely.
The Chooser reports selected location BEFORE the widget is initialised.
I have added a widget event handler to listen for the moment the widget is ready for commands.
At the moment the location selected in Chooser is being selected in Widget.

Please update your source code and clean your browser cache to get the latest widget .SWF
Do it carefully there are many new strings, including a special hack for IE.

"Object does not support this property..." error reported by Don and confirmed by Reinhart should gone away.

Reinhart, it is a complex task to provide a smooth synchronization chooser -> widget on startup.
Since widget is considered initialised (ready for commands) when the initial location is loaded.
So first you have the default location (New York) and then after sychronization you will see Vienna is loaded.
I would recommend you to manually select Vienna in HTML code of the widget.
This way the widget will be loaded smooth and fast.
Hopefully some day I will implement this case better.

Herman, thanks for sharing the page, looks great!
Get YoWindow weather app for your phone or tablet.

Image Image Image
User avatar
Don
Posts: 687
Joined: Tue Sep 14, 2010 12:14 am
Name: Don
Location: Roseville, California, United States of America
Contact:

Re: A location chooser for YoWindow widget

Post by Don »

Pavel,
I humbly request that you put the copyright information in the HTML code (like you did with the regular widget) instead of the java script so that we can have control of it's position and style.

Thanks, Don
User avatar
Don
Posts: 687
Joined: Tue Sep 14, 2010 12:14 am
Name: Don
Location: Roseville, California, United States of America
Contact:

Re: A location chooser for YoWindow widget

Post by Don »

Hi Pavel,
Your event handler was working on example page but it wouldn't work on my page so I compared the source code of the example page with the code displayed under the expandable link and found that "this." was missing in three places. See the fixed part of the code below.

Don

Code: Select all

 
        function onLoad() {
            installLocationChooser();
            installYoWidget();
        }
 
        function installLocationChooser() {
            var place = document.getElementById('location_chooser_place');
            this.locationChooser = new YoLocationChooser(place);
 
//Subscribe to onLocationChange event
            this.locationChooser.onLocationChange = onLocationChange;
 
/**
lc.open(); - let the user to choose the location, starting on country-level
lc.open("#auto"); - detect location by IP and open it
lc.open("United Kingdom/London"); - open London
*/
            this.locationChooser.open("#auto");
        }
User avatar
Don
Posts: 687
Joined: Tue Sep 14, 2010 12:14 am
Name: Don
Location: Roseville, California, United States of America
Contact:

Re: A location chooser for YoWindow widget

Post by Don »

Hey, it's me again. I got another error message from IE.
Don
IE_error3.jpg
IE_error3.jpg (95.08 KiB) Viewed 10793 times
ikarus1969
Posts: 1645
Joined: Wed Nov 18, 2009 9:58 am
Location: Vienna, Austria

Re: A location chooser for YoWindow widget

Post by ikarus1969 »

Don wrote:Hey, it's me again. I got another error message from IE.
Don
The attachment IE_error3.jpg is no longer available
together with diagnostic message (the method "isReadyForCommands" is missing in the .js-file):
YoWindow - location chooser.jpg
YoWindow - location chooser.jpg (113.61 KiB) Viewed 10787 times
»Man is impressive. In a universe full of untold secrets he has invented boredom.«
Post Reply