Skip to content

Commit c1cb6e3

Browse files
committed
Calendar: Use widget extension to render year and month select
1 parent 7ef7f3a commit c1cb6e3

File tree

1 file changed

+67
-4
lines changed

1 file changed

+67
-4
lines changed

demos/calendar/dropdown-month-year.html

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,81 @@
88
<link rel="stylesheet" href="../demos.css">
99
<script src="../../external/requirejs/require.js"></script>
1010
<script src="../bootstrap.js">
11-
$( "#calendar" ).calendar({
12-
changeMonth: true,
13-
changeYear: true
11+
$.widget( "ui.calendar", $.ui.calendar, {
12+
_buildTitle: function() {
13+
var title = $( "<div>", { role: "alert", id: this.gridId + "-month-label" } ),
14+
month = this._renderMonthSelect(),
15+
year = this._renderYearSelect();
16+
17+
this._addClass( title, "ui-calendar-title" )
18+
._addClass( month, "ui-calendar-month" )
19+
._addClass( year, "ui-calendar-year" );
20+
21+
return title
22+
.append( month )
23+
.append( " " )
24+
.append( year );
25+
},
26+
_renderMonthSelect: function() {
27+
var select = $( "<select>" ),
28+
date = this.date.clone(),
29+
i = 0,
30+
option;
31+
32+
this._on( select, {
33+
change: function() {
34+
this._off( select );
35+
this.date.setFullDate( this.date.year(), select.val(), this.date.day() );
36+
this._updateView();
37+
}
38+
} );
39+
40+
for ( ; i < 12; i++ ) {
41+
date.setFullDate( select.val(), i, this.date.day() );
42+
option = $( "<option>", { val: i, text: date.monthName() } );
43+
if ( this.date.month() === i ) {
44+
option.prop( "selected", true );
45+
}
46+
select.append( option );
47+
}
48+
49+
return select;
50+
},
51+
_renderYearSelect: function() {
52+
var current = new Date(),
53+
select = $( "<select>" ),
54+
i = current.getFullYear(),
55+
option;
56+
57+
this._on( select, {
58+
change: function() {
59+
this._off( select );
60+
this.date.setFullDate( select.val(), this.date.month(), this.date.day() );
61+
this._updateView();
62+
}
63+
} );
64+
65+
for ( ;i <= current.getFullYear() + 10; i++ ) {
66+
option = $( "<option>", { val: i, text: i } );
67+
if ( this.date.year() === i ) {
68+
option.prop( "selected", true );
69+
}
70+
select.append( option );
71+
}
72+
73+
return select;
74+
}
1475
});
76+
77+
$( "#calendar" ).calendar();
1578
</script>
1679
</head>
1780
<body>
1881

1982
<div id="calendar"></div>
2083

2184
<div class="demo-description">
22-
<p>Show month and year dropdowns in place of the static month/year header to facilitate navigation through large timeframes. Add the boolean <code>changeMonth</code> and <code>changeYear</code> options.</p>
85+
<p>Show month and year dropdowns in place of the static month/year header to facilitate navigation through large timeframes.</p>
2386
</div>
2487
</body>
2588
</html>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy