Skip to content

Commit 51fbac0

Browse files
committed
Enable customization for day rendering
1 parent 4de9650 commit 51fbac0

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

datepicker-rewrite/date.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,15 @@ $.date = function ( datestring, formatstring ) {
7171
var week = result[ result.length ] = {
7272
days: []
7373
};
74-
for ( var day = 0; day < 7; day++ ) {
75-
week.days.push( {
74+
for ( var dayx = 0; dayx < 7; dayx++ ) {
75+
var day = week.days[ week.days.length ] = {
7676
lead: printDate.getMonth() != date.getMonth(),
7777
date: printDate.getDate(),
7878
current: this.selected && this.selected.equal( printDate ),
7979
today: today.equal( printDate )
80-
});
80+
};
81+
day.render = day.selectable = !day.lead;
82+
this.eachDay( day );
8183
// TODO use adjust("D", 1)?
8284
printDate.setDate( printDate.getDate() + 1 );
8385
}

datepicker-rewrite/index.html

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@
3636
$( "#datepicker-inline" ).datepicker( {
3737
select: function( event, ui ) {
3838
$( "#inline-output" ).val( ui.date );
39+
},
40+
eachDay: function( day ) {
41+
if ( day.lead && day.date > 20 ) {
42+
day.selectable = false;
43+
day.render = true;
44+
day.title = "These are the days of last month";
45+
day.extraClasses = "ui-state-disabled";
46+
}
47+
if ( day.date == 1 ) {
48+
day.extraClasses = "ui-state-error";
49+
day.title = "Something bad explaining the error highlight";
50+
}
51+
if ( day.today ) {
52+
day.title = "A good day!";
53+
}
3954
}
4055
});
4156
$( "#datepicker, #datepicker2" ).datepicker();
@@ -64,10 +79,17 @@
6479
<tr>
6580
{{each(index, day) week.days}}
6681
<td>
67-
{{if !day.lead}}
68-
<a class="ui-state-default{{if day.current}} ui-state-active{{/if}}{{if day.today}} ui-state-highlight{{/if}}" href="#">
82+
{{if day.render}}
83+
{{if day.selectable}}
84+
<a title="${day.title}" class="ui-state-default{{if day.current}} ui-state-active{{/if}}{{if day.today}} ui-state-highlight{{/if}} ${day.extraClasses}" href="#">
6985
${day.date}
7086
</a>
87+
{{/if}}
88+
{{if !day.selectable}}
89+
<span title="${day.title}" class="{{if day.current}} ui-state-active{{/if}}{{if day.today}} ui-state-highlight{{/if}} ${day.extraClasses}">
90+
${day.date}
91+
</span>
92+
{{/if}}
7193
{{/if}}
7294
</td>
7395
{{/each}}

datepicker-rewrite/picker.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77

88
$.widget( "ui.datepicker", {
99
options: {
10+
eachDay: $.noop
1011
},
1112
_create: function() {
1213
var self = this;
1314
this.date = $.date();
15+
this.date.eachDay = this.options.eachDay;
1416
if ( this.element.is( "input" ) ) {
1517
self._bind( {
1618
click: "open",

0 commit comments

Comments
 (0)