JavaScript DHTML/YUI Library/YUI

Материал из Web эксперт
Перейти к: навигация, поиск

Adding new object members during parsing

 


<!--
Software License Agreement (BSD License)
Copyright (c) 2009, Yahoo! Inc.
All rights reserved.
Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright notice, this list of conditions and the
      following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    * Neither the name of Yahoo! Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Yahoo! Inc.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Sources of Intellectual Property Included in the YUI Library
YUI is issued by Yahoo! under the BSD license above. Below is a list of certain publicly available software that is the source of intellectual property in YUI, along with the licensing terms that pertain to thosesources of IP. This list is for informational purposes only and is not intended to represent an exhaustive list of third party contributions to the YUI.
    * Douglas Crockford"s JSON parsing and stringifying methods: In the JSON Utility, Douglas Crockford"s JSON parsing and stringifying methods are adapted from work published at JSON.org. The adapted work is in the public domain.
    * Robert Penner"s animation-easing algorithms: In the Animation Utility, YUI makes use of Robert Penner"s algorithms for easing.
    * Geoff Stearns"s SWFObject: In the Charts Control and the Uploader versions through 2.7.0, YUI makes use of Geoff Stearns"s SWFObject v1.5 for Flash Player detection and embedding. More information on SWFObject can be found here (http://blog.deconcept.ru/swfobject/). SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License (http://www.opensource.org/licenses/mit-license.php).
    * Diego Perini"s IEContentLoaded technique: The Event Utility employs a technique developed by Diego Perini and licensed under GPL. YUI"s use of this technique is included under our BSD license with the author"s permission.
-->

<head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Adding new object members during parsing</title>
<style type="text/css">
/*margin and padding on body element
  can introduce errors in determining
  element position and are not recommended;
  we turn them off as a foundation for YUI
  CSS treatments. */
body {
  margin:0;
  padding:0;
}
</style>
<link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/fonts/fonts-min.css" />
<script type="text/javascript" src="yui_2.7.0b-lib/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="yui_2.7.0b-lib/connection/connection-min.js"></script>
<script type="text/javascript" src="yui_2.7.0b-lib/json/json-min.js"></script>

<!--begin custom header content for this example-->
<style type="text/css">
#demo table {
    border: 3px solid #89d;
    border-collapse: collapse;
}
#demo caption {
    margin: 3px 0;
    font-weight: bold;
    color: #333;
    margin: 1em 0 1ex;
}
#demo table th {
    background: #89d;
    color: #fff;
    padding: 1ex 1em;
}
#demo table td {
    background: #fff;
    border: 1px solid #ddd;
    padding: .5ex 1ex;
}
</style>
<!--end custom header content for this example-->
</head>
<body class=" yui-skin-sam">

<h1>Adding new object members during parsing</h1>
<div class="exampleIntro">
  <p>This example shows how to use the <code>reviver</code> parameter in <code>JSON.parse</code> to add new object members and format existing members during the parsing phase.</p>
      
</div>
<!--BEGIN SOURCE CODE FOR EXAMPLE  -->
<div id="demo">
    <p>Choose a currency, then get the data</p>
    <select id="currencies">
        <option value="ARS">Argentine Peso</option>
        <option value="AUD">Australian Dollar</option>
        <option value="BRL">Brazilian Real</option>
        <option value="GBP">British Pound</option>
        <option value="CAD">Canadian Dollar</option>
        <option value="CNY">Chinese Yuan</option>
        <option value="COP">Colombian Peso</option>
        <option value="HRK">Croatian Kuna</option>
        <option value="CZK">Czech Koruna</option>
        <option value="DKK">Danish Krone</option>
        <option value="EEK">Estonian Kroon</option>
        <option value="EUR">Euro</option>
        <option value="HKD">Hong Kong Dollar</option>
        <option value="HUF">Hungarian Forint</option>
        <option value="ISK">Iceland Krona</option>
        <option value="INR">Indian Rupee</option>
        <option value="JPY">Japanese Yen</option>
        <option value="KRW">Korean Won</option>
        <option value="LVL">Latvian Lat</option>
        <option value="LTL">Lithuanian Lita</option>
        <option value="MYR">Malaysian Ringgit</option>
        <option value="MXN">Mexican Peso</option>
        <option value="NZD">New Zealand Dollar</option>
        <option value="NOK">Norwegian Krone</option>
        <option value="PHP">Philippine Peso</option>
        <option value="PLN">Polish Zloty</option>
        <option value="RUB">Russian Rouble</option>
        <option value="SGD">Singapore Dollar</option>
        <option value="SKK">Slovak Koruna</option>
        <option value="ZAR">South African Rand</option>
        <option value="LKR">Sri Lanka Rupee</option>
        <option value="SEK">Swedish Krona</option>
        <option value="TRY">Turkey Lira</option>
        <option value="USD" selected="selected">U.S. Dollar</option>
        <option value="CHF">Swiss Franc</option>
        <option value="TWD">Taiwan Dollar</option>
        <option value="THB">Thai Baht</option>
    </select>
    <input type="button" id="demo_go" value="Get Data">
    <table cellspacing="0">
    <caption>Inventory</caption>
    <thead>
        <tr>
            <th>SKU</th>
            <th>Item</th>
            <th>Price (USD)</th>
            <th>Price (<span>USD</span>)</th>
        </tr>
    </thead>
    <tbody>
        <tr><td colspan="4">Click <em>Get Data</em></td></tr>
    </tbody>
    </table>
</div>
<script type="text/javascript">
YAHOO.util.Event.onDOMReady(function () {
// Set up some shortcuts
var JSON  = YAHOO.lang.JSON,
    Dom   = YAHOO.util.Dom,
    Event = YAHOO.util.Event,
    Demo;
Demo = YAHOO.namespace("demo").JSONReviver = {
    rates : {"USD":1,"EUR":0.6661,"GBP":0.5207,"AUD":1.1225,"BRL":1.609,"NZD":1.4198,"CAD":1.0667,"CHF":1.0792,"CNY":6.8587 ,"DKK":4.9702,"HKD":7.8064,"INR":42.0168,"JPY":109.8901,"KRW":1000,"LKR":107.5269,"MXN":10.1317,"MYR" :3.3167,"NOK":5.3277,"SEK":6.2617,"SGD":1.4073,"THB":33.7838,"TWD":31.1526,"VEF":2.1445,"ZAR":7.6923 ,"BGN":1.3028,"CZK":16.0514,"EEK":10.4275,"HUF":158.7302,"LTL":2.2999,"LVL":0.4692,"PLN":2.1758,"RON" :2.3804,"SKK":20.2429,"ISK":4.8008,"HRK":81.3008,"RUB":24.3309,"TRY":1.1811,"PHP":44.2478,"COP":2000 ,"ARS":3.1289},
    currency : "USD",
    formatCurrency : function (amt) {
        amt += amt % 1 ? "0" : ".00";
        return amt.substr(0,amt.indexOf(".")+3);
    },
    convert : function (k,v) {
        // "this" will refer to the object containing the key:value pair,
        // so this will add a new object member while leaving the original
        // in tact (but formatted to two decimal places).  If the original
        // is not needed, just return the converted value.
        if (k === "Price") {
            var x = Math.round(v * Demo.rates[Demo.currency] * 100) / 100;
            this.convertedPrice = Demo.formatCurrency(x); // added to item
            return Demo.formatCurrency(v); // assigned to item.Price
        }
        return v;
    },
    updateTable : function (inventory) {
        var demo       = Dom.get("demo"),
            tbl        = demo.getElementsByTagName("table")[0],
            tbody      = tbl.getElementsByTagName("tbody")[0],
            col_header = tbl.getElementsByTagName("span")[0],
            tmp        = document.createElement("div"),
            html       = ["<table><tbody>"],i,j = 1,l,item;
        // Update the column header
        col_header.innerHTML = Demo.currency;
        if (inventory) {
            for (i = 0, l = inventory.length; i < l; ++i) {
                item = inventory[i];
                html[j++] = "<tr><td>";
                html[j++] = item.SKU;
                html[j++] = "</td><td>";
                html[j++] = item.Item;
                html[j++] = "</td><td>";
                html[j++] = item.Price;
                html[j++] = "</td><td>";
                html[j++] = item.convertedPrice;
                html[j++] = "</td></tr>";
            }
        } else {
            html[j++] = "<tr><td colspan="4">No Inventory data</td></tr>";
        }
        html[j] = "</tbody></table>";
        tmp.innerHTML = html.join("");
        tbl.replaceChild(tmp.getElementsByTagName("tbody")[0], tbody);
    }
};
Event.on("demo_go","click", function (e) {
    var self = this,     // Cache this for the async callback closure
        sel  = Dom.get("currencies"); // Store the requested currency
    // Disable the button temporarily
    this.disabled = true;
    // Store the requested currency
    Demo.currency = sel.value;
    YAHOO.util.Connect.asyncRequest("GET","yui_2.7.0b-assets/json-assets/data.php",{
        timeout : 3000,
        success : function (res) {
            var inventory;
            try {
                inventory = JSON.parse(res.responseText,Demo.convert);
                Demo.updateTable(inventory);
            }
            catch(e) {
                alert("Error getting inventory data");
            }
            finally {
                self.disabled = false;
            }
        },
        failure : function () {
            alert("Error getting inventory data");
        }
    });
});
});
</script>
</script>
<!--END SOURCE CODE FOR EXAMPLE  -->
</body>


