JavaScript DHTML/YUI Library/Calendar

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

Calendar and Select Fields

   <source lang="html4strict">

<!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 and Select Fields</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" /> <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>


<style type="text/css">

 #cal1Container { margin-right:10px; margin-bottom:10px }

</style>

</head> <body class=" yui-skin-sam">

Calendar and Select Fields

This example builds upon the <a href="events.html">Events</a> example, by demonstrating how you can use the select event to set the state of some dropdowns. It also demonstates how the current page and selected date can be set on the Calendar after it is first rendered.

<form name="dates">

   <select id="selMonth" name="selMonth">
       <option value="" selected> </option>
       <option value="Jan">1</option>
       <option value="Feb">2</option>
       <option value="Mar">3</option>
       <option value="Apr">4</option>
       <option value="May">5</option>
       <option value="Jun">6</option>
       <option value="Jul">7</option>
       <option value="Aug">8</option>
       <option value="Sep">9</option>
       <option value="Oct">10</option>
       <option value="Nov">11</option>
       <option value="Dec">12</option>
   </select>
   <select name="selDay" id="selDay">
       <option value="" selected> </option>
       <option value="1">1</option>
       <option value="2">2</option>
       <option value="3">3</option>
       <option value="4">4</option>
       <option value="5">5</option>
       <option value="6">6</option>
       <option value="7">7</option>
       <option value="8">8</option>
       <option value="9">9</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>
   <select name="selYear" id="selYear">
       <option value="" selected> </option>
       <option value="2006">2006</option>
       <option value="2007">2007</option>
       <option value="2008">2008</option>
       <option value="2009">2009</option>
       <option value="2010">2010</option>
   </select>

</form> <script type="text/javascript">

   YAHOO.namespace("example.calendar");
   YAHOO.example.calendar.init = function() {
   
       function handleSelect(type,args,obj) {
           var dates = args[0]; 
           var date = dates[0];
           var year = date[0], month = date[1], day = date[2];
           var selMonth = document.getElementById("selMonth");
           var selDay = document.getElementById("selDay");
           var selYear = document.getElementById("selYear");
           
           selMonth.selectedIndex = month;
           selDay.selectedIndex = day;
           for (var y=0;y<selYear.options.length;y++) {
               if (selYear.options[y].text == year) {
                   selYear.selectedIndex = y;
                   break;
               }
           }
       }
       function updateCal() {
           var selMonth = document.getElementById("selMonth");
           var selDay = document.getElementById("selDay");
           var selYear = document.getElementById("selYear");
           
           var month = parseInt(selMonth.options[selMonth.selectedIndex].text);
           var day = parseInt(selDay.options[selDay.selectedIndex].value);
           var year = parseInt(selYear.options[selYear.selectedIndex].value);
           
           if (! isNaN(month) && ! isNaN(day) && ! isNaN(year)) {
               var date = month + "/" + day + "/" + year;
               YAHOO.example.calendar.cal1.select(date);
               YAHOO.example.calendar.cal1.cfg.setProperty("pagedate", month + "/" + year);
               YAHOO.example.calendar.cal1.render();
           }
       }
       YAHOO.example.calendar.cal1 = new YAHOO.widget.Calendar("cal1","cal1Container", 
                                                                   { mindate:"1/1/2006",
                                                                     maxdate:"12/31/2010" });
       YAHOO.example.calendar.cal1.selectEvent.subscribe(handleSelect, YAHOO.example.calendar.cal1, true);
       YAHOO.example.calendar.cal1.render();
       YAHOO.util.Event.addListener(["selMonth","selDay","selYear"], "change", updateCal);
   }
   YAHOO.util.Event.onDOMReady(YAHOO.example.calendar.init);

</script>

</body> </html>


 </source>
   
  

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


Calendar and Text Fields

   <source lang="html4strict">

<!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 and Text Fields</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" /> <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>


<style type="text/css">

 #date1 { width:100px }
 #cal1Container { margin-right:10px;margin-bottom:10px }

</style>

</head> <body class=" yui-skin-sam">

Calendar and Text Fields

This example builds upon the <a href="events.html">Events</a> example, by demonstrating how you can use the select event to set the state of a text box on the page.

It also demonstates how to limit the dates which can be selected using the mindate/maxdate properties and how the current page and selected date can be set on the Calendar after it is first rendered.

<form name="dates" id="dates">

   <input type="text" name="date1" id="date1" />
   <button type="button" id="update">Update Calendar</button>

