|
8 | 8 | <link rel="stylesheet" href="../demos.css">
|
9 | 9 | <script src="../../external/requirejs/require.js"></script>
|
10 | 10 | <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 | + } |
14 | 75 | });
|
| 76 | + |
| 77 | + $( "#calendar" ).calendar(); |
15 | 78 | </script>
|
16 | 79 | </head>
|
17 | 80 | <body>
|
18 | 81 |
|
19 | 82 | <div id="calendar"></div>
|
20 | 83 |
|
21 | 84 | <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> |
23 | 86 | </div>
|
24 | 87 | </body>
|
25 | 88 | </html>
|
0 commit comments