<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>


Getting a Script File with YUI Get

 

<!--
Software License Agreement (BSD License)
Copyright (c) 2009, Yahoo! Inc.
All rights reserved.
Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright notice, this list of conditions and the
      following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    * Neither the name of Yahoo! Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Yahoo! Inc.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Sources of Intellectual Property Included in the YUI Library
YUI is issued by Yahoo! under the BSD license above. Below is a list of certain publicly available software that is the source of intellectual property in YUI, along with the licensing terms that pertain to thosesources of IP. This list is for informational purposes only and is not intended to represent an exhaustive list of third party contributions to the YUI.
    * Douglas Crockford"s JSON parsing and stringifying methods: In the JSON Utility, Douglas Crockford"s JSON parsing and stringifying methods are adapted from work published at JSON.org. The adapted work is in the public domain.
    * Robert Penner"s animation-easing algorithms: In the Animation Utility, YUI makes use of Robert Penner"s algorithms for easing.
    * Geoff Stearns"s SWFObject: In the Charts Control and the Uploader versions through 2.7.0, YUI makes use of Geoff Stearns"s SWFObject v1.5 for Flash Player detection and embedding. More information on SWFObject can be found here (http://blog.deconcept.ru/swfobject/). SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License (http://www.opensource.org/licenses/mit-license.php).
    * Diego Perini"s IEContentLoaded technique: The Event Utility employs a technique developed by Diego Perini and licensed under GPL. YUI"s use of this technique is included under our BSD license with the author"s permission.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Quickstart Example: Getting a Script File with YUI Get</title>
<style type="text/css">
/*margin and padding on body element
  can introduce errors in determining
  element position and are not recommended;
  we turn them off as a foundation for YUI
  CSS treatments. */
body {
  margin:0;
  padding:0;
}
</style>
<link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/fonts/fonts-min.css" />
<link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/button/assets/skins/sam/button.css" />
<script type="text/javascript" src="yui_2.7.0b-lib/yuiloader-dom-event/yuiloader-dom-event.js"></script>
<script type="text/javascript" src="yui_2.7.0b-lib/element/element-min.js"></script>
<script type="text/javascript" src="yui_2.7.0b-lib/button/button-min.js"></script>

<!--begin custom header content for this example-->
<style type="text/css">
  #returnedData {background-color:#0000ff; color:#ffffff; padding:1em; margin-top:1em; white-space:normal;}
</style>
<!--end custom header content for this example-->
</head>
<body class=" yui-skin-sam">

<h1>Quickstart Example: Getting a Script File with YUI Get</h1>
<div class="exampleIntro">
  <p>This example explores the simplest and most common use case for the <a href="http://developer.yahoo.ru/yui/get">YUI Get Utility</a>: fetching a script with <code>YAHOO.util.Get.script()</code> and making use of its contents.</p>
<p>Click the button to retrieve the script and output its data to the blue box.  The tutorial below gives you a full description of how to use this technique.</p>      
</div>
<!--BEGIN SOURCE CODE FOR EXAMPLE  -->
<div>
  <button id="getScript">Get Data from Script</button>
</div>
<pre id="returnedData">
  Data returned from the loaded script will appear here after you click the button above.
</pre>
<script language="JavaScript">
(function() {
  
  //We"ll use a YUI Button to actuate our request for the script:
  var button = new YAHOO.widget.Button("getScript", {type: "link"});
  
  //When the button is clicked, we"ll make the script request:
  button.on("click", function() {
    
    YAHOO.log("Button was clicked; loading script with Get Utility.", "info", "example");
    //We have a .js file at yui_2.7.0b-assets/get-assets/simple_get.js.  We will get
    //that script with the Get Utility:
    YAHOO.util.Get.script("yui_2.7.0b-assets/get-assets/simple_get.js", {
      
      //ALL OF THE CONFIGURATION OPTIONS BELOW ARE OPTIONAL;
      //IN MANY CASES, YOU"LL NEED ONLY TO DEFINE YOUR SUCCESS/
      //FAILURE HANDLERS.
      
      //callback to fire when the script is successfully loaded:
      onSuccess: function(obj) {
        YAHOO.log("Success handler was called. Transaction ID: " + obj.tId, "info", "example");
        document.getElementById("returnedData").innerHTML = YAHOO.lang.dump(YAHOO.simple_get.data, 3);
      },
      
      //callback to fire if the script does not successfully load:
      onFailure: function(o) {
        YAHOO.log("Failure handler was called. Transaction ID: " + obj.tId, "info", "example");
      },
      
      //context under which success and failure handlers should run;
      //default is the current window, which we"ll use for this example:
      scope: window,
      
      //by default, the script will be added to the current
      //window; use this property to override that default
      //(we"re just using the default in this example):
      win: window,
      
      //will be passed as a member of the callback object to
      //the success or failure handler:
      data: {testData: "value"},
      
      //For Safari 2.x, which does not support the script"s onload
      //event to determine when the script is loaded; instead, Get
      //will check for the presence of this varName (which is
      //defined in the script we"re retrieving) and use its presence
      //to determine when the script has been successfully loaded:
      varName: ["YAHOO.simple_get.data"]
    });
    
  });
  
})();
</script>
<!--END SOURCE CODE FOR EXAMPLE  -->
</body>
</html>
<!-- presentbright.corp.yahoo.ru uncompressed/chunked Thu Feb 19 10:53:15 PST 2009 -->


<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>


Looks at the "standard module format" used by many components in YUI to represent modular content on the page.

 

<!--
Software License Agreement (BSD License)
Copyright (c) 2009, Yahoo! Inc.
All rights reserved.
Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright notice, this list of conditions and the
      following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    * Neither the name of Yahoo! Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Yahoo! Inc.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Sources of Intellectual Property Included in the YUI Library
YUI is issued by Yahoo! under the BSD license above. Below is a list of certain publicly available software that is the source of intellectual property in YUI, along with the licensing terms that pertain to thosesources of IP. This list is for informational purposes only and is not intended to represent an exhaustive list of third party contributions to the YUI.
    * Douglas Crockford"s JSON parsing and stringifying methods: In the JSON Utility, Douglas Crockford"s JSON parsing and stringifying methods are adapted from work published at JSON.org. The adapted work is in the public domain.
    * Robert Penner"s animation-easing algorithms: In the Animation Utility, YUI makes use of Robert Penner"s algorithms for easing.
    * Geoff Stearns"s SWFObject: In the Charts Control and the Uploader versions through 2.7.0, YUI makes use of Geoff Stearns"s SWFObject v1.5 for Flash Player detection and embedding. More information on SWFObject can be found here (http://blog.deconcept.ru/swfobject/). SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License (http://www.opensource.org/licenses/mit-license.php).
    * Diego Perini"s IEContentLoaded technique: The Event Utility employs a technique developed by Diego Perini and licensed under GPL. YUI"s use of this technique is included under our BSD license with the author"s permission.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>The Module Control</title>
<style type="text/css">
/*margin and padding on body element
  can introduce errors in determining
  element position and are not recommended;
  we turn them off as a foundation for YUI
  CSS treatments. */
body {
  margin:0;
  padding:0;
}
</style>
<link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/fonts/fonts-min.css" />
<link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/container/assets/skins/sam/container.css" />
<script type="text/javascript" src="yui_2.7.0b-lib/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="yui_2.7.0b-lib/container/container-min.js"></script>
<!--there is no custom header content for this example-->
</head>
<body class=" yui-skin-sam">

<h1>The Module Control</h1>
<div class="exampleIntro">
  <p>This example looks at the "standard module format" used by many components in YUI to represent modular content on the page.  The Module Control is a JavaScript representation of a standard module, one that provides some basic plumbing for interacting with the head, body and foot sections of a standard module.  Convenience methods for showing, hinding and rendering the module are also included in the Module Control.</p>
<p>You"re most likely to use the Module Control when building a custom widget; its importance in the YUI Library is as a foundation rather than as a UI control in its own right.</p>      
</div>
<!--BEGIN SOURCE CODE FOR EXAMPLE  -->
<style type="text/css">
  .yui-module { border:1px dotted black;padding:5px;margin:10px; display:none; }
  .yui-module .hd { border:1px solid red;padding:5px; }
  .yui-module .bd { border:1px solid green;padding:5px; }
  .yui-module .ft { border:1px solid blue;padding:5px; }
</style>
<script type="text/javascript">
    YAHOO.namespace("example.container");
    YAHOO.util.Event.onDOMReady(function () {
        YAHOO.example.container.module1 = new YAHOO.widget.Module("module1", { visible: false });
        YAHOO.example.container.module1.render();
        YAHOO.example.container.module2 = new YAHOO.widget.Module("module2", { visible: false });
        YAHOO.example.container.module2.setHeader("Module #2 from Script");
        YAHOO.example.container.module2.setBody("This is a dynamically generated Module.");
        YAHOO.example.container.module2.setFooter("End of Module #2");
        YAHOO.example.container.module2.render();
        YAHOO.util.Event.addListener("show1", "click", YAHOO.example.container.module1.show, YAHOO.example.container.module1, true);
        YAHOO.util.Event.addListener("hide1", "click", YAHOO.example.container.module1.hide, YAHOO.example.container.module1, true);
        YAHOO.util.Event.addListener("show2", "click", YAHOO.example.container.module2.show, YAHOO.example.container.module2, true);
        YAHOO.util.Event.addListener("hide2", "click", YAHOO.example.container.module2.hide, YAHOO.example.container.module2, true);
    });
</script>
<div>
  <button id="show1">Show module1</button> 
  <button id="hide1">Hide module1</button>
</div>
<div id="module1">
  <div class="hd">Module #1 from Markup</div>
  <div class="bd">This is a Module that was marked up in the document.</div>
  <div class="ft">End of Module #1</div>
</div>
<div id="module2"></div>
<div>
  <button id="show2">Show module2</button> 
  <button id="hide2">Hide module2</button>
</div>
<!--END SOURCE CODE FOR EXAMPLE  -->
</body>
</html>
<!-- presentbright.corp.yahoo.ru uncompressed/chunked Thu Feb 19 10:53:10 PST 2009 -->


<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>


Retrieving a Yahoo! Weather RSS Feed

 
<!--
Software License Agreement (BSD License)
Copyright (c) 2009, Yahoo! Inc.
All rights reserved.
Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright notice, this list of conditions and the
      following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    * Neither the name of Yahoo! Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Yahoo! Inc.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Sources of Intellectual Property Included in the YUI Library
YUI is issued by Yahoo! under the BSD license above. Below is a list of certain publicly available software that is the source of intellectual property in YUI, along with the licensing terms that pertain to thosesources of IP. This list is for informational purposes only and is not intended to represent an exhaustive list of third party contributions to the YUI.
    * Douglas Crockford"s JSON parsing and stringifying methods: In the JSON Utility, Douglas Crockford"s JSON parsing and stringifying methods are adapted from work published at JSON.org. The adapted work is in the public domain.
    * Robert Penner"s animation-easing algorithms: In the Animation Utility, YUI makes use of Robert Penner"s algorithms for easing.
    * Geoff Stearns"s SWFObject: In the Charts Control and the Uploader versions through 2.7.0, YUI makes use of Geoff Stearns"s SWFObject v1.5 for Flash Player detection and embedding. More information on SWFObject can be found here (http://blog.deconcept.ru/swfobject/). SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License (http://www.opensource.org/licenses/mit-license.php).
    * Diego Perini"s IEContentLoaded technique: The Event Utility employs a technique developed by Diego Perini and licensed under GPL. YUI"s use of this technique is included under our BSD license with the author"s permission.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Retrieving a Yahoo! Weather RSS Feed</title>
<style type="text/css">
/*margin and padding on body element
  can introduce errors in determining
  element position and are not recommended;
  we turn them off as a foundation for YUI
  CSS treatments. */
body {
  margin:0;
  padding:0;
}
</style>
<link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/fonts/fonts-min.css" />
<script type="text/javascript" src="yui_2.7.0b-lib/yahoo/yahoo-min.js"></script>
<script type="text/javascript" src="yui_2.7.0b-lib/event/event-min.js"></script>
<script type="text/javascript" src="yui_2.7.0b-lib/connection/connection-min.js"></script>
<!--there is no custom header content for this example-->
</head>
<body class=" yui-skin-sam">

<h1>Retrieving a Yahoo! Weather RSS Feed</h1>
<div class="exampleIntro">
  <p>This example demonstrates how to use the <a href="http://developer.yahoo.ru/yui/connection/">Connection Manager</a> 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.ru/forecastrss</code>.</p>
<p>To try out the example, fill in your five-digit US zip code, or Location ID.</p>      
</div>
<!--BEGIN SOURCE CODE FOR EXAMPLE  -->
<form id="wForm">
<fieldset>
  <label>Zip Code or Location ID</label> <input type="text" name="zip" value="94089">
  <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>
</fieldset>
<div id="weatherModule"></div>
<input type="button" value="Get Weather RSS" onClick="getModule()">
</form>
<script>
var div = document.getElementById("weatherModule");
var oForm = document.getElementById("wForm");
function successHandler(o){
  YAHOO.log("Success handler called; handler will parse the retrieved XML and insert into DOM.", "info", "example");
  var root = o.responseXML.documentElement;
  var oTitle = root.getElementsByTagName("description")[0].firstChild.nodeValue;
  var oDateTime = root.getElementsByTagName("lastBuildDate")[0].firstChild.nodeValue;
  var descriptionNode = root.getElementsByTagName("description")[1].firstChild.nodeValue;
  div.innerHTML = "<p>" + oTitle + "</p>" + "<p>" + oDateTime + "</p>" + descriptionNode;
  YAHOO.log("Success handler is complete.", "info", "example");
}
function failureHandler(o){
  YAHOO.log("Failure handler called; http status: " + o.status, "info", "example");
  div.innerHTML = o.status + " " + o.statusText;
}
function getModule(){
  var iZip = oForm.elements["zip"].value;
  var entryPoint = "yui_2.7.0b-assets/connection-assets/weather.php";
  var queryString = encodeURI("?p=" + iZip);
  var sUrl = entryPoint + queryString;
  YAHOO.log("Submitting request; zip code: " + iZip, "info", "example");
  var request = YAHOO.util.Connect.asyncRequest("GET", sUrl, { success:successHandler, failure:failureHandler });
}
YAHOO.log("When you retrieve weather RSS data, relevant steps in the process will be reported here in the logger.", "info", "example");
</script>
<!--END SOURCE CODE FOR EXAMPLE  -->
</body>
</html>
<!-- presentbright.corp.yahoo.ru uncompressed/chunked Thu Feb 19 10:53:10 PST 2009 -->


<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>


Type-Checking Your Data

 
<!--
Software License Agreement (BSD License)
Copyright (c) 2009, Yahoo! Inc.
All rights reserved.
Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright notice, this list of conditions and the
      following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    * Neither the name of Yahoo! Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Yahoo! Inc.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Sources of Intellectual Property Included in the YUI Library
YUI is issued by Yahoo! under the BSD license above. Below is a list of certain publicly available software that is the source of intellectual property in YUI, along with the licensing terms that pertain to thosesources of IP. This list is for informational purposes only and is not intended to represent an exhaustive list of third party contributions to the YUI.
    * Douglas Crockford"s JSON parsing and stringifying methods: In the JSON Utility, Douglas Crockford"s JSON parsing and stringifying methods are adapted from work published at JSON.org. The adapted work is in the public domain.
    * Robert Penner"s animation-easing algorithms: In the Animation Utility, YUI makes use of Robert Penner"s algorithms for easing.
    * Geoff Stearns"s SWFObject: In the Charts Control and the Uploader versions through 2.7.0, YUI makes use of Geoff Stearns"s SWFObject v1.5 for Flash Player detection and embedding. More information on SWFObject can be found here (http://blog.deconcept.ru/swfobject/). SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License (http://www.opensource.org/licenses/mit-license.php).
    * Diego Perini"s IEContentLoaded technique: The Event Utility employs a technique developed by Diego Perini and licensed under GPL. YUI"s use of this technique is included under our BSD license with the author"s permission.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Type-Checking Your Data</title>
<style type="text/css">
/*margin and padding on body element
  can introduce errors in determining
  element position and are not recommended;
  we turn them off as a foundation for YUI
  CSS treatments. */
body {
  margin:0;
  padding:0;
}
</style>
<link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/fonts/fonts-min.css" />
<script type="text/javascript" src="yui_2.7.0b-lib/yahoo-dom-event/yahoo-dom-event.js"></script>

<!--begin custom header content for this example-->
<style type="text/css">
    #demo {
        border-collapse: collapse;
    }
    #demo th {
        background: #E76300;
        color: #fff;
        padding: .2em 1em;
        border: 1px solid #ccc;
    }
    #demo td {
        padding: .2em 1ex;
        border: 1px solid #ccc;
        text-align: center;
    }
    #demo code {
        background: #eee;
        display: block;
        text-align: left;
    }
</style>
<!--end custom header content for this example-->
</head>
<body class=" yui-skin-sam">

<h1>Type-Checking Your Data</h1>
<div class="exampleIntro">
  <p>The <a href="http://developer.yahoo.ru/yui/yahoo/">Yahoo Global Object</a> includes several useful type-checking methods in the <code>YAHOO.lang</code> object.  Click the Check button in each row to evaluate the data.</p>
      
</div>
<!--BEGIN SOURCE CODE FOR EXAMPLE  -->
<table id="demo">
    <thead>
        <tr>
            <th>Data</th>
            <th>isObject</th>
            <th>isArray</th>
            <th>isFunction</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>null<code></td>
            <td colspan="3"><input type="button" name="demo-1" id="demo-1" value="check"/></td>
        </tr>
        <tr>
            <td><code>[] or new Array()</code></td>
            <td colspan="3"><input type="button" name="demo-2" id="demo-2" value="check"/></td>
        </tr>
        <tr>
            <td><code>{} or new Object()</code></td>
            <td colspan="3"><input type="button" name="demo-3" id="demo-3" value="check"/></td>
        </tr>
        <tr>
            <td><code>function Foo() {}</code></td>
            <td colspan="3"><input type="button" name="demo-4" id="demo-4" value="check"/></td>
        </tr>
        <tr>
            <td><code>new Foo()</code></td>
            <td colspan="3"><input type="button" name="demo-5" id="demo-5" value="check"/></td>
        </tr>
        <tr>
            <td><code>elem.getElementsByTagName("p")</code></td>
            <td colspan="3"><input type="button" name="demo-6" id="demo-6" value="check"/></td>
        </tr>
        <tr>
            <td><code>YAHOO.util.Dom.
                        getElementsByClassName(<br/>
                        "foo","p",elem)</code></td>
            <td colspan="3"><input type="button" name="demo-7" id="demo-7" value="check"/></td>
        </tr>
    <tbody>