</form> <script type="text/javascript">

   YAHOO.namespace("example.calendar");
   YAHOO.example.calendar.init = function() {
       function handleSelect(type,args,obj) {
           var dates = args[0]; 
           var date = dates[0];
           var year = date[0], month = date[1], day = date[2];
           
           var txtDate1 = document.getElementById("date1");
           txtDate1.value = month + "/" + day + "/" + year;
       }
       function updateCal() {
           var txtDate1 = document.getElementById("date1");
           if (txtDate1.value != "") {
               YAHOO.example.calendar.cal1.select(txtDate1.value);
               var selectedDates = YAHOO.example.calendar.cal1.getSelectedDates();
               if (selectedDates.length > 0) {
                   var firstDate = selectedDates[0];
                   YAHOO.example.calendar.cal1.cfg.setProperty("pagedate", (firstDate.getMonth()+1) + "/" + firstDate.getFullYear());
                   YAHOO.example.calendar.cal1.render();
               } else {
                   alert("Cannot select a date before 1/1/2006 or after 12/31/2010");
               }
               
           }
       }
       // For this example page, stop the Form from being submitted, and update the cal instead
       function handleSubmit(e) {
           updateCal();
           YAHOO.util.Event.preventDefault(e);
       }
       
       YAHOO.example.calendar.cal1 = new YAHOO.widget.Calendar("cal1","cal1Container", 
                                                                   { mindate:"1/1/2006",
                                                                     maxdate:"12/31/2010" });
       YAHOO.example.calendar.cal1.selectEvent.subscribe(handleSelect, YAHOO.example.calendar.cal1, true);
       YAHOO.example.calendar.cal1.render();
       YAHOO.util.Event.addListener("update", "click", updateCal);
       YAHOO.util.Event.addListener("dates", "submit", handleSubmit);
   }
   YAHOO.util.Event.onDOMReady(YAHOO.example.calendar.init);

</script>

</body> </html>


 </source>
   
  

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


Calendar control wrapped in a Container (a Dialog control in this case) allows you to leverage Container features to position the Calendar

   <source lang="html4strict">


<!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>Popup Calendar - Advanced</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" /> <link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/container/assets/skins/sam/container.css" /> <link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/calendar/assets/skins/sam/calendar.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> <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> <script type="text/javascript" src="yui_2.7.0b-lib/container/container-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/calendar/calendar-min.js"></script>


<style type="text/css">

   /* Clear calendar"s float, using dialog inbuilt form element */
   #container .bd form {
       clear:left;
   }
   /* Have calendar squeeze upto bd bounding box */
   #container .bd {
       padding:0;
   }
   #container .hd {
       text-align:left;
   }
   /* Center buttons in the footer */
   #container .ft .button-group {
       text-align:center;
   }
   /* Prevent border-collapse:collapse from bleeding through in IE6, IE7 */
   #container_c.yui-overlay-hidden table {
       *display:none;
   }
   /* Remove calendar"s border and set padding in ems instead of px, so we can specify an width in ems for the container */
   #cal {
       border:none;
       padding:1em;
   }
   /* Datefield look/feel */
   .datefield {
       position:relative;
       top:10px;
       left:10px;
       white-space:nowrap;
       border:1px solid black;
       background-color:#eee;
       width:25em;
       padding:5px;
   }
   .datefield input,
   .datefield button,
   .datefield label  {
       vertical-align:middle;
   }
   .datefield label  {
       font-weight:bold;
   }
   .datefield input  {
       width:15em;
   }
   .datefield button  {
       padding:0 5px 0 5px;
       margin-left:2px;
   }
   .datefield button img {
       padding:0;
       margin:0;
       vertical-align:middle;
   }
   /* Example box */
   .box {
       position:relative;
       height:30em;
   }

</style>

</head> <body class=" yui-skin-sam">

Popup Calendar - Advanced

The default Calendar/CalendarGroup controls do not provide positioning or dragdrop support natively, as the Container family"s Overlay control and its subclasses do.

This example demonstrates how the Calendar control can be wrapped in a Container (a Dialog control in this case) which allows you to leverage Container family features to position the Calendar relative to a context element. It also show how you can setup click listeners on the document, to hide the dialog when the user clicks somewhere outside of the dialog.

