5
<title>Example: Simple Calendar with Selection</title>
6
<link rel="stylesheet" href="http://yui.yahooapis.com/3.4.0pr3/build/cssgrids/grids-min.css">
7
<link rel="stylesheet" href="../assets/css/main.css">
8
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
9
<script src="../../build/yui/yui-min.js"></script>
14
<h1>Example: Simple Calendar with Selection</h1>
19
<div id="main" class="yui3-u">
20
<div class="content"><style>
40
This example demonstrates how to instantiate a simple Calendar, with an initial date setting of September 2011. The Calendar is preconfigured to show the previous and next month's dates.
44
Try clicking on the toggle buttons to change the initial settings for showing the previous and next months' dates. You can also select dates in the calendar and see selected date on the right, reported via a <code>selectionChange</code> event, and formatted using DataType utility.
48
<div class="example yui3-skin-sam">
49
<!-- Load the YUI CSSButton CSS file from gallery to create simple and quick buttons -->
50
<link href="http://yui.yahooapis.com/gallery-2011.08.31-20-57/build/gallerycss-cssbutton/gallerycss-cssbutton.css" type="text/css" rel="stylesheet" />
52
<!-- Add an additional blue button style -->
54
.yui3-skin-sam .yui3-button-color-blue {
56
background-image: -webkit-gradient(linear, left top, left bottom, from(#599bdc), to(#3476b7));
57
background-image: -webkit-linear-gradient(top, #599bdc, #3476b7);
58
background-image: -moz-linear-gradient(top, #599bdc, #3476b7);
59
background-image: -ms-linear-gradient(top, #599bdc, #3476b7);
60
background-image: -o-linear-gradient(top, #599bdc, #3476b7);
61
background-image: linear-gradient(top, #599bdc, #3476b7);
62
filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#599bdc', EndColorStr='#3476b7');
63
background-color: #3476b7;
67
<div id="demo" class="yui3-skin-sam yui3-g">
68
<div id="leftcolumn" class="yui3-u">
69
<!-- Container for the calendar -->
70
<div id="mycalendar"></div>
72
<div id="rightcolumn" class="yui3-u">
73
<div id="links" style="padding-left:20px;">
74
<!-- The buttons are created simply by assigning the correct CSS class -->
75
<div id="togglePrevMonth" class="yui3-button yui3-button-color-blue">Toggle Previous Month's Dates</div><br>
76
<div id="toggleNextMonth" class="yui3-button yui3-button-color-blue">Toggle Next Month's Dates</div><br>
77
Selected date: <span id="selecteddate"></span>
82
<script type="text/javascript">
83
YUI().use('calendar', 'datatype-date', function(Y) {
85
// Create a new instance of calendar, placing it in
86
// #mycalendar container, setting its width to 340px,
87
// the flags for showing previous and next month's
88
// dates in available empty cells to true, and setting
89
// the date to August 2011.
90
var calendar = new Y.Calendar({
91
contentBox: "#mycalendar",
95
date: new Date(2011, 07, 01)}).render();
97
// Get a reference to Y.DataType.Date
98
var dtdate = Y.DataType.Date;
100
// Listen to calendar's selectionChange event.
101
calendar.on("selectionChange", function (ev) {
103
// Get the date from the list of selected
104
// dates returned with the event (since only
105
// single selection is enabled by default,
106
// we expect there to be only one date)
107
var newDate = ev.newSelection[0];
109
// Format the date and output it to a DOM
111
Y.one("#selecteddate").setContent(dtdate.format(newDate));
115
// When the 'Show Previous Month' link is clicked,
116
// modify the showPrevMonth property to show or hide
117
// previous month's dates
118
Y.one("#togglePrevMonth").on('click', function (ev) {
120
calendar.set('showPrevMonth', !(calendar.get("showPrevMonth")));
123
// When the 'Show Next Month' link is clicked,
124
// modify the showNextMonth property to show or hide
125
// next month's dates
126
Y.one("#toggleNextMonth").on('click', function (ev) {
128
calendar.set('showNextMonth', !(calendar.get("showNextMonth")));
135
<h2>Complete Example Source</h2>
137
<pre class="code prettyprint"><!-- Load the YUI CSSButton CSS file from gallery to create simple and quick buttons -->
138
<link href="http://yui.yahooapis.com/gallery-2011.08.31-20-57/build/gallerycss-cssbutton/gallerycss-cssbutton.css" type="text/css" rel="stylesheet" />
140
<!-- Add an additional blue button style -->
142
.yui3-skin-sam .yui3-button-color-blue {
144
background-image: -webkit-gradient(linear, left top, left bottom, from(#599bdc), to(#3476b7));
145
background-image: -webkit-linear-gradient(top, #599bdc, #3476b7);
146
background-image: -moz-linear-gradient(top, #599bdc, #3476b7);
147
background-image: -ms-linear-gradient(top, #599bdc, #3476b7);
148
background-image: -o-linear-gradient(top, #599bdc, #3476b7);
149
background-image: linear-gradient(top, #599bdc, #3476b7);
150
filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#599bdc', EndColorStr='#3476b7');
151
background-color: #3476b7;
155
<div id="demo" class="yui3-skin-sam yui3-g">
156
<div id="leftcolumn" class="yui3-u">
157
<!-- Container for the calendar -->
158
<div id="mycalendar"></div>
160
<div id="rightcolumn" class="yui3-u">
161
<div id="links" style="padding-left:20px;">
162
<!-- The buttons are created simply by assigning the correct CSS class -->
163
<div id="togglePrevMonth" class="yui3-button yui3-button-color-blue">Toggle Previous Month's Dates</div><br>
164
<div id="toggleNextMonth" class="yui3-button yui3-button-color-blue">Toggle Next Month's Dates</div><br>
165
Selected date: <span id="selecteddate"></span>
170
<script type="text/javascript">
171
YUI().use('calendar', 'datatype-date', function(Y) {
173
// Create a new instance of calendar, placing it in
174
// #mycalendar container, setting its width to 340px,
175
// the flags for showing previous and next month's
176
// dates in available empty cells to true, and setting
177
// the date to August 2011.
178
var calendar = new Y.Calendar({
179
contentBox: "#mycalendar",
180
width:'340px',
183
date: new Date(2011, 07, 01)}).render();
185
// Get a reference to Y.DataType.Date
186
var dtdate = Y.DataType.Date;
188
// Listen to calendar's selectionChange event.
189
calendar.on("selectionChange", function (ev) {
191
// Get the date from the list of selected
192
// dates returned with the event (since only
193
// single selection is enabled by default,
194
// we expect there to be only one date)
195
var newDate = ev.newSelection[0];
197
// Format the date and output it to a DOM
198
// element.
199
Y.one("#selecteddate").setContent(dtdate.format(newDate));
203
// When the 'Show Previous Month' link is clicked,
204
// modify the showPrevMonth property to show or hide
205
// previous month's dates
206
Y.one("#togglePrevMonth").on('click', function (ev) {
208
calendar.set('showPrevMonth', !(calendar.get("showPrevMonth")));
211
// When the 'Show Next Month' link is clicked,
212
// modify the showNextMonth property to show or hide
213
// next month's dates
214
Y.one("#toggleNextMonth").on('click', function (ev) {
216
calendar.set('showNextMonth', !(calendar.get("showNextMonth")));
219
</script></pre>
224
<div id="sidebar" class="yui3-u">
228
<div class="sidebox">
230
<h2 class="no-toc">Examples</h2>
234
<ul class="examples">
237
<li data-description="How to create a single-pane calendar with selectable dates">
238
<a href="calendar-simple.html">Simple Calendar with Selection</a>
243
<li data-description="How to create a multi-pane calendar with custom-rendered cells and multiple date selection.">
244
<a href="calendar-multipane.html">Two-Pane Calendar with Custom Rendering and Multiple Selection</a>
258
<script src="../assets/vendor/prettify/prettify-min.js"></script>
259
<script>prettyPrint();</script>