</table>
<script type="text/javascript">
    YAHOO.namespace("example");
    YAHOO.example.checkType = function (val) {
        return {
            "object"  : YAHOO.lang.isObject(val),
            "array"   : YAHOO.lang.isArray(val),
            "function": YAHOO.lang.isFunction(val)
        };
    }
    YAHOO.example.populateRow = function (e, data) {
        var cell = this.parentNode,
            row  = cell.parentNode;
        row.removeChild(cell);
        var td0 = document.createElement("td"),
            td1 = td0.cloneNode(false),
            td2 = td0.cloneNode(false);
        var results = YAHOO.example.checkType(data);
        td0.appendChild(document.createTextNode(
            results["object"] ?   "Y" : "N"));
        td1.appendChild(document.createTextNode(
            results["array"] ?    "Y" : "N"));
        td2.appendChild(document.createTextNode(
            results["function"] ? "Y" : "N"));
        row.appendChild(td0);
        row.appendChild(td1);
        row.appendChild(td2);
    }
    var foo = function () {};
    var f = document.getElementById("demo");
    YAHOO.util.Event.on("demo-1","click",YAHOO.example.populateRow, null);
    YAHOO.util.Event.on("demo-2","click",YAHOO.example.populateRow, []);
    YAHOO.util.Event.on("demo-3","click",YAHOO.example.populateRow, {});
    YAHOO.util.Event.on("demo-4","click",YAHOO.example.populateRow, foo);
    YAHOO.util.Event.on("demo-5","click",YAHOO.example.populateRow, new foo());
    YAHOO.util.Event.on("demo-6","click",YAHOO.example.populateRow,
        f.getElementsByTagName("tr"));
    YAHOO.util.Event.on("demo-7","click",YAHOO.example.populateRow,
        YAHOO.util.Dom.getElementsByClassName("foo","td",f));