<script type="text/javascript">

   YAHOO.util.Event.onDOMReady(function(){
       var Event = YAHOO.util.Event,
           Dom = YAHOO.util.Dom,
           dialog,
           calendar;
       var showBtn = Dom.get("show");
       Event.on(showBtn, "click", function() {
           // Lazy Dialog Creation - Wait to create the Dialog, and setup document click listeners, until the first time the button is clicked.
           if (!dialog) {
               // Hide Calendar if we click anywhere in the document other than the calendar
               Event.on(document, "click", function(e) {
                   var el = Event.getTarget(e);
                   var dialogEl = dialog.element;
                   if (el != dialogEl && !Dom.isAncestor(dialogEl, el) && el != showBtn && !Dom.isAncestor(showBtn, el)) {
                       dialog.hide();
                   }
               });
               function resetHandler() {
                   // Reset the current calendar page to the select date, or 
                   // to today if nothing is selected.
                   var selDates = calendar.getSelectedDates();
                   var resetDate;
       
                   if (selDates.length > 0) {
                       resetDate = selDates[0];
                   } else {
                       resetDate = calendar.today;
                   }
       
                   calendar.cfg.setProperty("pagedate", resetDate);
                   calendar.render();
               }
       
               function closeHandler() {
                   dialog.hide();
               }
               dialog = new YAHOO.widget.Dialog("container", {
                   visible:false,
                   context:["show", "tl", "bl"],
                   buttons:[ {text:"Reset", handler: resetHandler, isDefault:true}, {text:"Close", handler: closeHandler}],
                   draggable:false,
                   close:true
               });
               dialog.setHeader("Pick A Date");
dialog.setBody("
");
               dialog.render(document.body);
               dialog.showEvent.subscribe(function() {
                   if (YAHOO.env.ua.ie) {
                       // Since we"re hiding the table using yui-overlay-hidden, we 
                       // want to let the dialog know that the content size has changed, when
                       // shown
                       dialog.fireEvent("changeContent");
                   }
               });
           }
           // Lazy Calendar Creation - Wait to create the Calendar until the first time the button is clicked.
           if (!calendar) {
               calendar = new YAHOO.widget.Calendar("cal", {
                   iframe:false,          // Turn iframe off, since container has iframe support.
                   hide_blank_weeks:true  // Enable, to demonstrate how we handle changing height, using changeContent
               });
               calendar.render();
               calendar.selectEvent.subscribe(function() {
                   if (calendar.getSelectedDates().length > 0) {
                       var selDate = calendar.getSelectedDates()[0];
                       // Pretty Date Output, using Calendar"s Locale values: Friday, 8 February 2008
                       var wStr = calendar.cfg.getProperty("WEEKDAYS_LONG")[selDate.getDay()];
                       var dStr = selDate.getDate();
                       var mStr = calendar.cfg.getProperty("MONTHS_LONG")[selDate.getMonth()];
                       var yStr = selDate.getFullYear();
       
                       Dom.get("date").value = wStr + ", " + dStr + " " + mStr + " " + yStr;
                   } else {
                       Dom.get("date").value = "";
                   }
                   dialog.hide();
               });
               calendar.renderEvent.subscribe(function() {
                   // Tell Dialog it"s contents have changed, which allows 
                   // container to redraw the underlay (for IE6/Safari2)
                   dialog.fireEvent("changeContent");
               });
           }
           var seldate = calendar.getSelectedDates();
           if (seldate.length > 0) {
               // Set the pagedate to show the selected date if it exists
               calendar.cfg.setProperty("pagedate", seldate[0]);
               calendar.render();
           }
           dialog.show();
       });
   });

</script>

     <label for="date">Date: </label><input type="text" id="date" name="date" value="" /><button type="button" id="show" title="Show Calendar"><img src="yui_2.7.0b-assets/calendar-assets/calbtn.gif" width="18" height="18" alt="Calendar" ></button>

</body> </html>


 </source>
   
  

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


Calendar employs a feature called the Render Stack to allow you to customize the way that certain date cells are rendered on the Calendar

   <source lang="html4strict">


<!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>Using the Render Stack</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" /> <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>


<style type="text/css">

 .yui-skin-sam .yui-calendar td.sunday { background-color:#999; }

</style>

</head> <body class=" yui-skin-sam">

Using the Render Stack

Calendar employs a feature called the Render Stack to allow you to customize the way that certain date cells are rendered on the Calendar. The Render Stack consists of a collection of functions that can be executed when rendering certain dates. When the Calendar is rendered, each function in the Render Stack is executed for each applicable date. This functionality allows developers implementing the Calendar to alter the contents of date cells based on a set of rules.

This example shows you how to use any one of the built-in renderers provided with the Calendar, or write your own.

<script type="text/javascript">

 YAHOO.namespace("example.calendar");
 YAHOO.example.calendar.init = function() {
   YAHOO.example.calendar.cal1 = new YAHOO.widget.CalendarGroup("cal1","cal1Container", 
                                  { pagedate:"2/2008" } );
   YAHOO.example.calendar.cal1.addRenderer("2/29", YAHOO.example.calendar.cal1.renderBodyCellRestricted);
   YAHOO.example.calendar.cal1.addRenderer("2/1/2008-2/7/2008", YAHOO.example.calendar.cal1.renderCellStyleHighlight1);
   var myCustomRenderer = function(workingDate, cell) {
     cell.innerHTML = "X";
     YAHOO.util.Dom.addClass(cell, "sunday");
     return YAHOO.widget.Calendar.STOP_RENDER;
   }
   YAHOO.example.calendar.cal1.addWeekdayRenderer(1, myCustomRenderer);
   YAHOO.example.calendar.cal1.render();
 }
 YAHOO.util.Event.onDOMReady(YAHOO.example.calendar.init);

</script>

</body> </html>


 </source>
   
  

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


Calendar Localization - Germany

   <source lang="html4strict">


<!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>Localization - Germany</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" /> <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>

</head> <body class=" yui-skin-sam">

Localization - Germany

Calendar provides configuration properties that can be used to change the Calendar"s various data labels, when the Calendar is used in different locales. This example shows how to provide locale specific labels for month and weekday names, as well as how to configure the expected format of any date strings passed in to the Calendar. It uses Germany as an example locale

<script type="text/javascript">

   YAHOO.namespace("example.calendar");
   YAHOO.example.calendar.init = function() {
       YAHOO.example.calendar.cal1 = new YAHOO.widget.Calendar("cal1","cal1Container", 
                                                                   { LOCALE_WEEKDAYS:"short", 
                                                                     START_WEEKDAY: 1,
                                                                     MULTI_SELECT: true
                                                                    } );
       // Correct formats for Germany: dd.mm.yyyy, dd.mm, mm.yyyy
       YAHOO.example.calendar.cal1.cfg.setProperty("DATE_FIELD_DELIMITER", ".");
       YAHOO.example.calendar.cal1.cfg.setProperty("MDY_DAY_POSITION", 1);
       YAHOO.example.calendar.cal1.cfg.setProperty("MDY_MONTH_POSITION", 2);
       YAHOO.example.calendar.cal1.cfg.setProperty("MDY_YEAR_POSITION", 3);
       YAHOO.example.calendar.cal1.cfg.setProperty("MD_DAY_POSITION", 1);
       YAHOO.example.calendar.cal1.cfg.setProperty("MD_MONTH_POSITION", 2);
       
       // Date labels for German locale
       YAHOO.example.calendar.cal1.cfg.setProperty("MONTHS_SHORT",   ["Jan", "Feb", "M\u00E4r", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"]);
       YAHOO.example.calendar.cal1.cfg.setProperty("MONTHS_LONG",    ["Januar", "Februar", "M\u00E4rz", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"]);
       YAHOO.example.calendar.cal1.cfg.setProperty("WEEKDAYS_1CHAR", ["S", "M", "D", "M", "D", "F", "S"]);
       YAHOO.example.calendar.cal1.cfg.setProperty("WEEKDAYS_SHORT", ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"]);
       YAHOO.example.calendar.cal1.cfg.setProperty("WEEKDAYS_MEDIUM",["Son", "Mon", "Die", "Mit", "Don", "Fre", "Sam"]);
       YAHOO.example.calendar.cal1.cfg.setProperty("WEEKDAYS_LONG",  ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"]);
       YAHOO.example.calendar.cal1.select("1.10.2009-8.10.2009");
       YAHOO.example.calendar.cal1.cfg.setProperty("PAGEDATE", "10.2009");
       YAHOO.example.calendar.cal1.render();
   }
   YAHOO.util.Event.onDOMReady(YAHOO.example.calendar.init);

</script>

</body> </html>


 </source>
   
  

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


Calendar Localization - Japan

   <source lang="html4strict">


<!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>Localization - Japan</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" /> <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>


<style type="text/css">

 .yui-skin-sam .yui-calendar td.wd0 { background-color:#fde0e0; }
 .yui-skin-sam .yui-calendar td.wd0 a { color:red; }

</style>

</head> <body class=" yui-skin-sam">

Localization - Japan

Calendar provides configuration properties that can be used to change the Calendar"s various data labels, when the Calendar is used in different locales. This example shows how to provide locale specific labels for month and weekday names, how to configure the format of any date strings passed in to the Calendar and how to configure the format of the month, year label used in the header. It uses Japan as an example locale

<script type="text/javascript">

   YAHOO.namespace("example.calendar");
   YAHOO.example.calendar.init = function() {
       YAHOO.example.calendar.cal1 = new YAHOO.widget.CalendarGroup("cal1","cal1Container", { START_WEEKDAY: 1, MULTI_SELECT:true } );
       // Correct formats for Japan: yyyy/mm/dd, mm/dd, yyyy/mm
       YAHOO.example.calendar.cal1.cfg.setProperty("MDY_YEAR_POSITION", 1);
       YAHOO.example.calendar.cal1.cfg.setProperty("MDY_MONTH_POSITION", 2);
       YAHOO.example.calendar.cal1.cfg.setProperty("MDY_DAY_POSITION", 3);
       YAHOO.example.calendar.cal1.cfg.setProperty("MY_YEAR_POSITION", 1);
       YAHOO.example.calendar.cal1.cfg.setProperty("MY_MONTH_POSITION", 2);
       // Date labels for Japanese locale
       YAHOO.example.calendar.cal1.cfg.setProperty("MONTHS_SHORT",   ["1\u6708", "2\u6708", "3\u6708", "4\u6708", "5\u6708", "6\u6708", "7\u6708", "8\u6708", "9\u6708", "10\u6708", "11\u6708", "12\u6708"]);
       YAHOO.example.calendar.cal1.cfg.setProperty("MONTHS_LONG",    ["1\u6708", "2\u6708", "3\u6708", "4\u6708", "5\u6708", "6\u6708", "7\u6708", "8\u6708", "9\u6708", "10\u6708", "11\u6708", "12\u6708"]);
       YAHOO.example.calendar.cal1.cfg.setProperty("WEEKDAYS_1CHAR", ["\u65E5", "\u6708", "\u706B", "\u6C34", "\u6728", "\u91D1", "\u571F"]);
       YAHOO.example.calendar.cal1.cfg.setProperty("WEEKDAYS_SHORT", ["\u65E5", "\u6708", "\u706B", "\u6C34", "\u6728", "\u91D1", "\u571F"]);
       YAHOO.example.calendar.cal1.cfg.setProperty("WEEKDAYS_MEDIUM",["\u65E5", "\u6708", "\u706B", "\u6C34", "\u6728", "\u91D1", "\u571F"]);
       YAHOO.example.calendar.cal1.cfg.setProperty("WEEKDAYS_LONG",  ["\u65E5", "\u6708", "\u706B", "\u6C34", "\u6728", "\u91D1", "\u571F"]);
       // Month/Year label format for Japan
               YAHOO.example.calendar.cal1.cfg.setProperty("MY_LABEL_YEAR_POSITION",  1);
               YAHOO.example.calendar.cal1.cfg.setProperty("MY_LABEL_MONTH_POSITION",  2);
               YAHOO.example.calendar.cal1.cfg.setProperty("MY_LABEL_YEAR_SUFFIX",  "\u5E74");
               YAHOO.example.calendar.cal1.cfg.setProperty("MY_LABEL_MONTH_SUFFIX",  "");
       YAHOO.example.calendar.cal1.select("2009/10/1-2009/10/8");
       YAHOO.example.calendar.cal1.cfg.setProperty("PAGEDATE", "2009/10");
       YAHOO.example.calendar.cal1.render();
   }
   YAHOO.util.Event.onDOMReady(YAHOO.example.calendar.init);

</script>

</body> </html>


 </source>
   
  

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


Calendar Menu Button with Date on Button Face

   <source lang="html4strict">


<!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>


<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>

</head> <body class=" yui-skin-sam">

Calendar Menu Button with Date on Button Face

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.

<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>
         <label for="firstname">First Name: </label>
         <input type="text" id="firstname" name="firstname" value="">
         <label for="lastname">Last Name: </label>
         <input type="text" id="lastname" name="lastname" value="">
         <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="">
     <input type="submit" id="submit-button" name="submit-button" value="Submit Form">
   </fieldset>

</form>

</body> </html>


 </source>
   
  

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


Calendar range: Minimum/Maximum Dates

   <source lang="html4strict">


<!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>Minimum/Maximum Dates</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" /> <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>

</head> <body class=" yui-skin-sam">

Minimum/Maximum Dates

Calendar can be easily configured to prevent users from being able to select dates before and after given minimum and maximum dates. This example specifies both a minimum and maximum date, but you can also specify just one of the two, if you only want to limit the range on one end.

<script type="text/javascript">

 YAHOO.namespace("example.calendar");
 YAHOO.example.calendar.init = function() {
   YAHOO.example.calendar.cal1 = new YAHOO.widget.Calendar("cal1","cal1Container", 
                               { pagedate : "1/2009",
                                 mindate: "1/5/2009",
                                 maxdate: "1/15/2009" }
                               );
   YAHOO.example.calendar.cal1.render();
 }
 YAHOO.util.Event.onDOMReady(YAHOO.example.calendar.init);

</script>

</body> </html>


 </source>
   
  

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


Enable/configure Calendar Navigator and jump to a specific year/month without scrolling through months sequentially.

   <source lang="html4strict">


<!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 Navigator</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" /> <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>


<style type="text/css">

 #cal2Container { clear:left;margin-top:10px }

</style>

</head> <body class=" yui-skin-sam">

Calendar Navigator

This example shows you how to enable and configure the Calendar Navigator, which will allow users to quickly jump to a specific year/month without having to scroll through months sequentially.

<script type="text/javascript">

   YAHOO.namespace("example.calendar");
   YAHOO.example.calendar.init = function() {
       // Enable navigator with the default configuration
       YAHOO.example.calendar.cal1 = new YAHOO.widget.CalendarGroup("cal1Container", {navigator:true});
       YAHOO.example.calendar.cal1.render();
       
       // Enable navigator with a custom configuration
       var navConfig = {
           strings : {
               month: "Choose Month",
               year: "Enter Year",
               submit: "OK",
               cancel: "Cancel",
               invalidYear: "Please enter a valid year"
           },
           monthFormat: YAHOO.widget.Calendar.SHORT,
           initialFocus: "year"
       };
       YAHOO.example.calendar.cal2 = new YAHOO.widget.Calendar("cal2Container", {navigator: navConfig});
       YAHOO.example.calendar.cal2.render();
   }
   YAHOO.util.Event.onDOMReady(YAHOO.example.calendar.init);

</script>

</body> </html>


 </source>
   
  

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


Handling Calendar Events

   <source lang="html4strict">

<!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>Handling Calendar Events</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" /> <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>


<style type="text/css">

 #cal1Container {
    margin:1em;
 }
 #caleventlog {
   float:left;
   width:35em;
   margin:1em;
   background-color:#eee;
   border:1px solid #000;
 }
 #caleventlog .bd {
   overflow:auto;
   height:20em;
   padding:5px;
 }
 #caleventlog .hd {
   background-color:#aaa;
   border-bottom:1px solid #000;
   font-weight:bold;
   padding:2px;
 }
 #caleventlog .entry {
   margin:0;  
 }

</style>

</head> <body class=" yui-skin-sam">

Handling Calendar Events

The Calendar control exposes a number of CustomEvents, so that applications can listen for and react to interesting moments in the Calendar"s operation. This example demonstrates how to listen for the select and deselect events, which are fired whenever a date in the Calendar is selected or deselected.

<script type="text/javascript">

 YAHOO.namespace("example.calendar");
 YAHOO.example.calendar.init = function() {
   var eLog = YAHOO.util.Dom.get("evtentries");
   var eCount = 1;
   function logEvent(msg) {
eLog.innerHTML = "
<strong>" + eCount + ").</strong> " + msg + "
" + eLog.innerHTML;
     eCount++;
   }
   function dateToLocaleString(dt, cal) {
                 var wStr = cal.cfg.getProperty("WEEKDAYS_LONG")[dt.getDay()];
                 var dStr = dt.getDate();
                 var mStr = cal.cfg.getProperty("MONTHS_LONG")[dt.getMonth()];
                   var yStr = dt.getFullYear();
                 return (wStr + ", " + dStr + " " + mStr + " " + yStr);
   }
   function mySelectHandler(type,args,obj) {
     var selected = args[0];
     var selDate = this.toDate(selected[0]);
      
     logEvent("SELECTED: " + dateToLocaleString(selDate, this));
   };
   function myDeselectHandler(type, args, obj) {
     var deselected = args[0];
     var deselDate = this.toDate(deselected[0]);
     logEvent("DESELECTED: " + dateToLocaleString(deselDate, this));
   };
   YAHOO.example.calendar.cal1 = new YAHOO.widget.Calendar("cal1","cal1Container");
   YAHOO.example.calendar.cal1.selectEvent.subscribe(mySelectHandler, YAHOO.example.calendar.cal1, true);
   YAHOO.example.calendar.cal1.deselectEvent.subscribe(myDeselectHandler, YAHOO.example.calendar.cal1, true);
   YAHOO.example.calendar.cal1.render();
 }
 YAHOO.util.Event.onDOMReady(YAHOO.example.calendar.init);

</script>

Select/Deselect Events

</body> </html>


 </source>
   
  

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


Interval Selection Calendar

   <source lang="html4strict">

<!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>Interval Selection Calendar</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" /> <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>


<style type="text/css">

   #dates {
       float:left;
       border: 1px solid #000;
       background-color: #ccc;
       padding:10px;
       margin:10px;
   }
   #dates p {
       clear:both;
   }
   #dates label {
       float:left;
       display:block;
       width:7em;
       font-weight:bold;
   }

