<!--
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.com/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>Calendar Menu Button with Date on Button Face</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/calendar/assets/skins/sam/calendar.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/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="yui_2.7.0b-lib/calendar/calendar-min.js"></script>
<script type="text/javascript" src="yui_2.7.0b-lib/container/container_core-min.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">
/*
Set the "zoom" property to "normal" since it is set to "1" by the
".example-container .bd" rule in yui.css and this causes a Menu
instance's width to expand to 100% of the browser viewport.
*/
div.yuimenu .bd {
zoom: normal;
}
#calendarmenu {
position: absolute;
}
/*
Restore default padding of 10px for the calendar containtainer
that is overridden by the ".example-container .bd .bd" rule
in yui.css.
*/
#calendarcontainer {
padding:10px;
}
#personalinfo {
border: solid 1px #666;
padding: .5em;
}
#calendarpicker {
vertical-align: baseline;
}
div.field {
padding: .25em;
}
input#year {
width: 4em;
}
</style>
<!--end custom header content for this example-->
</head>
<body class=" yui-skin-sam">
<h1>Calendar Menu Button with Date on Button Face</h1>
<div class="exampleIntro">
<p>
This example demonstrates how to create a Menu Button whose Menu displays a
Calendar. Selecting a date from the Calendar updates the label of the Button
to reflect the currently selected date.
</p>
</div>
<!--BEGIN SOURCE CODE FOR EXAMPLE -->
<script type="text/javascript">
(function () {
var Event = YAHOO.util.Event,
Dom = YAHOO.util.Dom;
Event.onContentReady("datefields", function () {
var oCalendarMenu;
var onButtonClick = function () {
// Create a Calendar instance and render it into the body
// element of the Overlay.
var oCalendar = new YAHOO.widget.Calendar("buttoncalendar", oCalendarMenu.body.id);
oCalendar.render();
// Subscribe to the Calendar instance's "select" event to
// update the Button instance's label when the user
// selects a date.
oCalendar.selectEvent.subscribe(function (p_sType, p_aArgs) {
var aDate,
nMonth,
nDay,
nYear;
if (p_aArgs) {
aDate = p_aArgs[0][0];
nMonth = aDate[1];
nDay = aDate[2];
nYear = aDate[0];
oButton.set("label", (nMonth + "/" + nDay + "/" + nYear));
// Sync the Calendar instance's selected date with the date form fields
Dom.get("month").selectedIndex = (nMonth - 1);
Dom.get("day").selectedIndex = (nDay - 1);
Dom.get("year").value = nYear;
}
oCalendarMenu.hide();
});
// Pressing the Esc key will hide the Calendar Menu and send focus back to
// its parent Button
Event.on(oCalendarMenu.element, "keydown", function (p_oEvent) {
if (Event.getCharCode(p_oEvent) === 27) {
oCalendarMenu.hide();
this.focus();
}
}, null, this);
var focusDay = function () {
var oCalendarTBody = Dom.get("buttoncalendar").tBodies[0],
aElements = oCalendarTBody.getElementsByTagName("a"),
oAnchor;
if (aElements.length > 0) {
Dom.batch(aElements, function (element) {
if (Dom.hasClass(element.parentNode, "today")) {
oAnchor = element;
}
});
if (!oAnchor) {
oAnchor = aElements[0];
}
// Focus the anchor element using a timer since Calendar will try
// to set focus to its next button by default
YAHOO.lang.later(0, oAnchor, function () {
try {
oAnchor.focus();
}
catch(e) {}
});
}
};
// Set focus to either the current day, or first day of the month in
// the Calendar when it is made visible or the month changes
oCalendarMenu.subscribe("show", focusDay);
oCalendar.renderEvent.subscribe(focusDay, oCalendar, true);
// Give the Calendar an initial focus
focusDay.call(oCalendar);
// Re-align the CalendarMenu to the Button to ensure that it is in the correct
// position when it is initial made visible
oCalendarMenu.align();
// Unsubscribe from the "click" event so that this code is
// only executed once
this.unsubscribe("click", onButtonClick);
};
var oDateFields = Dom.get("datefields");
oMonthField = Dom.get("month"),
oDayField = Dom.get("day"),
oYearField = Dom.get("year");
// Hide the form fields used for the date so that they can be replaced by the
// calendar button.
oMonthField.style.display = "none";
oDayField.style.display = "none";
oYearField.style.display = "none";
// Create a Overlay instance to house the Calendar instance
oCalendarMenu = new YAHOO.widget.Overlay("calendarmenu", { visible: false });
// Create a Button instance of type "menu"
var oButton = new YAHOO.widget.Button({
type: "menu",
id: "calendarpicker",
label: "Choose A Date",
menu: oCalendarMenu,
container: "datefields" });
oButton.on("appendTo", function () {
// Create an empty body element for the Overlay instance in order
// to reserve space to render the Calendar instance into.
oCalendarMenu.setBody(" ");
oCalendarMenu.body.id = "calendarcontainer";
});
// Add a listener for the "click" event. This listener will be
// used to defer the creation the Calendar instance until the
// first time the Button's Overlay instance is requested to be displayed
// by the user.
oButton.on("click", onButtonClick);
});
}());
</script>
<form id="button-example-form" name="button-example-form" method="post">
<fieldset id="personalinfo">
<legend>Personal Information</legend>
<div class="field">
<label for="firstname">First Name: </label>
<input type="text" id="firstname" name="firstname" value="">
</div>
<div class="field">
<label for="lastname">Last Name: </label>
<input type="text" id="lastname" name="lastname" value="">
</div>
<div class="field" id="datefields">
<label for="month">Birthday: </label>
<select id="month" name="month">
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
<select id="day" name="day">
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<input type="text" id="year" name="year" value="">
</div>
<div class="field">
<input type="submit" id="submit-button" name="submit-button" value="Submit Form">
</div>
</fieldset>
</form>
<!--END SOURCE CODE FOR EXAMPLE -->
</body>
</html>
<!-- presentbright.corp.yahoo.com uncompressed/chunked Thu Feb 19 10:53:06 PST 2009 -->
|