</script>
<!--END SOURCE CODE FOR EXAMPLE  -->
</body>
</html>
<!-- presentbright.corp.yahoo.ru uncompressed/chunked Thu Feb 19 10:53:20 PST 2009 -->


<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>


Use YAHOO.env.ua to identify the user"s browser and to branch JavaScript logic based on what browser is being used.

 

<!--
Software License Agreement (BSD License)
Copyright (c) 2009, Yahoo! Inc.
All rights reserved.
Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright notice, this list of conditions and the
      following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    * Neither the name of Yahoo! Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Yahoo! Inc.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Sources of Intellectual Property Included in the YUI Library
YUI is issued by Yahoo! under the BSD license above. Below is a list of certain publicly available software that is the source of intellectual property in YUI, along with the licensing terms that pertain to thosesources of IP. This list is for informational purposes only and is not intended to represent an exhaustive list of third party contributions to the YUI.
    * Douglas Crockford"s JSON parsing and stringifying methods: In the JSON Utility, Douglas Crockford"s JSON parsing and stringifying methods are adapted from work published at JSON.org. The adapted work is in the public domain.
    * Robert Penner"s animation-easing algorithms: In the Animation Utility, YUI makes use of Robert Penner"s algorithms for easing.
    * Geoff Stearns"s SWFObject: In the Charts Control and the Uploader versions through 2.7.0, YUI makes use of Geoff Stearns"s SWFObject v1.5 for Flash Player detection and embedding. More information on SWFObject can be found here (http://blog.deconcept.ru/swfobject/). SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License (http://www.opensource.org/licenses/mit-license.php).
    * Diego Perini"s IEContentLoaded technique: The Event Utility employs a technique developed by Diego Perini and licensed under GPL. YUI"s use of this technique is included under our BSD license with the author"s permission.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>User Agent Detection</title>
<style type="text/css">
/*margin and padding on body element
  can introduce errors in determining
  element position and are not recommended;
  we turn them off as a foundation for YUI
  CSS treatments. */
body {
  margin:0;
  padding:0;
}
</style>
<link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/fonts/fonts-min.css" />
<script type="text/javascript" src="yui_2.7.0b-lib/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="yui_2.7.0b-lib/dragdrop/dragdrop-min.js"></script>

<!--begin custom header content for this example-->
<style type="text/css">
    #dd1,#dd2 {
        position: relative;
        margin: 1em 1em 0;
        width: 175px;
        float: left;
        cursor: move;
    }
    #demo p {
        position: relative;
        padding: 1em;
        height: 100%;
        margin: 0;
        font-weight: bold;
        text-align: center;
        z-index: 20;
    }
    #dd1 p {
        border: 10px solid #ccc;
        background-color: #eee;
    }
    #dd2 p {
        border: 10px solid #e76300;
        background-color: #fff5df;
    }
    #demo .shim {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        margin: 0;
        padding: 0;
        border: 0;
        z-index: 10;
    }