</style>

</head> <body class=" yui-skin-sam">

   

Interval Selection Calendar

The Calendar widget is commonly used to select pairs of dates, representing the start and end dates of an interval, for example flight departure and return dates, or hotel check-in and check-out dates.

This example defines a custom IntervalCalendar class, based on CalendarGroup, which is designed specifically for this use case.

<label for="in">Check In:</label><input type="text" name="in" id="in">

<label for="out">Check Out:</label><input type="text" name="out" id="out">

<script type="text/javascript"> (function() {

   /**
   * IntervalCalendar is an extension of the CalendarGroup designed specifically
   * for the selection of an interval of dates.
   *
   * @namespace YAHOO.example.calendar
   * @module calendar
   * @since 2.5.2
   * @requires yahoo, dom, event, calendar
   */
   /**
   * IntervalCalendar is an extension of the CalendarGroup designed specifically
   * for the selection of an interval of dates, as opposed to a single date or
   * an arbitrary collection of dates.
*

* Note: When using IntervalCalendar, dates should not be selected or * deselected using the "selected" configuration property or any of the * CalendarGroup select/deselect methods. Doing so will corrupt the internal * state of the control. Instead, use the provided methods setInterval and * resetInterval. *

*

* Similarly, when handling select/deselect/etc. events, do not use the * dates passed in the arguments to attempt to keep track of the currently * selected interval. Instead, use getInterval. *

   *
   * @namespace YAHOO.example.calendar
   * @class IntervalCalendar
   * @extends YAHOO.widget.CalendarGroup
   * @constructor
   * @param {String | HTMLElement} container The id of, or reference to, an HTML DIV element which will contain the control.
   * @param {Object} cfg optional The initial configuration options for the control.
   */
   function IntervalCalendar(container, cfg) {
       /**
       * The interval state, which counts the number of interval endpoints that have
       * been selected (0 to 2).
       * 
       * @private
       * @type Number
       */
       this._iState = 0;
       // Must be a multi-select CalendarGroup
       cfg = cfg || {};
       cfg.multi_select = true;
       // Call parent constructor
       IntervalCalendar.superclass.constructor.call(this, container, cfg);
       // Subscribe internal event handlers
       this.beforeSelectEvent.subscribe(this._intervalOnBeforeSelect, this, true);
       this.selectEvent.subscribe(this._intervalOnSelect, this, true);
       this.beforeDeselectEvent.subscribe(this._intervalOnBeforeDeselect, this, true);
       this.deselectEvent.subscribe(this._intervalOnDeselect, this, true);
   }
   /**
   * Default configuration parameters.
   * 
   * @property IntervalCalendar._DEFAULT_CONFIG
   * @final
   * @static
   * @private
   * @type Object
   */
   IntervalCalendar._DEFAULT_CONFIG = YAHOO.widget.CalendarGroup._DEFAULT_CONFIG;
   YAHOO.lang.extend(IntervalCalendar, YAHOO.widget.CalendarGroup, {
       /**
       * Returns a string representation of a date which takes into account
       * relevant localization settings and is suitable for use with
       * YAHOO.widget.CalendarGroup and YAHOO.widget.Calendar methods.
       * 
       * @method _dateString
       * @private
       * @param {Date} d The JavaScript Date object of which to obtain a string representation.
       * @return {String} The string representation of the JavaScript Date object.
       */
       _dateString : function(d) {
           var a = [];
           a[this.cfg.getProperty(IntervalCalendar._DEFAULT_CONFIG.MDY_MONTH_POSITION.key)-1] = (d.getMonth() + 1);
           a[this.cfg.getProperty(IntervalCalendar._DEFAULT_CONFIG.MDY_DAY_POSITION.key)-1] = d.getDate();
           a[this.cfg.getProperty(IntervalCalendar._DEFAULT_CONFIG.MDY_YEAR_POSITION.key)-1] = d.getFullYear();
           var s = this.cfg.getProperty(IntervalCalendar._DEFAULT_CONFIG.DATE_FIELD_DELIMITER.key);
           return a.join(s);
       },
       /**
       * Given a lower and upper date, returns a string representing the interval
       * of dates between and including them, which takes into account relevant
       * localization settings and is suitable for use with
       * YAHOO.widget.CalendarGroup and YAHOO.widget.Calendar methods.
*

* Note: No internal checking is done to ensure that the lower date * is in fact less than or equal to the upper date. *

       * 
       * @method _dateIntervalString
       * @private
       * @param {Date} l The lower date of the interval, as a JavaScript Date object.
       * @param {Date} u The upper date of the interval, as a JavaScript Date object.
       * @return {String} The string representing the interval of dates between and
       *                   including the lower and upper dates.
       */
       _dateIntervalString : function(l, u) {
           var s = this.cfg.getProperty(IntervalCalendar._DEFAULT_CONFIG.DATE_RANGE_DELIMITER.key);
           return (this._dateString(l)
                   + s + this._dateString(u));
       },
       /**
       * Returns the lower and upper dates of the currently selected interval, if an
       * interval is selected.
       * 
       * @method getInterval
       * @return {Array} An empty array if no interval is selected; otherwise an array
       *                 consisting of two JavaScript Date objects, the first being the
       *                 lower date of the interval and the second being the upper date.
       */
       getInterval : function() {
           // Get selected dates
           var dates = this.getSelectedDates();
           if(dates.length > 0) {
               // Return lower and upper date in array
               var l = dates[0];
               var u = dates[dates.length - 1];
               return [l, u];
           }
           else {
               // No dates selected, return empty array
               return [];
           }
       },
       /**
       * Sets the currently selected interval by specifying the lower and upper
       * dates of the interval (in either order).
*

* Note: The render method must be called after setting the interval * for any changes to be seen. *

       * 
       * @method setInterval
       * @param {Date} d1 A JavaScript Date object.
       * @param {Date} d2 A JavaScript Date object.
       */
       setInterval : function(d1, d2) {
           // Determine lower and upper dates
           var b = (d1 <= d2);
           var l = b ? d1 : d2;
           var u = b ? d2 : d1;
           // Update configuration
           this.cfg.setProperty("selected", this._dateIntervalString(l, u), false);
           this._iState = 2;
       },
       /**
       * Resets the currently selected interval.
*

* Note: The render method must be called after resetting the interval * for any changes to be seen. *

       * 
       * @method resetInterval
       */
       resetInterval : function() {
           // Update configuration
           this.cfg.setProperty("selected", [], false);
           this._iState = 0;
       },
       /**
       * Handles beforeSelect event.
       * 
       * @method _intervalOnBeforeSelect
       * @private
       */
       _intervalOnBeforeSelect : function(t,a,o) {
           // Update interval state
           this._iState = (this._iState + 1) % 3;
           if(this._iState == 0) {
               // If starting over with upcoming selection, first deselect all
               this.deselectAll();
               this._iState++;
           }
       },
       /**
       * Handles selectEvent event.
       * 
       * @method _intervalOnSelect
       * @private
       */
       _intervalOnSelect : function(t,a,o) {
           // Get selected dates
           var dates = this.getSelectedDates();
           if(dates.length > 1) {
               /* If more than one date is selected, ensure that the entire interval
                   between and including them is selected */
               var l = dates[0];
               var u = dates[dates.length - 1];
               this.cfg.setProperty("selected", this._dateIntervalString(l, u), false);
           }
           // Render changes
           this.render();
       },
       /**
       * Handles beforeDeselect event.
       * 
       * @method _intervalOnBeforeDeselect
       * @private
       */
       _intervalOnBeforeDeselect : function(t,a,o) {
           if(this._iState != 0) {
               /* If part of an interval is already selected, then swallow up
                   this event because it is superfluous (see _intervalOnDeselect) */
               return false;
           }
       },
       /**
       * Handles deselectEvent event.
       *
       * @method _intervalOnDeselect
       * @private
       */
       _intervalOnDeselect : function(t,a,o) {
           if(this._iState != 0) {
               // If part of an interval is already selected, then first deselect all
               this._iState = 0;
               this.deselectAll();
               // Get individual date deselected and page containing it
               var d = a[0];
               var date = YAHOO.widget.DateMath.getDate(d[0], d[1] - 1, d[2]);
               var page = this.getCalendarPage(date);
               if(page) {
                   // Now (re)select the individual date
                   page.beforeSelectEvent.fire();
                   this.cfg.setProperty("selected", this._dateString(date), false);
                   page.selectEvent.fire([d]);
               }
               // Swallow up since we called deselectAll above
               return false;
           }
       }
   });
   YAHOO.namespace("example.calendar");
   YAHOO.example.calendar.IntervalCalendar = IntervalCalendar;

})(); YAHOO.util.Event.onDOMReady(function() {

   var inTxt = YAHOO.util.Dom.get("in"),
       outTxt = YAHOO.util.Dom.get("out"),
       inDate, outDate, interval;
   inTxt.value = "";
   outTxt.value = "";
   var cal = new YAHOO.example.calendar.IntervalCalendar("cal1Container", {pages:2});
   cal.selectEvent.subscribe(function() {
       interval = this.getInterval();
       if (interval.length == 2) {
           inDate = interval[0];
           inTxt.value = (inDate.getMonth() + 1) + "/" + inDate.getDate() + "/" + inDate.getFullYear();
           if (interval[0].getTime() != interval[1].getTime()) {
               outDate = interval[1];
               outTxt.value = (outDate.getMonth() + 1) + "/" + outDate.getDate() + "/" + outDate.getFullYear();
           } else {
               outTxt.value = "";
           }
       }
   }, cal, true);
   
   cal.render();

}); </script>

