Yahoo! UI Library: Calendar
The Calendar component is a UI control that enables users to choose one or more dates from a graphical calendar presented in a one- or two-up view. The calendar generated by this control is completely client-side and can be navigated without any page refreshes.
ã«ã¬ã³ãã¼ã®ã©ã¤ãã©ãª
Calendarã³ã³ãã¼ãã³ãã¯ã°ã©ãã£ã«ã«ãªã«ã¬ã³ãã¼ããæ¥ä»ãããã¯ã¢ããã§ããUIã³ã³ããã¼ã«ã§ããã«ã¬ã³ãã¼ã¯ã¯ã©ã¤ã¢ã³ããµã¤ãã§å®çµããããã«ã¤ãããããã¼ã¸é·ç§»ããã«ããåãã§ãã¾ãã
Documentation
API Documentation: Reference documentation for each of the methods, properties, and parameters defined by this component.
ã¡ã½ããããã©ã¡ã¼ã¿ãçã ã®è©³ãããã¨ã¯APIããã¥ã¡ã³ããåç §ãã¦ãã ãã
Getting Started
ã³ã³ãã¼ãã³ãéã®ä¾åæ§ã«æ³¨æãã¦ãã ããã
<!-- Namespace source file --> <script src = "http://yourwebsite.com/util/YAHOO.js" ></script> <!-- Dependency source files --> <script src = "http://yourwebsite.com/util/dom.js" ></script> <script src = "http://yourwebsite.com/util/event.js" ></script> <!-- Calendar source file --> <script src = "http://yourwebsite.com/widget/calendar.js" ></script>Calendarãªãã¸ã§ã¯ãã¯YAHOO.widget.Calendar. ã§å®ç¾©ããã¾ãã
For a simple single-select calendar implementation, include a placeholder block that represents the area where the calendar will be rendered on the page:
<div id="cal1Container"></div>HTMLã¨CSSæºåã®åºæ¬
æ¥ä»ãä¸ã¤ã ãé¸æã§ããã«ã¬ã³ãã¼ã使ã£ã¦ã¿ã¾ããã«ã¬ã³ãã¼ãæç»ã§ããããã«ãããã¯è¦ç´ ã®é åãè¨ãã¦ãã ããã
Initializing the Calendar
Create a calendar by instantiating Calendar with the ID of the element where component is to be inserted on the page.
var cal1; function init() { cal1 = new YAHOO.widget.Calendar("cal1","cal1Container"); cal1.render(); }By default, the calendar is set to the current month, and enables a single selection to be made. In addition to the id, the calendar can accept two additional parameters -- the default month and year to display and the date(s) to select. The full constructor is defined as follows:
YAHOO.widget.Calendar(String id, String containerId, String monthyear, String selected)Where:
- id is the ID that should be assigned to the calendar component table element
- containerId is the id of the HTML element where the calendar will be inserted
- monthyear is the month/year string used to set the current calendar page
- selected is a string of date values formatted using the date parser.
The built-in default date format is MM/DD/YYYY. Ranges are defined using MM/DD/YYYY-MM/DD/YYYY. Month/day combinations are defined using MM/DD. Any combination of these can be combined by delimiting the string with commas. For example: "12/24/2005,12/25,1/18/2006-1/21/2006"
The basic 1-up calendar looks like this:
ã«ã¬ã³ãã¼ã®åæå
ã«ã¬ã³ãã¼ãä½ãã«ã¯è¦ç´ IDãã¤ãã£ã¦åæåãã¾ããè¦ç´ IDã¯ã³ã³ãã¼ãã³ããæ¿å ¥ããè¦ç´ ããã¨ãã¾ãã
//åæåé¢æ° var cal1; function init() { cal1 = new YAHOO.widget.Calendar("cal1","cal1Container"); cal1.render(); }åæè¨å®ã§ã«ã¬ã³ãã¼ã«ã¯ç¾æç¹ã§ã®æãã»ãããããã¾ããã¾ããæ¥ã«ã¡ãä¸ã¤ã ãé¸æã§ããã«ã¬ã³ãã¼ã«ãªã£ã¦ãã¾ããè¦ç´ IDã«å ãã¦ãï¼ã¤ã®è¿½å ãã©ã¡ã¼ã¿ã¼ã渡ãã¾ãã
â 表示ããå¹´ã»æ
â¡é¸æã§ãããæ¥ï¼
ã³ã³ã¹ãã©ã¯ã¿ã§å ¨é¨å®ç¾©ããã¨ãããªé¢¨ã«ãªãã¾ã//ãã©ã¡ã¼ã¿ã¯å ¨ã¦æåå㧠YAHOO.widget.Calendar(id, containerId, monthyear, selected)è£è¶³:
- idã¯ã«ã¬ã³ãã¼ã³ã³ãã¼ãã³ããã»ãããããã¼ãã«è¦ç´ ã®ID
- containerIDã¯ã«ã¬ã³ãã¼ãæ¿å ¥ããHTMLè¦ç´ ã®ID
- monthyer㯠ã«ã¬ã³ãã¼ã«ã»ããããããæãã¨ãå¹´ãã®æååã§ãã
- selected ã¯date parser ã使ã£ã¦ãã©ã¼ãããããããæ¥ãã®æååã§ãã
çµã¿è¾¼ã¿ã®æ¥ä»ãã©ã¼ãããã¯ã MM/DD/YYYY (æ/æ¥/å¹´)ã§ããæ¥ä»ã®ç¯å²ãæå®ããéã¯MM/DD/YYYY-MM/DD/YYYYãã¨æ¸ãã¾ã( '-' ãã¤ãã³ã«æ³¨æ) æ/æ¥ãã®ã»ããã¯ãMM/DDã§å®ç¾©ãã¾ããã³ã³ãã§åºåããå ¥ããã°ãã©ããªçµã¿åãããå¯è½ã§ãã
For example: "12/24/2005,12/25,1/18/2006-1/21/2006"
åºæ¬ã¨ãªãã1-upãã«ã¬ã³ãã¼ã¯ãã®ããã«ãªãã¾ãã
ï¼1-upã¯ä¸åã ãé¸æã§ããã«ã¬ã³ãã¼ã®ãã¨ã§ãããæ®æ©ãå¢ããããã³ã®ãã¨ã§ã¯ããã¾ãã・・・ï¼
Using Calendar
This section describes customizations to the Calendar component.
- Creating a 2-Up Calendar View
- Creating International Calendars
- Customizing the Calendar
- Customizing Events
ã«ã¬ã³ãã¼ã使ã
ãã®ã»ã¯ã·ã§ã³ã§ã¯ãCalendarã³ã³ãã¼ãã³ãã®ã«ã¹ã¿ãã¤ãºã®ä»æ¹ãè¼ãã¦ãã¾ã
- 2upã«ã¬ã³ãã¼ãã¤ãã
- å½éä»æ§ã®ã«ã¬ã³ãã¼ãã¤ãã
- ã«ã¬ã³ãã¼ã®ã«ã¹ã¿ãã¤ãº
- ã¤ãã³ãã®ã«ã¹ã¿ãã¤ãº
Creating a 2-Up Calendar View
Creating a 2-page calendar is as simple as modifying the markup and the class that is used. The container ID should be set into the container, and the Calendar2up class will handle the rest.
<div id="container1"></div>The constructor for Calendar2up is almost identical to the constructor for Calendar:
YAHOO.widget.Calendar(String id, String containerId, String monthyear, String selected)
The 2-up calendar looks like this:
2upã«ã¬ã³ãã¼ãä½ã
ï¼ãã¼ã¸ä»æ§ã®ã«ã¬ã³ãã¼ãä½ãä½æ¥ã¯ãHTMLã¨ã¯ã©ã¹ãã¡ãã£ã¨ãããç¨åº¦ã§ããcontainerIdãã³ã³ããã¨ãªãè¦ç´ ã«ã»ãããã¦ããå¿ è¦ãããã¾ããã®ããã®ä½æ¥ã¯Calendar2upã¯ã©ã¹ããã£ã¨ãã¦ããã¾ãã
<div id="container1"></div>Calendar2upã¯ã©ã¹ã®ã³ã³ã¹ãã©ã¯ã¿ã¯ãCalendarã¯ã©ã¹ã®ã³ã³ã¹ãã©ã¯ã¿ã¨ã»ã¼ä¸ç·ã§ãã
YAHOO.widget.Calendar(id, String containerId,monthyear,selected) ï¼å¼æ°ã¯å ¨ã¦æååã§çµæã¯ãããªæãã«ãªãã¾ãã
Creating International Calendars
The Calendar component has built in support for internationalization. To modify the locale, simply implement the Calendar's customConfig method to override the default Config.Locale object. The following code example produces a calendar in German:
var cal1 = new YAHOO.widget.Calendar("cal1","cal1Container"); cal1.prototype.customConfig = function(){ this.Config.Locale.MONTHS_SHORT = ["Jan", "Feb", "M䲦quot;, "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"]; this.Config.Locale.MONTHS_LONG = ["Januar", "Februar", "M䲺", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"]; this.Config.Locale.WEEKDAYS_1CHAR = ["S", "M", "D", "M", "D", "F", "S"]; this.Config.Locale.WEEKDAYS_SHORT = ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"]; this.Config.Locale.WEEKDAYS_MEDIUM = ["Son", "Mon", "Die", "Mit", "Don", "Fre", "Sam"]; this.Config.Locale.WEEKDAYS_LONG =["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"]; this.Config.Options.START_MONDAY = true; }See functional examples of German and Japanese calendars under Examples
å½éä»æ§ã®ã«ã¬ã³ãã¼ãä½ã
Calendarã³ã³ãã¼ãã³ãã¯å½éä»æ§ããµãã¼ããã¾ãããã±ã¼ã«(å°å)ãå¤ããã«ã¯ãcustomConfig()ã¡ã½ããã使ã£ã¦ããã©ã«ãã®Config.Localeãªãã¸ã§ã¯ãããªã¼ãã¼ã©ã¤ãããã ãã§ãããµã³ãã«ã®ã³ã¼ãã¯ãã¤ãä»æ§ã®ã«ã¬ã³ãã¼ã«ãªãã¾ãã
//ã³ã³ã¹ãã©ã¯ã¿ã®å¼ã³åºã var cal1 = new YAHOO.widget.Calendar("cal1","cal1Container"); cal1.prototype.customConfig = function(){ this.Config.Locale.MONTHS_SHORT = ["Jan", "Feb", "M䲦quot;, "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"]; this.Config.Locale.MONTHS_LONG = ["Januar", "Februar", "M䲺", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"]; this.Config.Locale.WEEKDAYS_1CHAR = ["S", "M", "D", "M", "D", "F", "S"]; this.Config.Locale.WEEKDAYS_SHORT = ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"]; this.Config.Locale.WEEKDAYS_MEDIUM = ["Son", "Mon", "Die", "Mit", "Don", "Fre", "Sam"]; this.Config.Locale.WEEKDAYS_LONG =["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"]; this.Config.Options.START_MONDAY = true; } ï¼customConfig()ããããããã£ãä»£å ¥ããå¼å ¨ä½ãè¦ã£ã¦ãããã¨ã«æ°ãã¤ãã¦ãã ãã ï¼ä¸é¨æååãã¢ãª
Customizing the Calendar
The behavior and appearance of the calendar can be customized by overriding the Calendar components events and rendering methods. The primary way to specify rendering behavior for a date or group of dates is by using the addRenderer method. The addRenderer method takes two parameters:
- sDates - The date string to change the style/behavior for. This string is specified in the same way as the string used in the constructor (e.g., "12/24/2005,12/25,1/18/2006-1/21/2006").
- fnRender - The function to execute on the active cell. More details below.
Render functions take two arguments: the date object representing the current calendar cell and the calendar cell itself. For example, the default method that renders a selectable cell looks like this:
renderCellDefault = function(workingDate, cell) { cell.innerHTML = ""; var link = document.createElement("a"); link.href="javascript:void(null);" link.name=this.id+"__"+cal.getFullYear()+"_"+(cal.getMonth()+1)+"_"+cal.getDate(); link.onclick = this._selectEvent; link.appendChild(document.createTextNode(this.buildDayLabel(workingDate))); cell.appendChild(link); }Note that the above method sets the contents of the cell, along with the behavior of the cell. Render methods can also simply set the style of a particular date cell that already has had its contents set:
renderCellNotThisMonth = function(workingDate, cell) { Calendar.setCssClasses(cell, [this.Config.Style.CSS_CELL,this.Config.Style.CSS_CELL_BLANK]); cell.innerHTML=workingDate.getDate(); return true; }
This example renders a cell that is outside of the scope of the current month. Note that it returns a value of Calendar.STOP_RENDER, which means that if this rule is processed, no more rules should be processed afterwards.
Render rules are processed in a LIFO (stack) method, where the last renderer added will be the first processed.
ã«ã¬ã³ãã¼ã®ã«ã¹ã¿ãã¤ãº
ã«ã¬ã³ãã¼ã®è¦ãæ¹ã¯Calendarã³ã³ãã¼ãã³ãã»ã¤ãã³ãã¨æç»ã¡ã½ããããªã¼ãã¼ã©ã¤ããããã¨ã§ã«ã¹ã¿ãã¤ãºã§ãã¾ãããæ¥ãã®è¦ãæ¹ãå¤ããã®ã§ããã°ãaddRenderer()ã¡ã½ããã使ãã®ã主è¦ãªããæ¹ã§ããaddRenderer()ã¡ã½ããã¯ï¼ã¤ãã©ã¡ã¼ã¿ãã¨ãã¾ãã
- sDates - ã¹ã¿ã¤ã«ãæ¯ãèããå¤ããã®ãæ¥ãã®æååããã®æååã¯ãã³ã³ã¹ãã©ã¯ã¿ã§æååãæ±ãããã«æå®ãã¾ãã
(e.g., "12/24/2005,12/25,1/18/2006-1/21/2006").
- fnRender() -ã¢ã¯ãã£ããªã»ã«ä¸ã§å¼ã³åºãããé¢æ°ã§ãã詳細ã¯ä¸è¨ã
Renderé¢æ°ã¯ãï¼ã¤ã®å¼æ°ãã¨ãã¾ãã
ã«ã¬ã³ãã¼ã»ã«ãããããæ¥ä»ãªãã¸ã§ã¯ãã¨ã«ã¬ã³ãã¼ã®ã»ã«ãã®ãã®ã§ããããã©ã«ãã®ã¡ã½ããã¯ãé¸æå¯è½ãªã»ã«ããããªé¢¨ã«æç»ãã¾ããrenderCellDefault = function(workingDate, cell) { cell.innerHTML = ""; var link = document.createElement("a"); link.href="javascript:void(null);" link.name=this.id+"__"+cal.getFullYear()+"_"+(cal.getMonth()+1)+"_"+cal.getDate(); link.onclick = this._selectEvent; link.appendChild(document.createTextNode(this.buildDayLabel(workingDate))); cell.appendChild(link); }ä¸è¨ã®ã¡ã½ããã¯ãã»ã«å ã®ã³ã³ãã³ããã»ããããã¾ãã»ã«ã®æ¯ãèãï¼è¦ãæ¹ï¼ï¼ã«å¾ããã¨ãé ã«å ¥ãã¦ããã¦ãã ãããRender()ã¡ã½ããã使ãã¨ããã§ã«ã³ã³ãã³ãã®ã»ãããå¾ãã¦ããæ¥ä»ã»ã«ã®ã¹ã¿ã¤ã«ãç°¡åã«å¤ãããã¨ãåºæ¥ã¾ãã
renderCellNotThisMonth = function(workingDate, cell) { Calendar.setCssClasses(cell, [this.Config.Style.CSS_CELL,this.Config.Style.CSS_CELL_BLANK]); cell.innerHTML=workingDate.getDate(); return true; }
ãã®ãµã³ãã«ã§ã¯ãç¾å¨ã®æã®ã¹ã³ã¼ãå¤ã®ã»ã«ãæ¸ãã¦ãã¾ããCalendar.STOP_RENDERãæ»ãå¤ã¨ãã¦è¿ããã¨ãè¦ãã¦ããã¦ãã ããããããã®å½ä»¤ãå¦çãããã¨ããã®å¾ã®å¦å½ä»¤ã®å¦çãä¸åãããªãã¨ãããã¨ã§ãã
æç»ã®å½ä»¤ã¯ãLIFO()メソッド[stack]ã§å¦çããã¾ããæå¾ã«ä»ãå ããå½ä»¤ããä¸çªæåã«å¦çããã¾ãã
Customizing Events
The calendar also has several events (see API documentation) that can be customized to alter the calendar's behavior. One such example is the onBeforeSelect event, which by default clears all other selections when a selection is made. By overriding this event (as in the example linked below) a multi-select calendar implementation can be easily created.
ã¤ãã³ãã®ã«ã¹ã¿ãã¤ãº
Calendarã¯ã©ã¹ã«ã¯ãã«ã¬ã³ãã¼ã®æ¯ãèããå¤ãããããããªã¤ãã³ããããã¾ããï¼APIããã¥ã¡ã³ããåç §ãã¦ãã ããï¼ãã®ä¸ã¤ãã¦ãonBeforeSelectã¤ãã³ããããã¾ããï¼ããã¯ãã«ã¬ã³ãã¼ãé¸æããæãä»ã®é¸æãåæå¤ã¸ã¨ã¯ãªã¢ãã¾ããï¼ãã®ã¤ãã³ãããªã¼ãã¼ã©ã¤ããããã¨ã§ãè¤æ°ã®æ¥ä»ãé¸æå¯è½ãªã«ã¬ã³ãã¼ãç°¡åã«ä½ãåºãã¾ãã