</style>
<!--end custom header content for this example-->
</head>
<body class=" yui-skin-sam">

<h1>User Agent Detection</h1>
<div class="exampleIntro">
  <p>This example demonstrates the use of <code>YAHOO.env.ua</code> to identify the user"s browser and to branch JavaScript logic based on what browser is being used.  (<strong>Note:</strong> We strongly recommend using feature detection rather than user-agent sniffing to fork code; only use this technique where it is absolutely necessary to do so &mdash; for example, in cases where browsers do not report their own capabilities accurately.)</p>
      
</div>
<!--BEGIN SOURCE CODE FOR EXAMPLE  -->
<div id="demo">
    <select name="foo">
        <option value="NONE" selected="selected">This is a very long select element for the example</option>
        <option value="1">Apple</option>
        <option value="2">Rutabaga</option>
        <option value="3">Motor oil</option>
    </select>
    <hr>
    <div id="dd1">
        <p>
            NO IFRAME<br>
            Drag over the select
        </p>
    </div>
    <div id="dd2">
        <p>
            IFRAME<br>
            Drag over the select
        </p>
    </div>
</div>
<script type="text/javascript">
YAHOO.util.Event.onDOMReady(function () {
    var dd1 = new YAHOO.util.DD("dd1");
    var dd2 = new YAHOO.util.DD("dd2");
    dd1.startDrag = function (x,y) {
        YAHOO.log("Drag started for element with no protection from the display bug", "info", "example");
    }
    if (YAHOO.env.ua.ie > 5 && YAHOO.env.ua.ie < 7) {
        // Create an iframe shim
        var shim = document.createElement("iframe");
        shim.src = "about:blank";
        shim.className = "shim";
        // Add the shim to the dragging element on the first startDrag
        dd2.startDrag = function (x,y) {
            var d = this.getEl();
            if (d.firstChild !== shim) {
                YAHOO.util.Dom.setStyle(shim, "height",d.offsetHeight);
                d.insertBefore(shim, d.firstChild);
                YAHOO.log("Your browser is IE " + YAHOO.env.ua.ie + ".  Shim added.", "info","example");
            } else {
                YAHOO.log("Your browser is IE " + YAHOO.env.ua.ie + ", but the shim was already added", "info","example");
            }
        }
    } else { // Not shim worthy
        dd2.startDrag = function (x,y) {
            YAHOO.log("Your browser is NOT IE.  No shim added.", "info", "example");
        }
    }
});
</script>
<!--END SOURCE CODE FOR EXAMPLE  -->
</body>
</html>
<!-- presentbright.corp.yahoo.ru uncompressed/chunked Thu Feb 19 10:53:20 PST 2009 -->


<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>