</body> </html>


 </source>
   
  

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


Multi-Select Calendar

   <source lang="html4strict">

<!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>Multi-Select Calendar</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" /> <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>

</head> <body class=" yui-skin-sam">

Multi-Select Calendar

By default the Calendar control is setup for single-select mode, allowing only a single date to be selected at a time. This example shows how you can easily configure the Calendar to support multiple date selections.

<script type="text/javascript">

 YAHOO.namespace("example.calendar");
 YAHOO.example.calendar.init = function() {
   YAHOO.example.calendar.cal1 =
     new YAHOO.widget.Calendar("cal1","cal1Container", { MULTI_SELECT: true } );
   YAHOO.example.calendar.cal1.render();
 }
 YAHOO.util.Event.onDOMReady(YAHOO.example.calendar.init);

</script>

</body> </html>


 </source>
   
  

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


Popup Calendar - Basic

   <source lang="html4strict">


<!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>Popup Calendar - Basic</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" /> <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>


<style type="text/css">

 #examplecontainer {height:450px;  position:relative}
 #show2up { position:absolute; left:5px; top:10px; clear:both}
 #show1up { position:absolute; left:5px; top:300px; clear:both}
 #cal1Container { display:none; position:absolute; left:5px; top:10px; z-index:2}
 #cal2Container { display:none; position:absolute; left:5px; top:300px; z-index:1}

