source: cows/branches/cows-vis/cows/pylons/project_templates/cows_server/+package+/public/js/yui/examples/io/io-weather_clean.html @ 5259

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows/branches/cows-vis/cows/pylons/project_templates/cows_server/+package+/public/js/yui/examples/io/io-weather_clean.html@5259
Revision 5259, 4.0 KB checked in by domlowe, 11 years ago (diff)

adding yui javascript

Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2<html>
3<head>
4<meta http-equiv="content-type" content="text/html; charset=utf-8">
5<title>XML Transaction &mdash; Retrieving a Yahoo! Weather RSS (XML) Feed via a Server-Side Proxy</title>
6
7<style type="text/css">
8/*margin and padding on body element
9  can introduce errors in determining
10  element position and are not recommended;
11  we turn them off as a foundation for YUI
12  CSS treatments. */
13body {
14        margin:0;
15        padding:0;
16}
17</style>
18
19<link type="text/css" rel="stylesheet" href="../../build/cssfonts/fonts-min.css" />
20<script type="text/javascript" src="../../build/yui/yui-min.js"></script>
21
22<!--there is no custom header content for this example-->
23
24</head>
25
26<body class=" yui-skin-sam">
27
28<h1>XML Transaction &mdash; Retrieving a Yahoo! Weather RSS (XML) Feed via a Server-Side Proxy</h1>
29
30<div class="exampleIntro">
31        <p>This example demonstrates how to use IO and a PHP proxy &mdash; to work around XMLHttpRequest's same-domain policy &mdash; to retrieve an XML document from <code>http://xml.weather.yahoo.com/forecastrss</code>.</p>
32
33<p>To try out the example, fill in your five-digit US zip code, or Location ID.</p>                     
34</div>
35
36<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->
37
38<form id="wForm">
39<fieldset>
40        <label>Zip Code or Location ID</label> <input type="text" id="zip" value="94089">
41        <p>Please enter a U.S. Zip Code or a location ID to get the current temperature.  The default is Zip Code 94089 for Sunnyvale, California; its location ID is: USCA1116.</p>
42</fieldset>
43<div id="weatherModule"></div>
44<input type="button" value="Get Weather RSS" id="getWeather">
45</form>
46
47
48<script language="javascript">
49
50YUI({base:"../../build/", timeout: 10000}).use("io",
51
52        function(Y) {
53
54                //Get a Node reference to the div we'll use for displaying
55                //results:
56                var div = Y.Node.get('#weatherModule');
57
58                //Define a function to handle a successful response from
59                //Yahoo! Weather.  The success handler will find the response
60                //object in its second argument:
61                function successHandler(id, o){
62                        Y.log("Success handler called; handler will parse the retrieved XML and insert into DOM.", "info", "example");
63                        var root = o.responseXML.documentElement;
64                        var oTitle = root.getElementsByTagName('description')[0].firstChild.nodeValue;
65                        var oDateTime = root.getElementsByTagName('lastBuildDate')[0].firstChild.nodeValue;
66                        var descriptionNode = root.getElementsByTagName('description')[1].firstChild.nodeValue;
67
68                        div.set("innerHTML", "<p>" + oTitle + "</p>" + "<p>" + oDateTime + "</p>" + descriptionNode);
69
70                        Y.log("Success handler is complete.", "info", "example");
71                }
72
73                //Provide a function that can help debug failed
74                //requests:
75                function failureHandler(id, o){
76                        Y.log("Failure handler called; http status: " + o.status, "info", "example");
77                        div.set("innerHTML", o.status + " " + o.statusText);
78                }
79
80                //When the Get RSS button is clicked, this function will fire
81                //and compose/dispatch the IO request:
82                function getModule(){
83                        //Get the input value:
84                        var iZip = Y.Node.get('#zip').get("value");
85
86                        //Create a querystring from the input value:
87                        var queryString = encodeURI('?p=' + iZip);
88
89                        //The location of our server-side proxy:
90                        var entryPoint = 'assets/weather.php';
91
92                        //Compile the full URI for the request:
93                        var sUrl = entryPoint + queryString;
94
95                        Y.log("Submitting request; zip code: " + iZip, "info", "example");
96
97                        //Make the reqeust:
98                        var request = Y.io(sUrl, {
99                                method:"GET",
100                                on:
101                                        {
102                                                success:successHandler,
103                                                failure:failureHandler
104                                        }
105                                }
106                        );
107                }
108
109                //Use the Event Utility to wire the Get RSS button
110                //to the getModule function:
111                Y.on("click", getModule, "#getWeather");
112
113                Y.log("When you retrieve weather RSS data, relevant steps in the process will be reported here in the logger/console.", "info", "example");
114        }
115);
116</script>
117
118<!--END SOURCE CODE FOR EXAMPLE =============================== -->
119
120</body>
121</html>
122<!-- delightfuture.corp.yahoo.com uncompressed/chunked Wed Aug 13 16:45:32 PDT 2008 -->
Note: See TracBrowser for help on using the repository browser.