</style>

</head> <body class=" yui-skin-sam">

Popup Calendar - Basic

Calendar can be positioned absolutely to make it float above the document. This example shows how to setup a "Popup" Calendar and uses a couple of configuration properties specifically provided for use when the Calendar is floated above other content.

If you"re familiar with the YUI Container family, it"s worth noting that the Calendar does not extend the Overlay control, but provides a couple of similar configuration properties.

   <button id="show2up" type="button">Show CalendarGroup</button>
   <button id="show1up" type="button">Show Calendar</button>

<script type="text/javascript">

 YAHOO.namespace("example.calendar");
 YAHOO.example.calendar.init = function() {
   YAHOO.example.calendar.cal1 = new YAHOO.widget.CalendarGroup("cal1","cal1Container", { pages:2, title:"Please make a selection:", close:true } );
   YAHOO.example.calendar.cal1.render();
   // Listener to show the 2 page Calendar when the button is clicked
   YAHOO.util.Event.addListener("show2up", "click", YAHOO.example.calendar.cal1.show, YAHOO.example.calendar.cal1, true);
   YAHOO.example.calendar.cal2 = new YAHOO.widget.Calendar("cal2","cal2Container", { title:"Choose a date:", close:true } );
   YAHOO.example.calendar.cal2.render();
   // Listener to show the 1-up Calendar when the button is clicked
   YAHOO.util.Event.addListener("show1up", "click", YAHOO.example.calendar.cal2.show, YAHOO.example.calendar.cal2, true);
 }
 YAHOO.util.Event.onDOMReady(YAHOO.example.calendar.init);

</script>

</body> </html>


 </source>
   
  

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


The CalendarGroup control is a specialized version of the Calendar control which allows you to display multiple months (pages) together

   <source lang="html4strict">

<!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>Multi-Page Calendar</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" /> <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>

</head> <body class=" yui-skin-sam">

Multi-Page Calendar

The CalendarGroup control is a specialized version of the Calendar control which allows you to display multiple months (pages) together. This example demonstrates how the set up a CalendarGroup control which displays three months at a time.

The code is very similar to that used to setup a basic Calendar and in general, all of the Calendar examples can be applied to a CalendarGroup also.

<script type="text/javascript">

 YAHOO.namespace("example.calendar");
 YAHOO.example.calendar.init = function() {
   YAHOO.example.calendar.cal1 = new YAHOO.widget.CalendarGroup("cal1","cal1Container", {PAGES:3});
   YAHOO.example.calendar.cal1.render();
 }
 YAHOO.util.Event.onDOMReady(YAHOO.example.calendar.init);

</script>

</body> </html>


 </source>
   
  

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


Walk you through the steps needed to get a default Calendar up and running.

   <source lang="html4strict">

<!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 Tutorial</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" /> <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>

</head> <body class=" yui-skin-sam">

Quickstart Tutorial

This basic example walks you through the steps needed to get a default Calendar up and running. It covers the set of file dependencies which need to be included as well as the basic markup and JS code required to get you started.

<script type="text/javascript">

 YAHOO.namespace("example.calendar");
 YAHOO.example.calendar.init = function() {
   YAHOO.example.calendar.cal1 = new YAHOO.widget.Calendar("cal1","cal1Container");
   YAHOO.example.calendar.cal1.render();
 }
 YAHOO.util.Event.onDOMReady(YAHOO.example.calendar.init);

</script>

</body> </html>


 </source>
   
  

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